add start method fix pinRead for port B
parent
3f0d0ad407
commit
ecb455e7ea
|
@ -36,9 +36,34 @@ class MCP23008 extends Device {
|
|||
return _u.pSeries(jobs)
|
||||
}
|
||||
|
||||
start() {
|
||||
let starts = []
|
||||
for (let port in this.ports) {
|
||||
if (this.inter(port)) {
|
||||
starts.push(
|
||||
this.read(portReg(0x08, port))
|
||||
.then(_u.pDelay(100)) // give enough time for mcp to reset its interupt
|
||||
.then(() => {
|
||||
return this.inter(port).start()
|
||||
.then(() => {
|
||||
return Promise.resolve(`interrupt port ${port} started`)
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
return Promise.all(starts)
|
||||
}
|
||||
|
||||
pin(id) { return this.ports.A.pin(id) } // get a reference to a particular pin's object
|
||||
|
||||
pid(address) { return this.ports.A.pid(address) } // return pin id for a given address on a port
|
||||
|
||||
portByPin(id) {
|
||||
if (this.ports.A.pin(id)) { return 'A' }
|
||||
return false
|
||||
}
|
||||
|
||||
inter(port = 'A') {
|
||||
return this.ports[port].interrupt
|
||||
}
|
||||
|
@ -95,11 +120,9 @@ class MCP23008 extends Device {
|
|||
if (!gpio) {
|
||||
reject('no pin found for given id')
|
||||
}
|
||||
if (gpio.port === 'B') {
|
||||
reg = reg + 0x10
|
||||
}
|
||||
// console.log('port - reg', gpio.port, reg)
|
||||
return mcpdev.read(reg).then(resp => {
|
||||
console.log('id of fired pin', id)
|
||||
console.log('port of fired pin', mcpdev.portByPin(id))
|
||||
return mcpdev.read(portReg(reg, mcpdev.portByPin(id))).then(resp => {
|
||||
resp = _u.byteFormat(resp, { in: 'DEC',
|
||||
out: 'ARY'
|
||||
})
|
||||
|
@ -168,9 +191,20 @@ class MCP23017 extends MCP23008 {
|
|||
return this.ports[port].pid(address)
|
||||
}
|
||||
|
||||
portByPin(id) {
|
||||
console.log('pin id in portbypin', id)
|
||||
if (this.ports.A.pin(id)) { return 'A' }
|
||||
if (this.ports.B.pin(id)) { return 'B' }
|
||||
return false
|
||||
}
|
||||
|
||||
} // end MCP23017 Class
|
||||
module.exports.MCP23017 = MCP23017
|
||||
|
||||
function portReg(reg, port) {
|
||||
if (port === 'B') { return reg += 0x10 } else { return reg }
|
||||
}
|
||||
|
||||
/* ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
|
||||
* or see MCP23017.pdf and MCP 23008.pdf in /docs
|
||||
* see table 1.5 and details in sections 1.6.x following
|
||||
|
|
Loading…
Reference in New Issue