working interrupt with both ports

master
David Kebler 2017-01-31 23:28:09 -08:00
parent 846979a48f
commit 4485f981a5
1 changed files with 13 additions and 20 deletions

View File

@ -21,8 +21,9 @@ class Interrupt extends EventEmitter {
this.path = GPIO_ROOT_PATH + 'gpio' + this.num + '/'
this.edge = opts.edge // default 'both'
this.delay = opts.delay // default = 50
this.pullup = opts.pullup ? opts.pullup : (num, state) => { return `raspi-gpio set ${num} ${state}` } // default rpi using raspi-gpio
// this.pullup = (num, state) => { return `raspi-gpio set ${num} ${state}` }
this.pull = opts.pull // default = pu
this.puller = opts.puller ? opts.puller : (num, state) => { return `raspi-gpio set ${num} ${state}` } // default rpi using raspi-gpio
// this.puller = (num, state) => { return `raspi-gpio set ${num} ${state}` }
this.dbt = opts.debounce ? opts.debounce : 200
this.poller = new Epoll(
debounce((err, fd, events) => {
@ -39,30 +40,22 @@ class Interrupt extends EventEmitter {
return _.pSeries([
this.exit(),
this._pull(this.num),
this._pull(this.num, this.pull),
this._export(this.num),
this._direction('in', this.delay),
() => this._edge(this.edge), // TODO determine why these need additional function
() => this._fd(),
() => this.clear().then(() => {
this.start()
return Promise.resolve('cleared and started')
})
() => this._fd()
])
}
// _test(num) {
// return Promise.resolve(num)
// }
fire(name = 'fired') {
this.emit(name, this.hook)
}
clear() {
let buffer = Buffer.from([0x00])
return fs.read(this.valuefd, buffer, 0, 1, 0);
return fs.read(this.valuefd, buffer, 0, 1, 0).then(() => { return Promise.resolve('interrupt cleared') })
}
exit() {
@ -88,7 +81,7 @@ class Interrupt extends EventEmitter {
}
start() {
this.poller.add(this.valuefd, Epoll.EPOLLPRI);
this.clear().then(() => this.poller.add(this.valuefd, Epoll.EPOLLPRI));
}
stop() {
@ -98,9 +91,9 @@ class Interrupt extends EventEmitter {
/*******private methods*********/
_pull(num, state = 'pu') {
if (this.pullup === 'external') { return Promise.resolve('pull must be set externally') } else {
return exec(this.pullup(num, state))
.then(() => { return Promise.resolve('pull set') })
if (this.puller === 'external') { return Promise.resolve('pull must be set externally') } else {
return exec(this.puller(num, state))
.then(() => { return Promise.resolve(`pull set ${state}`) })
}
}
@ -108,7 +101,7 @@ class Interrupt extends EventEmitter {
return fs.open(this.path + 'value', 'r+')
.then(fd => {
this.valuefd = fd
return Promise.resolve('value fd set')
return Promise.resolve(`value fd set ${fd}`)
})
}
@ -126,7 +119,7 @@ class Interrupt extends EventEmitter {
.then(() => {
return fs.writeFile(dir + 'direction', dir)
.then(() => {
return Promise.resolve('direction set')
return Promise.resolve(`direction set ${dir}`)
})
})
}
@ -134,7 +127,7 @@ class Interrupt extends EventEmitter {
_edge(edge = 'both') {
return fs.writeFile(this.path + 'edge', edge)
.then(() => {
return Promise.resolve('edge set')
return Promise.resolve(`edge set ${edge}`)
})
}