0.1.22 fix chip config bug for 23008, for interrupt find packet pass on all props from interrupt.
parent
be1787fa45
commit
b987c446a4
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/mcp",
|
"name": "@uci/mcp",
|
||||||
"main": "src",
|
"main": "src",
|
||||||
"version": "0.1.21",
|
"version": "0.1.22",
|
||||||
"description": "Classes and Helper Functions for using the MCP chip on I2C Bus",
|
"description": "Classes and Helper Functions for using the MCP chip on I2C Bus",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"relays": "node -r esm examples/relays",
|
"relays": "node -r esm examples/relays",
|
||||||
|
|
|
@ -2,7 +2,7 @@ import * as _ from '@uci-utils/byte'
|
||||||
import { CHIP, PIN } from './config'
|
import { CHIP, PIN } from './config'
|
||||||
import logger from '@uci-utils/logger'
|
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
|
// TODO add uci debug logging
|
||||||
|
@ -30,7 +30,7 @@ export default {
|
||||||
if (bus.error) return bus
|
if (bus.error) return bus
|
||||||
bus = await this.bus.read(0x05)
|
bus = await this.bus.read(0x05)
|
||||||
if (bus.error) return bus
|
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'})
|
let res = _.byteFormat(bus.response,{in:'DEC',out:'STR'})
|
||||||
if (res !== setting.val) return { cmd:'reply', error:`chip configuration failed ${res} != ${setting.val} (${cfg})`}
|
if (res !== setting.val) return { cmd:'reply', error:`chip configuration failed ${res} != ${setting.val} (${cfg})`}
|
||||||
return { cmd:'reply', response:res }
|
return { cmd:'reply', response:res }
|
||||||
|
@ -50,7 +50,7 @@ export default {
|
||||||
else cfg = PIN.cfgset[packet.cfg]
|
else cfg = PIN.cfgset[packet.cfg]
|
||||||
for(let name of Object.keys(PIN.setting)) {
|
for(let name of Object.keys(PIN.setting)) {
|
||||||
let op = cfg[name] ? 'on' : 'off'
|
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])
|
let busreply = await this.pin._state(packet,op,PIN.setting[name])
|
||||||
if (busreply.error) return busreply
|
if (busreply.error) return busreply
|
||||||
reply.status[name] = busreply.status
|
reply.status[name] = busreply.status
|
||||||
|
|
|
@ -25,9 +25,10 @@ class MCP230XX extends Device {
|
||||||
async init() {
|
async init() {
|
||||||
await super.init()
|
await super.init()
|
||||||
let res = await this.chipcfg({cfg:this.chipCfg})
|
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)}`
|
throw `${res.error} at address ${this.address}/${this.address.toString(16)}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // end of MCP230XX Class
|
} // end of MCP230XX Class
|
||||||
|
|
||||||
|
|
|
@ -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
|
// given a gpio interrupt then push a packet with cmd: 'pin.interrupt.find' and pin: the gpio pin number
|
||||||
find: async function(inter) {
|
find: async function(inter) {
|
||||||
// inter is a UCI packet
|
|
||||||
|
|
||||||
if (this.ready) {
|
if (this.ready) {
|
||||||
// protects tripped interrupt before it's fully initialized, or interrupt requests arriving before porcessing is complete
|
// protects tripped interrupt before it's fully initialized, or interrupt requests arriving before porcessing is complete
|
||||||
this.ready = false
|
this.ready = false
|
||||||
|
@ -145,8 +143,9 @@ const ipincommands = {
|
||||||
// avoid bad interrupt (i.e. no pin caused interrupt)
|
// avoid bad interrupt (i.e. no pin caused interrupt)
|
||||||
res.state = (await this.pin.status(packet)).status.pins[0][1]
|
res.state = (await this.pin.status(packet)).status.pins[0][1]
|
||||||
res.port = packet.port
|
res.port = packet.port
|
||||||
res.count = inter.count
|
res.ipin = inter.pin
|
||||||
res.inter = inter.pin
|
delete inter.cmd; delete inter._header; delete inter.pin
|
||||||
|
Object.assign(res,inter)
|
||||||
delete res.status
|
delete res.status
|
||||||
this.emit('interrupt', res)
|
this.emit('interrupt', res)
|
||||||
log.debug({msg:'found pin now resetting mcp port interrupt', response:res})
|
log.debug({msg:'found pin now resetting mcp port interrupt', response:res})
|
||||||
|
|
Loading…
Reference in New Issue