34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
import { I2CDevice as Device, map, changed, isPlainObject, to, merge} from '@uci/i2c-device'
|
|
import commands from './commands'
|
|
|
|
class MCP230XX extends Device {
|
|
constructor(opts) {
|
|
super(opts)
|
|
|
|
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
|
|
|
|
this.ready.addObserver('mcp:configure',this.ready.getObserver('i2c:device:ack').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}
|