From c4575be2716263a1a1c3735aec55daa9202c7d55 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Mon, 16 Jan 2017 22:44:10 -0800 Subject: [PATCH] last cleanup after uci-dev split out --- lib/bus.js | 62 ++++++++++++++++++++++++------------------------ test/bus.test.js | 8 +++---- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/bus.js b/lib/bus.js index 3eddb04..6632658 100644 --- a/lib/bus.js +++ b/lib/bus.js @@ -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 }; diff --git a/test/bus.test.js b/test/bus.test.js index 3a8faed..52fed6d 100644 --- a/test/bus.test.js +++ b/test/bus.test.js @@ -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 () {