import { I2CDevice as Device, map, changed, isPlainObject, to, merge} from '@uci/i2c-device' 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.pinsCfg = opts.pinsCfg || this.chip17 ? [{port:'A', pins:'all'},{port:'B', pins:'all'}] : [{pins:'all'}] this.commands = this.bindFuncs(commands) this.addNamespace('commands', 's') // allow access to commands via socket/server if (opts.lport) this.registerSocket('mcp-t','s','t',{port:opts.lport}) if (opts.lpath) this.registerSocket('mcp-n','s','n',{path: opts.lpath}) this.ready.addObserver('mcp',this.ready.getObserver('i2c').pipe( map(async ready => { if (ready) { let res = await this.commands.chip.cfg({cfg:this.chipCfg}) if (!res.error) { let res = await this.commands.pin.cfgs({configs:this.pinsCfg}) return res.error? false :true } return false } return false }) )) } // end contructor } // end of MCP230XX Class export default MCP230XX export {MCP230XX, map, changed, isPlainObject, to, merge}