2018-02-17 18:25:27 -08:00
|
|
|
import Device from '@uci/i2c-device'
|
|
|
|
// import Device from '../../uci-i2c-device/src/device-packet'
|
2018-07-31 10:29:11 -07:00
|
|
|
import commands from './commands'
|
2018-02-08 09:19:46 -08:00
|
|
|
|
2018-02-17 18:25:27 -08:00
|
|
|
import logger from '@uci/logger'
|
2018-02-08 09:19:46 -08:00
|
|
|
let log = {}
|
|
|
|
|
2019-01-01 19:45:25 -08:00
|
|
|
class MCP230XX extends Device {
|
2018-02-08 09:19:46 -08:00
|
|
|
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
|
|
|
|
})
|
2018-02-13 18:18:03 -08:00
|
|
|
this.chip17 = opts.chip17
|
2018-07-31 10:29:11 -07:00
|
|
|
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
|
2018-07-31 10:29:11 -07:00
|
|
|
this.chipcfg = this.commands.chip.cfg // add a simplier reference for local access
|
2018-02-08 09:19:46 -08:00
|
|
|
}
|
|
|
|
|
2019-01-01 19:45:25 -08:00
|
|
|
async init() {
|
2018-02-08 09:19:46 -08:00
|
|
|
await super.init()
|
2018-07-31 10:29:11 -07:00
|
|
|
let res = await this.chipcfg({})
|
2019-01-01 19:45:25 -08:00
|
|
|
let cfg = this.chip17 ? '10100010' : '00100010'
|
|
|
|
if (res.response !== cfg)
|
|
|
|
throw `could not configure mcp chip at ${
|
|
|
|
this.address
|
|
|
|
}=0x${this.address.toString(16)}`
|
2018-02-08 09:19:46 -08:00
|
|
|
}
|
|
|
|
} // end of MCP230XX Class
|
2019-01-01 19:45:25 -08:00
|
|
|
|
|
|
|
export default MCP230XX
|