uci-mcp/src/mcp230xx.js

27 lines
954 B
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/logger'
let log = {}
export default class MCP230XX extends Device {
constructor(opts) {
super(opts)
2018-05-16 07:19:03 -07:00
log = logger({file:'src/mcp230xx.js',class:'MCP230XX',name:'mcp',id:this.id})
this.chip17 = opts.chip17
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
}
async init(){
await super.init()
let res = await this.chipcfg({})
let cfg = this.chip17 ?'10100010':'00100010'
if (res.response !==cfg ) throw `could not configure mcp chip at ${this.address}=0x${this.address.toString(16)}`
}
} // end of MCP230XX Class