Ejemplo n.º 1
0
    def test_from_two_bytes(self):
        for i in range(32766, 32768):
            val = to_two_bytes(i)
            ret = from_two_bytes(val)
            self.assertEqual(ret, i)

        self.assertEqual(from_two_bytes(('\xff', '\xff')), 32767)
        self.assertEqual(from_two_bytes(('\x7f', '\xff')), 32767)
Ejemplo n.º 2
0
    def test_from_two_bytes(self):
        for i in range(32766, 32768):
            val = to_two_bytes(i)
            ret = from_two_bytes(val)
            self.assertEqual(ret, i)

        self.assertEqual(from_two_bytes(('\xff', '\xff')), 32767)
        self.assertEqual(from_two_bytes(('\x7f', '\xff')), 32767)
Ejemplo n.º 3
0
 def _handle_i2c_message(self, *args, **kwargs):
     address = util.from_two_bytes([args[0], args[1]])
     if address in self._i2c:
         x = self._i2c[address]
         if x.callBack is not None:
             values = []
             for i in range(2, len(args) - 1, 2):
                 values.append(util.from_two_bytes([args[i], args[i + 1]]))
             x.callBack(values)
             x.values[values[0]] = values[1:]
Ejemplo n.º 4
0
 def _handle_ping_read(self, pin_nr, *data):
     duration = (util.from_two_bytes(data[1:3]) << 24) \
                 + (util.from_two_bytes(data[3:5]) << 16) \
                 + (util.from_two_bytes(data[5:7]) << 8) \
                 + util.from_two_bytes(data[7:9])
     ping_distance = duration / 58.2
     # We can calculate the distance using an HC-SR04 as 'duration / 58.2'
     try:
         ## CALL CALLBACK
         if self.digital[pin_nr].ping_distance != ping_distance:
             for a in self._pings:
                 if a.index == pin_nr:
                     a._changecb(ping_distance)
         self.digital[pin_nr].ping_distance = ping_distance
     except IndexError:
         raise ValueError