ArduinoHardware.h
Go to the documentation of this file.
00001 /* 
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2011, Willow Garage, Inc.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  *  * Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *  * Redistributions in binary form must reproduce the above
00014  *    copyright notice, this list of conditions and the following
00015  *    disclaimer in the documentation and/or other materials provided
00016  *    with the distribution.
00017  *  * Neither the name of Willow Garage, Inc. nor the names of its
00018  *    contributors may be used to endorse or promote prducts derived
00019  *    from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  * POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00035 #ifndef ROS_ARDUINO_HARDWARE_H_
00036 #define ROS_ARDUINO_HARDWARE_H_
00037 
00038 #if ARDUINO>=100
00039   #include <Arduino.h>  // Arduino 1.0
00040 #else
00041   #include <WProgram.h>  // Arduino 0022
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>  // Teensy 3.0 and 3.1
00049     #define SERIAL_CLASS usb_serial_class
00050   #endif
00051 #elif defined(_SAM3XA_)
00052   #include <UARTClass.h>  // Arduino Due
00053   #define SERIAL_CLASS UARTClass
00054 #elif defined(USE_USBCON)
00055   // Arduino Leonardo USB Serial Port
00056   #define SERIAL_CLASS Serial_
00057 #else 
00058   #include <HardwareSerial.h>  // Arduino AVR
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       /* Leonardo support */
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       // Startup delay as a fail-safe to upload a new sketch
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


rosserial_arduino
Author(s): Michael Ferguson, Adam Stambler
autogenerated on Thu Jun 6 2019 19:56:27