From 61887a7f1c67a46f4441eddf98b999192498522e Mon Sep 17 00:00:00 2001 From: Kohei Watanabe Date: Fri, 18 Oct 2019 21:44:44 +0900 Subject: [PATCH] yarn build --- index.d.ts | 10 +++------- index.js | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/index.d.ts b/index.d.ts index 531c600..b761d8f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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; } export declare class InvalidAccessError extends Error { + constructor(message: string); } export declare class OperationError extends Error { + constructor(message: string); } export declare function requestGPIOAccess(): Promise; export {}; diff --git a/index.js b/index.js index 80f2676..ef4fb1a 100644 --- a/index.js +++ b/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() {