working interrupt with both ports
parent
e333378c36
commit
39b0e43d56
|
@ -10,6 +10,7 @@ class MCP23008 extends Device {
|
||||||
// this.registers = registers // load in register database
|
// this.registers = registers // load in register database
|
||||||
this.ports = {}
|
this.ports = {}
|
||||||
opts.portID = 'A'
|
opts.portID = 'A'
|
||||||
|
opts.pids = opts.pids ? opts.pids : opts.pidsA
|
||||||
this.ports.A = new Port(opts)
|
this.ports.A = new Port(opts)
|
||||||
this.chip_config = opts.chip_config // TODO allow opts.chip_config to be a byte instead of a string pointer
|
this.chip_config = opts.chip_config // TODO allow opts.chip_config to be a byte instead of a string pointer
|
||||||
this.ports.A.interrupt = opts.interruptA ? opts.interruptA : opts.interrupt
|
this.ports.A.interrupt = opts.interruptA ? opts.interruptA : opts.interrupt
|
||||||
|
@ -34,6 +35,7 @@ class MCP23008 extends Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
pin(id) { return this.ports.A.pin(id) } // get a reference to a particular pin's object
|
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) }
|
||||||
|
|
||||||
inter(port = 'A') {
|
inter(port = 'A') {
|
||||||
return this.ports[port].interrupt
|
return this.ports[port].interrupt
|
||||||
|
@ -61,7 +63,7 @@ class MCP23008 extends Device {
|
||||||
let pin = pins[i]
|
let pin = pins[i]
|
||||||
byte += pin.address.toFmt('DEC') * pin.cfg[setting]
|
byte += pin.address.toFmt('DEC') * pin.cfg[setting]
|
||||||
}
|
}
|
||||||
// console.log(`port ${port} - setting ${setting} - reg ${reg} - byte ${byte}`)
|
//console.log(`port ${port} - setting ${setting} - reg ${reg} - byte ${byte}`)
|
||||||
jobs.push(
|
jobs.push(
|
||||||
super.write(reg, byte).then(() => Promise.resolve(`config: wrote ${byte} to register ${reg} on port ${port}`))
|
super.write(reg, byte).then(() => Promise.resolve(`config: wrote ${byte} to register ${reg} on port ${port}`))
|
||||||
)
|
)
|
||||||
|
@ -71,16 +73,14 @@ class MCP23008 extends Device {
|
||||||
} // end writePinsCfg
|
} // end writePinsCfg
|
||||||
|
|
||||||
// reads all pins in all ports
|
// reads all pins in all ports
|
||||||
readPins(cmd, fmt) {
|
readPins(cmd = 'gpio', fmt) {
|
||||||
let jobs = []
|
let jobs = []
|
||||||
cmd = cmd ? cmd : 'gpio'
|
|
||||||
let reg = registers.pin_cmd[cmd]
|
let reg = registers.pin_cmd[cmd]
|
||||||
for (let port in this.ports) {
|
for (let port in this.ports) {
|
||||||
jobs.push(() => super.read(reg))
|
jobs.push(() => super.read(reg))
|
||||||
reg += 0x10
|
reg += 0x10
|
||||||
}
|
}
|
||||||
return _u.pSeries(jobs)
|
return _u.pSeries(jobs)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pinRead(id, opts) {
|
pinRead(id, opts) {
|
||||||
|
@ -94,22 +94,21 @@ class MCP23008 extends Device {
|
||||||
reject('no pin found for given id')
|
reject('no pin found for given id')
|
||||||
}
|
}
|
||||||
if (gpio.port === 'B') {
|
if (gpio.port === 'B') {
|
||||||
reg = reg + 16
|
reg = reg + 0x10
|
||||||
}
|
}
|
||||||
// call device class read (response is always decimal)
|
|
||||||
console.log('port - reg', gpio.port, reg)
|
console.log('port - reg', gpio.port, reg)
|
||||||
return mcpdev.read(reg).then(resp => {
|
return mcpdev.read(reg).then(resp => {
|
||||||
resp = _u.byteFormat(resp, { in: 'DEC',
|
resp = _u.byteFormat(resp, { in: 'DEC',
|
||||||
out: 'ARY'
|
out: 'ARY'
|
||||||
})
|
})
|
||||||
let addr = gpio.pin.address.toFmt('ARY')
|
let addr = gpio.adr.toFmt('ARY')
|
||||||
console.log(addr)
|
console.log(addr)
|
||||||
console.log(resp)
|
console.log(resp)
|
||||||
resolve(_u.sum(_u.and(addr, resp))) // resolve 1 or 0
|
resolve(_u.sum(_u.and(addr, resp))) // resolve 1 or 0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.then(state => console.log(`pin state ${state}`))
|
// .then(state => console.log(`pin state ${state}`))
|
||||||
.catch(err => console.log(err)) // end Promise
|
// .catch(err => console.log(err)) // end Promise
|
||||||
} // end pinRead
|
} // end pinRead
|
||||||
|
|
||||||
pinWrite(id, opts) {
|
pinWrite(id, opts) {
|
||||||
|
@ -148,6 +147,7 @@ class MCP23017 extends MCP23008 {
|
||||||
super(busObj, i2cAddress, opts)
|
super(busObj, i2cAddress, opts)
|
||||||
// add a second port
|
// add a second port
|
||||||
opts.portID = 'B'
|
opts.portID = 'B'
|
||||||
|
opts.pids = opts.pidsB
|
||||||
this.ports.B = new Port(opts)
|
this.ports.B = new Port(opts)
|
||||||
this.ports.B.interrupt = opts.interruptB ? opts.interruptB : opts.interrupt
|
this.ports.B.interrupt = opts.interruptB ? opts.interruptB : opts.interrupt
|
||||||
}
|
}
|
||||||
|
@ -159,6 +159,13 @@ class MCP23017 extends MCP23008 {
|
||||||
return this.ports[port].pin(id)
|
return this.ports[port].pin(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid(address, port) {
|
||||||
|
if (!port) {
|
||||||
|
return this.ports.A.pid(address) ? this.ports.A.pid(address) : this.ports.B.pid(address)
|
||||||
|
}
|
||||||
|
return this.ports[port].pid(address)
|
||||||
|
}
|
||||||
|
|
||||||
} // end MCP23017 Class
|
} // end MCP23017 Class
|
||||||
module.exports.MCP23017 = MCP23017
|
module.exports.MCP23017 = MCP23017
|
||||||
|
|
||||||
|
@ -175,7 +182,7 @@ let chip_config = {
|
||||||
// byte: ['NULL','INTPOL','ODR','HAEN','DISSLW','SEQOP','MIRROR','BANK'] // see page 18 of 23017 datasheet for 8 setting details
|
// byte: ['NULL','INTPOL','ODR','HAEN','DISSLW','SEQOP','MIRROR','BANK'] // see page 18 of 23017 datasheet for 8 setting details
|
||||||
cmd: 0x0A, // IOCON.BANK=0 (msb) at powerup so need to use 0x0A, if set to 1 then use
|
cmd: 0x0A, // IOCON.BANK=0 (msb) at powerup so need to use 0x0A, if set to 1 then use
|
||||||
default: {
|
default: {
|
||||||
val: '10100010', // Split Banks port A + 0x10 = Port B,(ignored by 23008), Sequential operation disabled, open drain int
|
val: '10100010', // Split Banks port A + 0x10 = Port B,(ignored by 23008), Sequential operation disabled, active high=pulldown
|
||||||
fmt: 'STR'
|
fmt: 'STR'
|
||||||
},
|
},
|
||||||
oneint: {
|
oneint: {
|
||||||
|
@ -184,13 +191,6 @@ let chip_config = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// function chipSetByte(setting = 'default') {
|
|
||||||
// setting = chip_config[setting]
|
|
||||||
// return _u.byteFormat(setting.val, { in: setting.fmt,
|
|
||||||
// out: 'DEC'
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
let registers = {
|
let registers = {
|
||||||
pin_config: {
|
pin_config: {
|
||||||
dir: 0,
|
dir: 0,
|
||||||
|
|
Loading…
Reference in New Issue