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__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
00045 #if defined(USE_TEENSY_HW_SERIAL)
00046 #define SERIAL_CLASS HardwareSerial // Teensy HW Serial
00047 #else
00048 #include <usb_serial.h>
00049 #define SERIAL_CLASS usb_serial_class
00050 #endif
00051 #elif defined(_SAM3XA_)
00052 #include <UARTClass.h>
00053 #define SERIAL_CLASS UARTClass
00054 #elif defined(USE_USBCON)
00055
00056 #define SERIAL_CLASS Serial_
00057 #else
00058 #include <HardwareSerial.h>
00059 #define SERIAL_CLASS HardwareSerial
00060 #endif
00061
00062 class ArduinoHardware {
00063 public:
00064 ArduinoHardware(SERIAL_CLASS* io , long baud= 57600){
00065 iostream = io;
00066 baud_ = baud;
00067 }
00068 ArduinoHardware()
00069 {
00070 #if defined(USBCON) and !(defined(USE_USBCON))
00071
00072 iostream = &Serial1;
00073 #else
00074 iostream = &Serial;
00075 #endif
00076 baud_ = 57600;
00077 }
00078 ArduinoHardware(ArduinoHardware& h){
00079 this->iostream = iostream;
00080 this->baud_ = h.baud_;
00081 }
00082
00083 void setBaud(long baud){
00084 this->baud_= baud;
00085 }
00086
00087 int getBaud(){return baud_;}
00088
00089 void init(){
00090 #if defined(USE_USBCON)
00091
00092 delay(3000);
00093 #endif
00094 iostream->begin(baud_);
00095 }
00096
00097 int read(){return iostream->read();};
00098 void write(uint8_t* data, int length){
00099 for(int i=0; i<length; i++)
00100 iostream->write(data[i]);
00101 }
00102
00103 unsigned long time(){return millis();}
00104
00105 protected:
00106 SERIAL_CLASS* iostream;
00107 long baud_;
00108 };
00109
00110 #endif