0.1.22 fix chip config bug for 23008, for interrupt find packet pass on all props from interrupt.

master
David Kebler 2019-03-11 14:52:22 -07:00
parent be1787fa45
commit b987c446a4
4 changed files with 10 additions and 10 deletions

View File

@ -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",

View File

@ -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

View File

@ -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

View File

@ -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})