uci-mcp/src/mcp230xx.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

import Device from '@uci/i2c-device'
// import Device from '../../uci-i2c-device/src/device-packet'
import commands from './commands'
import logger from '@uci-utils/logger'
let log = {}
2019-01-01 19:45:25 -08:00
class MCP230XX extends Device {
constructor(opts) {
super(opts)
2019-01-01 19:45:25 -08:00
log = logger({
file: 'src/mcp230xx.js',
class: 'MCP230XX',
name: 'mcp',
id: this.id
})
this.chip17 = opts.chip17
this.chipCfg = opts.chipCfg || 'default'
this.commands = this.bindFuncs(commands)
2019-01-01 19:45:25 -08:00
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
}
2019-01-01 19:45:25 -08:00
async init() {
await super.init()
let res = await this.chipcfg({cfg:this.chipCfg})
if (res.error) {
log.fatal({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)}`
}
}
} // end of MCP230XX Class
2019-01-01 19:45:25 -08:00
export default MCP230XX