-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
31 lines (26 loc) · 720 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// prevent module being loaded on anything other than Linux
const os = require('os');
if (os.type() === 'Linux') {
// entry point
const libgpiod = require('bindings')('node-libgpiod');
libgpiod.Chip.prototype.getLine = function getLine(n) {
return new libgpiod.Line(this, n);
};
libgpiod.available = function () {
return true;
}
libgpiod.Pin = function Pin(n) {
// defaults to chip 0
const chip = new libgpiod.Chip(0);
const line = chip.getLine(n);
return line;
}
module.exports = libgpiod;
} else {
const libgpiod = {
available: function () {
return false;
}
}
module.exports = libgpiod;
}