working on interrupt init

master
David Kebler 2017-01-24 14:46:01 -08:00
parent ff72b670ab
commit 65e02f4fc6
2 changed files with 21 additions and 24 deletions

View File

@ -19,27 +19,24 @@ class Interrupt extends EventEmitter {
this.hook = opts.hook // will be passed back with the emit
this.path = GPIO_ROOT_PATH + 'gpio' + this.num + '/'
this.edge = opts.edge ? opts.edge : 'falling'
this.delay = opts.delay ? opts.delay : 1000
this.delay = opts.delay ? opts.delay : 50
this.dbt = opts.debounce ? opts.debounce : 300
this.poller = new Epoll(
debounce((err, fd, events) => {
if (err) { this.emit('error', err) } else { this.clear().then(this.emit('fired', this.hook)) }
}, this.dbt, true)
)
// this.poller = new Epoll(
// debounce((err, fd, events) => {
// if (err) { this.emit('error', err) } else { this.clear().then(this.emit('fired', this.hook)) }
// }, this.dbt, true)
// )
}
init() {
let tasks = [
() => { return fs.writeFile(GPIO_ROOT_PATH + 'export', this.num).then(() => { console.log('exported') }) },
() => {
return pWaitFor(() => pathExists(this.path + 'direction')).then(_.pDelay(this.delay))
.then(() => { return fs.writeFile(this.path + 'direction', 'in').then(() => { console.log('direction', 'in') }) })
//.then(() => { return fs.writeFile(this.path + 'value', 1).then(() => { console.log('pulled up') }) })
},
() => { return fs.writeFile(this.path + 'edge', this.edge).then(() => { console.log('edge', this.edge) }) },
() => { return fs.open(this.path + 'value', 'r+').then(fd => { this.valuefd = fd }) },
() => { return this.clear().then(() => { return this.start() }) }
fs.writeFile(GPIO_ROOT_PATH + 'export', this.num).then(() => { console.log('exported', this.num) }),
pWaitFor(() => pathExists(this.path + 'direction')).then(_.pDelay(this.delay))
.then(() => { return fs.writeFile(this.path + 'direction', 'in').then(() => { console.log('direction', 'in') }) }),
fs.writeFile(this.path + 'edge', this.edge).then(() => { console.log('edge', this.edge) }),
fs.open(this.path + 'value', 'r+').then(fd => { this.valuefd = fd }),
this.clear().then(() => { return this.start() })
]
process.on('SIGINT', () => {
@ -48,8 +45,8 @@ class Interrupt extends EventEmitter {
return this.exit() // make sure pin is unexported
.then((resp) => {
console.log(resp)
return _.pSeries(tasks)
console.log('ready to init', tasks)
return _.pSeries(tasks).then(console.log('finsihed tasks'))
})
}

View File

@ -15,13 +15,13 @@ let inter17 = new Interrupt(17, { hook: 'a hook to something to do' })
// console.log('Listener fired and returned:', hook)
// })
inter17.on('fired', hook => { counter(hook) })
inter17.init()
.then(() => {
console.log('initialzed, waiting for interrupt to fire')
})
.catch(err => console.log("returned error:", err))
// inter17.init()
// .then(() => {
// console.log('initialzed, waiting for interrupt to fire')
// })
// .catch(err => console.log("returned error:", err))
//
// inter17.on('fired', hook => { counter(hook) })
let count = 0