Source

pyFirmata_nickraptis_mq / FirmwareString.diff

Full commit
# HG changeset patch
# Parent 4ffd4fbde16a05ab6b4ee0f8d3edfb184717da1b
Better way to get firmware string

diff -r 4ffd4fbde16a -r e421765cc803 pyfirmata/pyfirmata.py
--- a/pyfirmata/pyfirmata.py	Sun Feb 20 14:18:56 2011 +0100
+++ b/pyfirmata/pyfirmata.py	Mon May 16 22:48:46 2011 +0300
@@ -95,6 +95,18 @@
         lsb, msb = bytes
         return msb << 7 | lsb
         
+    def two_byte_to_str(self, bytes):
+        bytes = list(bytes)
+        chars = []
+        while bytes:
+            lsb = bytes.pop(0)
+            try:
+                msb = bytes.pop(0)
+            except IndexError:
+                msb = 0x00
+            chars.append(chr(self.received_as_two_bytes((lsb, msb))))
+        return ''.join(chars)
+
     def setup_layout(self, board_layout):
         """
         Setup the Pin instances based on the given board-layout. Maybe it will
@@ -288,7 +300,7 @@
         major = data[0]
         minor = data[1]
         self.firmata_version = (major, minor)
-        self.firmware = ''.join([chr(x) for x in data[2:]]) # TODO this is more complicated, values is send as 7 bit bytes
+        self.firmware = self.two_byte_to_str(data[2:])
 
 class Port(object):
     """ An 8-bit port on the board """