0.1.18 update deps, clean up logging
parent
f257831d1a
commit
b665379223
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@uci/i2c-bus",
|
||||
"version": "0.1.17",
|
||||
"version": "0.1.18",
|
||||
"description": "I2c Bus Classes for Communication to I2C bus via socket or direct call",
|
||||
"main": "src/bus",
|
||||
"scripts": {
|
||||
|
@ -32,8 +32,8 @@
|
|||
"i2c-bus": "^4.0.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uci/base": "^0.1.18",
|
||||
"@uci-utils/logger": "^0.0.13",
|
||||
"@uci/base": "^0.1.20",
|
||||
"@uci-utils/logger": "^0.0.14",
|
||||
"better-try-catch": "^0.6.2",
|
||||
"pify": "^4.0.1"
|
||||
},
|
||||
|
|
16
src/bus.js
16
src/bus.js
|
@ -24,7 +24,7 @@ class I2CBus extends Base {
|
|||
opts.sockets = (opts.sockets ? opts.sockets + ',' : '') + 'ts#s>t'
|
||||
}
|
||||
super(opts)
|
||||
log.info({ opts: opts }, 'created bus with these opts')
|
||||
log.debug({ opts: opts }, 'created bus with these opts')
|
||||
this.busnum = opts.busnum || 1
|
||||
this.i2cbus = i2c.open(this.busnum, () => {})
|
||||
this.bus = bus_funcs
|
||||
|
@ -35,9 +35,10 @@ class I2CBus extends Base {
|
|||
await super.init()
|
||||
}
|
||||
|
||||
// TODO see if default processing of base can handle this now
|
||||
// if none of these then call the default processor
|
||||
// could use the default if it included a validation hook plugin
|
||||
// TODO use the resplacement method instead of replacing _packetPorcess
|
||||
// or refactor bus_funcs and add to a namespace so default processing can be used
|
||||
// which will allow adding more command to the this module
|
||||
// can use a packet Hook to do validation.
|
||||
async _packetProcess(sname, packet) {
|
||||
if (!packet.cmd) return { error: 'no cmd: key in packet', packet: packet }
|
||||
if (this.bus[packet.cmd]) {
|
||||
|
@ -48,12 +49,13 @@ class I2CBus extends Base {
|
|||
packet.response = res || ''
|
||||
packet.cmd = 'reply'
|
||||
return packet
|
||||
} else
|
||||
} else {
|
||||
return {
|
||||
error: 'no i2c bus function available for packet command',
|
||||
packet: packet
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end of Bus Packet Class
|
||||
|
||||
export default I2CBus
|
||||
|
@ -114,11 +116,11 @@ const bus_funcs = {
|
|||
)
|
||||
},
|
||||
read: function(args) {
|
||||
// console.log('read: address, cmd', address, cmd)
|
||||
log.debug({msg:'read i2c bus', method:'read', line:118, args:args})
|
||||
return pify(this.i2cbus.readByte).bind(this.i2cbus)(args.address, args.cmd)
|
||||
},
|
||||
write: function(args) {
|
||||
// console.log('write: address, cmd, byte', args.address, args.cmd, args.byte)
|
||||
log.debug({msg:'write i2c bus', method:'write', line:122, args:args})
|
||||
return pify(this.i2cbus.writeByte.bind(this.i2cbus))(
|
||||
args.address,
|
||||
args.cmd,
|
||||
|
|
Loading…
Reference in New Issue