parent
cb1977a8ea
commit
31c15c2230
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@uci/mcp",
|
"name": "@uci/mcp",
|
||||||
"main": "src/mcp230xx-packet.mjs",
|
"main": "src",
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
"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": {
|
||||||
|
@ -28,6 +28,7 @@
|
||||||
"homepage": "https://github.com/uCOMmandIt/uci-mcp#readme",
|
"homepage": "https://github.com/uCOMmandIt/uci-mcp#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@uci/i2c-device": "^0.1.1",
|
"@uci/i2c-device": "^0.1.1",
|
||||||
|
"@uci/interrupt": "^0.1.1",
|
||||||
"@uci/logger": "0.0.1",
|
"@uci/logger": "0.0.1",
|
||||||
"@uci/utils": "^0.1.1"
|
"@uci/utils": "^0.1.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -100,21 +100,25 @@ export const pin = {
|
||||||
// will create packet to determine pin caused interrupt, packet will come from interrupt module
|
// will create packet to determine pin caused interrupt, packet will come from interrupt module
|
||||||
interrupt: {
|
interrupt: {
|
||||||
reset: async function (port) {
|
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))
|
return await this.bus.read(sreg(PIN.cmd.intcap,port))
|
||||||
},
|
},
|
||||||
find: async function (inter) {
|
find: async function (inter) {
|
||||||
console.log('lookup info on device and port for pin fired',inter.pin, inter.times)
|
// console.dir(inter)
|
||||||
let port = null
|
// console.log(inter.count,'th interrupt: pin fired',inter.pin, inter.port)
|
||||||
let packet = {pins:'all',reg:'intf', port:port}
|
let packet = {pins:'all',reg:'intf'}
|
||||||
|
packet.port = inter.port==='B' ? inter.port : 'A'
|
||||||
let res = await this.pin.status(packet)
|
let res = await this.pin.status(packet)
|
||||||
this.pin.interrupt.reset()
|
this.pin.interrupt.reset(packet.port)
|
||||||
let pin = _.byteFormat(res.status.port, { in: 'ARY', out: 'PLC' })[0]
|
if (!res.status) return {error:'no pin associated with interrupt'}
|
||||||
console.log('pin that caused the interrupt', pin)
|
let pin = _.byteFormat(res.status.port, { in: 'ARY', out: 'PLC' })
|
||||||
// found it now tell someone what relay(s) to fire
|
// console.log('pin and port that caused the interrupt', pin, packet.port)
|
||||||
res.pin = pin
|
res.pin = pin[0]
|
||||||
res.times = inter.times
|
res.port = packet.port
|
||||||
|
res.count = inter.count
|
||||||
res.inter = inter.pin
|
res.inter = inter.pin
|
||||||
|
delete res.status
|
||||||
|
this.emit('interrupt',res)
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
report: ()=>{}, // come here after determining which pin to report to requester
|
report: ()=>{}, // come here after determining which pin to report to requester
|
||||||
|
|
|
@ -41,13 +41,21 @@ export const PIN = {
|
||||||
usedef: 0, // if usedef = 0 defval not used
|
usedef: 0, // if usedef = 0 defval not used
|
||||||
defval: 0
|
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: {
|
momentary_switch: {
|
||||||
dir: 1, // 0 output,1 input
|
dir: 1, // 0 output,1 input
|
||||||
ivrt: 1, // for reading let 1 be zero and vice versa
|
ivrt: 1, // for reading let 1 be zero and vice versa
|
||||||
pullup: 1,
|
pullup: 1,
|
||||||
intr: 1, // if intr = 0 usedef,deval not used
|
intr: 1, // if intr = 0 usedef,deval not used
|
||||||
usedef: 1, // if usedef = 0 defval 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: {
|
cmd: {
|
||||||
|
|
Loading…
Reference in New Issue