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

View File

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