last cleanup after uci-dev split out

master
David Kebler 2017-01-16 22:44:10 -08:00
parent 7f9b54e2c7
commit c4575be271
2 changed files with 35 additions and 35 deletions

View File

@ -1,51 +1,51 @@
'use strict' 'use strict'
const i2c = require('i2c-bus'), const i2c = require('i2c-bus'),
pify = require('pify'), pify = require('pify'),
PQueue = require('p-queue') PQueue = require('p-queue')
// TODO Create a Bus master class then BusRPi classes etc for actual hardware. // TODO Create a Bus master class then BusRPi classes etc for actual hardware.
class Bus { class Bus {
constructor(busnum = 1) { constructor(busnum = 1) {
this.busnum = busnum this.busnum = busnum
this.queue = new PQueue({ concurrency: 1 }); this.queue = new PQueue({ concurrency: 1 });
this.qAdd = (p) => { this.queue.add(() => p) } // p is a promise this.qAdd = (p) => { this.queue.add(() => p) } // p is a promise
this.bus = i2c.open(this.busnum, () => {}) this.bus = i2c.open(this.busnum, () => {})
} }
scan() { return pify(this.bus.scan).bind(this.bus)() } scan() { return pify(this.bus.scan).bind(this.bus)() }
close() { return pify(this.bus.close).bind(this.bus)() } close() { return pify(this.bus.close).bind(this.bus)() }
readRaw(address, length, buffer) { readRaw(address, length, buffer) {
return pify(this.bus.i2cRead).bind(this.bus)(address, length, buffer) return pify(this.bus.i2cRead).bind(this.bus)(address, length, buffer)
} }
writeRaw(address, length, buffer) { writeRaw(address, length, buffer) {
return pify(this.bus.i2cWrite).bind(this.bus)(address, length, buffer) return pify(this.bus.i2cWrite).bind(this.bus)(address, length, buffer)
} }
read(address, cmd) { read(address, cmd) {
// console.log("read: address, cmd", address, cmd) // console.log("read: address, cmd", address, cmd)
return pify(this.bus.readByte).bind(this.bus)(address, cmd) return pify(this.bus.readByte).bind(this.bus)(address, cmd)
} }
write(address, cmd, byte) { write(address, cmd, byte) {
// console.log("write: address, cmd, byte", address, cmd, byte) // console.log('write: address, cmd, byte', address, cmd, byte)
return pify(this.bus.writeByte.bind(this.bus))(address, cmd, byte) return pify(this.bus.writeByte.bind(this.bus))(address, cmd, byte)
} }
read2(address, cmd) { read2(address, cmd) {
return pify(this.bus.readWord.bind(this.bus))(address, cmd) return pify(this.bus.readWord.bind(this.bus))(address, cmd)
} }
write2(address, cmd, bytes) { write2(address, cmd, bytes) {
return pify(this.bus.writeWord.bind(this.bus))(address, cmd, bytes) return pify(this.bus.writeWord.bind(this.bus))(address, cmd, bytes)
} }
} // end of Bus Class } // end of Bus Class
module.exports = { module.exports = {
Bus Bus
}; };

View File

@ -2,16 +2,16 @@
const chai = require('chai'), const chai = require('chai'),
chaiAsPromised = require("chai-as-promised"), chaiAsPromised = require("chai-as-promised"),
Bus = require('../lib/bus').Bus, Bus = require('../lib/bus').Bus
Device = require('../lib/device').Device
chai.use(chaiAsPromised); chai.use(chaiAsPromised)
const expect = chai.expect const expect = chai.expect
let bus = new Bus() let bus = new Bus()
let addresses = [0x20, 0x23, 0x27] // const addresses = [0x20, 0x26, 0x27]
const addresses = []
describe('Bus Class - ', function () { describe('Bus Class - ', function () {