Install onoff for better button watching

This commit is contained in:
mmcwilliams 2017-08-22 01:31:27 -04:00
parent 77a10fa80a
commit 524aba90d8
3 changed files with 49 additions and 17 deletions

View File

@ -1,6 +1,26 @@
'use strict' 'use strict'
const gpio = require('gpio') const Gpio = require('onoff')
const PINS = {
fwd : {
pin : 4,
dir : 'out'
},
bwd : {
pin : 5,
dir : 'out'
},
micro : {
pin : 6,
dir : 'in',
edge : 'rising'
},
release : {
pin : 7,
dir : 'in',
edge : 'both'
}
}
class Intval { class Intval {
constructor () { constructor () {
@ -9,20 +29,10 @@ class Intval {
this._declarePins() this._declarePins()
} }
_declarePins () { _declarePins () {
this._pin.fwd = gpio.export(4, { this._pin.fwd = Gpio(4, 'out')
direction: 'out', this._pin.bwd = Gpio(5, 'out')
interval: 100, this._pin.micro = Gpio(6, 'in', 'rising')
ready : () => { this._pin.release = Gpio(7, 'in', 'both')
console.info(`Set pin 4 to OUTPUT`)
}
})
this._pin.bwd = gpio.export(5, {
direction: 'out',
interval: 100,
ready : () => {
console.info(`Set pin 5 to OUTPUT`)
}
})
} }
_startFwd () { _startFwd () {
this._pin.fwd.set(1) this._pin.fwd.set(1)

25
package-lock.json generated
View File

@ -30,6 +30,11 @@
"tweetnacl": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz" "tweetnacl": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz"
} }
}, },
"bindings": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz",
"integrity": "sha1-FK1hE4EtLTfXLme0ystLtyZQXxE="
},
"bleno": { "bleno": {
"version": "https://registry.npmjs.org/bleno/-/bleno-0.4.2.tgz", "version": "https://registry.npmjs.org/bleno/-/bleno-0.4.2.tgz",
"integrity": "sha1-IesK10O850eU45L0ph4TsHOT26o=", "integrity": "sha1-IesK10O850eU45L0ph4TsHOT26o=",
@ -161,6 +166,15 @@
"jsbn": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz" "jsbn": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz"
} }
}, },
"epoll": {
"version": "0.1.22",
"resolved": "https://registry.npmjs.org/epoll/-/epoll-0.1.22.tgz",
"integrity": "sha1-GrmmN8/xGiCXDIiLHKIXi2TPUpE=",
"requires": {
"bindings": "1.2.1",
"nan": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz"
}
},
"escape-regexp-component": { "escape-regexp-component": {
"version": "https://registry.npmjs.org/escape-regexp-component/-/escape-regexp-component-1.0.2.tgz", "version": "https://registry.npmjs.org/escape-regexp-component/-/escape-regexp-component-1.0.2.tgz",
"integrity": "sha1-nGO20LJf8qiMOtvRjFthrMO5+qI=" "integrity": "sha1-nGO20LJf8qiMOtvRjFthrMO5+qI="
@ -371,8 +385,7 @@
}, },
"nan": { "nan": {
"version": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz", "version": "https://registry.npmjs.org/nan/-/nan-2.6.2.tgz",
"integrity": "sha1-5P805slf37WuzAjeZZb0NgWn20U=", "integrity": "sha1-5P805slf37WuzAjeZZb0NgWn20U="
"optional": true
}, },
"ncp": { "ncp": {
"version": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", "version": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz",
@ -403,6 +416,14 @@
"wrappy": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" "wrappy": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz"
} }
}, },
"onoff": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/onoff/-/onoff-1.1.5.tgz",
"integrity": "sha1-tkT9pSe4eJ60ZDwD9YIqqVclCu4=",
"requires": {
"epoll": "0.1.22"
}
},
"path-is-absolute": { "path-is-absolute": {
"version": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "version": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",

View File

@ -27,6 +27,7 @@
"cron": "^1.2.1", "cron": "^1.2.1",
"gpio": "^0.2.7", "gpio": "^0.2.7",
"node-ipc": "^9.1.0", "node-ipc": "^9.1.0",
"onoff": "^1.1.5",
"restify": "^5.2.0", "restify": "^5.2.0",
"uuid": "^3.1.0", "uuid": "^3.1.0",
"winston": "^2.3.1" "winston": "^2.3.1"