uci-i2c-bus/lib/bus.js

25 lines
531 B
JavaScript
Raw Normal View History

2017-01-12 19:50:06 -08:00
'use strict'
const i2c = require('i2c-bus'),
2017-01-13 19:51:55 -08:00
pA = require('bluebird').promisifyAll,
pQ = require('promisqueue')
2017-01-12 19:50:06 -08:00
2017-01-13 19:51:55 -08:00
// TODO Create a Bus master class then BusRPi classes etc for actual hardware.
2017-01-12 19:50:06 -08:00
class Bus {
2017-01-13 19:51:55 -08:00
constructor(busnum) {
this.methods = pA(i2c.open(busnum, () => {}), { suffix: "_p" }) //,multiArgs: true})
this.q = new pQ({ limit: 1 })
}
2017-01-12 19:50:06 -08:00
2017-01-13 19:51:55 -08:00
scan() { return this.bus.scan_p() }
close() { return this.bus.close_p() }
2017-01-12 19:50:06 -08:00
2017-01-13 19:51:55 -08:00
qAdd(job) { this.q.add(() => job) }
2017-01-12 19:50:06 -08:00
} // end of Bus Class
2017-01-13 21:13:39 -08:00
module.exports = {
Bus
};