0.1.23 remove init method, Initialize sockets via base class methods
listen for connection to bus then do a ack. if all ok emit a ready:i2c event that can be used by extended classes/instancesmaster
parent
6011e3e37a
commit
d29b9295fc
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/i2c-device",
|
"name": "@uci/i2c-device",
|
||||||
"version": "0.1.21",
|
"version": "0.1.23",
|
||||||
"description": "Device Classes for I2C Interfacing",
|
"description": "Device Classes for I2C Interfacing",
|
||||||
"main": "src/device",
|
"main": "src/device",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/uCOMmandIt/i2c#readme",
|
"homepage": "https://github.com/uCOMmandIt/i2c#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@uci/base": "^0.1.30",
|
"@uci/base": "^0.1.31",
|
||||||
"@uci-utils/logger": "^0.0.15"
|
"@uci-utils/logger": "^0.0.15"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -28,20 +28,18 @@ class I2CDevice extends Base {
|
||||||
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)
|
||||||
this._s.ack = async (packet) => { return Object.assign(packet,await this.bus.ack()) } // give socket access to bus.ack
|
this._s.ack = async (packet) => { return Object.assign(packet,await this.bus.ack()) } // give socket access to bus.ack
|
||||||
}
|
this.getSocket('bus').on('connection:socket',async ev=>{
|
||||||
|
if (ev.state==='connected') {
|
||||||
async init() {
|
let res = await this.bus.ack()
|
||||||
let res = await super.init()
|
// console.log('bus address ack was', res.ack)
|
||||||
if (res.errors) return {error: res.errors, msg:'socket initialization', }
|
|
||||||
res = await this.bus.ack()
|
|
||||||
let socket = this.getSocket('bus').opts
|
let socket = this.getSocket('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, 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)}`}
|
let err ={level:'fatal', res:res, socket:socket, method:'i2c-device', line:37, connection:connection, address:this.address, msg:`no bus or device on bus at address ${this.address}=0x${this.address.toString(16)}`}
|
||||||
log.error(err)
|
this.emit('log', err)
|
||||||
return err
|
} else this.emit('ready:i2c',{bus:socket, connection:connection})
|
||||||
}
|
}
|
||||||
return res
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO enable mux board channel set
|
// TODO enable mux board channel set
|
||||||
|
|
Loading…
Reference in New Issue