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__) || defined(__MKL26Z64__)
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 #elif (defined(__STM32F1__) and !(defined(USE_STM32_HW_SERIAL))) or defined(SPARK)
00058
00059 #define SERIAL_CLASS USBSerial
00060 #else
00061 #include <HardwareSerial.h>
00062 #define SERIAL_CLASS HardwareSerial
00063 #endif
00064
00065 class ArduinoHardware {
00066 public:
00067 ArduinoHardware(SERIAL_CLASS* io , long baud= 57600){
00068 iostream = io;
00069 baud_ = baud;
00070 }
00071 ArduinoHardware()
00072 {
00073 #if defined(USBCON) and !(defined(USE_USBCON))
00074
00075 iostream = &Serial1;
00076 #elif defined(USE_TEENSY_HW_SERIAL) or defined(USE_STM32_HW_SERIAL)
00077 iostream = &Serial1;
00078 #else
00079 iostream = &Serial;
00080 #endif
00081 baud_ = 57600;
00082 }
00083 ArduinoHardware(ArduinoHardware& h){
00084 this->iostream = h.iostream;
00085 this->baud_ = h.baud_;
00086 }
00087
00088 void setBaud(long baud){
00089 this->baud_= baud;
00090 }
00091
00092 int getBaud(){return baud_;}
00093
00094 void init(){
00095 #if defined(USE_USBCON)
00096
00097 delay(3000);
00098 #endif
00099 iostream->begin(baud_);
00100 }
00101
00102 int read(){return iostream->read();};
00103 void write(uint8_t* data, int length){
00104 for(int i=0; i<length; i++)
00105 iostream->write(data[i]);
00106 }
00107
00108 unsigned long time(){return millis();}
00109
00110 protected:
00111 SERIAL_CLASS* iostream;
00112 long baud_;
00113 };
00114
00115 #endif