From 65e02f4fc6005970c7a3c9700d39a0cfd326b1aa Mon Sep 17 00:00:00 2001 From: David Kebler Date: Tue, 24 Jan 2017 14:46:01 -0800 Subject: [PATCH] working on interrupt init --- lib/interrupt.js | 31 ++++++++++++++----------------- test/interrupt.test.js | 14 +++++++------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/lib/interrupt.js b/lib/interrupt.js index 5cdb2dd..e7f8c6c 100644 --- a/lib/interrupt.js +++ b/lib/interrupt.js @@ -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')) }) } diff --git a/test/interrupt.test.js b/test/interrupt.test.js index a502781..8c66d66 100644 --- a/test/interrupt.test.js +++ b/test/interrupt.test.js @@ -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