From 5e2ee6daf2da7c6cb8b58c8ce07405bbfdf5d351 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Tue, 1 Jan 2019 19:34:06 -0800 Subject: [PATCH] little cleanup update dependencies --- package.json | 4 ++-- src/.gitignore | 1 - src/device.js | 40 ++++++++++++++++++++++++---------------- 3 files changed, 26 insertions(+), 19 deletions(-) delete mode 100644 src/.gitignore diff --git a/package.json b/package.json index aa29d49..ec3aeae 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ }, "homepage": "https://github.com/uCOMmandIt/i2c#readme", "dependencies": { - "@uci/base": "^0.1.7", - "@uci/logger": "0.0.3" + "@uci/base": "^0.1.8", + "@uci/logger": "0.0.6" }, "devDependencies": { "chai": "^4.1.2", diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index 2ccbe46..0000000 --- a/src/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/node_modules/ diff --git a/src/device.js b/src/device.js index ff6a67f..a10270f 100644 --- a/src/device.js +++ b/src/device.js @@ -5,33 +5,41 @@ import commands from './bus-device-commands' import logger from '@uci/logger' let log = {} -export default class Device extends Base { +class I2CDevice extends Base { constructor(opts) { opts.bus = opts.bus || {} if (opts.bus.host || opts.host) { - opts.bus.host = opts.host || opts.bus.host, - opts.bus.port = opts.bus.port || opts.port || 1776 - opts.sockets = (opts.sockets ? (opts.sockets + ',') : '') + 'bus#c>t' - } - else { + (opts.bus.host = opts.host || opts.bus.host), + (opts.bus.port = opts.bus.port || opts.port || 1776) + opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'bus#c>t' + } else { opts.bus.path = opts.bus.path || opts.path || 'i2c-bus' - opts.sockets = (opts.sockets ? (opts.sockets + ',') : '') + 'bus#c>n' + opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'bus#c>n' } super(opts) - // console.log('created i2c device with these options\n', opts) - log = logger({file:'src/device-packet.js',class:'Device',name:'i2c-device',id:this.id}) - if (!opts.address) log.fatal({opts:opts},'no i2c bus address supplied' ) + log = logger({ + file: 'src/device-packet.js', + class: 'Device', + name: 'i2c-device', + id: this.id + }) + if (!opts.address) log.fatal({ opts: opts }, 'no i2c bus address supplied') this.address = opts.address - this._channel = opts.channel // if using TAC9546A channel number on which device is attached + this._channel = opts.channel // if using TAC9546A channel number on which device is attached this.bus = this.bindFuncs(commands) } - async init(){ + async init() { await super.init() let res = await this.bus.ack() let socket = this.socket.bus.opts let connection = socket.path || socket.host + ':' + socket.port - if (!res.ack) throw `no device operational on bus '${socket.id}' (${connection}) at address ${this.address}=0x${this.address.toString(16)}` + if (!res.ack) + throw `no device operational on bus '${ + socket.id + }' (${connection}) at address ${this.address}=0x${this.address.toString( + 16 + )}` return res } @@ -42,8 +50,8 @@ export default class Device extends Base { // if (!await this.socket.bus.send(address) { return Promise.reject('Channel set but no mux on bus')} // return await this.socket.bus.send(set(this._channel) // } - return Promise.resolve() // no channel for device either no mux or device is attached to mux bypass + return Promise.resolve() // no channel for device either no mux or device is attached to mux bypass } - - } // end of i2c Device Class + +export default I2CDevice