ArduinoHardware.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote prducts derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef ROS_ARDUINO_HARDWARE_H_
36 #define ROS_ARDUINO_HARDWARE_H_
37 
38 #if ARDUINO>=100
39  #include <Arduino.h> // Arduino 1.0
40 #else
41  #include <WProgram.h> // Arduino 0022
42 #endif
43 
44 #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__)
45  #if defined(USE_TEENSY_HW_SERIAL)
46  #define SERIAL_CLASS HardwareSerial // Teensy HW Serial
47  #else
48  #include <usb_serial.h> // Teensy 3.0 and 3.1
49  #define SERIAL_CLASS usb_serial_class
50  #endif
51 #elif defined(_SAM3XA_)
52  #include <UARTClass.h> // Arduino Due
53  #define SERIAL_CLASS UARTClass
54 #elif defined(USE_USBCON)
55  // Arduino Leonardo USB Serial Port
56  #define SERIAL_CLASS Serial_
57 #elif (defined(__STM32F1__) and !(defined(USE_STM32_HW_SERIAL))) or defined(SPARK)
58  // Stm32duino Maple mini USB Serial Port
59  #define SERIAL_CLASS USBSerial
60 #else
61  #include <HardwareSerial.h> // Arduino AVR
62  #define SERIAL_CLASS HardwareSerial
63 #endif
64 
66  public:
67  ArduinoHardware(SERIAL_CLASS* io , long baud= 57600){
68  iostream = io;
69  baud_ = baud;
70  }
72  {
73 #if defined(USBCON) and !(defined(USE_USBCON))
74  /* Leonardo support */
75  iostream = &Serial1;
76 #elif defined(USE_TEENSY_HW_SERIAL) or defined(USE_STM32_HW_SERIAL)
77  iostream = &Serial1;
78 #else
79  iostream = &Serial;
80 #endif
81  baud_ = 57600;
82  }
84  this->iostream = h.iostream;
85  this->baud_ = h.baud_;
86  }
87 
88  void setBaud(long baud){
89  this->baud_= baud;
90  }
91 
92  int getBaud(){return baud_;}
93 
94  void init(){
95 #if defined(USE_USBCON)
96  // Startup delay as a fail-safe to upload a new sketch
97  delay(3000);
98 #endif
99  iostream->begin(baud_);
100  }
101 
102  int read(){return iostream->read();};
103  void write(uint8_t* data, int length){
104  for(int i=0; i<length; i++)
105  iostream->write(data[i]);
106  }
107 
108  unsigned long time(){return millis();}
109 
110  protected:
112  long baud_;
113 };
114 
115 #endif
#define SERIAL_CLASS
ArduinoHardware(ArduinoHardware &h)
SERIAL_CLASS * iostream
void write(uint8_t *data, int length)
void setBaud(long baud)
ArduinoHardware(SERIAL_CLASS *io, long baud=57600)
baud
unsigned long time()


rosserial_arduino
Author(s): Michael Ferguson, Adam Stambler
autogenerated on Mon Jun 10 2019 14:53:34