CMUcam4 Arduino Interface Library  For Firmware Versions 1.00 - 1.03
Application Programmable Interface Online Documentation
 All Classes Files Functions Variables Macros Pages
CMUcom4.h
Go to the documentation of this file.
1 /***************************************************************************//**
2 * @file
3 * Portable serial and timer wrapper library.
4 *
5 * @version @n 1.0
6 * @date @n 8/3/2012
7 *
8 * @authors @n Kwabena W. Agyeman & Christopher J. Leaf
9 * @copyright @n (c) 2012 Kwabena W. Agyeman & Christopher J. Leaf
10 * @n All rights reserved - Please see the end of the file for the terms of use
11 *
12 * @par Update History:
13 * @n v0.1 - Beta code - 3/20/2012
14 * @n v0.9 - Original release - 4/18/2012
15 * @n v1.0 - Documented and updated release - 8/3/2012
16 *******************************************************************************/
17 
18 #ifndef _CMUCOM4_H_
19 #define _CMUCOM4_H_
20 
21 /**@cond CMUCOM4_PRIVATE*******************************************************/
22 
23 // Handle Arduino Library renaming.
24 #if defined(ARDUINO) && (ARDUINO >= 100)
25 #include "Arduino.h"
26 #else
27 #include "WProgram.h"
28 #endif
29 
30 // Try to save RAM for non-Mega boards.
31 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
32 #define CMUCOM4_INPUT_BUFFER_SIZE 256 ///< Responce input buffer size.
33 #define CMUCOM4_OUTPUT_BUFFER_SIZE 256 ///< Command output buffer size.
34 #else
35 #define CMUCOM4_INPUT_BUFFER_SIZE 160 ///< Responce input buffer size.
36 #define CMUCOM4_OUTPUT_BUFFER_SIZE 96 ///< Command output buffer size.
37 #endif
38 
39 /***************************************************************************//**
40 * This function macro expands whatever argument name that was passed to this
41 * function macro into a string. @par For example:
42 * <tt>@#define ARDUINO 100</tt> @n
43 * <tt>%CMUCOM4_N_TO_S(ARDUINO)</tt> exapands to @c "ARDUINO"
44 *******************************************************************************/
45 #define CMUCOM4_N_TO_S(x) #x
46 
47 /***************************************************************************//**
48 * This function macro expands whatever argument value that was passed to this
49 * function macro into a string. @par For example:
50 * <tt>@#define ARDUINO 100</tt> @n
51 * <tt>%CMUCOM4_V_TO_S(ARDUINO)</tt> exapands to @c "100"
52 *******************************************************************************/
53 #define CMUCOM4_V_TO_S(x) CMUCOM4_N_TO_S(x)
54 
55 /***************************************************************************//**
56 * Default firmware startup baud rate number.
57 *******************************************************************************/
58 #define CMUCOM4_SLOW_BAUD_RATE 19200
59 
60 /***************************************************************************//**
61 * Default firmware startup baud rate string.
62 *******************************************************************************/
63 #define CMUCOM4_SLOW_BR_STRING CMUCOM4_V_TO_S(CMUCOM4_SLOW_BAUD_RATE)
64 
65 /***************************************************************************//**
66 * Version 1.01 firmware and below maximum baud rate number.
67 *******************************************************************************/
68 #define CMUCOM4_MEDIUM_BAUD_RATE 115200
69 
70 /***************************************************************************//**
71 * Version 1.01 firmware and below maximum baud rate string.
72 *******************************************************************************/
73 #define CMUCOM4_MEDIUM_BR_STRING CMUCOM4_V_TO_S(CMUCOM4_MEDIUM_BAUD_RATE)
74 
75 /***************************************************************************//**
76 * Version 1.02 firmware and above maximum baud rate number.
77 *******************************************************************************/
78 #define CMUCOM4_FAST_BAUD_RATE 250000
79 
80 /***************************************************************************//**
81 * Version 1.02 firmware and above maximum baud rate string.
82 *******************************************************************************/
83 #define CMUCOM4_FAST_BR_STRING CMUCOM4_V_TO_S(CMUCOM4_FAST_BAUD_RATE)
84 
85 /***************************************************************************//**
86 * Default firmware startup stop bits number.
87 *******************************************************************************/
88 #define CMUCOM4_SLOW_STOP_BITS 0
89 
90 /***************************************************************************//**
91 * Default firmware startup stop bits string.
92 *******************************************************************************/
93 #define CMUCOM4_SLOW_SB_STRING CMUCOM4_V_TO_S(CMUCOM4_SLOW_STOP_BITS)
94 
95 /***************************************************************************//**
96 * Version 1.01 firmware and below necessary stop bits number.
97 *******************************************************************************/
98 #define CMUCOM4_MEDIUM_STOP_BITS 0
99 
100 /***************************************************************************//**
101 * Version 1.01 firmware and below necessary stop bits string.
102 *******************************************************************************/
103 #define CMUCOM4_MEDIUM_SB_STRING CMUCOM4_V_TO_S(CMUCOM4_MEDIUM_STOP_BITS)
104 
105 /***************************************************************************//**
106 * Version 1.02 firmware and above necessary stop bits number.
107 *******************************************************************************/
108 #define CMUCOM4_FAST_STOP_BITS 0
109 
110 /***************************************************************************//**
111 * Version 1.02 firmware and above necessary stop bits string.
112 *******************************************************************************/
113 #define CMUCOM4_FAST_SB_STRING CMUCOM4_V_TO_S(CMUCOM4_FAST_STOP_BITS)
114 
115 /***************************************************************************//**
116 * Serial CMUcom4::begin() post delay in milliseconds.
117 *******************************************************************************/
118 #define CMUCOM4_BEGIN_DELAY 1
119 
120 /***************************************************************************//**
121 * Serial CMUcom4::end() post delay in milliseconds.
122 *******************************************************************************/
123 #define CMUCOM4_END_DELAY 1
124 
125 /**@endcond********************************************************************/
126 
127 /***************************************************************************//**
128 * This is a convenient macro for specifying the Serial port when initializing a
129 * CMUcam4 or CMUcom4 object.
130 *******************************************************************************/
131 #define CMUCOM4_SERIAL 0
132 
133 /***************************************************************************//**
134 * This is a convenient macro for specifying the Serial1 port on an Arduino Mega
135 * when initializing a CMUcam4 or CMUcom4 object.
136 *******************************************************************************/
137 #define CMUCOM4_SERIAL1 1
138 
139 /***************************************************************************//**
140 * This is a convenient macro for specifying the Serial2 port on an Arduino Mega
141 * when initializing a CMUcam4 or CMUcom4 object.
142 *******************************************************************************/
143 #define CMUCOM4_SERIAL2 2
144 
145 /***************************************************************************//**
146 * This is a convenient macro for specifying the Serial3 port on an Arduino Mega
147 * when initializing a CMUcam4 or CMUcom4 object.
148 *******************************************************************************/
149 #define CMUCOM4_SERIAL3 3
150 
151 /***************************************************************************//**
152 * This is a hardware abstraction layer for the %CMUcam4 class. The %CMUcom4
153 * class targets the Ardunio prototyping platform by default.
154 *******************************************************************************/
155 class CMUcom4
156 {
157 
158 public:
159 
160 /***************************************************************************//**
161 * Initialize the %CMUcom4 object to use the default Serial port.
162 *******************************************************************************/
163 CMUcom4();
164 
165 /***************************************************************************//**
166 * Initialize the %CMUcom4 object to use the @c port Serial port.
167 * @param [in] port The port.
168 * @see CMUCOM4_SERIAL
169 * @see CMUCOM4_SERIAL1
170 * @see CMUCOM4_SERIAL2
171 * @see CMUCOM4_SERIAL3
172 *******************************************************************************/
173 CMUcom4(int port);
174 
175 /***************************************************************************//**
176 * Arduino Serial.begin() wrapper.
177 * @param [in] baud In bits per second.
178 * @see http://arduino.cc/en/Serial/Begin
179 *******************************************************************************/
180 void begin(unsigned long baud);
181 
182 /***************************************************************************//**
183 * Arduino Serial.end() wrapper.
184 * @see http://arduino.cc/en/Serial/End
185 *******************************************************************************/
186 void end();
187 
188 /***************************************************************************//**
189 * Arduino Serial.read() wrapper.
190 * @return The first byte of incoming serial data.
191 * @see http://arduino.cc/en/Serial/Read
192 *******************************************************************************/
193 int read();
194 
195 /***************************************************************************//**
196 * Arduino Serial.write() wrapper.
197 * @param [in] buffer An array to send as a series of bytes.
198 * @param [in] size The size of the buffer.
199 * @return The number of bytes written.
200 * @see http://arduino.cc/en/Serial/Write
201 *******************************************************************************/
202 size_t write(const uint8_t * buffer, size_t size);
203 
204 /***************************************************************************//**
205 * Arduino Serial.write() wrapper.
206 * @param [in] str A string to send as a series of bytes.
207 * @return The number of bytes written.
208 * @see http://arduino.cc/en/Serial/Write
209 *******************************************************************************/
210 size_t write(const char * str);
211 
212 /***************************************************************************//**
213 * Arduino Serial.write() wrapper.
214 * @param [in] c A character to send as a single byte.
215 * @return The number of bytes written.
216 * @see http://arduino.cc/en/Serial/Write
217 *******************************************************************************/
218 size_t write(uint8_t c);
219 
220 /***************************************************************************//**
221 * Arduino Serial.available() wrapper.
222 * @return The number of bytes available to be read.
223 * @see http://arduino.cc/en/Serial/Available
224 *******************************************************************************/
225 int available();
226 
227 /***************************************************************************//**
228 * Arduino Serial.flush() wrapper.
229 * @see http://arduino.cc/en/Serial/Flush
230 *******************************************************************************/
231 void flush();
232 
233 /***************************************************************************//**
234 * Arduino Serial.peek() wrapper.
235 * @return The first byte of incoming serial data available.
236 * @see http://arduino.cc/en/Serial/Peek
237 *******************************************************************************/
238 int peek();
239 
240 /***************************************************************************//**
241 * Arduino delay() wrapper.
242 * @param [in] ms The number of milliseconds to pause for.
243 * @see http://arduino.cc/en/Reference/Delay
244 *******************************************************************************/
245 void delayMilliseconds(unsigned long ms);
246 
247 /***************************************************************************//**
248 * Arduino millis() wrapper.
249 * @return Number of milliseconds since the program started.
250 * @see http://arduino.cc/en/Reference/Millis
251 *******************************************************************************/
252 unsigned long milliseconds();
253 
254 private:
255 
256 /***************************************************************************//**
257 * Selected serial port storage.
258 * @see CMUCOM4_SERIAL1
259 * @see CMUCOM4_SERIAL2
260 * @see CMUCOM4_SERIAL3
261 *******************************************************************************/
262 int _port;
263 };
264 
265 #endif
266 
267 /***************************************************************************//**
268 * @file
269 * @par MIT License - TERMS OF USE:
270 * @n Permission is hereby granted, free of charge, to any person obtaining a
271 * copy of this software and associated documentation files (the "Software"), to
272 * deal in the Software without restriction, including without limitation the
273 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
274 * sell copies of the Software, and to permit persons to whom the Software is
275 * furnished to do so, subject to the following conditions:
276 * @n
277 * @n The above copyright notice and this permission notice shall be included in
278 * all copies or substantial portions of the Software.
279 * @n
280 * @n THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
281 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
282 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
283 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
284 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
285 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
286 * SOFTWARE.
287 *******************************************************************************/