openFrameworksArduino
ofArduino.h
1 /*
2  * Copyright 2007-2008 (c) Erik Sjodin, eriksjodin.net
3  * Adapted from Wiring version 2011 (c) Carlos Mario Rodriguez and
4  * Hernando Barragan by Dominic Amato
5  * Adapted from Arbotix Firmata version 2014 (c) David Cofer
6  * NeuroRoboticTechnologies, LLC
7  *
8  * Permission is hereby granted, free of charge, to any person
9  * obtaining a copy of this software and associated documentation
10  * files (the "Software"), to deal in the Software without
11  * restriction, including without limitation the rights to use,
12  * copy, modify, merge, publish, distribute, sublicense, and/or sell
13  * copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following
15  * conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  */
29 #pragma once
30 
31 #include <list>
32 #include <vector>
33 #include <string>
34 #include <iostream>
35 #include <boost/timer.hpp>
36 #include <boost/signals2/signal.hpp>
37 #include <boost/bind.hpp>
38 #include "ofSerialWin.h"
39 #include "ofSerialLinux.h"
40 
41 /*
42  * Version numbers for the protocol. The protocol is still changing, so these
43  * version numbers are important. This number can be queried so that host
44  * software can test whether it will be compatible with the currently installed firmware.
45  */
46 
47 #define FIRMATA_MAJOR_VERSION 2 // for non-compatible changes
48 #define FIRMATA_MINOR_VERSION 0 // for backwards compatible changes
49 #define FIRMATA_MAX_DATA_BYTES 32 // max number of data bytes in non-Sysex messages
50 // message command bytes (128-255/0x80-0xFF)
51 #define FIRMATA_DIGITAL_MESSAGE 0x90 // send data for a digital pin
52 #define FIRMATA_ANALOG_MESSAGE 0xE0 // send data for an analog pin (or PWM)
53 #define FIRMATA_REPORT_ANALOG 0xC0 // enable analog input by pin #
54 #define FIRMATA_REPORT_DIGITAL 0xD0 // enable digital input by port pair
55 //
56 #define FIRMATA_SET_PIN_MODE 0xF4 // set a pin to INPUT/OUTPUT/PWM/etc
57 //
58 #define FIRMATA_REPORT_VERSION 0xF9 // report protocol version
59 #define FIRMATA_SYSTEM_RESET 0xFF // reset from MIDI
60 //
61 #define FIRMATA_START_SYSEX 0xF0 // start a MIDI Sysex message
62 #define FIRMATA_END_SYSEX 0xF7 // end a MIDI Sysex message
63 // pin modes
64 #define FIRMATA_INPUT 0x00
65 #define FIRMATA_OUTPUT 0x01
66 #define FIRMATA_ANALOG 0x02 // analog pin in analogInput mode
67 #define FIRMATA_PWM 0x03 // digital pin in PWM output mode
68 #define FIRMATA_SERVO 0x04 // digital pin in Servo output mode
69 #define SHIFT 0x05 // shiftIn/shiftOut mode
70 #define I2C 0x06 // pin included in I2C setup
71 #define FIRMATA_INPUT_PULLUP 0x07 // pull-up resistors enabled
72 #define TOTAL_PIN_MODES 8
73 // extended command set using SysEx (0-127/0x00-0x7F)
74 /* 0x00-0x0F reserved for custom commands */
75 #define FIRMATA_SYSEX_SERVO_CONFIG 0x70 // set max angle, minPulse, maxPulse, freq
76 #define FIRMATA_SYSEX_FIRMATA_STRING 0x71 // a string message with 14-bits per char
77 #define SHIFT_DATA 0x75 // a bitstram to/from a shift register
78 #define I2C_REQUEST 0x76 // send an I2C read/write request
79 #define I2C_REPLY 0x77 // a reply to an I2C request
80 #define I2C_CONFIG 0x78 // config I2C settings such as delay times and power pins
81 #define EXTENDED_ANALOG 0x6F // analog write (PWM, Servo, etc) to any pin
82 #define PIN_STATE_QUERY 0x6D // ask for a pin's current mode and value
83 #define PIN_STATE_RESPONSE 0x6E // reply with pin's current mode and value
84 #define CAPABILITY_QUERY 0x6B // ask for supported modes and resolution of all pins
85 #define CAPABILITY_RESPONSE 0x6C // reply with supported modes and resolution
86 #define ANALOG_MAPPING_QUERY 0x69 // ask for mapping of analog to pin numbers
87 #define ANALOG_MAPPING_RESPONSE 0x6A // reply with mapping info
88 #define FIRMATA_SYSEX_REPORT_FIRMWARE 0x79 // report name and version of the firmware
89 #define SAMPLING_INTERVAL 0x7A // set the poll rate of the main loop
90 #define FIRMATA_SYSEX_NON_REALTIME 0x7E // MIDI Reserved for non-realtime messages
91 #define FIRMATA_SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages
92 
93 #define MAX_DYNAMIXEL_SERVOS 50
94 #define DYNAMIXEL_KEY_DATA_LENGTH 6*2+1
95 #define DYNAMIXEL_ALL_DATA_LENGTH 10*2+1
96 #define DYNAMIXEL_GET_REGISTER_LENGTH 5*2+1
97 #define COMMANDER_DATA_LENGTH 6*2+1
98 
99 #define SYSEX_DYNAMIXEL_KEY_SERVO_DATA 0x68 // Data packet of key (pos, speed) Dynamixel data.
100 #define SYSEX_DYNAMIXEL_ALL_SERVO_DATA 0x67 // Data packet of all (pos, speed, load, voltage, temp) Dynamixel data.
101 #define SYSEX_DYNAMIXEL_CONFIG 0x66 // Data packet to configure firmata to listen for dynamixel data.
102 #define SYSEX_DYNAMIXEL_SYNCH_MOVE_START 0x65 // Data packet to configure up to 5 motors to move using synch move command.
103 #define SYSEX_DYNAMIXEL_SYNCH_MOVE_ADD 0x64 // Data packet to configure up to 5 motors to move using synch move command.
104 #define SYSEX_DYNAMIXEL_SYNCH_MOVE_EXECUTE 0x63 // Data packet to configure up to 5 motors to move using synch move command.
105 #define SYSEX_DYNAMIXEL_MOVE 0x62 // Data packet to send immediate move command.
106 #define SYSEX_DYNAMIXEL_STOP 0x61 // Data packet to send immediate move command.
107 #define SYSEX_DYNAMIXEL_TRANSMIT_ERROR 0x60 // Data packet for when there is a transmission error detected on the arbotix side.
108 #define SYSEX_DYNAMIXEL_SET_REGISTER 0x59 // Data packet to set a specific register in a Dynamixel servo.
109 #define SYSEX_DYNAMIXEL_GET_REGISTER 0x58 // Data packet to get a specific register in a Dynamixel servo.
110 #define SYSEX_DYNAMIXEL_CONFIGURE_SERVO 0x57 // Data packet to configure key motor params like cw and ccw limits.
111 #define SYSEX_DYNAMIXEL_STOPPED 0x56 // Data packet to configure reporting of when a servo stops moving.
112 #define SYSEX_COMMANDER_DATA 0x55 // Data packet with commander remote control buttons pressed.
113 
114 // ---- arduino constants (for Arduino NG and Diecimila)
115 
116 // board settings
117 #define ARD_TOTAL_DIGITAL_PINS 22 // total number of pins currently supported
118 #define ARD_TOTAL_ANALOG_PINS 6
119 #define ARD_TOTAL_PORTS 3 // total number of ports for the board
120 // pin modes
121 #define ARD_INPUT 0x00
122 #define ARD_OUTPUT 0x01
123 #define ARD_ANALOG 0x02 // analog pin in analogInput mode
124 #define ARD_PWM 0x03 // digital pin in PWM output mode
125 #define ARD_SERVO 0x04 // digital pin in Servo output mode
126 #define ARD_INPUT_PULLUP 0x07 // pull-up rsistors enabled
127 #define ARD_HIGH 1
128 #define ARD_LOW 0
129 #define ARD_ON 1
130 #define ARD_OFF 0
131 
132 /*
133  #if defined(__AVR_ATmega168__) // Arduino NG and Diecimila
134  #define ARD_TOTAL_ANALOG_PINS 8
135  #define ARD_TOTAL_DIGITAL_PINS 22 // 14 digital + 8 analog
136  #define ARD_TOTAL_PORTS 3 // total number of ports for the board
137  #define ARD_ANALOG_PORT 2 // port# of analog used as digital
138  #elif defined(__AVR_ATmega8__) // old Arduinos
139  #define ARD_TOTAL_ANALOG_PINS 6
140  #define ARD_TOTAL_DIGITAL_PINS 20 // 14 digital + 6 analog
141  #define ARD_TOTAL_PORTS 3 // total number of ports for the board
142  #define ARD_ANALOG_PORT 2 // port# of analog used as digital
143  #elif defined(__AVR_ATmega128__)// Wiring
144  #define ARD_TOTAL_ANALOG_PINS 8
145  #define ARD_TOTAL_DIGITAL_PINS 43
146  #define ARD_TOTAL_PORTS 5 // total number of ports for the board
147  #define ARD_ANALOG_PORT 2 // port# of analog used as digital
148  #else // anything else
149  #define ARD_TOTAL_ANALOG_PINS 6
150  #define ARD_TOTAL_DIGITAL_PINS 14
151  #define ARD_TOTAL_PORTS 3 // total number of ports for the board
152  #define ARD_ANALOG_PORT 2 // port# of analog used as digital
153  #endif
154  */
155 
156 // DEPRECATED as of firmata v2.2
157 #define SYSEX_SERVO_ATTACH 0x00
158 #define SYSEX_SERVO_DETACH 0x01
159 #define SYSEX_SERVO_WRITE 0x02
160 
161 #define OF_ARDUINO_DELAY_LENGTH 10.0
162 
163 #define FIRMWARE2_2 22
164 #define FIRMWARE2_3 23
165 
166 
173 class ARDUINO_PORT ofDynamixelData {
174 public:
175  bool _keyChanged;
176  bool _allChanged;
177  unsigned int _id;
178  unsigned int _goalPosition;
179  unsigned int _actualPosition;
180  unsigned int _goalSpeed;
181  unsigned int _actualSpeed;
182  unsigned int _load;
183  unsigned char _temperature;
184  unsigned char _voltage;
185  bool _moving;
186  unsigned char _LED;
187  unsigned char _alarm;
188 
190  {
191  _keyChanged = false;
192  _allChanged = false;
193  _id = 0;
194  _goalPosition = 0;
195  _actualPosition = 0;
196  _goalSpeed = 0;
197  _actualSpeed = 0;
198  _load = 0;
199  _temperature = 0;
200  _voltage = 0;
201  _moving = false;
202  _LED = 0;
203  _alarm = 0;
204  };
205 };
206 
207 class ARDUINO_PORT ofCommanderData {
208 public:
209  bool _changed;
210  signed char _walkV;
211  signed char _walkH;
212  signed char _lookV;
213  signed char _lookH;
214  unsigned char _buttons;
215  unsigned char _ext;
216 
218  {
219  _changed = false;
220  _walkV = 0;
221  _walkH = 0;
222  _lookV = 0;
223  _lookH = 0;
224  _buttons = 0;
225  _ext = 0;
226  };
227 };
228 
229 
230 class ARDUINO_PORT ofArduino{
231 
232  public:
233  ofArduino();
234 
235  virtual ~ofArduino();
236 
237 
238  // --- setup functions
239  virtual bool connect(std::string device, int baud = 57600);
240  // opens a serial port connection to the arduino
241 
242  virtual void disconnect();
243  // closes the serial port connection
244 
245  virtual bool isArduinoReady();
246 
247  virtual void setUseDelay(bool bDelay);
248 
249  virtual void update();
250  // polls data from the serial port, this has to be called periodically
251 
252  virtual bool isInitialized();
253  // returns true if a succesfull connection has been established and the Arduino has reported a firmware
254 
255  virtual void setDigitalHistoryLength(int length);
256  virtual void setAnalogHistoryLength(int length);
257  virtual void setStringHistoryLength(int length);
258  virtual void setSysExHistoryLength(int nSysEx);
259 
260  // --- senders
261 
262  virtual void sendDigitalPinMode(int pin, int mode);
263  // pin: 2-13
264  // mode: ARD_INPUT, ARD_OUTPUT, ARD_PWM
265  // setting a pins mode to ARD_INPUT turns on reporting for the port the pin is on
266  // Note: analog pins 0-5 can be used as digitial pins 16-21 but if the mode of _one_ of these pins is set to ARD_INPUT then _all_ analog pin reporting will be turned off
267 
268  virtual void sendAnalogPinReporting(int pin, int mode);
269  // pin: 0-5
270  // mode: ARD_ON or ARD_OFF
271  // Note: analog pins 0-5 can be used as digitial pins 16-21 but if reporting for _one_ analog pin is enabled then reporting for _all_ of digital pin 16-21 will be turned off
272 
273  virtual void sendDigital(int pin, int value, bool force = false);
274  // pin: 2-13
275  // value: ARD_LOW or ARD_HIGH
276  // the pins mode has to be set to ARD_OUTPUT or ARD_INPUT (in the latter mode pull-up resistors are enabled/disabled)
277  // Note: pin 16-21 can also be used if analog inputs 0-5 are used as digital pins
278 
279  virtual void sendPwm(int pin, int value, bool force = false);
280  // pin: 3, 5, 6, 9, 10 and 11
281  // value: 0 (always off) to 255 (always on).
282  // the pins mode has to be set to ARD_PWM
283  // TODO check if the PWM bug still is there causing frequent digital port reporting...
284 
285  virtual void sendSysEx(int command, std::vector<unsigned char> data);
286 
287  virtual void sendString(std::string str);
288  // firmata can not handle strings longer than 12 characters.
289 
290  virtual void sendProtocolVersionRequest();
291 
292  virtual void sendFirmwareVersionRequest();
293 
294  virtual void sendReset();
295 
296  // --- senders for SysEx communication
297 
298  virtual void sendSysExBegin();
299  // sends the FIRMATA_START_SYSEX command
300 
301  virtual void sendSysExEnd();
302  // sends the FIRMATA_END_SYSEX command
303 
304  virtual void sendByte(unsigned char value);
305  // sends a byte without wrapping it in a firmata message, data has to be in the 0-127 range,
306  // values > 127 will be interpreted as commands.
307 
308  virtual void sendValueAsTwo7bitBytes(int value);
309  // sends a value as two 7-bit bytes without wrapping it in a firmata message
310  // values in the range 0 - 16384 will be sent as two bytes within the 0-127 data range.
311 
312  // --- getters
313 
314  virtual int getPwm(int pin);
315  // pin: 3, 5, 6, 9, 10 and 11
316  // returns the last set PWM value (0-255) for the given pin
317  // the pins mode has to be ARD_PWM
318  // Note: pin 16-21 can also be used if analog inputs 0-5 are used as digital pins
319 
320  virtual int getDigital(int pin);
321  // pin: 2-13
322  // returns the last received value (if the pin mode is ARD_INPUT) or the last set value (if the pin mode is ARD_OUTPUT) for the given pin
323  // Note: pin 16-21 can also be used if analog inputs 0-5 are used as digital pins
324 
325  virtual int getAnalog(int pin);
326  // pin: 0-5
327  // returns the last received analog value (0-1023) for the given pin
328 
329  virtual std::vector<unsigned char> getSysEx();
330  // returns the last received SysEx message
331 
332  virtual std::string getString();
333  // returns the last received string
334 
335  virtual int getMajorProtocolVersion();
336  // returns the major firmware version
337 
338  virtual int getMinorProtocolVersion();
339  // returns the minor firmware version
340 
341  virtual int getMajorFirmwareVersion();
342  // returns the major firmware version
343 
344  virtual int getMinorFirmwareVersion();
345  // returns the minor firmware version
346 
347  virtual std::string getFirmwareName();
348  // returns the name of the firmware
349 
350  virtual std::list<int>* getDigitalHistory(int pin);
351  // pin: 2-13
352  // returns a pointer to the digital data history list for the given pin
353  // Note: pin 16-21 can also be used if analog inputs 0-5 are used as digital pins
354 
355  virtual std::list<int>* getAnalogHistory(int pin);
356  // pin: 0-5
357  // returns a pointer to the analog data history list for the given pin
358 
359  virtual std::list<std::vector<unsigned char> >* getSysExHistory();
360  // returns a pointer to the SysEx history
361 
362  virtual std::list<std::string>* getStringHistory();
363  // returns a pointer to the string history
364 
365  virtual int makeWord(unsigned char low, unsigned char high);
366  //Combines two bytes into a word
367 
368  virtual unsigned char getLowByte(int val);
369  //Gets the low byte of an int
370 
371  virtual unsigned char getHighByte(int val);
372  //gets the high byte of an int.
373 
374  ofDynamixelData _dynamixelServos[MAX_DYNAMIXEL_SERVOS];
375 
376  ofCommanderData _commanderData;
377 
378  int getDigitalPinMode(int pin);
379  // returns ARD_INPUT, ARD_OUTPUT, ARD_PWM, ARD_SERVO, ARD_ANALOG
380 
381  int getAnalogPinReporting(int pin);
382  // returns ARD_ON, ARD_OFF
383 
384  int getValueFromTwo7bitBytes(unsigned char lsb, unsigned char msb);
385  // useful for parsing SysEx messages
386 
387  unsigned int getByteFromDataIterator(std::vector<unsigned char>::iterator &it, std::vector<unsigned char>::iterator &end);
388  // useful for parsing SysEx messages
389 
390  unsigned int GetWordFromDataIterator(std::vector<unsigned char>::iterator &it, std::vector<unsigned char>::iterator &end);
391  // useful for parsing SysEx messages
392 
393  // --- events
394 
395  boost::signals2::signal<void (const int)> EDigitalPinChanged;
396  // triggered when a digital pin changes value, the pin that changed is passed as an argument
397 
398  boost::signals2::signal<void (const int)> EAnalogPinChanged;
399  // triggered when an analog pin changes value, the pin that changed is passed as an argument
400 
401  boost::signals2::signal<void (const std::vector<unsigned char>)> ESysExReceived;
402  // triggered when a SysEx message that isn't in the extended command set is received, the SysEx message is passed as an argument
403 
404  boost::signals2::signal<void (const int)> EProtocolVersionReceived;
405  // triggered when a protocol version is received, the major version is passed as an argument
406 
407  boost::signals2::signal<void (const int)> EFirmwareVersionReceived;
408  // triggered when a firmware version is received, the major version is passed as an argument
409 
410  boost::signals2::signal<void (const int)> EInitialized;
411  // triggered when the firmware version is received upon connect, the major firmware version is passed as an argument
412  // from this point it's safe to send to the Arduino.
413 
414  boost::signals2::signal<void (const std::string)> EStringReceived;
415  // triggered when a string is received, the string is passed as an argument
416 
417  boost::signals2::signal<void (const int)> EDynamixelAllReceived;
418  // triggered when a dynamixel data update packet is received, the servo ID is passed as an argument
419 
420  boost::signals2::signal<void (const int)> EDynamixelKeyReceived;
421  // triggered when a dynamixel data update packet is received, the servo ID is passed as an argument
422 
423  boost::signals2::signal<void (const int, const int)> EDynamixelTransmitError;
424  // triggered when the arbotix gets a transmission error like an invalid checksum
425 
426  boost::signals2::signal<void (const unsigned char, const unsigned char, const unsigned int)> EDynamixelGetRegister;
427  // triggered when the arbotix sends back a register value from one of the Dynamixel motors.
428 
429  boost::signals2::signal<void (const int)> EDynamixelStopped;
430  // triggered when a dynamixel stopped packet is received, the servo ID is passed as an argument
431 
432  boost::signals2::signal<void (const int)> ECommanderDataReceived;
433  // triggered when a commander data update packet is received, the servo ID is passed as an argument
434 
435  // -- servo
436  virtual void sendServo(int pin, int value, bool force=false);
437  // pin: 9, 10
438  // the pin has to have a servo attached
439 
440  // angle parameter DEPRECATED as of Firmata 2.2
441  virtual void sendServoAttach(int pin, int minPulse=544, int maxPulse=2400, int angle=180);
442  // pin: 9, 10
443  // attaches a servo to a pin
444 
445  // sendServoDetach DEPRECATED as of Firmata 2.2
446  virtual void sendServoDetach(int pin);
447  // pin: 9, 10
448  // detaches a servo from a pin, the pin mode remains as OUTPUT
449 
450  virtual int getServo(int pin);
451  // returns the last set servo value for a pin if the pin has a servo attached
452 
453  //Tells an arbotix board to monitor a given servo and report back its data.
454  virtual void sendDynamixelServoAttach(unsigned char servo);
455 
456  //Tells an arbotix board to quit monitoring a given servo and report back its data.
457  virtual void sendDynamixelServoDetach(unsigned char servo);
458 
459  //Sends a SynchMove start command to the Arbotix telling it that a new set of move commands are coming.
460  virtual void sendDynamixelSynchMoveStart();
461 
462  //Transmits the command to setup a motor as part of a synch motor move command.
463  //You can setup any number of moves to participate in this move command and then
464  //call sendDynamixelSynchMoveExecute to trigger the movement.
465  virtual void sendDynamixelSynchMoveAdd(unsigned char servo, int pos, int speed);
466 
467  //Transmits the command to move the servos that have been setup using addDynamixelSynchMove
468  virtual void sendDynamixelSynchMoveExecute();
469 
470  //Transmits the command to move a single motor. Does not use the synch move.
471  virtual void sendDynamixelMove(unsigned char servo, int pos, int speed);
472 
473  //Transmits the stop to move a single motor. When the Arbotix recieves this command it will
474  //slow the servo down to is slowest setting, then quickly query the servo for its current
475  //position and the set the goal position to be the current position to stop it from moving.
476  virtual void sendDynamixelStop(unsigned char servo);
477 
478  //Transmits the command to set a byte of the servo register.
479  virtual void sendDynamixelSetRegister(unsigned char servo, unsigned char reg, unsigned char length, unsigned int value);
480 
481  //Transmits the command to get a byte of the servo register.
482  virtual void sendDynamixelGetRegister(unsigned char servo, unsigned char reg, unsigned char length);
483 
484  //Transmits the command to get a byte of the servo register.
485  virtual void sendDynamixelConfigureServo(unsigned char servo, unsigned int cwlimit, unsigned int ccwlimit,
486  unsigned int maxtorque, unsigned char delaytime,
487  unsigned char cwcomplmargin, unsigned char ccwcomplmargin,
488  unsigned char cwcomplslope, unsigned char ccwcomplslope);
489 
490  //Transmits the command to check if the servo is moving and when it is no longer moving send a signal back.
491  virtual void sendDynamixelStopped(unsigned char servo);
492 
493  virtual bool waitForSysExMessage(unsigned char cmd, unsigned int timeout_sec = 1);
494 
495  protected:
496  bool _initialized;
497 
498  void initPins();
499  int _totalDigitalPins;
500 
501  virtual void sendDigitalPinReporting(int pin, int mode);
502  // sets pin reporting to ARD_ON or ARD_OFF
503  // enables / disables reporting for the pins port
504 
505  virtual void sendDigitalPortReporting(int port, int mode);
506  // sets port reporting to ARD_ON or ARD_OFF
507  // enables / disables reporting for ports 0-2
508  // port 0: pins 2-7 (0,1 are serial RX/TX)
509  // port 1: pins 8-13 (14,15 are disabled for the crystal)
510  // port 2: pins 16-21 analog pins used as digital, all analog reporting will be turned off if this is set to ARD_ON
511 
512  virtual void processData(unsigned char inputData);
513  virtual void processDigitalPort(int port, unsigned char value);
514  virtual void processSysExData(std::vector<unsigned char> data);
515 
516  virtual void checkIncomingSysExMessage(unsigned char cmd);
517 
518  ofSerial _port;
519  int _portStatus;
520 
521  // --- history variables
522  int _analogHistoryLength;
523  int _digitalHistoryLength;
524  int _stringHistoryLength;
525  int _sysExHistoryLength;
526 
527  // --- data processing variables
528  int _waitForData;
529  int _executeMultiByteCommand;
530  int _multiByteChannel; // indicates which pin data came from
531 
532  // --- data holders
533  unsigned char _storedInputData[FIRMATA_MAX_DATA_BYTES];
534  std::vector<unsigned char> _sysExData;
535  int _majorProtocolVersion;
536  int _minorProtocolVersion;
537  int _majorFirmwareVersion;
538  int _minorFirmwareVersion;
539  std::string _firmwareName;
540  bool _firmwareReceived;
541 
542  // sum of majorFirmwareVersion * 10 + minorFirmwareVersion
543  int _firmwareVersionSum;
544 
545  std::list<std::vector<unsigned char> > _sysExHistory;
546  // maintains a history of received sysEx messages (excluding SysEx messages in the extended command set)
547 
548  std::list<std::string> _stringHistory;
549  // maintains a history of received strings
550 
551  std::list<int> _analogHistory[ARD_TOTAL_ANALOG_PINS];
552  // a history of received data for each analog pin
553 
554  std::list<int> _digitalHistory[ARD_TOTAL_DIGITAL_PINS];
555  // a history of received data for each digital pin
556 
557  int _digitalPinMode[ARD_TOTAL_DIGITAL_PINS];
558  // the modes for all digital pins
559 
560  int _digitalPinValue[ARD_TOTAL_DIGITAL_PINS];
561  // the last set values (DIGITAL/PWM) on all digital pins
562 
563  int _digitalPortValue[ARD_TOTAL_PORTS];
564  // the last set values on all ports
565 
566  int _digitalPortReporting[ARD_TOTAL_PORTS];
567  // whether pin reporting is enabled / disabled
568 
569  int _digitalPinReporting[ARD_TOTAL_DIGITAL_PINS];
570  // whether pin reporting is enabled / disabled
571 
572  int _analogPinReporting[ARD_TOTAL_ANALOG_PINS];
573  // whether pin reporting is enabled / disabled
574 
575  bool bUseDelay;
576 
577  bool connected;
578 
579  int _servoValue[ARD_TOTAL_DIGITAL_PINS];
580  // the last set servo values
581 
582  boost::timer _Timer;
583 
584  //Keeps track of how many synch move adds have been added since last execute or start
585  int _dynamixelMoveAdds;
586 
587  //A specific SysEx message we are waiting on. -1 if not waiting.
588  int _waitingForSysExMessage;
589 
590  //set to true when the message we are waiting on is found. false otherwise
591  bool _sysExMessageFound;
592 };
593 
595 
Definition: ofArduino.h:230
Definition: ofArduino.h:207
This class extend ofStandardFirmata and provides additional functionality like servo support through ...
Definition: ofArduino.h:173
Definition: ofSerial.h:27