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 {
(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 {};

View file

@ -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() {