From 54872314ba14ced1b6b04eca6082944ee7f6f452 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sat, 27 Apr 2019 15:47:37 -0700 Subject: [PATCH] 0.1.16 fix old access to socket to using getSocket --- package.json | 2 +- src/bus-device-commands.js | 17 ++++++++--------- src/device.js | 12 +++++------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 621f101..243dc98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci/i2c-device", - "version": "0.1.15", + "version": "0.1.16", "description": "Device Classes for I2C Interfacing", "main": "src/device", "scripts": { diff --git a/src/bus-device-commands.js b/src/bus-device-commands.js index 69389c8..0f245dd 100644 --- a/src/bus-device-commands.js +++ b/src/bus-device-commands.js @@ -12,46 +12,45 @@ export default { }, receive: async function() { - await this._setChannel() + if (this.channel) await this._setChannel() return await this.send('bus',{ cmd:'receive', args: {address:this.address}}) }, send: async function(byte) { - await this._setChannel() + if (this.channel) await this._setChannel() return await this.send('bus',{ cmd:'send', args: {address:this.address, byte:byte }}) }, // for devices needing a buffer/stream readRaw: async function (length, buffer) { - await this._setChannel() + if (this.channel) await this._setChannel() return await this.send('bus',{ cmd:'readRaw', args: {address:this.address, length:length, buffer:buffer }}) }, writeRaw: async function (length, buffer) { - await this._setChannel() + if (this.channel) await this._setChannel() return await this.send('bus',{ cmd:'writeRaw', args: {address:this.address, length:length, buffer:buffer }}) }, // both cmd and byte should be a single byte as a decimal or hex read: async function (cmd) { - await this._setChannel() + if (this.channel) await this._setChannel() return await this.send('bus',{ cmd:'read', args: {address:this.address, cmd:cmd }}) }, write: async function (cmd, byte) { - await this._setChannel() + if (this.channel) await this._setChannel() return await this.send('bus',{ cmd:'write', args: {address:this.address, cmd:cmd, byte:byte }}) }, // for I2C devices that use a word length packackage read2: async function (cmd) { - await this._setChannel() + if (this.channel) await this._setChannel() return await this.send('bus',{ cmd:'read2', args: {address:this.address, cmd:cmd }}) }, write2: async function (cmd, bytes) { - await this._setChannel() + if (this.channel) await this._setChannel() return await this.send('bus',{ cmd:'write2', args: {address:this.address, cmd:cmd, byte:bytes }}) } - } diff --git a/src/device.js b/src/device.js index 08bff85..05a1c57 100644 --- a/src/device.js +++ b/src/device.js @@ -1,7 +1,5 @@ import Base from '@uci/base' -// import Base from '../../uci-base/src/base' import commands from './bus-device-commands' -// import logger from '../../uci-logger/src/logger' import logger from '@uci-utils/logger' let log = {} @@ -25,14 +23,14 @@ class I2CDevice extends Base { }) if (!opts.address) log.fatal({ opts: opts, method:'constructor', line:26, msg:'no i2c bus address supplied'}) this.address = +opts.address // make sure any passed number is number not a string - 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() { await super.init() let res = await this.bus.ack() - let socket = this.socket.bus.opts + let socket = this.getSocket('bus').opts let connection = socket.path || socket.host + ':' + socket.port if (!res.ack) { let err ={error:'ack', res:res, socket:socket, method:'init', line:38, connection:connection, address:this.address, msg:`no bus or device on bus at address ${this.address}=0x${this.address.toString(16)}`} @@ -42,9 +40,9 @@ class I2CDevice extends Base { return res } - // TODO enable mux channel set - // async _setChannel() { - // } + // TODO enable mux board channel set + async _setChannel() { + } } // end of i2c Device Class