mcp test edits
parent
4dca2803ac
commit
34b951f528
|
@ -2,58 +2,80 @@
|
|||
|
||||
const expect = require('chai').expect,
|
||||
i2c = require('uci-i2c'),
|
||||
_u = require('uci-utils')
|
||||
_u = require('uci-utils'),
|
||||
MCP = require('../lib/mcp23008-17')
|
||||
|
||||
let bus1 = new i2c.Bus(1)
|
||||
|
||||
const config_sets = {
|
||||
output: {
|
||||
dir: 0, // 0 output,1 input
|
||||
ivrt: 0,
|
||||
pullup: 0,
|
||||
intr: 0, // if intr = 0 usedef,deval not used
|
||||
usedef: 0, // if usedef = 0 defval not used
|
||||
defval: 0
|
||||
},
|
||||
toggle_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: 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
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(bus1)
|
||||
// bus1.scan((devs)=>{console.log('devices: ', devs)})
|
||||
//bus1.scan().then(results=>console.log(results))
|
||||
|
||||
describe('I2C Device Classes - ', function () {
|
||||
|
||||
let mcp17 = new i2c.MCP.MCP23017(bus1, 0x20, {
|
||||
let mcp17 = new MCP.MCP23017(bus1, 0x20, {
|
||||
pin_cfg_default: 'momentary_switch',
|
||||
name: 'switches 1-16'
|
||||
})
|
||||
|
||||
describe('MCP23017 Class - ', function () {
|
||||
|
||||
it('can set and get a single pin config', function () {
|
||||
expect(mcp17.pin(8).cfg.dir, "pin address getter failed").to.equal(0)
|
||||
mcp17.portA.pin(8).cfg.dir = 1
|
||||
console.log(mcp17.pin(8).cfg.dir)
|
||||
|
||||
it('can set and get a single pin config on both ports', function () {
|
||||
expect(mcp17.pin(1).cfg, "pin configs getter failed").to.deep.equal(config_sets.momentary_switch)
|
||||
// expect(mcp17.pin(8).cfg.dir, "pin config getter failed").to.equal(0)
|
||||
// mcp17.pin(8).cfg.dir = 1
|
||||
// expect(mcp17.pin(8).config.dir, "pin address setter failed").to.equal(1)
|
||||
// expect(mcp17.pin(8, 'B').cfg.dir, "pin address getter port B failed").to.equal(0)
|
||||
// mcp17.pin(8, 'B').cfg.dir = 1
|
||||
// expect(mcp17.pin(8, 'B').config.dir, "pin address setter failed").to.equal(1)
|
||||
});
|
||||
|
||||
it('a pin can access device methods when attached to a device', function () {
|
||||
expect(mcp17.portA.pin(8).device.address.val).to.equal(mcp17.address.val)
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
let mcp8 = new i2c.MCP.MCP23008(bus1, 0x21, {
|
||||
cfgDefault: 'output',
|
||||
let mcp8 = new MCP.MCP23008(bus1, 0x21, {
|
||||
pin_cfg_default: 'toggle_switch',
|
||||
name: 'relay 1-8'
|
||||
})
|
||||
|
||||
describe('MCP23008 Class - ', function () {
|
||||
|
||||
mcp8.pin(8).dir = 1
|
||||
it('can set and get a single pin config', function () {
|
||||
expect(mcp8.port.pin(8).dir, "pin address getter failed").to.equal(1)
|
||||
mcp8.port.pin(8).dir = 0
|
||||
expect(mcp8.port.pin(8).dir, "pin address getter failed").to.equal(0)
|
||||
expect(mcp8.port.pin(8).itr, "pin address getter failed").to.equal(Boolean(0))
|
||||
expect(mcp8.pin(1).cfg, "pin configs getter failed").to.deep.equal(config_sets.toggle_switch)
|
||||
// expect(mcp8.pin(8).cfg.dir, "pin address getter failed").to.equal(1)
|
||||
// expect(mcp8.pin(8).cfg.ivrt, "pin address getter failed").to.equal(1)
|
||||
// expect(mcp8.pin(8).cfg.usedef, "pin address getter failed").to.equal(0)
|
||||
// mcp8.pin(8).cfg.dir = 0
|
||||
// expect(mcp8.pin(8).cfg.dir, "pin address setter failed").to.equal(0)
|
||||
// expect(mcp8.pin(8).ivrt, "pin address getter failed").to.equal(1)
|
||||
});
|
||||
|
||||
it('a pin can access device methods when attached to a device', function () {
|
||||
expect(mcp17.portA.pin(8).device.address.val).to.equal(mcp17.address.val)
|
||||
})
|
||||
|
||||
// console.log(bus1.bus.writeI2cBlock_p)
|
||||
// mcp8.func()
|
||||
|
||||
const ADDR = 0x21,
|
||||
DIR = 0x00,
|
||||
RW = 0x09,
|
||||
|
|
Loading…
Reference in New Issue