updated on Wed Jan 18 08:00:29 UTC 2012
[aur-mirror.git] / pyduino-svn / firmata-2.1.patch
blob4eaeb5c5bf8f156b003c385dbf7c3da0039731c8
1 # This is the patch that has been applied on the original
2 # pyduino library to produce this version of the library
4 --- pyduino.py 2010-05-10 21:49:06.000000000 +0200
5 +++ pyduino-new.py 2010-05-10 21:55:39.000000000 +0200
6 @@ -2,6 +2,7 @@
8 """pyduino - A python library to interface with the firmata arduino firmware.
9 Copyright (C) 2007 Joe Turner <orphansandoligarchs@gmail.com>
10 +Modified by Ferrazzo Riccardo <f.riccardo87@gmail.com>
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 @@ -38,6 +39,8 @@
15 REPORT_VERSION = 0xF9 # report firmware version
16 SYSTEM_RESET = 0xFF # reset from MIDI
18 +QUERY_FIRMWARE = 0x79 # report firmware name and version
20 # Pin modes
21 UNAVAILABLE = -1
22 DIGITAL_INPUT = 0
23 @@ -51,9 +54,15 @@
24 """Base class for the arduino board"""
26 def __init__(self, port):
27 - self.sp = serial.Serial(port, 115200, timeout=0.02)
28 + self.sp = serial.Serial(port, 57600, timeout=1.5)
29 # Allow 2 secs for Diecimila auto-reset to happen
30 time.sleep(2)
32 + # Empty all default messages sent wen connecting to the arduino
33 + while True:
34 + x = self.sp.read()
35 + if ord(x) == "":
36 + break
38 self.analog = []
39 for i in range(6):
40 @@ -78,8 +87,9 @@
41 self.digital += self.digital_ports[1].pins[:6]
43 # Obtain firmata version
44 - self.firmata_version = None
45 - self.sp.write(chr(REPORT_VERSION))
46 + self.firmware_version = None
47 + self.firmware_name = ""
48 + self._sysex_message(QUERY_FIRMWARE)
49 self.iterate()
51 def __str__(self):
52 @@ -121,13 +131,29 @@
53 msb = ord(msb)
54 value = float(msb << 7 | lsb) / 1023
55 self.analog[pin_number].set_value(value)
56 - elif data == REPORT_VERSION:
57 - minor, major = self.sp.read(2)
58 - self.firmata_version = (ord(major), ord(minor))
59 + elif data == START_SYSEX:
60 + # Parse sysex messages
61 + data = self.sp.read()
62 + if ord(data) == QUERY_FIRMWARE:
63 + print "firmware"
64 + major, minor = self.sp.read(2)
65 + self.firmware_version = (ord(major), ord(minor))
66 + while True:
67 + char = self.sp.read()
68 + if ord(char) == END_SYSEX:
69 + break
70 + self.firmware_name = self.firmware_name + char
72 def get_firmata_version(self):
73 """Return a (major, minor) version tuple for the firmata firmware"""
74 - return self.firmata_version
75 + return self.firmware_version
77 + def get_firmware_name(self):
78 + """Return the firmware name as it is in the arduino .pde file"""
79 + return self.firmware_name
81 + def _sysex_message(self, message):
82 + self.sp.write(chr(START_SYSEX)+chr(message)+chr(END_SYSEX))
84 def exit(self):
85 """Exit the application cleanly"""