adding interrupt class for gpio pins on RPi and the like
parent
6366815b03
commit
87cb9d1a75
|
@ -1 +0,0 @@
|
|||
module.exports.hello = function (what) { return 'Hello ' + what }
|
|
@ -0,0 +1,32 @@
|
|||
'use strict'
|
||||
|
||||
const Gpio = require('onoff').Gpio
|
||||
|
||||
// **********************************
|
||||
|
||||
class Interrupt {
|
||||
// bus is i2c-bus bus object
|
||||
constructor(pin_number, processor, opts = {}) {
|
||||
let dtimeout = opts.debounceTimeout ? opts.debounceTimeout : 200
|
||||
this.pin = new Gpio(pin_number, 'in', 'falling', { debounceTimeout: dtimeout })
|
||||
this.processor = processor
|
||||
}
|
||||
|
||||
init() {
|
||||
this.addListener(this.processor)
|
||||
process.on('SIGINT', function () {
|
||||
this.pin.unexport();
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
addListener(processor) {
|
||||
this.pin.watch((err, value) => {
|
||||
if (err) { return Promise.reject(err) }
|
||||
return processor
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.Interrupt = Interrupt
|
12
package.json
12
package.json
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "uci-template-changeme",
|
||||
"name": "uci-interrupt",
|
||||
"version": "0.0.1",
|
||||
"description": "A template for a starting a uci package",
|
||||
"description": "a class for adding interrupt processesing via sysfs and gpio pins on Raspberry and similar",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"testw": "./node_modules/.bin/mocha --reporter list --recursive --watch",
|
||||
|
@ -11,7 +11,7 @@
|
|||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/uCOMmandIt/uci-pkg-template.git"
|
||||
"url": "git+https://github.com/uCOMmandIt/uci-interrrupt.git"
|
||||
},
|
||||
"keywords": [
|
||||
"node.js",
|
||||
|
@ -21,14 +21,16 @@
|
|||
"helpers"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/uCOMmandIt/utilities/issues"
|
||||
"url": "https://github.com/uCOMmandIt/uci-interrrupt/issues"
|
||||
},
|
||||
"homepage": "https://github.com/uCOMmandIt/utilities#readme",
|
||||
"homepage": "https://github.com/uCOMmandIt/uci-interrrupt#readme",
|
||||
"dependencies": {
|
||||
"onoff": "^1.1.1",
|
||||
"require-all": "git+https://github.com/dkebler/node-require-all.git#merge"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.5.0",
|
||||
"chai-as-promised": "^6.0.0",
|
||||
"codecov": "^1.0.1",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^3.2.0"
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
'use strict'
|
||||
|
||||
const chai = require('chai'),
|
||||
chaiAsPromised = require("chai-as-promised"),
|
||||
lib = require('../')
|
||||
|
||||
chai.use(chaiAsPromised);
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Promise Stuff - ', function () {
|
||||
|
||||
it('Can test a promise', function () {
|
||||
|
||||
return expect(lib.apromise).to.eventually.equal('some promise hey')
|
||||
return Promise.resolve().then(() => expect(lib.apromise).to.eventually.equal('some promise hey'))
|
||||
|
||||
})
|
||||
})
|
|
@ -1,16 +1,16 @@
|
|||
'use strict'
|
||||
|
||||
const expect = require('chai').expect,
|
||||
lib = require('../')
|
||||
|
||||
//time-stamp for use when watching to distinguish reruns in console
|
||||
// place in alpha first file only
|
||||
let date = new Date(Date.now())
|
||||
console.log(date.getMinutes(), "\:", date.getSeconds())
|
||||
|
||||
const expect = require('chai').expect,
|
||||
lib = require('../')
|
||||
describe('Test a template module ', function () {
|
||||
|
||||
describe('A template module ', function () {
|
||||
|
||||
it('Should ....', function () {
|
||||
it('Should test all methods', function () {
|
||||
expect(lib.hello('Forest Gump')).to.equal('Hello Forest Gump')
|
||||
})
|
||||
|
Loading…
Reference in New Issue