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
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
15 REPORT_VERSION = 0xF9 # report firmware version
16 SYSTEM_RESET = 0xFF # reset from MIDI
18 +QUERY_FIRMWARE = 0x79 # report firmware name and version
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
32 + # Empty all default messages sent wen connecting to the arduino
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)
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:
64 + major, minor = self.sp.read(2)
65 + self.firmware_version = (ord(major), ord(minor))
67 + char = self.sp.read()
68 + if ord(char) == END_SYSEX:
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))
85 """Exit the application cleanly"""