0.1.15 update deps, cleanup logging

master
David Kebler 2019-04-26 11:09:33 -07:00
parent 0f33f7c38b
commit 26e480725c
4 changed files with 14 additions and 17 deletions

View File

@ -3,3 +3,7 @@ test/
*.test.js *.test.js
testing/ testing/
yarn.lock yarn.lock
examples/
.eslintrc.js
travis.yml

View File

@ -1,6 +1,6 @@
{ {
"name": "@uci/i2c-device", "name": "@uci/i2c-device",
"version": "0.1.14", "version": "0.1.15",
"description": "Device Classes for I2C Interfacing", "description": "Device Classes for I2C Interfacing",
"main": "src/device", "main": "src/device",
"scripts": { "scripts": {
@ -26,8 +26,8 @@
}, },
"homepage": "https://github.com/uCOMmandIt/i2c#readme", "homepage": "https://github.com/uCOMmandIt/i2c#readme",
"dependencies": { "dependencies": {
"@uci/base": "^0.1.18", "@uci/base": "^0.1.20",
"@uci-utils/logger": "0.0.13" "@uci-utils/logger": "0.0.14"
}, },
"devDependencies": { "devDependencies": {
"chai": "^4.1.2", "chai": "^4.1.2",

View File

@ -35,13 +35,11 @@ export default {
// both cmd and byte should be a single byte as a decimal or hex // both cmd and byte should be a single byte as a decimal or hex
read: async function (cmd) { read: async function (cmd) {
await this._setChannel() await this._setChannel()
// console.log('after set before read',this.address,this.id,cmd)
return await this.send('bus',{ cmd:'read', args: {address:this.address, cmd:cmd }}) return await this.send('bus',{ cmd:'read', args: {address:this.address, cmd:cmd }})
}, },
write: async function (cmd, byte) { write: async function (cmd, byte) {
await this._setChannel() await this._setChannel()
// console.log('after set, before write',this.address,this.id,cmd,byte)
return await this.send('bus',{ cmd:'write', args: {address:this.address, cmd:cmd, byte:byte }}) return await this.send('bus',{ cmd:'write', args: {address:this.address, cmd:cmd, byte:byte }})
}, },

View File

@ -23,7 +23,7 @@ class I2CDevice extends Base {
name: 'i2c-device', name: 'i2c-device',
id: this.id id: this.id
}) })
if (!opts.address) log.fatal({ opts: opts }, 'no i2c bus address supplied') 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.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) this.bus = this.bindFuncs(commands)
@ -35,22 +35,17 @@ class I2CDevice extends Base {
let socket = this.socket.bus.opts let socket = this.socket.bus.opts
let connection = socket.path || socket.host + ':' + socket.port let connection = socket.path || socket.host + ':' + socket.port
if (!res.ack) { if (!res.ack) {
let err ={error:'ack', res:res, socket:socket, connection:connection, address:this.address, msg:`no bus or device on bus at address ${this.address}=0x${this.address.toString(16)}`} 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)}`}
log.warn(err) log.error(err)
return err return err
} }
return res return res
} }
async _setChannel() { // TODO enable mux channel set
// TODO convert to package - uci-mux // async _setChannel() {
// console.log('before set',this.address,this.id,this._channel, await this.socket.bus.send(getState)
// if (this._channel) {
// 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
}
} // end of i2c Device Class } // end of i2c Device Class
export default I2CDevice export default I2CDevice