Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 #ifndef ROS_ARDUINO_HARDWARE_H_
00036 #define ROS_ARDUINO_HARDWARE_H_
00037 
00038 #if ARDUINO>=100
00039   #include <Arduino.h>  
00040 #else
00041   #include <WProgram.h>  
00042 #endif
00043 
00044 #if defined(__MK20DX128__) || defined(__MK20DX256__)
00045   #include <usb_serial.h>  
00046   #define SERIAL_CLASS usb_serial_class
00047 #elif defined(_SAM3XA_)
00048   #include <UARTClass.h>  
00049   #define SERIAL_CLASS UARTClass
00050 #elif defined(USE_USBCON)
00051   
00052   #define SERIAL_CLASS Serial_
00053 #else 
00054   #include <HardwareSerial.h>  
00055   #define SERIAL_CLASS HardwareSerial
00056 #endif
00057 
00058 class ArduinoHardware {
00059   public:
00060     ArduinoHardware(SERIAL_CLASS* io , long baud= 57600){
00061       iostream = io;
00062       baud_ = baud;
00063     }
00064     ArduinoHardware()
00065     {
00066 #if defined(USBCON) and !(defined(USE_USBCON))
00067       
00068       iostream = &Serial;
00069 #else
00070       iostream = &Serial;
00071 #endif
00072       baud_ = 57600;
00073     }
00074     ArduinoHardware(ArduinoHardware& h){
00075       this->iostream = iostream;
00076       this->baud_ = h.baud_;
00077     }
00078   
00079     void setBaud(long baud){
00080       this->baud_= baud;
00081     }
00082   
00083     int getBaud(){return baud_;}
00084 
00085     void init(){
00086 #if defined(USE_USBCON)
00087       
00088       delay(3000); 
00089 #endif
00090       iostream->begin(baud_);
00091     }
00092 
00093     int read(){return iostream->read();};
00094     void write(uint8_t* data, int length){
00095       for(int i=0; i<length; i++)
00096         iostream->write(data[i]);
00097     }
00098 
00099     unsigned long time(){return millis();}
00100 
00101   protected:
00102     SERIAL_CLASS* iostream;
00103     long baud_;
00104 };
00105 
00106 #endif