00001 /* 00002 * Copyright 2007-2008 (c) Erik Sjodin, eriksjodin.net 00003 * 00004 * Permission is hereby granted, free of charge, to any person 00005 * obtaining a copy of this software and associated documentation 00006 * files (the "Software"), to deal in the Software without 00007 * restriction, including without limitation the rights to use, 00008 * copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 * copies of the Software, and to permit persons to whom the 00010 * Software is furnished to do so, subject to the following 00011 * conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be 00014 * included in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00018 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00020 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00021 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00022 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00023 * OTHER DEALINGS IN THE SOFTWARE. 00024 */ 00025 00026 #ifndef OF_ARDUINO_H 00027 #define OF_ARDUINO_H 00028 00029 #include "ofStandardFirmata.h" 00030 00031 #define SYSEX_SERVO_ATTACH 0x00 00032 #define SYSEX_SERVO_DETACH 0x01 00033 #define SYSEX_SERVO_WRITE 0x02 00034 00035 #define OF_ARDUINO_DELAY_LENGTH 4.0 00036 00037 00045 class ofArduino: public ofStandardFirmata{ 00046 00047 public: 00048 ofArduino(); 00049 00050 virtual ~ofArduino(); 00051 00052 int connect(string device, int baud=57600); 00053 // opens a serial port connection to the arduino 00054 // Note: GlueFirmata is set to use 57600 bps by default since 115200 (the firmata default) has proven to be unreliable 00055 00056 bool isArduinoReady(); 00057 00058 00059 void setUseDelay(bool bDelay); 00060 00061 00062 // -- servo 00063 void sendServo(int pin, int value, bool force=false); 00064 // pin: 9, 10 00065 // the pin has to have a servo attached 00066 00067 void sendServoAttach(int pin, int minPulse=544, int maxPulse=2400, int angle=180); 00068 // pin: 9, 10 00069 // attaches a servo to a pin 00070 00071 void sendServoDetach(int pin); 00072 // pin: 9, 10 00073 // detaches a servo from a pin, the pin mode remains as OUTPUT 00074 00075 int getServo(int pin); 00076 // returns the last set servo value for a pin if the pin has a servo attached 00077 00078 protected: 00079 00080 bool bUseDelay; 00081 00082 bool connected; 00083 00084 float connectTime; 00085 00086 void processSysExData(vector<unsigned char> data); 00087 00088 int _servoValue[ARD_TOTAL_DIGITAL_PINS]; 00089 // the last set servo values 00090 00091 float _temp; 00092 // the last received temperature 00093 00094 float _humidity; 00095 // the last received humidity 00096 00097 }; 00098 00099 #endif