working on interrupt init
parent
ff72b670ab
commit
65e02f4fc6
|
@ -19,27 +19,24 @@ class Interrupt extends EventEmitter {
|
||||||
this.hook = opts.hook // will be passed back with the emit
|
this.hook = opts.hook // will be passed back with the emit
|
||||||
this.path = GPIO_ROOT_PATH + 'gpio' + this.num + '/'
|
this.path = GPIO_ROOT_PATH + 'gpio' + this.num + '/'
|
||||||
this.edge = opts.edge ? opts.edge : 'falling'
|
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.dbt = opts.debounce ? opts.debounce : 300
|
||||||
this.poller = new Epoll(
|
// this.poller = new Epoll(
|
||||||
debounce((err, fd, events) => {
|
// debounce((err, fd, events) => {
|
||||||
if (err) { this.emit('error', err) } else { this.clear().then(this.emit('fired', this.hook)) }
|
// if (err) { this.emit('error', err) } else { this.clear().then(this.emit('fired', this.hook)) }
|
||||||
}, this.dbt, true)
|
// }, this.dbt, true)
|
||||||
)
|
// )
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
|
||||||
let tasks = [
|
let tasks = [
|
||||||
() => { return fs.writeFile(GPIO_ROOT_PATH + 'export', this.num).then(() => { console.log('exported') }) },
|
fs.writeFile(GPIO_ROOT_PATH + 'export', this.num).then(() => { console.log('exported', this.num) }),
|
||||||
() => {
|
pWaitFor(() => pathExists(this.path + 'direction')).then(_.pDelay(this.delay))
|
||||||
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 + 'direction', 'in').then(() => { console.log('direction', 'in') }) })
|
fs.writeFile(this.path + 'edge', this.edge).then(() => { console.log('edge', this.edge) }),
|
||||||
//.then(() => { return fs.writeFile(this.path + 'value', 1).then(() => { console.log('pulled up') }) })
|
fs.open(this.path + 'value', 'r+').then(fd => { this.valuefd = fd }),
|
||||||
},
|
this.clear().then(() => { return this.start() })
|
||||||
() => { 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() }) }
|
|
||||||
]
|
]
|
||||||
|
|
||||||
process.on('SIGINT', () => {
|
process.on('SIGINT', () => {
|
||||||
|
@ -48,8 +45,8 @@ class Interrupt extends EventEmitter {
|
||||||
|
|
||||||
return this.exit() // make sure pin is unexported
|
return this.exit() // make sure pin is unexported
|
||||||
.then((resp) => {
|
.then((resp) => {
|
||||||
console.log(resp)
|
console.log('ready to init', tasks)
|
||||||
return _.pSeries(tasks)
|
return _.pSeries(tasks).then(console.log('finsihed tasks'))
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@ let inter17 = new Interrupt(17, { hook: 'a hook to something to do' })
|
||||||
// console.log('Listener fired and returned:', hook)
|
// console.log('Listener fired and returned:', hook)
|
||||||
// })
|
// })
|
||||||
|
|
||||||
inter17.on('fired', hook => { counter(hook) })
|
// inter17.init()
|
||||||
|
// .then(() => {
|
||||||
inter17.init()
|
// console.log('initialzed, waiting for interrupt to fire')
|
||||||
.then(() => {
|
// })
|
||||||
console.log('initialzed, waiting for interrupt to fire')
|
// .catch(err => console.log("returned error:", err))
|
||||||
})
|
//
|
||||||
.catch(err => console.log("returned error:", err))
|
// inter17.on('fired', hook => { counter(hook) })
|
||||||
|
|
||||||
let count = 0
|
let count = 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue