use correct offset for GPIO0

https://github.com/raspberrypi/linux/issues/6037
This commit is contained in:
Nebel 2024-10-04 23:28:26 +09:00
parent 8ce22e2be1
commit cd50093ae2
Signed by: nebel
GPG key ID: 79807D08C6EF6460

View file

@ -1,6 +1,7 @@
import { EventEmitter } from 'events';
import { promises as fs } from 'fs';
import * as path from 'path';
import { EventEmitter } from 'node:events';
import { promises as fs } from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
/**
* 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}.`);
}
/**
* 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;
/** ポート名 */
@ -151,7 +161,7 @@ export class GPIOPort extends EventEmitter {
constructor(portNumber: PortNumber) {
super();
this._portNumber = parseUint16(portNumber.toString());
this._portNumber = parseUint16(portNumber.toString()) + GpioOffset;
this._pollingInterval = PollingInterval;
this._direction = new OperationError('Unknown direction.');
this._exported = new OperationError('Unknown export.');