From b987c446a4d23930388ca71cf4224ffb50ecec0f Mon Sep 17 00:00:00 2001 From: David Kebler Date: Mon, 11 Mar 2019 14:52:22 -0700 Subject: [PATCH] 0.1.22 fix chip config bug for 23008, for interrupt find packet pass on all props from interrupt. --- package.json | 2 +- src/commands.js | 6 +++--- src/mcp230xx.js | 5 +++-- src/mcp230xxi.js | 7 +++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 309f692..d472ebd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@uci/mcp", "main": "src", - "version": "0.1.21", + "version": "0.1.22", "description": "Classes and Helper Functions for using the MCP chip on I2C Bus", "scripts": { "relays": "node -r esm examples/relays", diff --git a/src/commands.js b/src/commands.js index 1343197..14d471a 100644 --- a/src/commands.js +++ b/src/commands.js @@ -2,7 +2,7 @@ import * as _ from '@uci-utils/byte' import { CHIP, PIN } from './config' import logger from '@uci-utils/logger' -let log = {file:'/src/commands.js', package:'@uci/mcp'} +let log = logger({file:'/src/commands.js', package:'@uci/mcp'}) // TODO add uci debug logging @@ -30,7 +30,7 @@ export default { if (bus.error) return bus bus = await this.bus.read(0x05) if (bus.error) return bus - if (!this.chip17) bus.response = bus.response - 127 + if (!this.chip17) bus.response = bus.response + 128 let res = _.byteFormat(bus.response,{in:'DEC',out:'STR'}) if (res !== setting.val) return { cmd:'reply', error:`chip configuration failed ${res} != ${setting.val} (${cfg})`} return { cmd:'reply', response:res } @@ -50,7 +50,7 @@ export default { else cfg = PIN.cfgset[packet.cfg] for(let name of Object.keys(PIN.setting)) { let op = cfg[name] ? 'on' : 'off' - console.log({msg:'setting pin register', operation:op, registerName:name, resgisterNum:PIN.setting[name]}) + log.debug({msg:'setting pin register', operation:op, registerName:name, resgisterNum:PIN.setting[name]}) let busreply = await this.pin._state(packet,op,PIN.setting[name]) if (busreply.error) return busreply reply.status[name] = busreply.status diff --git a/src/mcp230xx.js b/src/mcp230xx.js index f11260e..cf35e37 100644 --- a/src/mcp230xx.js +++ b/src/mcp230xx.js @@ -25,9 +25,10 @@ class MCP230XX extends Device { async init() { await super.init() let res = await this.chipcfg({cfg:this.chipCfg}) - log.fatal({msg:'unable to configure mcp chip',cfg:this.chipCfg, address:this.address}) - if (res.error) + 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)}` + } } } // end of MCP230XX Class diff --git a/src/mcp230xxi.js b/src/mcp230xxi.js index 23ab2a4..ebbe07c 100644 --- a/src/mcp230xxi.js +++ b/src/mcp230xxi.js @@ -127,8 +127,6 @@ const ipincommands = { }, // given a gpio interrupt then push a packet with cmd: 'pin.interrupt.find' and pin: the gpio pin number find: async function(inter) { - // inter is a UCI packet - if (this.ready) { // protects tripped interrupt before it's fully initialized, or interrupt requests arriving before porcessing is complete this.ready = false @@ -145,8 +143,9 @@ const ipincommands = { // avoid bad interrupt (i.e. no pin caused interrupt) res.state = (await this.pin.status(packet)).status.pins[0][1] res.port = packet.port - res.count = inter.count - res.inter = inter.pin + res.ipin = inter.pin + delete inter.cmd; delete inter._header; delete inter.pin + Object.assign(res,inter) delete res.status this.emit('interrupt', res) log.debug({msg:'found pin now resetting mcp port interrupt', response:res})