0.1.37 Added listener for read:i2c which call the chip config function for at least the default configuration
can register custom function to also call emits ready:mcp if chip is configured correctly emits log eventsmaster
parent
d3f905e86c
commit
9650698683
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@uci/mcp",
|
||||
"main": "src",
|
||||
"version": "0.1.36",
|
||||
"version": "0.1.37",
|
||||
"description": "Classes and Helper Functions for using the MCP chip on I2C Bus",
|
||||
"scripts": {
|
||||
"relays": "node -r esm examples/relays",
|
||||
|
|
|
@ -16,21 +16,31 @@ class MCP230XX extends Device {
|
|||
})
|
||||
this.chip17 = opts.chip17
|
||||
this.chipCfg = opts.chipCfg || 'default'
|
||||
// this._configured = false
|
||||
this.commands = this.bindFuncs(commands)
|
||||
this.addNamespace('commands', 's') // allow access to commands via socket/server
|
||||
// this._pin = this.commands.pin // add a simplier reference for local access
|
||||
// this._chipcfg = this.commands.chip.cfg // add a simplier reference for local access
|
||||
this.once('ready:i2c', () =>{
|
||||
this.configure()
|
||||
if (this._ready) this._ready.call(this)
|
||||
})
|
||||
}
|
||||
|
||||
async init() {
|
||||
await super.init()
|
||||
async registerReadyFunc(func) {
|
||||
this._ready = func
|
||||
}
|
||||
|
||||
async configure() {
|
||||
let res = await this.commands.chip.cfg({cfg:this.chipCfg})
|
||||
if (res.error) {
|
||||
log.fatal({method:'init', line:82, msg:'unable to configure mcp chip', error:res.error, cfg:this.chipCfg, address:this.address})
|
||||
throw `${res.error} at address ${this.address}/${this.address.toString(16)}`
|
||||
let err={level:'fatal', msg:'unable to configure mcp chip', error:res.error, cfg:this.chipCfg, address:this.address}
|
||||
log.fatal(err)
|
||||
this.emit('status', err)
|
||||
} else {
|
||||
this.emit('status', {level:'info', msg:'mcp chip was properly configured', cfg:this.chipCfg})
|
||||
this.emit('ready:mcp')
|
||||
}
|
||||
await this.commands.pin.cfg({pins:'all'}) //pins are outputs by default
|
||||
if (this.chip17) await this.commands.pin.cfg({pins:'all', port:'B'})
|
||||
}
|
||||
} // end of MCP230XX Class
|
||||
|
||||
|
|
Loading…
Reference in New Issue