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.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)}` } 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 export default MCP230XX