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__)
00045   #include <usb_serial.h>  // Teensy 3.0 and 3.1
00046   #define SERIAL_CLASS usb_serial_class
00047 #elif defined(_SAM3XA_)
00048   #include <UARTClass.h>  // Arduino Due
00049   #define SERIAL_CLASS UARTClass
00050 #elif defined(USE_USBCON)
00051   // Arduino Leonardo USB Serial Port
00052   #define SERIAL_CLASS Serial_
00053 #else 
00054   #include <HardwareSerial.h>  // Arduino AVR
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       /* Leonardo support */
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       // Startup delay as a fail-safe to upload a new sketch
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


ric_mc
Author(s): RoboTiCan
autogenerated on Fri May 20 2016 03:48:54