Skip to content

Commit

Permalink
use correct offset for GPIO0
Browse files Browse the repository at this point in the history
  • Loading branch information
kou029w committed Oct 4, 2024
1 parent 8ce22e2 commit cd50093
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
/** ポート名 */
Expand Down Expand Up @@ -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.');
Expand Down

0 comments on commit cd50093

Please sign in to comment.