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 = {} class MCP230XX extends Device { constructor(opts) { super(opts) 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) 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({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)}` } await this.commands.pin.cfg({pins:'all'}) //pins are outputs by default } } // end of MCP230XX Class export default MCP230XX