Nick Raptis avatar Nick Raptis committed 0ad0026

Some initial patches

Comments (0)

Files changed (5)

+# HG changeset patch
+# Parent e421765cc80307de1e8fd2cd4693635ed1f17c1e
+Function to query Board for available bytes.
+
+Since Board.iterate() blocks, this is useful.
+Also it's coherent with Arduino's Serial.available
+However, it returns a more pythonic 0 when there's
+nothing waiting instead of Arduino's C-like -1
+
+diff -r e421765cc803 -r b87536297995 pyfirmata/pyfirmata.py
+--- a/pyfirmata/pyfirmata.py	Mon May 16 22:48:46 2011 +0300
++++ b/pyfirmata/pyfirmata.py	Mon May 16 22:56:53 2011 +0300
+@@ -218,6 +218,9 @@
+             self.sp.write(byte)
+         self.sp.write(chr(END_SYSEX))
+         
++    def available(self):
++        return self.sp.inWaiting()
++
+     def iterate(self):
+         """ 
+         Reads and handles data from the microcontroller over the serial port.
+diff -r e421765cc803 -r b87536297995 pyfirmata/util.py
+--- a/pyfirmata/util.py	Mon May 16 22:48:46 2011 +0300
++++ b/pyfirmata/util.py	Mon May 16 22:56:53 2011 +0300
+@@ -96,7 +96,7 @@
+     def run(self):
+         while 1:
+             try:
+-                while self.board.iterate():
++                while self.board.available():
+                     self.board.iterate()
+                 time.sleep(0.001)
+             except (AttributeError, serial.SerialException, OSError), e:

FirmwareString.diff

+# 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 """
+# HG changeset patch
+# Parent cc2fbead01b6384500b380c6bfd34a0a2154024b
+Pass parameters to Boards.
+
+Previously, all user-passed parameters were discarded.
+
+diff -r cc2fbead01b6 -r 651f06a045e5 pyfirmata/util.py
+--- a/pyfirmata/util.py	Mon May 16 23:01:17 2011 +0300
++++ b/pyfirmata/util.py	Mon May 16 23:04:43 2011 +0300
+@@ -81,7 +81,7 @@
+     will raise an IOError if it can't find a board, on a serial, or if it
+     finds more than one.
+     """
+-    boards = Boards(base_dir='/dev/', identifier='tty.usbserial')
++    boards = Boards(base_dir=base_dir, identifier=identifier)
+     if len(boards) == 0:
+         raise IOError, "No boards found in %s with identifier %s" % (base_dir, identifier)
+     elif len(boards) > 1:
+# HG changeset patch
+# Parent b87536297995a9e7f51b475f47c92bdf473aa94d
+Wait and iterate over initial firmata messages
+
+Specifically get Firmware and Port Init messages
+when openning a Board, instead of depending to the
+user to set up an iterator or loop.
+
+diff -r b87536297995 -r cc2fbead01b6 pyfirmata/pyfirmata.py
+--- a/pyfirmata/pyfirmata.py	Mon May 16 22:56:53 2011 +0300
++++ b/pyfirmata/pyfirmata.py	Mon May 16 23:01:17 2011 +0300
+@@ -67,14 +67,18 @@
+     
+     def __init__(self, port, layout, baudrate=57600, name=None):
+         self.sp = serial.Serial(port, baudrate)
+-        # Allow 2 secs for Arduino's auto-reset to happen
+-        # TODO Is this still necessary?
+-        self.pass_time(2)
++        # Allow 5 secs for Arduino's auto-reset to happen
++        # Alas, Firmata blinks it's version before printing it to serial
++        # For 2.3, even 5 seconds might not be enough.
++        self.pass_time(5)
+         self.name = name
+         if not self.name:
+             self.name = port
+         self.setup_layout(layout)
+-        # TODO Test if we get a firmware name and version, otherwise there 
++        # Iterate over the first messages to get firmware data
++        while self.available():
++            self.iterate()
++        # TODO Test whether we got a firmware name and version, otherwise there 
+         # probably isn't any Firmata installed
+         
+     def __str__(self):
+FirmwareString.diff
+Available.diff
+WaitAndInit.diff
+GetBoardBug.diff
 # Placed by Bitbucket
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.