From 31c15c2230a20f1b6863405b3b26b57fe946787c Mon Sep 17 00:00:00 2001 From: David Kebler Date: Fri, 2 Mar 2018 08:30:54 -0800 Subject: [PATCH] add no pullup input update interrupt processing add index to src/ --- package.json | 3 ++- src/commands.mjs | 24 ++++++++++++++---------- src/config.mjs | 10 +++++++++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 18f9d2e..7331f16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci/mcp", - "main": "src/mcp230xx-packet.mjs", + "main": "src", "version": "0.1.2", "description": "Classes and Helper Functions for using the MCP chip on I2C Bus", "scripts": { @@ -28,6 +28,7 @@ "homepage": "https://github.com/uCOMmandIt/uci-mcp#readme", "dependencies": { "@uci/i2c-device": "^0.1.1", + "@uci/interrupt": "^0.1.1", "@uci/logger": "0.0.1", "@uci/utils": "^0.1.1" }, diff --git a/src/commands.mjs b/src/commands.mjs index f5c923a..77beef2 100644 --- a/src/commands.mjs +++ b/src/commands.mjs @@ -100,21 +100,25 @@ export const pin = { // will create packet to determine pin caused interrupt, packet will come from interrupt module interrupt: { reset: async function (port) { - console.log('resetting interrupt for port', (port ? 'B' : 'A')) + // console.log('resetting interrupt for port',port || 'A') return await this.bus.read(sreg(PIN.cmd.intcap,port)) }, find: async function (inter) { - console.log('lookup info on device and port for pin fired',inter.pin, inter.times) - let port = null - let packet = {pins:'all',reg:'intf', port:port} + // console.dir(inter) + // console.log(inter.count,'th interrupt: pin fired',inter.pin, inter.port) + let packet = {pins:'all',reg:'intf'} + packet.port = inter.port==='B' ? inter.port : 'A' let res = await this.pin.status(packet) - this.pin.interrupt.reset() - let pin = _.byteFormat(res.status.port, { in: 'ARY', out: 'PLC' })[0] - console.log('pin that caused the interrupt', pin) - // found it now tell someone what relay(s) to fire - res.pin = pin - res.times = inter.times + this.pin.interrupt.reset(packet.port) + if (!res.status) return {error:'no pin associated with interrupt'} + let pin = _.byteFormat(res.status.port, { in: 'ARY', out: 'PLC' }) + // console.log('pin and port that caused the interrupt', pin, packet.port) + res.pin = pin[0] + res.port = packet.port + res.count = inter.count res.inter = inter.pin + delete res.status + this.emit('interrupt',res) return res }, report: ()=>{}, // come here after determining which pin to report to requester diff --git a/src/config.mjs b/src/config.mjs index fd98506..b5e9be0 100644 --- a/src/config.mjs +++ b/src/config.mjs @@ -41,13 +41,21 @@ export const PIN = { usedef: 0, // if usedef = 0 defval not used defval: 0 }, + toggle_switch_no_pullup: { + dir: 1, // 0 output,1 input + ivrt: 1, // for reading let 1 be zero and vice versa + pullup: 0, // use external pullup 5V with external resister! + intr: 1, // if intr = 0 usedef,deval not used + usedef: 0, // if usedef = 0 defval not used + defval: 0 + }, momentary_switch: { dir: 1, // 0 output,1 input ivrt: 1, // for reading let 1 be zero and vice versa pullup: 1, intr: 1, // if intr = 0 usedef,deval not used usedef: 1, // if usedef = 0 defval not used - defval: 1 + defval: 1 // only throw interrupt when switch closes (1 becasue ivrt is 1) } }, cmd: {