def test_set_offset_2(self): spi = SPI(zdok=0, test=True) self.assertEqual(spi.regs, []) offsets = [0.0] * 4 spi.set_offsets(offsets) self.assertEqual(len(spi.regs), 12) regs = [(hex(int(x)), hex(int(y))) for x, y in spi.regs] exp = [ ("0x8f", "0x1"), ("0xa0", "0x80"), ("0x90", "0x8"), ("0x8f", "0x2"), ("0xa0", "0x80"), ("0x90", "0x8"), ("0x8f", "0x3"), ("0xa0", "0x80"), ("0x90", "0x8"), ("0x8f", "0x4"), ("0xa0", "0x80"), ("0x90", "0x8"), ] self.assertEqual(exp, regs)
def test_set_offset(self): spi = SPI(zdok=0, test=True) self.assertEqual(spi.regs, []) offsets = [-2.535, -5.0077, -6.7831, -2.5544] spi.set_offsets(offsets) self.assertEqual(len(spi.regs), 12) regs = [(hex(int(x)), hex(int(y))) for x, y in spi.regs] exp = [ ("0x8f", "0x1"), ("0xa0", "0x7a"), ("0x90", "0x8"), ("0x8f", "0x2"), ("0xa0", "0x73"), ("0x90", "0x8"), ("0x8f", "0x3"), ("0xa0", "0x6f"), ("0x90", "0x8"), ("0x8f", "0x4"), ("0xa0", "0x79"), ("0x90", "0x8"), ] self.assertEqual(exp, regs) spi.set_offsets([0.0, 0.0, 0.0, 0.0]) regs = [(hex(int(x)), hex(int(y))) for x, y in spi.regs]