コード例 #1
0
 def __init__(self, i2c_addr):
     super(Ds6923OpticalInterface, self).__init__()
     self.Unexport(['Alias', 'LastChange', 'Name', 'Status'])
     self.Unexport(objects=['Stats'])
     # The i2c module shifts the address right by 1 for some reason.
     self.i2c_addr = i2c_addr << 1
     self.i2c = i2c.Util(I2C_BUS)
コード例 #2
0
 def testReadOneBlock(self):
     buf = [3] * 32
     bus = self.smbus_mocker.CreateMock(SMBus)
     bus.read_i2c_block_data(self.i2c_addr, 0, 1).AndReturn([0])
     bus.read_i2c_block_data(self.i2c_addr, 20, 32).AndReturn(buf)
     self.smbus_mocker.ReplayAll()
     helper = i2c.Util(bus)
     data = helper.Read(self.address, 20, 32)
     self.smbus_mocker.VerifyAll()
     self.assertEquals(buf, data)
コード例 #3
0
 def testWriteOneBlock(self):
     buf = [3] * 32
     i2c_buf = []
     i2c_buf.extend(buf)
     bus = self.smbus_mocker.CreateMock(SMBus)
     bus.write_i2c_block_data(self.i2c_addr, 20, i2c_buf).AndReturn(None)
     self.smbus_mocker.ReplayAll()
     helper = i2c.Util(bus)
     helper.Write(self.address, 20, buf)
     self.smbus_mocker.VerifyAll()
コード例 #4
0
 def testWriteThreeBlocks(self):
     buf = [3] * 96
     i2c_buf = []
     i2c_buf.extend([3] * 32)
     bus = self.smbus_mocker.CreateMock(SMBus)
     bus.write_i2c_block_data(self.i2c_addr, 10, i2c_buf).AndReturn(None)
     bus.write_i2c_block_data(self.i2c_addr, 42, i2c_buf).AndReturn(None)
     bus.write_i2c_block_data(self.i2c_addr, 74, i2c_buf).AndReturn(None)
     self.smbus_mocker.ReplayAll()
     helper = i2c.Util(bus)
     helper.Write(self.address, 10, buf)
     self.smbus_mocker.VerifyAll()
コード例 #5
0
 def testReadThreeBlocks(self):
     buf = [3] * 96
     result = [3] * 32
     bus = self.smbus_mocker.CreateMock(SMBus)
     bus.read_i2c_block_data(self.i2c_addr, 0, 1).AndReturn([0])
     bus.read_i2c_block_data(self.i2c_addr, 10, 32).AndReturn(result)
     bus.read_i2c_block_data(self.i2c_addr, 42, 32).AndReturn(result)
     bus.read_i2c_block_data(self.i2c_addr, 74, 32).AndReturn(result)
     self.smbus_mocker.ReplayAll()
     helper = i2c.Util(bus)
     data = helper.Read(self.address, 10, 96)
     self.smbus_mocker.VerifyAll()
     self.assertEquals(buf, data)
コード例 #6
0
 def testReadByte(self):
     bus = self.smbus_mocker.CreateMock(SMBus)
     bus.read_i2c_block_data(self.i2c_addr, 0, 1).AndReturn(None)
     bus.read_byte(self.i2c_addr).AndReturn(0)
     bus.write_byte(self.i2c_addr, 10).AndReturn(None)
     bus.read_byte(self.i2c_addr).AndReturn(1)
     bus.write_byte(self.i2c_addr, 11).AndReturn(None)
     bus.read_byte(self.i2c_addr).AndReturn(2)
     bus.write_byte(self.i2c_addr, 12).AndReturn(None)
     bus.read_byte(self.i2c_addr).AndReturn(3)
     self.smbus_mocker.ReplayAll()
     helper = i2c.Util(bus)
     data = helper.Read(self.address, 10, 3)
     self.smbus_mocker.VerifyAll()
     self.assertEquals([1, 2, 3], data)