forked from weinzmi/daumUSB2BLE
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgpio.js
More file actions
46 lines (38 loc) · 1.09 KB
/
Copy pathgpio.js
File metadata and controls
46 lines (38 loc) · 1.09 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const Gpio = require('onoff').Gpio;
const EventEmitter = require('events').EventEmitter;
const shiftUp = new Gpio(4, 'in', 'rising', {debounceTimeout: 10});
const shiftDown = new Gpio(17, 'in', 'rising', {debounceTimeout: 10});
const DEBUG = true;
function gpio() {
let gear = 0;
this.gears = function () {
const self = this;
self.emitter = new EventEmitter();
shiftUp.watch((err, value) => {
if (err) {
// self.emitter.emit('error', err );
throw err;
}
gear = gear + 1;
self.emitter.emit('key', gear);
self.emitter.emit('setGear', gear);
if (DEBUG) console.log("[gpio.js] Shift to Gear: " + gear);
});
process.on('SIGINT', () => {
shiftUp.unexport();
});
shiftDown.watch((err, value) => {
if (err) {
// self.emitter.emit('error', err );
throw err;
}
gear = gear - 1;
if (DEBUG) console.log("[gpio.js] Shift to Gear: " + gear);
self.emitter.emit('setGear', gear);
});
process.on('SIGINT', () => {
shiftDown.unexport();
});
};
}
module.exports = gpio;