parent
cb1977a8ea
commit
31c15c2230
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Reference in New Issue