def test_setClock(self): tester = BbTester() banger = bitbang.BitBanger(CLK_PIN, MISO_PIN, MOSI_PIN, ENABLE_PIN, tester) banger.setClock() self.assertEqual([(ENABLE_PIN, tester.LOW), (ENABLE_PIN, tester.HIGH), (CLK_PIN, tester.HIGH)], tester.pinActions)
def test_clearMosi(self): tester = BbTester() banger = bitbang.BitBanger(CLK_PIN, MISO_PIN, MOSI_PIN, ENABLE_PIN, tester) banger.clearMosi() self.assertEqual([(ENABLE_PIN, tester.LOW), (ENABLE_PIN, tester.HIGH), (MOSI_PIN, tester.LOW)], tester.pinActions)
def test_setup(self): tester = BbTester() banger = bitbang.BitBanger(CLK_PIN, MISO_PIN, MOSI_PIN, ENABLE_PIN, tester) self.assertEqual(tester.BOARD, tester.mode) self.assertEqual(tester.OUT, tester.pinModes[CLK_PIN]) self.assertEqual(tester.IN, tester.pinModes[MISO_PIN]) self.assertEqual(tester.OUT, tester.pinModes[MOSI_PIN]) self.assertEqual(tester.OUT, tester.pinModes[ENABLE_PIN])
def test_waitForReadySignal(self): tester = BbTester() banger = bitbang.BitBanger(CLK_PIN, MISO_PIN, MOSI_PIN, ENABLE_PIN, tester) tester.pinSettings[MISO_PIN] = [tester.LOW] with self.assertRaises(bitbang.SendByteTimeoutException): banger.sendByte(0x00) tester.pinSettings[MISO_PIN] = [tester.HIGH] banger.sendByte(0x00)
def test_receiveByte(self): tester = BbTester() banger = bitbang.BitBanger(CLK_PIN, MISO_PIN, MOSI_PIN, ENABLE_PIN, tester) tester.pinSettings[MISO_PIN] = [ tester.LOW, tester.HIGH, tester.LOW, tester.HIGH, tester.LOW, tester.HIGH, tester.LOW, tester.HIGH ] result = banger.receiveByte() self.assertEqual(0x55, result)
def test_sendByteLastBit(self): tester = BbTester() banger = bitbang.BitBanger(CLK_PIN, MISO_PIN, MOSI_PIN, ENABLE_PIN, tester) banger.sendByte(0x01) c = CLK_PIN m = MOSI_PIN e = ENABLE_PIN h = tester.HIGH l = tester.LOW self.assertEqual([(e, l), (e, h), (c, l), (m, l), (c, h), (c, l), (m, l), (c, h), (c, l), (m, l), (c, h), (c, l), (m, l), (c, h), (c, l), (m, l), (c, h), (c, l), (m, l), (c, h), (c, l), (m, l), (c, h), (c, l), (m, h), (c, h), (c, l)], tester.pinActions)
def __init__(self, addressBytes, clockPin, misoPin, mosiPin, enablePin, bitBanger=None): self.addressBytes = addressBytes if (bitBanger == None): bitBanger = bitbang.BitBanger(clockPin, misoPin, mosiPin, enablePin) self.bitBanger = bitBanger # wait a bit for the PIC to cycle up for x in range(1000000): pass
def test_getMiso(self): tester = BbTester() banger = bitbang.BitBanger(CLK_PIN, MISO_PIN, MOSI_PIN, ENABLE_PIN, tester) tester.pinSettings[MISO_PIN] = [tester.HIGH] self.assertEqual(tester.HIGH, banger.getMiso())