0.1.13 Change to new logger location and fix issue where address was a string instead of a number because it came from datbase that way. Now will cast any string to number

0.1.12
master
David Kebler 2019-02-26 11:53:30 -08:00
parent 5e2ee6daf2
commit 7b4c532bdb
3 changed files with 16 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@uci/i2c-device", "name": "@uci/i2c-device",
"version": "0.1.4", "version": "0.1.13",
"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.8", "@uci/base": "^0.1.16",
"@uci/logger": "0.0.6" "@uci-utils/logger": "0.0.13"
}, },
"devDependencies": { "devDependencies": {
"chai": "^4.1.2", "chai": "^4.1.2",

View File

@ -1,3 +1,5 @@
// TODO add uci logging debug
export default { export default {
ack: async function (){ ack: async function (){
@ -5,7 +7,7 @@ export default {
let bus = await this.send('bus',{ cmd:'scan'}) let bus = await this.send('bus',{ cmd:'scan'})
if (bus.error) return bus if (bus.error) return bus
let res = { cmd:'reply', ack: false, address:this.address, scan:bus.response} let res = { cmd:'reply', ack: false, address:this.address, scan:bus.response}
if (bus.response.indexOf(this.address) !== -1) res.ack = true if (bus.response.indexOf(+this.address) !== -1) res.ack = true
return res return res
}, },
@ -33,13 +35,13 @@ 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,this._channel,await this.socket.bus.send(getState) // 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,this._channel,await this.socket.bus.send(getState) // 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

@ -2,7 +2,7 @@ import Base from '@uci/base'
// import Base from '../../uci-base/src/base' // import Base from '../../uci-base/src/base'
import commands from './bus-device-commands' import commands from './bus-device-commands'
// import logger from '../../uci-logger/src/logger' // import logger from '../../uci-logger/src/logger'
import logger from '@uci/logger' import logger from '@uci-utils/logger'
let log = {} let log = {}
class I2CDevice extends Base { class I2CDevice extends Base {
@ -24,8 +24,8 @@ class I2CDevice extends Base {
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 }, 'no i2c bus address supplied')
this.address = opts.address 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)
} }
@ -34,12 +34,11 @@ class I2CDevice extends Base {
let res = await this.bus.ack() let res = await this.bus.ack()
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) {
throw `no device operational on bus '${ 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)}`}
socket.id log.warn(err)
}' (${connection}) at address ${this.address}=0x${this.address.toString( return err
16 }
)}`
return res return res
} }