uci-mcp/src/mcp230xx-packet.mjs

37 lines
1.0 KiB
JavaScript

import Device from '@uci/i2c-device'
// import Device from '../../uci-i2c-device/src/device-packet'
import { pin, chip } from './commands'
// import logger from '../../uci-logger/src/logger'
import logger from '@uci/logger'
let log = {}
const LOG_OPTS = (id) => {
return {
repo:'uci-mcp',
npm:'@uci/mcp',
file:'src/mcp230xx-packet.mjs',
class:'MCP230XX',
id:id,
instance_created:new Date().getTime()
}}
export default class MCP230XX extends Device {
constructor(opts) {
super(opts)
log = logger.child(LOG_OPTS(this.id))
if (!opts.address) log.fatal({opts:opts},'no i2c bus address supplied' )
this.address = opts.address
this.chip17 = opts.chip17
this.pin = this.bindFuncs(pin)
this.chip = this.bindFuncs(chip)
}
async init(){
await super.init()
let res = await this.chip.cfg({})
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