def test_poll_int_async(self): device = MCP23017(1, 0x20) def f_1(pin): print("{} Interrupt on pin {}".format(f_1.c, pin)) f_1.c += 1 pin = "A_0" device.set_pin_dir(pin, 1) device.set_pin_intcon(pin, 1) device.set_pin_def_val(pin, 0) device.set_pin_int(pin, 1) device.set_pin_debounce(pin, 200) f_1.c = 0 device.set_int_handl_func(pin, f_1, pin) def f(pin): print("{} Interrupt on pin {}".format(f.c, pin)) f.c += 1 pin = "A_1" device.set_pin_dir(pin, 1) device.set_pin_intcon(pin, 1) device.set_pin_def_val(pin, 0) device.set_pin_int(pin, 1) device.set_pin_debounce(pin, 200) f.c = 0 device.set_int_handl_func(pin, f, pin) device.poll_int_async(['A_0', 'A_1']) time.sleep(5) device.poll_int_async(['A_0', 'A_1']) device.stop_poll_int_async()
def test_read_write(self): device = MCP23017(1, 0x20) device.set_pin_dir("A_0", 0) device.write("A_0", 1) self.assertEqual(device.read("A_0"), 1, "Should be 1") device.write("A_0", 0) self.assertEqual(device.read("A_0"), 0, "Should be 0")
def test_set_pin_pull_up(self): device = MCP23017(1, 0x20) device.set_pin_pull_up("A_0", 0) device.set_pin_pull_up("A_1", 0) device.set_pin_pull_up("B_5", 1) self.assertEqual(device.get_pin_pull_up("A_0"), 0, "Should be 0") self.assertEqual(device.get_pin_pull_up("A_1"), 0, "Should be 0") self.assertEqual(device.get_pin_pull_up("B_5"), 1, "Should be 1")
def test_set_pin_dir(self): device = MCP23017(1, 0x20) device.set_pin_dir("A_0", 0) device.set_pin_dir("A_1", 0) device.set_pin_dir("B_5", 0) self.assertEqual(device.get_pin_dir("A_0"), 0, "Should be 0") self.assertEqual(device.get_pin_dir("A_1"), 0, "Should be 0") self.assertEqual(device.get_pin_dir("B_5"), 0, "Should be 0")
def test_wait_for_edge(self): device = MCP23017(1, 0x20) pin = "A_0" device.set_pin_dir(pin, 1) device.set_pin_intcon(pin, 1) device.set_pin_def_val(pin, 0) val = device.wait_pin_for_edge(pin) self.assertEqual(val, 1, "Should be 1") val = device.wait_pin_for_edge(pin, timeout=2000) self.assertEqual(val, 0, "Should be 0")
def test_set_bank(self): device = MCP23017(1, 0x20) device.hardware_interfaces[device._i2c].write(device._address, device.IODIRB, 100) d = device.hardware_interfaces[device._i2c].read( device._address, device.IODIRB) self.assertEqual(device.IODIRB, 0x01, "Should be {}".format(0x01)) self.assertEqual(d, 100, "Should be {}".format(100)) device.set_bank(1) d = device.hardware_interfaces[device._i2c].read( device._address, device.IODIRB) self.assertEqual(device.IODIRB, 0x10, "Should be {}".format(0x10)) self.assertEqual(d, 100, "Should be {}".format(100))
def test_set_intpol(self): device = MCP23017(1, 0x20) device.set_intpol(0) self.assertEqual(device.get_intpol(), 0, "Should be 0") device.set_intpol(1) self.assertEqual(device.get_intpol(), 1, "Should be 1")
def test_set_bank(self): device = MCP23017(1, 0x20) device.set_bank(0) self.assertEqual(device.get_bank(), 0, "Should be 0")