yarn build

This commit is contained in:
Nebel 2019-10-18 21:44:44 +09:00
parent 23038476a6
commit 61887a7f1c
2 changed files with 15 additions and 12 deletions

10
index.d.ts vendored
View file

@ -12,12 +12,6 @@ interface GPIOChangeEvent {
interface GPIOChangeEventHandler { interface GPIOChangeEventHandler {
(event: GPIOChangeEvent): void; (event: GPIOChangeEvent): void;
} }
/**
* Not a specification in Web GPIO API.
*/
interface GPIOPortChangeEventHandler {
(event: GPIOChangeEvent["value"]): void;
}
export declare class GPIOAccess extends EventEmitter { export declare class GPIOAccess extends EventEmitter {
private readonly _ports; private readonly _ports;
onchange: GPIOChangeEventHandler | undefined; onchange: GPIOChangeEventHandler | undefined;
@ -40,7 +34,7 @@ export declare class GPIOPort extends EventEmitter {
private _exported; private _exported;
private _value; private _value;
private _timeout; private _timeout;
onchange: GPIOPortChangeEventHandler | undefined; onchange: GPIOChangeEventHandler | undefined;
constructor(portNumber: PortNumber); constructor(portNumber: PortNumber);
readonly portNumber: PortNumber; readonly portNumber: PortNumber;
readonly portName: PortName; readonly portName: PortName;
@ -53,8 +47,10 @@ export declare class GPIOPort extends EventEmitter {
write(value: GPIOValue): Promise<void>; write(value: GPIOValue): Promise<void>;
} }
export declare class InvalidAccessError extends Error { export declare class InvalidAccessError extends Error {
constructor(message: string);
} }
export declare class OperationError extends Error { export declare class OperationError extends Error {
constructor(message: string);
} }
export declare function requestGPIOAccess(): Promise<GPIOAccess>; export declare function requestGPIOAccess(): Promise<GPIOAccess>;
export {}; export {};

View file

@ -21,8 +21,7 @@ class GPIOAccess extends events_1.EventEmitter {
constructor(ports) { constructor(ports) {
super(); super();
this._ports = ports == null ? new GPIOPortMap() : ports; this._ports = ports == null ? new GPIOPortMap() : ports;
this._ports.forEach(port => port.on("change", value => { this._ports.forEach(port => port.on("change", event => {
const event = { value, port };
this.emit("change", event); this.emit("change", event);
})); }));
this.on("change", (event) => { this.on("change", (event) => {
@ -54,9 +53,9 @@ class GPIOPort extends events_1.EventEmitter {
this._pollingInterval = PollingInterval; this._pollingInterval = PollingInterval;
this._direction = new OperationError("Unknown direction."); this._direction = new OperationError("Unknown direction.");
this._exported = new OperationError("Unknown export."); this._exported = new OperationError("Unknown export.");
this.on("change", (value) => { this.on("change", (event) => {
if (this.onchange !== undefined) if (this.onchange !== undefined)
this.onchange(value); this.onchange(event);
}); });
} }
get portNumber() { get portNumber() {
@ -125,7 +124,7 @@ class GPIOPort extends events_1.EventEmitter {
const value = parseUint16(buffer.toString()); const value = parseUint16(buffer.toString());
if (this._value !== value) { if (this._value !== value) {
this._value = value; this._value = value;
this.emit("change", value); this.emit("change", { value, port: this });
} }
return value; return value;
} }
@ -147,9 +146,17 @@ class GPIOPort extends events_1.EventEmitter {
} }
exports.GPIOPort = GPIOPort; exports.GPIOPort = GPIOPort;
class InvalidAccessError extends Error { class InvalidAccessError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name;
}
} }
exports.InvalidAccessError = InvalidAccessError; exports.InvalidAccessError = InvalidAccessError;
class OperationError extends Error { class OperationError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name;
}
} }
exports.OperationError = OperationError; exports.OperationError = OperationError;
async function requestGPIOAccess() { async function requestGPIOAccess() {