uci-mcp/test/gpio.test.js.off

64 lines
2.1 KiB
Plaintext
Raw Normal View History

'use strict'
const expect = require('chai').expect,
gpio = require('../lib/gpio')
let pin = new gpio.Pin(128)
describe('GPIO Pin Class - ', function () {
it('Verify getter and setter ', function () {
expect(pin.cfg, 'config getter failed').to.deep.equal(gpio.configs('output'))
expect(pin.cfg.intr, 'config get subkeys failed').to.equal(0)
pin.cfg = gpio.configs('toggle_switch')
expect(pin.cfg, 'config setter failed').to.deep.equal(gpio.configs('toggle_switch'))
expect(pin.adr.value, 'pin address getter failed').to.equal(128)
expect(pin.adr.fmt, 'pin address format getter failed').to.equal('DEC')
expect(pin.id, 'pin id default from address failed').to.equal(8)
pin.adr = {
'val': 20,
'fmt': 'HEX'
}
expect(pin.adr.value, 'pin address setter failed').to.equal(20)
expect(pin.adr.fmt, 'pin address format setter failed').to.equal('HEX')
pin.id = 2
expect(pin.id, 'pin id setter failed').to.equal(2)
pin.adr = 32
expect(pin.adr.value, 'pin address setter failed').to.equal(32)
expect(pin.adr.fmt, 'pin address format setter failed').to.equal('DEC')
})
it('should merge partial config change', function () {
pin.cfg = gpio.configs('output')
pin.cfg = { dir: 15 }
let merged = { dir: 15, ivrt: 0, pullup: 0, intr: 0, usedef: 0, defval: 0 }
expect(pin.cfg, 'single config value change failed').to.deep.equal(merged)
})
// TODO waiting on new clone function
// it('should clone a new Pin with change of address', function () {
// expect(newPin.adr.val, "clone pin failed").to.equal(4)
// expect(newPin.cfg.dir, "clone pin failed").to.equal(15)
// })
})
let port = new gpio.Port({ portID: 'A1' })
describe('GPIO Port Class - ', function () {
it('should set the pin ids and addresses by default', function () {
expect(port.pin(7).id, 'a pin\'s id failed').to.equal(7)
expect(port.pin(7).adr.value, 'id and address don\'t match').to.equal(64)
})
let port2 = new gpio.Port({ reverse: true })
it('reversing pin number order should work', function () {
expect(port2.pin(2).adr.value, 'reversing pin numbers failed').to.equal(64)
})
//TODO add a pin map for the port so pins could be arranged in any order
})