mirror of
https://github.com/chirimen-oh/node-web-gpio.git
synced 2025-01-18 16:08:00 +00:00
use correct offset for GPIO0
https://github.com/raspberrypi/linux/issues/6037
This commit is contained in:
parent
8ce22e2be1
commit
cd50093ae2
1 changed files with 14 additions and 4 deletions
18
index.ts
18
index.ts
|
@ -1,6 +1,7 @@
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'node:events';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'node:fs';
|
||||||
import * as path from 'path';
|
import * as os from 'node:os';
|
||||||
|
import * as path from 'node:path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interval of file system polling, in milliseconds.
|
* Interval of file system polling, in milliseconds.
|
||||||
|
@ -35,6 +36,15 @@ function parseUint16(parseString: string) {
|
||||||
else throw new RangeError(`Must be between 0 and ${Uint16Max}.`);
|
else throw new RangeError(`Must be between 0 and ${Uint16Max}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GPIO0 オフセット
|
||||||
|
* @see {@link https://github.com/raspberrypi/linux/issues/6037}
|
||||||
|
*/
|
||||||
|
const GpioOffset =
|
||||||
|
process.platform === 'linux' && 6.6 <= Number(os.release().match(/\d+\.\d+/))
|
||||||
|
? 512
|
||||||
|
: 0;
|
||||||
|
|
||||||
/** ポート番号 */
|
/** ポート番号 */
|
||||||
type PortNumber = number;
|
type PortNumber = number;
|
||||||
/** ポート名 */
|
/** ポート名 */
|
||||||
|
@ -151,7 +161,7 @@ export class GPIOPort extends EventEmitter {
|
||||||
constructor(portNumber: PortNumber) {
|
constructor(portNumber: PortNumber) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._portNumber = parseUint16(portNumber.toString());
|
this._portNumber = parseUint16(portNumber.toString()) + GpioOffset;
|
||||||
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.');
|
||||||
|
|
Loading…
Add table
Reference in a new issue