This commit is contained in:
Nebel 2019-10-15 20:50:47 +09:00
parent 3c05ccf9ce
commit d79f14234a
2 changed files with 8 additions and 6 deletions

View file

@ -81,7 +81,7 @@ class GPIOPort extends events_1.EventEmitter {
try {
clearInterval(this._timeout);
await fs_1.promises.writeFile(`/sys/class/gpio/export`, parseUint16(this.portNumber.toString()).toString());
await fs_1.promises.writeFile(`/sys/class/gpio/${parseUint16(this.portNumber.toString())}/direction`, direction);
await fs_1.promises.writeFile(`/sys/class/gpio/gpio${parseUint16(this.portNumber.toString())}/direction`, direction);
if (direction === "in") {
this._timeout = setInterval(this.read.bind(this), this._pollingInterval);
}
@ -104,7 +104,7 @@ class GPIOPort extends events_1.EventEmitter {
}
async read() {
try {
const buffer = await fs_1.promises.readFile(`/sys/class/gpio/${parseUint16(this.portNumber.toString())}/value`);
const buffer = await fs_1.promises.readFile(`/sys/class/gpio/gpio${parseUint16(this.portNumber.toString())}/value`);
const value = parseUint16(buffer.toString());
if (this._value !== value) {
this._value = value;
@ -118,7 +118,7 @@ class GPIOPort extends events_1.EventEmitter {
}
async write(value) {
try {
await fs_1.promises.writeFile(`/sys/class/gpio/${parseUint16(this.portNumber.toString())}/value`, parseUint16(value.toString()).toString());
await fs_1.promises.writeFile(`/sys/class/gpio/gpio${parseUint16(this.portNumber.toString())}/value`, parseUint16(value.toString()).toString());
}
catch (error) {
throw new OperationError(error);

View file

@ -134,7 +134,9 @@ export class GPIOPort extends EventEmitter {
parseUint16(this.portNumber.toString()).toString()
);
await fs.writeFile(
`/sys/class/gpio/${parseUint16(this.portNumber.toString())}/direction`,
`/sys/class/gpio/gpio${parseUint16(
this.portNumber.toString()
)}/direction`,
direction
);
if (direction === "in") {
@ -169,7 +171,7 @@ export class GPIOPort extends EventEmitter {
async read() {
try {
const buffer = await fs.readFile(
`/sys/class/gpio/${parseUint16(this.portNumber.toString())}/value`
`/sys/class/gpio/gpio${parseUint16(this.portNumber.toString())}/value`
);
const value = parseUint16(buffer.toString()) as GPIOValue;
@ -188,7 +190,7 @@ export class GPIOPort extends EventEmitter {
async write(value: GPIOValue) {
try {
await fs.writeFile(
`/sys/class/gpio/${parseUint16(this.portNumber.toString())}/value`,
`/sys/class/gpio/gpio${parseUint16(this.portNumber.toString())}/value`,
parseUint16(value.toString()).toString()
);
} catch (error) {