mirror of
https://github.com/chirimen-oh/node-web-gpio.git
synced 2025-01-18 16:08:00 +00:00
yarn build
This commit is contained in:
parent
23038476a6
commit
61887a7f1c
2 changed files with 15 additions and 12 deletions
10
index.d.ts
vendored
10
index.d.ts
vendored
|
@ -12,12 +12,6 @@ interface GPIOChangeEvent {
|
|||
interface GPIOChangeEventHandler {
|
||||
(event: GPIOChangeEvent): void;
|
||||
}
|
||||
/**
|
||||
* Not a specification in Web GPIO API.
|
||||
*/
|
||||
interface GPIOPortChangeEventHandler {
|
||||
(event: GPIOChangeEvent["value"]): void;
|
||||
}
|
||||
export declare class GPIOAccess extends EventEmitter {
|
||||
private readonly _ports;
|
||||
onchange: GPIOChangeEventHandler | undefined;
|
||||
|
@ -40,7 +34,7 @@ export declare class GPIOPort extends EventEmitter {
|
|||
private _exported;
|
||||
private _value;
|
||||
private _timeout;
|
||||
onchange: GPIOPortChangeEventHandler | undefined;
|
||||
onchange: GPIOChangeEventHandler | undefined;
|
||||
constructor(portNumber: PortNumber);
|
||||
readonly portNumber: PortNumber;
|
||||
readonly portName: PortName;
|
||||
|
@ -53,8 +47,10 @@ export declare class GPIOPort extends EventEmitter {
|
|||
write(value: GPIOValue): Promise<void>;
|
||||
}
|
||||
export declare class InvalidAccessError extends Error {
|
||||
constructor(message: string);
|
||||
}
|
||||
export declare class OperationError extends Error {
|
||||
constructor(message: string);
|
||||
}
|
||||
export declare function requestGPIOAccess(): Promise<GPIOAccess>;
|
||||
export {};
|
||||
|
|
17
index.js
17
index.js
|
@ -21,8 +21,7 @@ class GPIOAccess extends events_1.EventEmitter {
|
|||
constructor(ports) {
|
||||
super();
|
||||
this._ports = ports == null ? new GPIOPortMap() : ports;
|
||||
this._ports.forEach(port => port.on("change", value => {
|
||||
const event = { value, port };
|
||||
this._ports.forEach(port => port.on("change", event => {
|
||||
this.emit("change", event);
|
||||
}));
|
||||
this.on("change", (event) => {
|
||||
|
@ -54,9 +53,9 @@ class GPIOPort extends events_1.EventEmitter {
|
|||
this._pollingInterval = PollingInterval;
|
||||
this._direction = new OperationError("Unknown direction.");
|
||||
this._exported = new OperationError("Unknown export.");
|
||||
this.on("change", (value) => {
|
||||
this.on("change", (event) => {
|
||||
if (this.onchange !== undefined)
|
||||
this.onchange(value);
|
||||
this.onchange(event);
|
||||
});
|
||||
}
|
||||
get portNumber() {
|
||||
|
@ -125,7 +124,7 @@ class GPIOPort extends events_1.EventEmitter {
|
|||
const value = parseUint16(buffer.toString());
|
||||
if (this._value !== value) {
|
||||
this._value = value;
|
||||
this.emit("change", value);
|
||||
this.emit("change", { value, port: this });
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
@ -147,9 +146,17 @@ class GPIOPort extends events_1.EventEmitter {
|
|||
}
|
||||
exports.GPIOPort = GPIOPort;
|
||||
class InvalidAccessError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = this.constructor.name;
|
||||
}
|
||||
}
|
||||
exports.InvalidAccessError = InvalidAccessError;
|
||||
class OperationError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = this.constructor.name;
|
||||
}
|
||||
}
|
||||
exports.OperationError = OperationError;
|
||||
async function requestGPIOAccess() {
|
||||
|
|
Loading…
Add table
Reference in a new issue