'use strict' const expect = require('chai').expect, i2c = require('uci-i2c'), _u = require('uci-utils') let bus1 = new i2c.Bus(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, { 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) // expect(mcp17.pin(8).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', 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)) }); 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, ALLPINS = 0x40, NOPINS = 0x00 mcp8.write(DIR, 0x00).then(() => mcp8.write(RW, ALLPINS).then(() => mcp8.read(RW, ALLPINS).then((resp) => { console.log('relays on', resp) }) ) ) }); });