gpio-mock-test-nodejs/gpio.js

28 lines
550 B
JavaScript
Raw Normal View History

2022-11-09 20:28:42 +01:00
var fs = require('fs');
// Post 3.18.x kernel
var sysFsPath = '/sys/class/gpio/gpio';
var pinMapping = {
'16': 23
};
function open(pinNumber, direction, callback) {
const path = sysFsPath + pinMapping[pinNumber] + '/direction';
fs.writeFile(path, direction, (callback || noOp));
}
function write(pinNumber, value, callback) {
const path = sysFsPath + pinMapping[pinNumber] + '/value';
value = !!value ? '1' : '0';
fs.writeFile(path, value, 'utf8', callback);
}
function noOp() {}
module.exports = {
open: open,
write: write
};