CMUcam4 Arduino Interface Library  For Firmware Versions 1.00 - 1.03
Application Programmable Interface Online Documentation
 All Classes Files Functions Variables Macros Pages
CMUcam4.h
Go to the documentation of this file.
1 /***************************************************************************//**
2 * @file
3 * Portable %CMUcam4 interface library.
4 *
5 * @version @n 1.1
6 * @date @n 2/7/2013
7 *
8 * @authors @n Kwabena W. Agyeman & Christopher J. Leaf
9 * @copyright @n (c) 2013 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 * @n v1.1 - Added support for the Arduino Due, fixed the send frame command,
17  and fixed a number of compile time warnings - 2/7/2013.
18 *******************************************************************************/
19 
20 #ifndef _CMUCAM4_H_
21 #define _CMUCAM4_H_
22 
23 #include "CMUcom4.h"
24 
25 #include <setjmp.h>
26 #include <stdbool.h>
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <stdio.h>
30 #include <string.h>
31 
32 /***************************************************************************//**
33 * %CMUcam4 firmware version 1.00.
34 *******************************************************************************/
35 #define CMUCAM4_FIRMWARE_V100 100
36 
37 /***************************************************************************//**
38 * %CMUcam4 firmware version 1.01.
39 *******************************************************************************/
40 #define CMUCAM4_FIRMWARE_V101 101
41 
42 /***************************************************************************//**
43 * %CMUcam4 firmware version 1.02.
44 *******************************************************************************/
45 #define CMUCAM4_FIRMWARE_V102 102
46 
47 /***************************************************************************//**
48 * %CMUcam4 firmware version 1.03.
49 *******************************************************************************/
50 #define CMUCAM4_FIRMWARE_V103 103
51 
52 /***************************************************************************//**
53 * The native horizontal resolution.
54 *******************************************************************************/
55 #define CMUCAM4_NATIVE_H_RES 160
56 
57 /***************************************************************************//**
58 * The native vertical resolution.
59 *******************************************************************************/
60 #define CMUCAM4_NATIVE_V_RES 120
61 
62 /***************************************************************************//**
63 * The binary bitmap horizontal resolution.
64 *******************************************************************************/
65 #define CMUCAM4_BINARY_H_RES (CMUCAM4_NATIVE_H_RES / 2)
66 
67 /***************************************************************************//**
68 * The binary bitmap vertical resolution.
69 *******************************************************************************/
70 #define CMUCAM4_BINARY_V_RES (CMUCAM4_NATIVE_V_RES / 2)
71 
72 /***************************************************************************//**
73 * The first native row.
74 *******************************************************************************/
75 #define CMUCAM4_MIN_NATIVE_ROW 0
76 
77 /***************************************************************************//**
78 * The first native column.
79 *******************************************************************************/
80 #define CMUCAM4_MIN_NATIVE_COLUMN 0
81 
82 /***************************************************************************//**
83 * The last native row.
84 *******************************************************************************/
85 #define CMUCAM4_MAX_NATIVE_ROW (CMUCAM4_NATIVE_V_RES - 1)
86 
87 /***************************************************************************//**
88 * The last native column.
89 *******************************************************************************/
90 #define CMUCAM4_MAX_NATIVE_COLUMN (CMUCAM4_NATIVE_H_RES - 1)
91 
92 /***************************************************************************//**
93 * The first binary bitmap row.
94 *******************************************************************************/
95 #define CMUCAM4_MIN_BINARY_ROW 0
96 
97 /***************************************************************************//**
98 * The first binary bitmap column.
99 *******************************************************************************/
100 #define CMUCAM4_MIN_BINARY_COLUMN 0
101 
102 /***************************************************************************//**
103 * The last binary bitmap row.
104 *******************************************************************************/
105 #define CMUCAM4_MAX_BINARY_ROW (CMUCAM4_BINARY_V_RES - 1)
106 
107 /***************************************************************************//**
108 * The last binary bitmap column.
109 *******************************************************************************/
110 #define CMUCAM4_MAX_BINARY_COLUMN (CMUCAM4_BINARY_H_RES - 1)
111 
112 /***************************************************************************//**
113 * This is a convenient macro for comparing the pan pin to low and the tilt pin
114 * to low.
115 * @see CMUcam4::getInputs()
116 *******************************************************************************/
117 #define CMUCAM4_IN_TP_LL 0
118 
119 /***************************************************************************//**
120 * This is a convenient macro for comparing the pan pin to high and the tilt pin
121 * to low.
122 * @see CMUcam4::getInputs()
123 *******************************************************************************/
124 #define CMUCAM4_IN_TP_LH 1
125 
126 /***************************************************************************//**
127 * This is a convenient macro for comparing the pan pin to low and the tilt pin
128 * to high.
129 * @see CMUcam4::getInputs()
130 *******************************************************************************/
131 #define CMUCAM4_IN_TP_HL 2
132 
133 /***************************************************************************//**
134 * This is a convenient macro for comparing the pan pin to high and the tilt pin
135 * to high.
136 * @see CMUcam4::getInputs()
137 *******************************************************************************/
138 #define CMUCAM4_IN_TP_HH 3
139 
140 /***************************************************************************//**
141 * This is a convenient macro for specifying the pan pin to be an input and the
142 * tilt pin to be an input.
143 * @see CMUcam4::setOutputs()
144 *******************************************************************************/
145 #define CMUCAM4_DIR_TP_II 0
146 
147 /***************************************************************************//**
148 * This is a convenient macro for specifying the pan pin to be an output and the
149 * tilt pin to be an input.
150 * @see CMUcam4::setOutputs()
151 *******************************************************************************/
152 #define CMUCAM4_DIR_TP_IO 1
153 
154 /***************************************************************************//**
155 * This is a convenient macro for specifying the pan pin to be an input and the
156 * tilt pin to be an output.
157 * @see CMUcam4::setOutputs()
158 *******************************************************************************/
159 #define CMUCAM4_DIR_TP_OI 2
160 
161 /***************************************************************************//**
162 * This is a convenient macro for specifying the pan pin to be an output and the
163 * tilt pin to be an output.
164 * @see CMUcam4::setOutputs()
165 *******************************************************************************/
166 #define CMUCAM4_DIR_TP_OO 3
167 
168 /***************************************************************************//**
169 * This is a convenient macro for specifying the pan pin to output low and the
170 * tilt pin to output low.
171 * @see CMUcam4::setOutputs()
172 *******************************************************************************/
173 #define CMUCAM4_OUT_TP_LL 0
174 
175 /***************************************************************************//**
176 * This is a convenient macro for specifying the pan pin to output high and the
177 * tilt pin to output low.
178 * @see CMUcam4::setOutputs()
179 *******************************************************************************/
180 #define CMUCAM4_OUT_TP_LH 1
181 
182 /***************************************************************************//**
183 * This is a convenient macro for specifying the pan pin to output low and the
184 * tilt pin to output high.
185 * @see CMUcam4::setOutputs()
186 *******************************************************************************/
187 #define CMUCAM4_OUT_TP_HL 2
188 
189 /***************************************************************************//**
190 * This is a convenient macro for specifying the pan pin to output high and the
191 * tilt pin to output high.
192 * @see CMUcam4::setOutputs()
193 *******************************************************************************/
194 #define CMUCAM4_OUT_TP_HH 3
195 
196 /***************************************************************************//**
197 * This is a convenient macro for specifying that the LED should be off when the
198 * %CMUcam4 is idling.
199 * @see CMUcam4::LEDOn()
200 *******************************************************************************/
201 #define CMUCAM4_LED_OFF -1
202 
203 /***************************************************************************//**
204 * This is a convenient macro for specifying that the LED should be on when the
205 * %CMUcam4 is idling.
206 * @see CMUcam4::LEDOn()
207 *******************************************************************************/
208 #define CMUCAM4_LED_ON 0
209 
210 /***************************************************************************//**
211 * This is a convenient macro for specifying the pan servo.
212 * @see CMUcam4::getServoPosition()
213 * @see CMUcam4::setServoPosition()
214 *******************************************************************************/
215 #define CMUCAM4_PAN_SERVO 0
216 
217 /***************************************************************************//**
218 * This is a convenient macro for specifying the tilt servo.
219 * @see CMUcam4::getServoPosition()
220 * @see CMUcam4::setServoPosition()
221 *******************************************************************************/
222 #define CMUCAM4_TILT_SERVO 1
223 
224 /***************************************************************************//**
225 * This is a convenient macro for specifying the histogram's red channel.
226 * @see CMUcam4::getHistogram()
227 *******************************************************************************/
228 #define CMUCAM4_RED_CHANNEL 0
229 
230 /***************************************************************************//**
231 * This is a convenient macro for specifying the histogram's green channel.
232 * @see CMUcam4::getHistogram()
233 *******************************************************************************/
234 #define CMUCAM4_GREEN_CHANNEL 1
235 
236 /***************************************************************************//**
237 * This is a convenient macro for specifying the histogram's blue channel.
238 * @see CMUcam4::getHistogram()
239 *******************************************************************************/
240 #define CMUCAM4_BLUE_CHANNEL 2
241 
242 /***************************************************************************//**
243 * This is a convenient macro for specifying a 1-bin histogram.
244 * @see CMUcam4::getHistogram()
245 *******************************************************************************/
246 #define CMUCAM4_H1_BINS 0
247 
248 /***************************************************************************//**
249 * This is a convenient macro for specifying a 2-bin histogram.
250 * @see CMUcam4::getHistogram()
251 *******************************************************************************/
252 #define CMUCAM4_H2_BINS 1
253 
254 /***************************************************************************//**
255 * This is a convenient macro for specifying a 4-bin histogram.
256 * @see CMUcam4::getHistogram()
257 *******************************************************************************/
258 #define CMUCAM4_H4_BINS 2
259 
260 /***************************************************************************//**
261 * This is a convenient macro for specifying a 8-bin histogram.
262 * @see CMUcam4::getHistogram()
263 *******************************************************************************/
264 #define CMUCAM4_H8_BINS 3
265 
266 /***************************************************************************//**
267 * This is a convenient macro for specifying a 16-bin histogram.
268 * @see CMUcam4::getHistogram()
269 *******************************************************************************/
270 #define CMUCAM4_H16_BINS 4
271 
272 /***************************************************************************//**
273 * This is a convenient macro for specifying a 32-bin histogram.
274 * @see CMUcam4::getHistogram()
275 *******************************************************************************/
276 #define CMUCAM4_H32_BINS 5
277 
278 /***************************************************************************//**
279 * This is a convenient macro for specifying a 64-bin histogram.
280 * @see CMUcam4::getHistogram()
281 *******************************************************************************/
282 #define CMUCAM4_H64_BINS 6
283 
284 /***************************************************************************//**
285 * This is a convenient macro for specifying a horizontal resolution of 640
286 * pixels for CMUcam4::dumpFrame() and CMUcam4::sendFrame().
287 *******************************************************************************/
288 #define CMUCAM4_HR_640 0
289 
290 /***************************************************************************//**
291 * This is a convenient macro for specifying a horizontal resolution of 320
292 * pixels for CMUcam4::dumpFrame() and CMUcam4::sendFrame().
293 *******************************************************************************/
294 #define CMUCAM4_HR_320 1
295 
296 /***************************************************************************//**
297 * This is a convenient macro for specifying a horizontal resolution of 160
298 * pixels for CMUcam4::dumpFrame() and CMUcam4::sendFrame().
299 *******************************************************************************/
300 #define CMUCAM4_HR_160 2
301 
302 /***************************************************************************//**
303 * This is a convenient macro for specifying a horizontal resolution of 80
304 * pixels for CMUcam4::dumpFrame() and CMUcam4::sendFrame().
305 *******************************************************************************/
306 #define CMUCAM4_HR_80 3
307 
308 /***************************************************************************//**
309 * This is a convenient macro for specifying a vertical resolution of 480 pixels
310 * to for CMUcam4::dumpFrame() and CMUcam4::sendFrame().
311 *******************************************************************************/
312 #define CMUCAM4_VR_480 0
313 
314 /***************************************************************************//**
315 * This is a convenient macro for specifying a vertical resolution of 240 pixels
316 * to for CMUcam4::dumpFrame() and CMUcam4::sendFrame().
317 *******************************************************************************/
318 #define CMUCAM4_VR_240 1
319 
320 /***************************************************************************//**
321 * This is a convenient macro for specifying a vertical resolution of 120 pixels
322 * to for CMUcam4::dumpFrame() and CMUcam4::sendFrame().
323 *******************************************************************************/
324 #define CMUCAM4_VR_120 2
325 
326 /***************************************************************************//**
327 * This is a convenient macro for specifying a vertical resolution of 60 pixels
328 * to for CMUcam4::dumpFrame() and CMUcam4::sendFrame().
329 *******************************************************************************/
330 #define CMUCAM4_VR_60 3
331 
332 /***************************************************************************//**
333 * The number of rows of bytes in the binary bitmap.
334 *******************************************************************************/
335 #define CMUCAM4_ID_T_R CMUCAM4_BINARY_V_RES
336 
337 /***************************************************************************//**
338 * The number of columns of bytes in the binary bitmap.
339 *******************************************************************************/
340 #define CMUCAM4_ID_T_C (CMUCAM4_BINARY_H_RES / 8)
341 
342 /***************************************************************************//**
343 * The number of bytes in the binary bitmap.
344 * @see CMUcam4_image_data_t
345 *******************************************************************************/
346 #define CMUCAM4_ID_T_LENGTH (CMUCAM4_ID_T_R * CMUCAM4_ID_T_C)
347 
348 /***************************************************************************//**
349 * 1-bin histogram data structure length in bytes.
350 * @see CMUcam4_histogram_data_1_t
351 *******************************************************************************/
352 #define CMUCAM4_HD_1_T_LENGTH (1 << CMUCAM4_H1_BINS)
353 
354 /***************************************************************************//**
355 * 2-bin histogram data structure length in bytes.
356 * @see CMUcam4_histogram_data_2_t
357 *******************************************************************************/
358 #define CMUCAM4_HD_2_T_LENGTH (1 << CMUCAM4_H2_BINS)
359 
360 /***************************************************************************//**
361 * 4-bin histogram data structure length in bytes.
362 * @see CMUcam4_histogram_data_4_t
363 *******************************************************************************/
364 #define CMUCAM4_HD_4_T_LENGTH (1 << CMUCAM4_H4_BINS)
365 
366 /***************************************************************************//**
367 * 8-bin histogram data structure length in bytes.
368 * @see CMUcam4_histogram_data_8_t
369 *******************************************************************************/
370 #define CMUCAM4_HD_8_T_LENGTH (1 << CMUCAM4_H8_BINS)
371 
372 /***************************************************************************//**
373 * 16-bin histogram data structure length in bytes.
374 * @see CMUcam4_histogram_data_16_t
375 *******************************************************************************/
376 #define CMUCAM4_HD_16_T_LENGTH (1 << CMUCAM4_H16_BINS)
377 
378 /***************************************************************************//**
379 * 32-bin histogram data structure length in bytes.
380 * @see CMUcam4_histogram_data_32_t
381 *******************************************************************************/
382 #define CMUCAM4_HD_32_T_LENGTH (1 << CMUCAM4_H32_BINS)
383 
384 /***************************************************************************//**
385 * 64-bin histogram data structure length in bytes.
386 * @see CMUcam4_histogram_data_64_t
387 *******************************************************************************/
388 #define CMUCAM4_HD_64_T_LENGTH (1 << CMUCAM4_H64_BINS)
389 
390 /***************************************************************************//**
391 * Partition volume label string length in numerical form.
392 *******************************************************************************/
393 #define CMUCAM4_VL_LENGTH 11
394 
395 /***************************************************************************//**
396 * File system type string length in numerical form.
397 *******************************************************************************/
398 #define CMUCAM4_FST_LENGTH 8
399 
400 /***************************************************************************//**
401 * Directory entry name string length in numerical form.
402 *******************************************************************************/
403 #define CMUCAM4_NAME_LENGTH 12
404 
405 /***************************************************************************//**
406 * Directory entry attribute string length in numerical form.
407 *******************************************************************************/
408 #define CMUCAM4_ATTR_LENGTH 6
409 
410 /***************************************************************************//**
411 * The operation was successful. Non-negative values are usually successes.
412 *******************************************************************************/
413 #define CMUCAM4_RETURN_SUCCESS 0
414 
415 /***************************************************************************//**
416 * The operation was unsuccessful. This is usually caused by a NULL pointer.
417 *******************************************************************************/
418 #define CMUCAM4_RETURN_FAILURE -1
419 
420 /***************************************************************************//**
421 * The %CMUcam4 and the interface library have not been initialized yet.
422 *******************************************************************************/
423 #define CMUCAM4_NOT_ACTIVATED -2
424 
425 /***************************************************************************//**
426 * The %CMUcam4 responded to the command with a NCK.
427 *******************************************************************************/
428 #define CMUCAM4_NCK_RESPONCE -3
429 
430 /***************************************************************************//**
431 * The %CMUcam4 firmware version is unknown and unsupported.
432 *******************************************************************************/
433 #define CMUCAM4_UNSUPPORTED_VERSION -4
434 
435 /***************************************************************************//**
436 * The %CMUcam4 responded to the command with something unexpected.
437 *******************************************************************************/
438 #define CMUCAM4_UNEXPECTED_RESPONCE -5
439 
440 /***************************************************************************//**
441 * The command buffer overflowed. This error is usually caused by passing
442 * strings that are too large to the interface library.
443 *******************************************************************************/
444 #define CMUCAM4_COMMAND_OVERFLOW -6
445 
446 /***************************************************************************//**
447 * The responce buffer overflowed. This error is usually caused by not handling
448 * communication with the %CMUcam4 fast enough. In particular, whenever the
449 * %CMUcam4 sends a large amount of binary data this can cause the responce
450 * buffer to overflow if not handled quickly.
451 *******************************************************************************/
452 #define CMUCAM4_RESPONCE_OVERFLOW -7
453 
454 /***************************************************************************//**
455 * The %CMUcam4 is not streaming data packets.
456 *******************************************************************************/
457 #define CMUCAM4_STREAM_END -8
458 
459 /***************************************************************************//**
460 * The %CMUcam4 is not responding.
461 *******************************************************************************/
462 #define CMUCAM4_SERIAL_TIMEOUT -9
463 
464 /***************************************************************************//**
465 * The %CMUcam4 is having problems with the camera module's parallel data bus.
466 *******************************************************************************/
467 #define CMUCAM4_CAMERA_TIMEOUT_ERROR -10
468 
469 /***************************************************************************//**
470 * The %CMUcam4 is having problems with the camera module's serial data bus.
471 *******************************************************************************/
472 #define CMUCAM4_CAMERA_CONNECTION_ERROR -11
473 
474 /***************************************************************************//**
475 * An error occured communicating with the micro secure digital card.
476 *******************************************************************************/
477 #define CMUCAM4_DISK_IO_ERROR -12
478 
479 /***************************************************************************//**
480 * The file system is corrupted. Try non-quickly reformatting the file system.
481 *******************************************************************************/
482 #define CMUCAM4_FILE_SYSTEM_CORRUPTED -13
483 
484 /***************************************************************************//**
485 * The file system is unsupported. Try non-quickly reformatting the file system.
486 *******************************************************************************/
487 #define CMUCAM4_FILE_SYSTEM_UNSUPPORTED -14
488 
489 /***************************************************************************//**
490 * A micro secure digital card was not found.
491 *******************************************************************************/
492 #define CMUCAM4_CARD_NOT_DETECTED -15
493 
494 /***************************************************************************//**
495 * The micro secure digital card may be full. The error is "may be" because of
496 * the time it would take to verify the if disk was completely full.
497 *******************************************************************************/
498 #define CMUCAM4_DISK_MAY_BE_FULL -16
499 
500 /***************************************************************************//**
501 * The directory entry slots in the current directory are completely full. Some
502 * directory entries may use multiple directory entry slots.
503 *******************************************************************************/
504 #define CMUCAM4_DIRECTORY_FULL -17
505 
506 /***************************************************************************//**
507 * The target name of a file system path string is malformed.
508 *******************************************************************************/
509 #define CMUCAM4_EXPECTED_AN_ENTRY -18
510 
511 /***************************************************************************//**
512 * A directory name in a file system path string is malformed.
513 *******************************************************************************/
514 #define CMUCAM4_EXPECTED_A_DIRECTORY -19
515 
516 /***************************************************************************//**
517 * The target name of the file system path string cannot be accessed.
518 *******************************************************************************/
519 #define CMUCAM4_ENTRY_NOT_ACCESSIBLE -20
520 
521 /***************************************************************************//**
522 * The target name of the file system path string cannot be modified.
523 *******************************************************************************/
524 #define CMUCAM4_ENTRY_NOT_MODIFIABLE -21
525 
526 /***************************************************************************//**
527 * The target or a directory in a file system path string cannot be found.
528 *******************************************************************************/
529 #define CMUCAM4_ENTRY_NOT_FOUND -22
530 
531 /***************************************************************************//**
532 * The file or directory already exists.
533 *******************************************************************************/
534 #define CMUCAM4_ENTRY_ALREADY_EXISTS -23
535 
536 /***************************************************************************//**
537 * An error occured trying to move a folder.
538 *******************************************************************************/
539 #define CMUCAM4_DIRECTORY_LINK_MISSING -24
540 
541 /***************************************************************************//**
542 * Directories must be empty first to be deleted.
543 *******************************************************************************/
544 #define CMUCAM4_DIRECTORY_NOT_EMPTY -25
545 
546 /***************************************************************************//**
547 * The target of a directory only operation is not a directory.
548 *******************************************************************************/
549 #define CMUCAM4_NOT_A_DIRECTORY -26
550 
551 /***************************************************************************//**
552 * The target of a file only operation is not a file.
553 *******************************************************************************/
554 #define CMUCAM4_NOT_A_FILE -27
555 
556 /**@cond CMUCAM4_PRIVATE*******************************************************/
557 
558 /***************************************************************************//**
559 * Partition volume label string length in string form.
560 *******************************************************************************/
561 #define CMUCAM4_VL_LENGTH_STR CMUCOM4_V_TO_S(CMUCAM4_VL_LENGTH)
562 
563 /***************************************************************************//**
564 * File system type string length in string form.
565 *******************************************************************************/
566 #define CMUCAM4_FST_LENGTH_STR CMUCOM4_V_TO_S(CMUCAM4_FST_LENGTH)
567 
568 /***************************************************************************//**
569 * Directory entry name string length in string form.
570 *******************************************************************************/
571 #define CMUCAM4_NAME_LENGTH_STR CMUCOM4_V_TO_S(CMUCAM4_NAME_LENGTH)
572 
573 /***************************************************************************//**
574 * Directory entry attribute string length in string form.
575 *******************************************************************************/
576 #define CMUCAM4_ATTR_LENGTH_STR CMUCOM4_V_TO_S(CMUCAM4_ATTR_LENGTH)
577 
578 /***************************************************************************//**
579 * Error string checksum of the error string "Camera Timeout Error".
580 *******************************************************************************/
581 #define CMUCAM4_CAMERA_TIMEOUT_ERROR_SUM ('E'+'R'+'R'+':'+' '+\
582 'C'+'a'+'m'+'e'+'r'+'a'+' '+\
583 'T'+'i'+'m'+'e'+'o'+'u'+'t'+' '+\
584 'E'+'r'+'r'+'o'+'r')
585 
586 /***************************************************************************//**
587 * Error string checksum of the error string "Camera Connection Error".
588 *******************************************************************************/
589 #define CMUCAM4_CAMERA_CONNECTION_ERROR_SUM ('E'+'R'+'R'+':'+' '+\
590 'C'+'a'+'m'+'e'+'r'+'a'+' '+\
591 'C'+'o'+'n'+'n'+'e'+'c'+'t'+'i'+'o'+'n'+' '+\
592 'E'+'r'+'r'+'o'+'r')
593 
594 /***************************************************************************//**
595 * Error string checksum of the error string "Disk IO Error".
596 *******************************************************************************/
597 #define CMUCAM4_DISK_IO_ERROR_SUM ('E'+'R'+'R'+':'+' '+\
598 'D'+'i'+'s'+'k'+' '+\
599 'I'+'O'+' '+\
600 'E'+'r'+'r'+'o'+'r')
601 
602 /***************************************************************************//**
603 * Error string checksum of the error string "File System Corrupted".
604 *******************************************************************************/
605 #define CMUCAM4_FILE_SYSTEM_CORRUPTED_SUM ('E'+'R'+'R'+':'+' '+\
606 'F'+'i'+'l'+'e'+' '+\
607 'S'+'y'+'s'+'t'+'e'+'m'+' '+\
608 'C'+'o'+'r'+'r'+'u'+'p'+'t'+'e'+'d')
609 
610 /***************************************************************************//**
611 * Error string checksum of the error string "File System Unsupported".
612 *******************************************************************************/
613 #define CMUCAM4_FILE_SYSTEM_UNSUPPORTED_SUM ('E'+'R'+'R'+':'+' '+\
614 'F'+'i'+'l'+'e'+' '+\
615 'S'+'y'+'s'+'t'+'e'+'m'+' '+\
616 'U'+'n'+'s'+'u'+'p'+'p'+'o'+'r'+'t'+'e'+'d')
617 
618 /***************************************************************************//**
619 * Error string checksum of the error string "Card Not Detected".
620 *******************************************************************************/
621 #define CMUCAM4_CARD_NOT_DETECTED_SUM ('E'+'R'+'R'+':'+' '+\
622 'C'+'a'+'r'+'d'+' '+\
623 'N'+'o'+'t'+' '+\
624 'D'+'e'+'t'+'e'+'c'+'t'+'e'+'d')
625 
626 /***************************************************************************//**
627 * Error string checksum of the error string "Disk May Be Full".
628 *******************************************************************************/
629 #define CMUCAM4_DISK_MAY_BE_FULL_SUM ('E'+'R'+'R'+':'+' '+\
630 'D'+'i'+'s'+'k'+' '+\
631 'M'+'a'+'y'+' '+\
632 'B'+'e'+' '+\
633 'F'+'u'+'l'+'l')
634 
635 /***************************************************************************//**
636 * Error string checksum of the error string "Directory Full Sum".
637 *******************************************************************************/
638 #define CMUCAM4_DIRECTORY_FULL_SUM ('E'+'R'+'R'+':'+' '+\
639 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y'+' '+\
640 'F'+'u'+'l'+'l')
641 
642 /***************************************************************************//**
643 * Error string checksum of the error string "Expected An Entry".
644 *******************************************************************************/
645 #define CMUCAM4_EXPECTED_AN_ENTRY_SUM ('E'+'R'+'R'+':'+' '+\
646 'E'+'x'+'p'+'e'+'c'+'t'+'e'+'d'+' '+\
647 'A'+'n'+' '+\
648 'E'+'n'+'t'+'r'+'y')
649 
650 /***************************************************************************//**
651 * Error string checksum of the error string "Expected A Directory".
652 *******************************************************************************/
653 #define CMUCAM4_EXPECTED_A_DIRECTORY_SUM ('E'+'R'+'R'+':'+' '+\
654 'E'+'x'+'p'+'e'+'c'+'t'+'e'+'d'+' '+\
655 'A'+' '+\
656 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y')
657 
658 /***************************************************************************//**
659 * Error string checksum of the error string "Entry Not Accessible".
660 *******************************************************************************/
661 #define CMUCAM4_ENTRY_NOT_ACCESSIBLE_SUM ('E'+'R'+'R'+':'+' '+\
662 'E'+'n'+'t'+'r'+'y'+' '+\
663 'N'+'o'+'t'+' '+\
664 'A'+'c'+'c'+'e'+'s'+'s'+'i'+'b'+'l'+'e')
665 
666 /***************************************************************************//**
667 * Error string checksum of the error string "Entry Not Modifiable".
668 *******************************************************************************/
669 #define CMUCAM4_ENTRY_NOT_MODIFIABLE_SUM ('E'+'R'+'R'+':'+' '+\
670 'E'+'n'+'t'+'r'+'y'+' '+\
671 'N'+'o'+'t'+' '+\
672 'M'+'o'+'d'+'i'+'f'+'i'+'a'+'b'+'l'+'e')
673 
674 /***************************************************************************//**
675 * Error string checksum of the error string "Entry Not Found".
676 *******************************************************************************/
677 #define CMUCAM4_ENTRY_NOT_FOUND_SUM ('E'+'R'+'R'+':'+' '+\
678 'E'+'n'+'t'+'r'+'y'+' '+\
679 'N'+'o'+'t'+' '+\
680 'F'+'o'+'u'+'n'+'d')
681 
682 /***************************************************************************//**
683 * Error string checksum of the error string "Entry Already Exists".
684 *******************************************************************************/
685 #define CMUCAM4_ENTRY_ALREADY_EXISTS_SUM ('E'+'R'+'R'+':'+' '+\
686 'E'+'n'+'t'+'r'+'y'+' '+\
687 'A'+'l'+'r'+'e'+'a'+'d'+'y'+' '+\
688 'E'+'x'+'i'+'s'+'t'+'s')
689 
690 /***************************************************************************//**
691 * Error string checksum of the error string "Directory Link Missing".
692 *******************************************************************************/
693 #define CMUCAM4_DIRECTORY_LINK_MISSING_SUM ('E'+'R'+'R'+':'+' '+\
694 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y'+' '+\
695 'L'+'i'+'n'+'k'+' '+\
696 'M'+'i'+'s'+'s'+'i'+'n'+'g')
697 
698 /***************************************************************************//**
699 * Error string checksum of the error string "Directory Not Empty".
700 *******************************************************************************/
701 #define CMUCAM4_DIRECTORY_NOT_EMPTY_SUM ('E'+'R'+'R'+':'+' '+\
702 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y'+' '+\
703 'N'+'o'+'t'+' '+\
704 'E'+'m'+'p'+'t'+'y')
705 
706 /***************************************************************************//**
707 * Error string checksum of the error string "Not A Directory".
708 *******************************************************************************/
709 #define CMUCAM4_NOT_A_DIRECTORY_SUM ('E'+'R'+'R'+':'+' '+\
710 'N'+'o'+'t'+' '+\
711 'A'+' '+\
712 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y')
713 
714 /***************************************************************************//**
715 * Error string checksum of the error string "Not A File".
716 *******************************************************************************/
717 #define CMUCAM4_NOT_A_FILE_SUM ('E'+'R'+'R'+':'+' '+\
718 'N'+'o'+'t'+' '+\
719 'A'+' '+\
720 'F'+'i'+'l'+'e')
721 
722 /***************************************************************************//**
723 * Responce (input) storage buffer size alias.
724 *******************************************************************************/
725 #define CMUCAM4_RES_BUFFER_SIZE CMUCOM4_INPUT_BUFFER_SIZE
726 #if (CMUCAM4_RES_BUFFER_SIZE < 1) // Responce buffer size limit.
727 #error "Error: The responce (input) buffer size is too small!"
728 #endif
729 
730 /***************************************************************************//**
731 * Command (output) storage buffer size alias.
732 *******************************************************************************/
733 #define CMUCAM4_CMD_BUFFER_SIZE CMUCOM4_OUTPUT_BUFFER_SIZE
734 #if (CMUCAM4_CMD_BUFFER_SIZE < 1) // Command buffer size limit.
735 #error "Error: The command (output) buffer size is too small!"
736 #endif
737 
738 /***************************************************************************//**
739 * Number of CMUcam4::begin() reset tries.
740 *******************************************************************************/
741 #define CMUCAM4_RESET_TRIES 4
742 
743 /***************************************************************************//**
744 * Number of milliseconds to wait for CMUcam4::begin() reset tries.
745 *******************************************************************************/
746 #define CMUCAM4_RESET_TIMEOUT 2250
747 
748 /***************************************************************************//**
749 * Number of CMUcam4::idleCamera() idle tries.
750 *******************************************************************************/
751 #define CMUCAM4_IDLE_TRIES 4
752 
753 /***************************************************************************//**
754 * Number of milliseconds to wait for CMUcam4::idleCamera() idle tries.
755 *******************************************************************************/
756 #define CMUCAM4_IDLE_TIMEOUT 750
757 
758 /***************************************************************************//**
759 * Non-file system related operations timeout in milliseconds.
760 *******************************************************************************/
761 #define CMUCAM4_NON_FS_TIMEOUT 1000
762 
763 /***************************************************************************//**
764 * File system related operations timeout in milliseconds.
765 *******************************************************************************/
766 #define CMUCAM4_FS_TIMEOUT 3600000
767 
768 /***************************************************************************//**
769 * The CMUcam4::idleCamera() shift register comparison string.
770 *******************************************************************************/
771 #define CMUCAM4_IC_STRING ":ACK\rCMUcam4 v%d.%02d\r:"
772 
773 /***************************************************************************//**
774 * The CMUcam4::idleCamera() shift register comparison length.
775 *******************************************************************************/
776 #define CMUCAM4_IC_LENGTH sizeof(CMUCAM4_IC_STRING)
777 
778 /***************************************************************************//**
779 * The frame horizontal resolution.
780 *******************************************************************************/
781 #define CMUCAM4_FRAME_H_RES 640
782 
783 /***************************************************************************//**
784 * The native vertical resolution.
785 *******************************************************************************/
786 #define CMUCAM4_FRAME_V_RES 480
787 
788 /**@endcond********************************************************************/
789 
790 /***************************************************************************//**
791 * %CMUcam4 tracking parameters structure.
792 * @see CMUcam4::getTrackingParameters()
793 *******************************************************************************/
795 {
796  int redMin; ///< The lower red or V threshold value - [0 : 255].
797  int redMax; ///< The upper red or V threshold value - [0 : 255].
798  int greenMin; ///< The lower green or Y threshold value - [0 : 255].
799  int greenMax; ///< The upper green or Y threshold value - [0 : 255].
800  int blueMin; ///< The lower blue or U threshold value - [0 : 255].
801  int blueMax; ///< The upper blue or U threshold value - [0 : 255].
802 }
804 
805 /***************************************************************************//**
806 * %CMUcam4 tracking window structure.
807 * @see CMUcam4::getTrackingWindow()
808 *******************************************************************************/
810 {
811  int topLeftX; ///< The X1 tracking window coordinate - [0 : 159].
812  int topLeftY; ///< The Y1 tracking window coordinate - [0 : 119].
813  int bottomRightX; ///< The X2 tracking window coordinate - [X1 : 159].
814  int bottomRightY; ///< The Y2 tracking window coordinate - [Y1 : 119].
815 }
817 
818 /***************************************************************************//**
819 * %CMUcam4 binary bitmap structure. The binary bitmap is 80x60 pixels where
820 * each pixel is one bit. A 0 bit represents an untracked pixel. A 1 bit
821 * represents a tracked pixel. Basic frame differencing can be accomplished by
822 * post processing the binary bitmap among other interesting things. The binary
823 * bitmap has 4,800 pixels contained in 600 bytes. The MSB of every byte is the
824 * left most pixel while the LSB is the right most pixel.
825 * @see CMUcam4::getTypeFDataPacket()
826 * @see CMUcam4::sendBitmap()
827 * @see CMUcam4::getPixel()
828 * @see CMUcam4::setPixel()
829 *******************************************************************************/
830 typedef struct CMUcam4_image_data_t
831 {
832  uint8_t pixels[CMUCAM4_ID_T_LENGTH]; ///< The binary bitmap array.
833 }
835 
836 /***************************************************************************//**
837 * %CMUcam4 1-bin histogram structure. The sum of all the bins is less than or
838 * equal to 255. Each bin contains the percentage (0 to 255) of pixels in the
839 * image that fell within that bin. E.g. Each bin in a 1-bin histogram
840 * represents 256 pixel values.
841 * @par For example:
842 * <tt>{ bin0[0 - 255] }</tt>
843 * @see CMUcam4::getHistogram(int channel, int bins)
844 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_1_t * pointer)
845 *******************************************************************************/
847 {
848  uint8_t bins[CMUCAM4_HD_1_T_LENGTH]; ///< 1-bin histogram array.
849 }
851 
852 /***************************************************************************//**
853 * %CMUcam4 2-bin histogram structure. The sum of all the bins is less than or
854 * equal to 255. Each bin contains the percentage (0 to 255) of pixels in the
855 * image that fell within that bin. E.g. Each bin in a 2-bin histogram
856 * represents 128 pixel values.
857 * @par For example:
858 * <tt>{ bin0[0 - 127], bin1[128 - 255] }</tt>
859 * @see CMUcam4::getHistogram(int channel, int bins)
860 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_2_t * pointer)
861 *******************************************************************************/
863 {
864  uint8_t bins[CMUCAM4_HD_2_T_LENGTH]; ///< 2-bin histogram array.
865 }
867 
868 /***************************************************************************//**
869 * %CMUcam4 4-bin histogram structure. The sum of all the bins is less than or
870 * equal to 255. Each bin contains the percentage (0 to 255) of pixels in the
871 * image that fell within that bin. E.g. Each bin in a 4-bin histogram
872 * represents 64 pixel values.
873 * @par For example:
874 * <tt>{ bin0[0 - 63], bin1[64 - 127], bin2[128 - 191], bin3[192 - 255] }</tt>
875 * @see CMUcam4::getHistogram(int channel, int bins)
876 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_4_t * pointer)
877 *******************************************************************************/
879 {
880  uint8_t bins[CMUCAM4_HD_4_T_LENGTH]; ///< 4-bin histogram array.
881 }
883 
884 /***************************************************************************//**
885 * %CMUcam4 8-bin histogram structure. The sum of all the bins is less than or
886 * equal to 255. Each bin contains the percentage (0 to 255) of pixels in the
887 * image that fell within that bin. E.g. Each bin in a 8-bin histogram
888 * represents 32 pixel values.
889 * @par For example:
890 * <tt>{ bin0[0 - 31], bin1[32 - 63], ..., bin7[224 - 255] }</tt>
891 * @see CMUcam4::getHistogram(int channel, int bins)
892 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_8_t * pointer)
893 *******************************************************************************/
895 {
896  uint8_t bins[CMUCAM4_HD_8_T_LENGTH]; ///< 8-bin histogram array.
897 }
899 
900 /***************************************************************************//**
901 * %CMUcam4 16-bin histogram structure. The sum of all the bins is less than or
902 * equal to 255. Each bin contains the percentage (0 to 255) of pixels in the
903 * image that fell within that bin. E.g. Each bin in a 16-bin histogram
904 * represents 16 pixel values.
905 * @par For example:
906 * <tt>{ bin0[0 - 15], bin1[16 - 31], ..., bin15[240 - 255] }</tt>
907 * @see CMUcam4::getHistogram(int channel, int bins)
908 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_16_t * pointer)
909 *******************************************************************************/
911 {
912  uint8_t bins[CMUCAM4_HD_16_T_LENGTH]; ///< 16-bin histogram array.
913 }
915 
916 /***************************************************************************//**
917 * %CMUcam4 32-bin histogram structure. The sum of all the bins is less than or
918 * equal to 255. Each bin contains the percentage (0 to 255) of pixels in the
919 * image that fell within that bin. E.g. Each bin in a 32-bin histogram
920 * represents 8 pixel values.
921 * @par For example:
922 * <tt>{ bin0[0 - 7], bin1[8 - 15], ..., bin31[248 - 255] }</tt>
923 * @see CMUcam4::getHistogram(int channel, int bins)
924 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_32_t * pointer)
925 *******************************************************************************/
927 {
928  uint8_t bins[CMUCAM4_HD_32_T_LENGTH]; ///< 32-bin histogram array.
929 }
931 
932 /***************************************************************************//**
933 * %CMUcam4 64-bin histogram structure. The sum of all the bins is less than or
934 * equal to 255. Each bin contains the percentage (0 to 255) of pixels in the
935 * image that fell within that bin. E.g. Each bin in a 64-bin histogram
936 * represents 4 pixel values.
937 * @par For example:
938 * <tt>{ bin0[0 - 3], bin1[4 - 7], ..., bin63[252 - 255] }</tt>
939 * @see CMUcam4::getHistogram(int channel, int bins)
940 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_64_t * pointer)
941 *******************************************************************************/
943 {
944  uint8_t bins[CMUCAM4_HD_64_T_LENGTH]; ///< 64-bin histogram array.
945 }
947 
948 /***************************************************************************//**
949 * %CMUcam4 statistics data structure. Please note that the distribution of each
950 * color channel is not normal.
951 * @see CMUcam4::getMean()
952 * @see CMUcam4::getTypeSDataPacket()
953 *******************************************************************************/
955 {
956  int RMean; ///< Red or V channel mean - [0 : 255].
957  int GMean; ///< Green or Y channel mean - [0 : 255].
958  int BMean; ///< Blue or U channel mean - [0 : 255].
959  int RMedian; ///< Red or V channel median - [0 : 255].
960  int GMedian; ///< Green or Y channel median - [0 : 255].
961  int BMedian; ///< Blue or U channel median - [0 : 255].
962  int RMode; ///< Red or V channel mode - [0 : 255].
963  int GMode; ///< Green or Y channel mode - [0 : 255].
964  int BMode; ///< Blue or U channel mode - [0 : 255].
965  int RStDev; ///< Red or V channel standard deviation - [0 : 255].
966  int GStDev; ///< Green or Y channel standard deviation - [0 : 255].
967  int BStDev; ///< Blue or U channel standard deviation - [0 : 255].
968 }
970 
971 /***************************************************************************//**
972 * %CMUcam4 tracking data structure. The middle mass is also called the centroid
973 * and is the average position of all the tracked pixels in the image. The
974 * bounding box surrounds all the tracked pixels in the image. The @c pixels
975 * value can be used to infer the size or distance of the color blob of tracked
976 * pixels - the higher the @c pixels then the larger or closer the color blob.
977 * The @c confidence value can be used to infer the density or quality of the
978 * lock on the target color blob of tracked pixels - the higher the @c
979 * confidence then the better the lock on the color blob.
980 * @see CMUcam4::trackColor()
981 * @see CMUcam4::trackWindow()
982 * @see CMUcam4::getTypeTDataPacket()
983 *******************************************************************************/
985 {
986  int mx; ///< The middle mass X position of the tracked pixels - [0:159].
987  int my; ///< The middle mass Y position of the tracked pixels - [0:119].
988  int x1; ///< The upper left X coordinate of the bounding box - [0:159].
989  int y1; ///< The upper left Y coordinate of the bounding box - [0:119].
990  int x2; ///< The bottom right X coordinate of the bounding box - [X1:159].
991  int y2; ///< The bottom right Y coordinate of the bounding box - [Y1:119].
992  int pixels; ///< The percentage of tracked pixels in the image - [0:255].
993  int confidence; ///< The density of tracked pixels in the image - [0:255].
994 }
996 
997 /***************************************************************************//**
998 * Disk information data structure. @par Member relationships:
999 * <tt>diskSize = bytesPerSector * countOfDataSectors</tt>
1000 * @n <tt>countOfDataSectors = sectorsPerCluster * countOfClusters</tt>
1001 * @see CMUcam4::diskInformation()
1002 *******************************************************************************/
1004 {
1005  unsigned long diskSignature; ///< 32-bit disk signature.
1006  unsigned long volumeIdentification; ///< 32-bit volume identification.
1007  unsigned long countOfDataSectors; ///< Count of data sectors.
1008  unsigned long bytesPerSector; ///< Bytes per sector.
1009  unsigned long sectorsPerCluster; ///< Sectors per cluster.
1010  unsigned long countOfClusters; ///< Count of clusters.
1011  /// Volume label string.
1013  /// File system type string. Either "FAT 16" or "FAT 32".
1015 }
1017 
1018 /***************************************************************************//**
1019 * Disk space data structure. @par Member relationships:
1020 * <tt>diskSize = bytesPerSector * (freeSectorCount + usedSectorCount)</tt>
1021 * @n <tt>countOfDataSectors = (freeSectorCount + usedSectorCount)</tt>
1022 * @see CMUcam4::diskSpace()
1023 *******************************************************************************/
1024 typedef struct CMUcam4_disk_space_t
1025 {
1026  unsigned long freeSectorCount; ///< Count of free sectors.
1027  unsigned long usedSectorCount; ///< Count of used sectors.
1028 }
1030 
1031 /***************************************************************************//**
1032 * File or directory attributes data structure. The
1033 * CMUcam4_entry_attributes_t data structure is the
1034 * CMUcam4_directory_entry_t.attributes string.
1035 * @see CMUcam4::listDirectory()
1036 * @see CMUcam4::isReadOnly()
1037 * @see CMUcam4::isHidden()
1038 * @see CMUcam4::isSystem()
1039 * @see CMUcam4::isVolumeID()
1040 * @see CMUcam4::isDirectory()
1041 * @see CMUcam4::isArchive()
1042 *******************************************************************************/
1044 {
1045  char readOnly; ///< Will be either 'R' or '_'.
1046  char hidden; ///< Will be either 'H' or '_'.
1047  char system; ///< Will be either 'S' or '_'.
1048  char volumeID; ///< Constant value of '_'.
1049  char directory; ///< Will be either 'D' or '_'.
1050  char archive; ///< Will be either 'A' or '_'.
1051  char nullTerminator; ///< Constant value of '\0'.
1052 }
1054 
1055 /***************************************************************************//**
1056 * File or directory entry data structure. The
1057 * CMUcam4_directory_entry_t.attributes string is the CMUcam4_entry_attributes_t
1058 * data structure.
1059 * @see CMUcam4::listDirectory()
1060 * @see CMUcam4::isReadOnly()
1061 * @see CMUcam4::isHidden()
1062 * @see CMUcam4::isSystem()
1063 * @see CMUcam4::isVolumeID()
1064 * @see CMUcam4::isDirectory()
1065 * @see CMUcam4::isArchive()
1066 *******************************************************************************/
1068 {
1069  unsigned long size; ///< Entry size in bytes. Between 0 and 2,147,483,647.
1070  char name[CMUCAM4_NAME_LENGTH + 1]; ///< Entry name.
1071  char attributes[CMUCAM4_ATTR_LENGTH + 1]; ///< Entry attributes.
1072 }
1074 
1075 /***************************************************************************//**
1076 * The %CMUcam4 class implements a generic C++ interface library for the
1077 * %CMUcam4. This interface library provides a wrapper function for all native
1078 * %CMUcam4 functions. Addtionally, this interface library has built in utility
1079 * functions for manipulating data structures and low level camera settings.
1080 *******************************************************************************/
1081 class CMUcam4
1082 {
1083 
1084 public:
1085 
1086 /***************************************************************************//**
1087 * Initialize the %CMUcam4 object to use the default Serial port.
1088 *******************************************************************************/
1089 CMUcam4();
1090 
1091 /***************************************************************************//**
1092 * Initialize the %CMUcam4 object to use the @c port Serial port.
1093 * @param [in] port The port.
1094 * @see CMUCOM4_SERIAL
1095 * @see CMUCOM4_SERIAL1
1096 * @see CMUCOM4_SERIAL2
1097 * @see CMUCOM4_SERIAL3
1098 *******************************************************************************/
1099 CMUcam4(int port);
1100 
1101 /***************************************************************************//**
1102 * Gets a pixel (0 or 1) from a binary bitmap data structure.
1103 * @param [in] pointer A pointer to the binary bitmap data structure.
1104 * @param [in] row The pixel row. Must be between 0 and 59.
1105 * @param [in] column The pixel column. Must be between 0 and 79.
1106 * @return The pixel value on success and a negative error value on failure.
1107 * @see CMUcam4_image_data_t
1108 * @see CMUcam4::getTypeFDataPacket()
1109 * @see CMUcam4::sendBitmap()
1110 * @see CMUCAM4_GET_PIXEL()
1111 *******************************************************************************/
1112 int getPixel(CMUcam4_image_data_t * pointer, int row, int column);
1113 
1114 /***************************************************************************//**
1115 * Gets a pixel (0 or 1) from a binary bitmap data structure. This function
1116 * macro is included for speed and not safety. Please use it carefully!
1117 * @param [in] pointer A pointer to the binary bitmap data structure.
1118 * @param [in] row The pixel row. Must be between 0 and 59.
1119 * @param [in] column The pixel column. Must be between 0 and 79.
1120 * @return The pixel value (0 or 1).
1121 * @see CMUcam4_image_data_t
1122 * @see CMUcam4::getTypeFDataPacket()
1123 * @see CMUcam4::sendBitmap()
1124 * @see CMUcam4::getPixel()
1125 *******************************************************************************/
1126 #define CMUCAM4_GET_PIXEL(pointer, row, column) \
1127 \
1128 (((pointer)->pixels[((row) * CMUCAM4_ID_T_C) + ((column) / 8)] \
1129 >> (7 - ((column) & 7))) & 1)
1130 
1131 /***************************************************************************//**
1132 * Sets a pixel (0 or 1) in a binary bitmap data structure.
1133 * @param [out] pointer A pointer to the binary bitmap data structure.
1134 * @param [in] row The pixel row. Must be between 0 and 59.
1135 * @param [in] column The pixel column. Must be between 0 and 79.
1136 * @param [in] value The pixel value (0 or 1).
1137 * @return 0 on success and a negative error value on failure.
1138 * @see CMUcam4_image_data_t
1139 * @see CMUcam4::getTypeFDataPacket()
1140 * @see CMUcam4::sendBitmap()
1141 * @see CMUCAM4_SET_PIXEL()
1142 *******************************************************************************/
1143 int setPixel(CMUcam4_image_data_t * pointer, int row, int column, int value);
1144 
1145 /***************************************************************************//**
1146 * Sets a pixel (0 or 1) to a binary bitmap data structure. This function
1147 * macro is included for speed and not safety. Please use it carefully!
1148 * @param [out] pointer A pointer to the binary bitmap data structure.
1149 * @param [in] row The pixel row. Must be between 0 and 59.
1150 * @param [in] column The pixel column. Must be between 0 and 79.
1151 * @param [in] value The pixel value (0 or 1).
1152 * @see CMUcam4_image_data_t
1153 * @see CMUcam4::getTypeFDataPacket()
1154 * @see CMUcam4::sendBitmap()
1155 * @see CMUcam4::setPixel()
1156 *******************************************************************************/
1157 #define CMUCAM4_SET_PIXEL(pointer, row, column, value) \
1158 do { \
1159 int bitIndex = (7 - ((column) & 7)); \
1160 int byteIndex = (((row) * CMUCAM4_ID_T_C) + ((column) / 8)); \
1161 \
1162 (pointer)->pixels[byteIndex] = \
1163 (((~(1<<bitIndex))&((pointer)->pixels[byteIndex]))|(((value)?1:0)<<bitIndex)) \
1164 ; } while(false)
1165 
1166 /***************************************************************************//**
1167 * Logically AND's two binary bitmaps together - useful for image manipulation.
1168 * @param [out] destination A pointer to a binary bitmap data structure.
1169 * @param [in] source0 A pointer to a binary bitmap data structure.
1170 * @param [in] source1 A pointer to a binary bitmap data structure.
1171 * @return Zero on success and a negative value if any parameter is invalid.
1172 * @see CMUcam4_image_data_t
1173 * @see CMUcam4::getTypeFDataPacket()
1174 * @see CMUcam4::sendBitmap()
1175 *******************************************************************************/
1176 int andPixels(CMUcam4_image_data_t * destination,
1177  CMUcam4_image_data_t * source0,
1178  CMUcam4_image_data_t * source1);
1179 
1180 /***************************************************************************//**
1181 * Logically OR's two binary bitmaps together - useful for image manipulation.
1182 * @param [out] destination A pointer to a binary bitmap data structure.
1183 * @param [in] source0 A pointer to a binary bitmap data structure.
1184 * @param [in] source1 A pointer to a binary bitmap data structure.
1185 * @return Zero on success and a negative value if any parameter is invalid.
1186 * @see CMUcam4_image_data_t
1187 * @see CMUcam4::getTypeFDataPacket()
1188 * @see CMUcam4::sendBitmap()
1189 *******************************************************************************/
1190 int orPixels(CMUcam4_image_data_t * destination,
1191  CMUcam4_image_data_t * source0,
1192  CMUcam4_image_data_t * source1);
1193 
1194 /***************************************************************************//**
1195 * Logically XOR's two binary bitmaps together - useful for image manipulation.
1196 * @param [out] destination A pointer to a binary bitmap data structure.
1197 * @param [in] source0 A pointer to a binary bitmap data structure.
1198 * @param [in] source1 A pointer to a binary bitmap data structure.
1199 * @return Zero on success and a negative value if any parameter is invalid.
1200 * @see CMUcam4_image_data_t
1201 * @see CMUcam4::getTypeFDataPacket()
1202 * @see CMUcam4::sendBitmap()
1203 *******************************************************************************/
1204 int xorPixels(CMUcam4_image_data_t * destination,
1205  CMUcam4_image_data_t * source0,
1206  CMUcam4_image_data_t * source1);
1207 
1208 /***************************************************************************//**
1209 * Logically NOT's a binary bitmap - useful for image manipulation.
1210 * @param [in, out] destination A pointer to a binary bitmap data structure.
1211 * @return Zero on success and a negative value if any parameter is invalid.
1212 * @see CMUcam4_image_data_t
1213 * @see CMUcam4::getTypeFDataPacket()
1214 * @see CMUcam4::sendBitmap()
1215 *******************************************************************************/
1216 int notPixels(CMUcam4_image_data_t * destination);
1217 
1218 /***************************************************************************//**
1219 * Returns if a directory entry is read-only (0 or 1).
1220 * @param [in] pointer A pointer to a directory entry data structure.
1221 * @return 1 if read-only, 0 if not, and a negative value if @c pointer is NULL.
1222 * @see CMUcam4_directory_entry_t
1223 * @see CMUcam4::listDirectory()
1224 *******************************************************************************/
1225 int isReadOnly(CMUcam4_directory_entry_t * pointer);
1226 
1227 /***************************************************************************//**
1228 * Returns if a directory entry is hidden (0 or 1).
1229 * @param [in] pointer A pointer to a directory entry data structure.
1230 * @return 1 if hidden, 0 if not, and a negative value if @c pointer is NULL.
1231 * @see CMUcam4_directory_entry_t
1232 * @see CMUcam4::listDirectory()
1233 *******************************************************************************/
1234 int isHidden(CMUcam4_directory_entry_t * pointer);
1235 
1236 /***************************************************************************//**
1237 * Returns if a directory entry is system (0 or 1).
1238 * @param [in] pointer A pointer to a directory entry data structure.
1239 * @return 1 if system, 0 if not, and a negative value if @c pointer is NULL.
1240 * @see CMUcam4_directory_entry_t
1241 * @see CMUcam4::listDirectory()
1242 *******************************************************************************/
1243 int isSystem(CMUcam4_directory_entry_t * pointer);
1244 
1245 /***************************************************************************//**
1246 * Returns if a directory entry is the volume ID (0 or 1). This function is
1247 * included for completeness only. The %CMUcam4's %listDirectory function does
1248 * not list the volume ID located in the root directory.
1249 * @param [in] pointer A pointer to a directory entry data structure.
1250 * @return 1 if ID, 0 if not, and a negative value if @c pointer is NULL.
1251 * @see CMUcam4_directory_entry_t
1252 * @see CMUcam4::listDirectory()
1253 *******************************************************************************/
1254 int isVolumeID(CMUcam4_directory_entry_t * pointer);
1255 
1256 /***************************************************************************//**
1257 * Returns if a directory entry is a directory (0 or 1).
1258 * @param [in] pointer A pointer to a directory entry data structure.
1259 * @return 1 if a directory, 0 if not, and a negative value if @c pointer is
1260 * NULL.
1261 * @see CMUcam4_directory_entry_t
1262 * @see CMUcam4::listDirectory()
1263 *******************************************************************************/
1264 int isDirectory(CMUcam4_directory_entry_t * pointer);
1265 
1266 /***************************************************************************//**
1267 * Returns if a directory entry is ready to archive (0 or 1).
1268 * @param [in] pointer A pointer to a directory entry data structure.
1269 * @return 1 if ready to archive, 0 if not, and a negative value if @c pointer
1270 * is NULL.
1271 * @see CMUcam4_directory_entry_t
1272 * @see CMUcam4::listDirectory()
1273 *******************************************************************************/
1274 int isArchive(CMUcam4_directory_entry_t * pointer);
1275 
1276 /***************************************************************************//**
1277 * Activates the interface library.
1278 * @return 0 on success and a negative error value on failure.
1279 * @see CMUcam4::end()
1280 *******************************************************************************/
1281 int begin();
1282 
1283 /***************************************************************************//**
1284 * Deactivates the interface library.
1285 * @return 0 on success and a negative error value on failure.
1286 * @see CMUcam4::begin()
1287 *******************************************************************************/
1288 int end();
1289 
1290 /***************************************************************************//**
1291 * Gets the %CMUcam4's firmware version number.
1292 * @return The version number on success and a negative error value on failure.
1293 * @see CMUCAM4_FIRMWARE_V100
1294 * @see CMUCAM4_FIRMWARE_V101
1295 * @see CMUCAM4_FIRMWARE_V102
1296 * @see CMUCAM4_FIRMWARE_V103
1297 *******************************************************************************/
1298 int getVersion();
1299 
1300 /***************************************************************************//**
1301 * Resets the %CMUcam4 device.
1302 * @return 0 on success and a negative error value on failure.
1303 *******************************************************************************/
1304 int resetSystem();
1305 
1306 /***************************************************************************//**
1307 * Causes the %CMUcam4 to sleep deeply. This disables servo outputs.
1308 * @return 0 on success and a negative error value on failure.
1309 *******************************************************************************/
1310 int sleepDeeply();
1311 
1312 /***************************************************************************//**
1313 * Causes the %CMUcam4 to sleep lightly. This does not disable servo outputs.
1314 * @return 0 on success and a negative error value on failure.
1315 *******************************************************************************/
1316 int sleepLightly();
1317 
1318 /***************************************************************************//**
1319 * Change the camera brightness setting - useful for low brightness situations.
1320 * @param [in] brightness Between -127 and 127. The default is 0.
1321 * @return 0 on success and a negative error value on failure.
1322 *******************************************************************************/
1323 int cameraBrightness(int brightness);
1324 
1325 /***************************************************************************//**
1326 * Change the camera contrast setting - useful for low contrast situations.
1327 * @param [in] contrast Between -31 and 31. The default is 0.
1328 * @return 0 on success and a negative error value on failure.
1329 *******************************************************************************/
1330 int cameraContrast(int contrast);
1331 
1332 /***************************************************************************//**
1333 * Read a camera register value.
1334 * @param [in] reg The register address. Between 0 and 255.
1335 * @return The register value on success and a negative error value on failure.
1336 *******************************************************************************/
1337 int cameraRegisterRead(int reg);
1338 
1339 /***************************************************************************//**
1340 * Write a camera register value.
1341 * @param [in] reg The register address. Between 0 and 255.
1342 * @param [in] value The value to write. Between 0 and 255.
1343 * @param [in] mask The mask of bit positions to write to. Between 0 and 255.
1344 * @return 0 on success and a negative error value on failure.
1345 *******************************************************************************/
1346 int cameraRegisterWrite(int reg, int value, int mask);
1347 
1348 /***************************************************************************//**
1349 * Turns the camera automatic gain control off or on.
1350 * @param [in] active 0 for off and 1 for on.
1351 * @return 0 on success and a negative error value on failure.
1352 *******************************************************************************/
1353 int autoGainControl(int active);
1354 
1355 /***************************************************************************//**
1356 * Turns the camera automatic white balance off or on.
1357 * @param [in] active 0 for off and 1 for on.
1358 * @return 0 on success and a negative error value on failure.
1359 *******************************************************************************/
1360 int autoWhiteBalance(int active);
1361 
1362 /***************************************************************************//**
1363 * Horizontally mirror the camera module image.
1364 * @param [in] active 0 for normal mode and 1 for horizontally mirrored mode.
1365 * @return 0 on success and a negative error value on failure.
1366 *******************************************************************************/
1367 int horizontalMirror(int active);
1368 
1369 /***************************************************************************//**
1370 * Vertically flip the camera module image.
1371 * @param [in] active 0 for normal mode and 1 for vertically flipped mode.
1372 * @return 0 on success and a negative error value on failure.
1373 *******************************************************************************/
1374 int verticalFlip(int active);
1375 
1376 /***************************************************************************//**
1377 * Cause the camera to output a black and white image.
1378 * @param [in] active 0 for normal mode and 1 for black and white mode.
1379 * @return 0 on success and a negative error value on failure.
1380 *******************************************************************************/
1381 int blackAndWhiteMode(int active);
1382 
1383 /***************************************************************************//**
1384 * Cause the camera to output a negative image.
1385 * @param [in] active 0 for normal mode and 1 for negative mode.
1386 * @return 0 on success and a negative error value on failure.
1387 *******************************************************************************/
1388 int negativeMode(int active);
1389 
1390 /***************************************************************************//**
1391 * Returns the user button state on the %CMUcam4. 0 for released. 1 for pressed.
1392 * @return 0 or 1 on success and a negative error value on failure.
1393 *******************************************************************************/
1394 int getButtonState();
1395 
1396 /***************************************************************************//**
1397 * Returns the user button duration in the current state on the %CMUcam4 in
1398 * milliseconds. Between 0 and 65,535 milliseconds.
1399 * @return The button duration in state in milliseconds on success and a
1400 * negative error value on failure.
1401 *******************************************************************************/
1402 long getButtonDuration();
1403 
1404 /***************************************************************************//**
1405 * Returns if the user button was pressed. 0 for no and 1 for yes.
1406 * @return 0 or 1 on success and a negative error value on failure.
1407 *******************************************************************************/
1408 int getButtonPressed();
1409 
1410 /***************************************************************************//**
1411 * Returns if the user button was released. 0 for no and 1 for yes.
1412 * @return 0 or 1 on success and a negative error value on failure.
1413 *******************************************************************************/
1414 int getButtonReleased();
1415 
1416 /***************************************************************************//**
1417 * Gets the digital state of the pan pin on the %CMUcam4.
1418 * @return 0 or 1 on success and a negative error value on failure.
1419 *******************************************************************************/
1420 int panInput();
1421 
1422 /***************************************************************************//**
1423 * Sets the digital state of the pan pin on the %CMUcam4.
1424 * @param [in] direction The boolean direction state. 0 for input. 1 for output.
1425 * @param [in] output The boolean output state. 0 for low. 1 for high.
1426 * @return 0 on success and a negative error value on failure.
1427 *******************************************************************************/
1428 int panOutput(int direction, int output);
1429 
1430 /***************************************************************************//**
1431 * Gets the digital state of the tilt pin on the %CMUcam4.
1432 * @return 0 or 1 on success and a negative error value on failure.
1433 *******************************************************************************/
1434 int tiltInput();
1435 
1436 /***************************************************************************//**
1437 * Sets the digital state of the tilt pin on the %CMUcam4.
1438 * @param [in] direction The boolean direction state. 0 for input. 1 for output.
1439 * @param [in] output The boolean output state. 0 for low. 1 for high.
1440 * @return 0 on success and a negative error value on failure.
1441 *******************************************************************************/
1442 int tiltOutput(int direction, int output);
1443 
1444 /***************************************************************************//**
1445 * Gets the digital states of the pan and tilt pins on the %CMUcam4.
1446 * The pan pin is bit 0. The tilt pin is bit 1.
1447 * @return 0, 1, 2, or 3 on success and a negative error value on failure.
1448 *******************************************************************************/
1449 int getInputs();
1450 
1451 /***************************************************************************//**
1452 * Sets the digital states of the pan and tilt pins on the %CMUcam4.
1453 * The pan pin is bit 0. The tilt pin is bit 1.
1454 * @param [in] directions The boolean direction states.
1455 * 0 for input. 1 for output.
1456 * @param [in] outputs The boolean output states.
1457 * 0 for low. 1 for high.
1458 * @return 0 on success and a negative error value on failure.
1459 *******************************************************************************/
1460 int setOutputs(int directions, int outputs);
1461 
1462 /***************************************************************************//**
1463 * Disables the auxiliary LED on the %CMUcam4.
1464 * @return 0 on success and a negative error value on failure.
1465 *******************************************************************************/
1466 int LEDOff();
1467 
1468 /***************************************************************************//**
1469 * Enables the auxiliary LED on the %CMUcam4.
1470 * @param [in] frequency The frequency to blink the auxiliary to at.
1471  Between 0 Hz and 10,000,000 Hz. -1 to turn off.
1472 * @return 0 on success and a negative error value on failure.
1473 *******************************************************************************/
1474 int LEDOn(long frequency);
1475 
1476 /***************************************************************************//**
1477 * Gets the pan or tilt servo pulse length in microseconds.
1478 * Between 750 to 2,250 us - 0 when the servo is disabled.
1479 * @param [in] servo The servo number. 0 for pan and 1 for tilt.
1480 * @return The pulse length on success and a negative error value on failure.
1481 *******************************************************************************/
1482 int getServoPosition(int servo);
1483 
1484 /***************************************************************************//**
1485 * Sets the pan or tilt servo pulse length in microseconds.
1486 * Between 750 to 2,250 us.
1487 * @param [in] servo The servo number. 0 for pan and 1 for tilt.
1488 * @param [in] active The servo state. 0 for disabled and 1 for enabled.
1489 * @param [in] pulseLength The servo pulse length in microseconds.
1490 * @return 0 on success and a negative error value on failure.
1491 *******************************************************************************/
1492 int setServoPosition(int servo, int active, int pulseLength);
1493 
1494 /***************************************************************************//**
1495 * Setup automatic pan control.
1496 * @param [in] active The function state. 0 for disabled and 1 for enabled.
1497 * @param [in] reverse 0 for not reversed and 1 for reversed.
1498 * @return 0 on success and a negative error value on failure.
1499 *******************************************************************************/
1500 int automaticPan(int active, int reverse);
1501 
1502 /***************************************************************************//**
1503 * Setup automatic tilt control.
1504 * @param [in] active The function state. 0 for disabled and 1 for enabled.
1505 * @param [in] reverse 0 for not reversed and 1 for reversed.
1506 * @return 0 on success and a negative error value on failure.
1507 *******************************************************************************/
1508 int automaticTilt(int active, int reverse);
1509 
1510 /***************************************************************************//**
1511 * Setup automatic pan control gain values.
1512 * @param [in] proportionalGain PD loop P gain. Between 0 (disable) and 1000.
1513 * @param [in] derivativeGain PD loop D gain. Between 0 (disable) and 1000.
1514 * @return 0 on success and a negative error value on failure.
1515 *******************************************************************************/
1516 int autoPanParameters(int proportionalGain, int derivativeGain);
1517 
1518 /***************************************************************************//**
1519 * Setup automatic tilt control gain values.
1520 * @param [in] proportionalGain PD loop P gain. Between 0 (disable) and 1000.
1521 * @param [in] derivativeGain PD loop D gain. Between 0 (disable) and 1000.
1522 * @return 0 on success and a negative error value on failure.
1523 *******************************************************************************/
1524 int autoTiltParameters(int proportionalGain, int derivativeGain);
1525 
1526 /***************************************************************************//**
1527 * Turn the television monitor signal off.
1528 * @return 0 on success and a negative error value on failure.
1529 *******************************************************************************/
1530 int monitorOff();
1531 
1532 /***************************************************************************//**
1533 * Turn the television monitor signal on.
1534 * @return 0 on success and a negative error value on failure.
1535 *******************************************************************************/
1536 int monitorOn();
1537 
1538 /***************************************************************************//**
1539 * Freeze the television monitor signal.
1540 * @param [in] active 0 to unfreeze and 1 to freeze.
1541 * @return 0 on success and a negative error value on failure.
1542 *******************************************************************************/
1543 int monitorFreeze(int active);
1544 
1545 /***************************************************************************//**
1546 * Change the television monitor signal.
1547 * @param [in] active 0 for NTSC and 1 for PAL.
1548 * @return 0 on success and a negative error value on failure.
1549 *******************************************************************************/
1550 int monitorSignal(int active);
1551 
1552 /***************************************************************************//**
1553 * Populates a CMUcam4_tracking_parameters_t data structure with the current
1554 * color tracking threshold parameters in use by the %CMUcam4.
1555 * @param [out] pointer A pointer to a CMUcam4_tracking_parameters_t data
1556 * structure.
1557 * @return 0 on success and a negative error value on failure.
1558 * @see CMUcam4_tracking_parameters_t
1559 *******************************************************************************/
1561 
1562 /***************************************************************************//**
1563 * Populates a CMUcam4_tracking_window_t data structure with the current
1564 * color tracking window parameters in use by the %CMUcam4.
1565 * @param [out] pointer A pointer to a CMUcam4_tracking_window_t data
1566 * structure.
1567 * @return 0 on success and a negative error value on failure.
1568 * @see CMUcam4_tracking_window_t
1569 *******************************************************************************/
1571 
1572 /***************************************************************************//**
1573 * Reset the color tracking threshold parameters to track all possible colors.
1574 * @return 0 on success and a negative error value on failure.
1575 *******************************************************************************/
1576 int setTrackingParameters();
1577 
1578 /***************************************************************************//**
1579 * Set the color tracking threshold parameters to track a range of colors. A
1580 * pixel's red, green, and blue components must fall between the @c redMin,
1581 * @c redMax, @c greenMin, @c greenMax, @c blueMin, and @c blueMax thresholds
1582 * for the pixel to be tracked.
1583 * @param [in] redMin The minimum red threshold - between 0 to 255.
1584 * @param [in] redMax The maximum red threshold - between 0 to 255.
1585 * @param [in] greenMin The minimum green threshold - between 0 to 255.
1586 * @param [in] greenMax The maximum green threshold - between 0 to 255.
1587 * @param [in] blueMin The minimum blue threshold - between 0 to 255.
1588 * @param [in] blueMax The maximum blue threshold - between 0 to 255.
1589 * @return 0 on success and a negative error value on failure.
1590 *******************************************************************************/
1591 int setTrackingParameters(int redMin, int redMax,
1592  int greenMin, int greenMax,
1593  int blueMin, int blueMax);
1594 
1595 /***************************************************************************//**
1596 * Reset the color tracking window parameters to track all possible pixels.
1597 * @return 0 on success and a negative error value on failure.
1598 *******************************************************************************/
1599 int setTrackingWindow();
1600 
1601 /***************************************************************************//**
1602 * Set the color tracking window parameters to track a range of pixels. A
1603 * pixel's horizontal position and vertical position must fall between the
1604 * @c topLeftX, @c topLeftY, @c bottomRightX, and @c bottomRightY positions for
1605 * the pixel to be tracked.
1606 * @param [in] topLeftX Top left X position (X1) - between 0 and 159.
1607 * @param [in] topLeftY Top left Y position (Y1) - between 0 and 119.
1608 * @param [in] bottomRightX Bottom right X position (X2) - between X1 and 159.
1609 * @param [in] bottomRightY Bottom right Y position (Y2) - between Y2 and 119.
1610 * @return 0 on success and a negative error value on failure.
1611 *******************************************************************************/
1612 int setTrackingWindow(int topLeftX, int topLeftY,
1613  int bottomRightX, int bottomRightY);
1614 
1615 /***************************************************************************//**
1616 * Causes the %CMUcam4 to enter idle mode and do nothing. The %CMUcam4 will
1617 * automatically exit streaming mode if any function other than the
1618 * getType_DataPackets functions is called.
1619 * @return 0 on success and a negative error value on failure.
1620 *******************************************************************************/
1621 int idleCamera();
1622 
1623 /***************************************************************************//**
1624 * Causes the %CMUcam4 to enter stream mode and begin sending type T data
1625 * packets. Only the getType_DataPackets functions may be called after calling
1626 * this function to get packets. The %CMUcam4 will automatically exit streaming
1627 * mode if any function other than the getType_DataPackets functions is called.
1628 * This function doesn't change the color tracking settings when called.
1629 * @return 0 on success and a negative error value on failure.
1630 * @see CMUcam4::getTypeTDataPacket()
1631 *******************************************************************************/
1632 int trackColor();
1633 
1634 /***************************************************************************//**
1635 * Causes the %CMUcam4 to enter stream mode and begin sending type T data
1636 * packets. Only the getType_DataPackets functions may be called after calling
1637 * this function to get packets. The %CMUcam4 will automatically exit streaming
1638 * mode if any function other than the getType_DataPackets functions is called.
1639 * This function does change the color tracking settings when called.
1640 * @param [in] redMin The minimum red threshold - between 0 to 255.
1641 * @param [in] redMax The maximum red threshold - between 0 to 255.
1642 * @param [in] greenMin The minimum green threshold - between 0 to 255.
1643 * @param [in] greenMax The maximum green threshold - between 0 to 255.
1644 * @param [in] blueMin The minimum blue threshold - between 0 to 255.
1645 * @param [in] blueMax The maximum blue threshold - between 0 to 255.
1646 * @return 0 on success and a negative error value on failure.
1647 * @see CMUcam4::getTypeTDataPacket()
1648 *******************************************************************************/
1649 int trackColor(int redMin, int redMax,
1650  int greenMin, int greenMax,
1651  int blueMin, int blueMax);
1652 
1653 /***************************************************************************//**
1654 * Causes the %CMUcam4 to enter stream mode and begin sending type T data
1655 * packets. Only the getType_DataPackets functions may be called after calling
1656 * this function to get packets. The %CMUcam4 will automatically exit streaming
1657 * mode if any function other than the getType_DataPackets functions is called.
1658 * This function automatically changes the color tracking settings when called.
1659 * @param [in] redRange The red average from the center of the color tracking
1660 * window plus and minus the @c redRange is used to set the redMax and redMin
1661 * values for the color tracking threshold parameters.
1662 * @param [in] greenRange The green average from the center of the color
1663 * tracking window plus and minus the @c greenRange is used to set the greenMax
1664 * and greenMin values for the color tracking threshold parameters.
1665 * @param [in] blueRange The blue average from the center of the color
1666 * tracking window plus and minus the @c blueRange is used to set the blueMax
1667 * and blueMin values for the color tracking threshold parameters.
1668 * @return 0 on success and a negative error value on failure.
1669 * @see CMUcam4::getTypeTDataPacket()
1670 *******************************************************************************/
1671 int trackWindow(int redRange, int greenRange, int blueRange);
1672 
1673 /***************************************************************************//**
1674 * Causes the %CMUcam4 to enter stream mode and begin sending type H data
1675 * packets. Only the getType_DataPackets functions may be called after calling
1676 * this function to get packets. The %CMUcam4 will automatically exit streaming
1677 * mode if any function other than the getType_DataPackets functions is called.
1678 * The red and blue channels can have up to 32 bins. The green channel can have
1679 * up to 64 bins.
1680 * @param [in] channel The color channel of the histogram to send:
1681 * 0 = Red Channel, 1 = Green Channel, 2 = Blue Channel.
1682 * @param [in] bins The number of bins of the histogram channel to send:
1683 * 0=1 bin, 1=2 bins, 2=4 bins, 3=8 bins, 4=16 bins, 5=32 bins, 6=64 bins.
1684 * @return 0 on success and a negative error value on failure.
1685 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_1_t * pointer)
1686 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_2_t * pointer)
1687 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_4_t * pointer)
1688 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_8_t * pointer)
1689 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_16_t * pointer)
1690 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_32_t * pointer)
1691 * @see CMUcam4::getTypeHDataPacket(CMUcam4_histogram_data_64_t * pointer)
1692 *******************************************************************************/
1693 int getHistogram(int channel, int bins);
1694 
1695 /***************************************************************************//**
1696 * Causes the %CMUcam4 to enter stream mode and begin sending type S data
1697 * packets. Only the getType_DataPackets functions may be called after calling
1698 * this function to get packets. The %CMUcam4 will automatically exit streaming
1699 * mode if any function other than the getType_DataPackets functions is called.
1700 * @return 0 on success and a negative error value on failure.
1701 * @see CMUcam4::getTypeSDataPacket()
1702 *******************************************************************************/
1703 int getMean();
1704 
1705 /***************************************************************************//**
1706 * Waits for a type F data packet to appear in the data stream from the %CMUcam4
1707 * and stores that type F data packet in a CMUcam4_image_data_t data strucutre.
1708 * A stream of type F data packets must be started first for this function not
1709 * to fail and timeout waiting for a type F data packet.
1710 * @param [out] pointer A pointer to a CMUcam4_image_data_t data
1711 * structure to store the received type F data packet to.
1712 * @return 0 on success and a negative error value on failure.
1713 * @see CMUcam4::lineMode()
1714 *******************************************************************************/
1716 
1717 /***************************************************************************//**
1718 * Waits for a type H-1 data packet to appear in the data stream from the
1719 * %CMUcam4 and stores that type H data packet in a CMUcam4_histogram_data_1_t
1720 * data structure. A stream of type H-1 data packets must be started first for
1721 * this function not to fail and timeout waiting for a type H-1 data packet.
1722 * @param [out] pointer A pointer to a CMUcam4_histogram_data_1_t data
1723 * structure to store the received type H-1 data packet to.
1724 * @return 0 on success and a negative error value on failure.
1725 * @see CMUcam4::getHistogram()
1726 * @see CMUcam4::lineMode()
1727 *******************************************************************************/
1729 
1730 /***************************************************************************//**
1731 * Waits for a type H-2 data packet to appear in the data stream from the
1732 * %CMUcam4 and stores that type H data packet in a CMUcam4_histogram_data_2_t
1733 * data structure. A stream of type H-2 data packets must be started first for
1734 * this function not to fail and timeout waiting for a type H-2 data packet.
1735 * @param [out] pointer A pointer to a CMUcam4_histogram_data_2_t data
1736 * structure to store the received type H-2 data packet to.
1737 * @return 0 on success and a negative error value on failure.
1738 * @see CMUcam4::getHistogram()
1739 * @see CMUcam4::lineMode()
1740 *******************************************************************************/
1742 
1743 /***************************************************************************//**
1744 * Waits for a type H-4 data packet to appear in the data stream from the
1745 * %CMUcam4 and stores that type H data packet in a CMUcam4_histogram_data_4_t
1746 * data structure. A stream of type H-4 data packets must be started first for
1747 * this function not to fail and timeout waiting for a type H-4 data packet.
1748 * @param [out] pointer A pointer to a CMUcam4_histogram_data_4_t data
1749 * structure to store the received type H-4 data packet to.
1750 * @return 0 on success and a negative error value on failure.
1751 * @see CMUcam4::getHistogram()
1752 * @see CMUcam4::lineMode()
1753 *******************************************************************************/
1755 
1756 /***************************************************************************//**
1757 * Waits for a type H-8 data packet to appear in the data stream from the
1758 * %CMUcam4 and stores that type H data packet in a CMUcam4_histogram_data_8_t
1759 * data structure. A stream of type H-8 data packets must be started first for
1760 * this function not to fail and timeout waiting for a type H-8 data packet.
1761 * @param [out] pointer A pointer to a CMUcam4_histogram_data_8_t data
1762 * structure to store the received type H-8 data packet to.
1763 * @return 0 on success and a negative error value on failure.
1764 * @see CMUcam4::getHistogram()
1765 * @see CMUcam4::lineMode()
1766 *******************************************************************************/
1768 
1769 /***************************************************************************//**
1770 * Waits for a type H-16 data packet to appear in the data stream from the
1771 * %CMUcam4 and stores that type H data packet in a CMUcam4_histogram_data_16_t
1772 * data structure. A stream of type H-16 data packets must be started first for
1773 * this function not to fail and timeout waiting for a type H-16 data packet.
1774 * @param [out] pointer A pointer to a CMUcam4_histogram_data_16_t data
1775 * structure to store the received type H-16 data packet to.
1776 * @return 0 on success and a negative error value on failure.
1777 * @see CMUcam4::getHistogram()
1778 * @see CMUcam4::lineMode()
1779 *******************************************************************************/
1781 
1782 /***************************************************************************//**
1783 * Waits for a type H-32 data packet to appear in the data stream from the
1784 * %CMUcam4 and stores that type H data packet in a CMUcam4_histogram_data_32_t
1785 * data structure. A stream of type H-32 data packets must be started first for
1786 * this function not to fail and timeout waiting for a type H-32 data packet.
1787 * @param [out] pointer A pointer to a CMUcam4_histogram_data_32_t data
1788 * structure to store the received type H-32 data packet to.
1789 * @return 0 on success and a negative error value on failure.
1790 * @see CMUcam4::getHistogram()
1791 * @see CMUcam4::lineMode()
1792 *******************************************************************************/
1794 
1795 /***************************************************************************//**
1796 * Waits for a type H-64 data packet to appear in the data stream from the
1797 * %CMUcam4 and stores that type H data packet in a CMUcam4_histogram_data_64_t
1798 * data structure. A stream of type H-64 data packets must be started first for
1799 * this function not to fail and timeout waiting for a type H-64 data packet.
1800 * @param [out] pointer A pointer to a CMUcam4_histogram_data_64_t data
1801 * structure to store the received type H-64 data packet to.
1802 * @return 0 on success and a negative error value on failure.
1803 * @see CMUcam4::getHistogram()
1804 * @see CMUcam4::lineMode()
1805 *******************************************************************************/
1807 
1808 /***************************************************************************//**
1809 * Waits for a type S data packet to appear in the data stream from the %CMUcam4
1810 * and stores that type S data packet in a CMUcam4_statistics_data_t data
1811 * structure. A stream of type S data packets must be started first for this
1812 * function not to fail and timeout waiting for a type S data packet.
1813 * @param [out] pointer A pointer to a CMUcam4_statistics_data_t data structure
1814 * to store the received type S data packet to.
1815 * @return 0 on success and a negative error value on failure.
1816 * @see CMUcam4::getMean()
1817 * @see CMUcam4::lineMode()
1818 * @see CMUcam4::switchingMode()
1819 *******************************************************************************/
1821 
1822 /***************************************************************************//**
1823 * Waits for a type T data packet to appear in the data stream from the %CMUcam4
1824 * and stores that type T data packet in a CMUcam4_tracking_data_t data
1825 * strucutre. A stream of type T data packets must be started first for this
1826 * function not to fail and timeout waiting for a type T data packet.
1827 * @param [out] pointer A pointer to a CMUcam4_tracking_data_t data structure to
1828 * store the received type T data packet to.
1829 * @return 0 on success and a negative error value on failure.
1830 * @see CMUcam4::trackColor()
1831 * @see CMUcam4::trackWindow()
1832 * @see CMUcam4::lineMode()
1833 * @see CMUcam4::switchingMode()
1834 *******************************************************************************/
1836 
1837 /***************************************************************************//**
1838 * Turn poll mode off or on. Poll mode causes the %CMUcam4 to send one and only
1839 * one type F, H, S, or T packet after calling CMUcam4::trackColor(),
1840 * CMUcam4::trackWindow(), CMUcam4::getHistogram(), or CMUcam4::getMean()
1841 * instead of a stream of packets that the %CMUcam4 would normally send.
1842 * @param [in] active 0 for off and 1 for on.
1843 * @return 0 on success and a negative error value on failure.
1844 *******************************************************************************/
1845 int pollMode(int active);
1846 
1847 /***************************************************************************//**
1848 * Turn line mode off or on. Line mode causes the %CMUcam4 to send type F data
1849 * packets after sending type H, S, or T data packets.
1850 * @param [in] active 0 for off and 1 for on.
1851 * @return 0 on success and a negative error value on failure.
1852 * @see CMUcam4::getTypeFDataPacket()
1853 * @see CMUcam4_image_data_t
1854 *******************************************************************************/
1855 int lineMode(int active);
1856 
1857 /***************************************************************************//**
1858 * Turn switching mode off or on. Switching mode causes the %CMUcam4 to send
1859 * type S data packets after sending type T data packets and vice versa.
1860 * @param [in] active 0 for off and 1 for on.
1861 * @return 0 on success and a negative error value on failure.
1862 *******************************************************************************/
1863 int switchingMode(int active);
1864 
1865 /***************************************************************************//**
1866 * Turn test mode off or on. Test mode causes the %CMUcam4 to process an image
1867 * of color bars instead of processing the normal image.
1868 * @param [in] active 0 for off and 1 for on.
1869 * @return 0 on success and a negative error value on failure.
1870 *******************************************************************************/
1871 int testMode(int active);
1872 
1873 /***************************************************************************//**
1874 * Turn color tracking off or on.
1875 * If off, then the %CMUcam4 operates in RGB mode. In RGB mode R maps to the red
1876 * channel, G maps to the green channel, and B maps to the blue channel.
1877 * @n @n If on, then the %CMUcam4 operates in YUV mode. In YUV mode Y maps to
1878 * the green channel, U maps to the blue channel, and V maps to the red channel.
1879 * @param [in] active 0 for off and 1 for on.
1880 * @return 0 on success and a negative error value on failure.
1881 *******************************************************************************/
1882 int colorTracking(int active);
1883 
1884 /***************************************************************************//**
1885 * Turn histogram tracking off or on.
1886 * If off, then the %CMUcam4 calculates the histogram and image statisitcs on
1887 * all tracked and untracked pixels inside of the color tracking window.
1888 * @n @n If on, then the %CMUcam4 calculates the histogram and image statisitcs
1889 * on all tracked pixels inside of the color tracking window.
1890 * @param [in] active 0 for off and 1 for on.
1891 * @return 0 on success and a negative error value on failure.
1892 *******************************************************************************/
1893 int histogramTracking(int active);
1894 
1895 /***************************************************************************//**
1896 * Turn the inverted filter off or on.
1897 * If off, then the %CMUcam4 tracks all pixels that fall inside of the color
1898 * tracking bounds.
1899 * @n @n If on, then the %CMUcam4 tracks all pixels that fall outside of the
1900 * color tracking bounds.
1901 * @param [in] active 0 for off and 1 for on.
1902 * @return 0 on success and a negative error value on failure.
1903 *******************************************************************************/
1904 int invertedFilter(int active);
1905 
1906 /***************************************************************************//**
1907 * Turn the noise filter off or on.
1908 * @par For example:
1909 * 0 to filter out no pixels
1910 * @n 1 to filter out the leading 1 pixels in any group of pixels in a row
1911 * @n 2 to filter out the leading 2 pixels in any group of pixels in a row
1912 * @n ...
1913 * @n 255 to filter out the leading 255 pixels in any group of pixels in a row
1914 * @param [in] threshold 0 for off and 1 or more for on.
1915 * @return 0 on success and a negative error value on failure.
1916 *******************************************************************************/
1917 int noiseFilter(int threshold);
1918 
1919 /***************************************************************************//**
1920 * Change a file's or directory's attributes on the disk.
1921 * @param [in] fileOrDirectoryPathName The file or directory to change.
1922 * @param [in] attributes The new attribute string. E.g. "RHSA" or "_".
1923 * @return 0 on success and a negative error value on failure.
1924 *******************************************************************************/
1925 int changeAttributes(const char * fileOrDirectoryPathName,
1926  const char * attributes);
1927 
1928 /***************************************************************************//**
1929 * Change the working directory.
1930 * @param [in] directoryPathAndName The directory to change to.
1931 * @return 0 on success and a negative error value on failure.
1932 *******************************************************************************/
1933 int changeDirectory(const char * directoryPathAndName);
1934 
1935 /***************************************************************************//**
1936 * Get information about the disk's geometry.
1937 * @param [out] pointer A pointer to a CMUcam4_disk_information_t structure to
1938 * be filled with information about the disk's geometry.
1939 * @return 0 on success and a negative error value on failure.
1940 *******************************************************************************/
1942 
1943 /***************************************************************************//**
1944 * Get information about the disk's free and used sector space.
1945 * @param [out] pointer A pointer to a CMUcam4_disk_space_t structure to be
1946 * filled with information about the disk's free and used sector space.
1947 * @return 0 on success and a negative error value on failure.
1948 *******************************************************************************/
1949 int diskSpace(CMUcam4_disk_space_t * pointer);
1950 
1951 /***************************************************************************//**
1952 * Deletes all files and directories on the disk.
1953 * @return 0 on success and a negative error value on failure.
1954 *******************************************************************************/
1955 int formatDisk();
1956 
1957 /***************************************************************************//**
1958 * Reads all or part of the entries in the working directory to a buffer.
1959 * @param [out] pointer The array to store directory entry information to.
1960 * @param [in] size The size of the CMUcam4_directory_entry_t array.
1961 * @param [in] offset The number of entries to skip before storing.
1962 * @return The absolute number of directory entries in the working directory on
1963 * success and a negative error value on failure.
1964 *******************************************************************************/
1966  size_t size, unsigned long offset);
1967 
1968 /***************************************************************************//**
1969 * Makes a new directory on the disk.
1970 * @param [in] directoryPathAndName The new directory to make.
1971 * @return 0 on success and a negative error value on failure.
1972 *******************************************************************************/
1973 int makeDirectory(const char * directoryPathAndName);
1974 
1975 /***************************************************************************//**
1976 * Moves a file or directory on the disk.
1977 * @param [in] oldEntryPathAndName The source entry to move.
1978 * @param [in] newEntryPathAndName The destination of the entry to move.
1979 * @return 0 on success and a negative error value on failure.
1980 *******************************************************************************/
1981 int moveEntry(const char * oldEntryPathAndName,
1982  const char * newEntryPathAndName);
1983 
1984 /***************************************************************************//**
1985 * Prints a line of text to a file.
1986 * @param [in] filePathAndName The file to append to.
1987 * @param [in] textToAppend The string to append to the file.
1988 * @return 0 on success and a negative error value on failure.
1989 *******************************************************************************/
1990 int printLine(const char * filePathAndName, const char * textToAppend);
1991 
1992 /***************************************************************************//**
1993 * Reads all or part of a file to a buffer.
1994 * @param [in] filePathAndName The file to read.
1995 * @param [out] buffer The buffer to store all or part of the file to.
1996 * @param [in] size The size of the buffer in bytes.
1997 * @param [in] offset The offset in the file to start to read from in bytes.
1998 * @return The absolute file size in bytes on success and a negative error value
1999 * on failure.
2000 *******************************************************************************/
2001 long filePrint(const char * filePathAndName, uint8_t * buffer,
2002  size_t size, unsigned long offset);
2003 
2004 /***************************************************************************//**
2005 * Deletes a file or empty directory on the disk.
2006 * @param [in] fileOrDirectoryPathAndName The file or directory to delete.
2007 * @return 0 on success and a negative error value on failure.
2008 *******************************************************************************/
2009 int removeEntry(const char * fileOrDirectoryPathAndName);
2010 
2011 /***************************************************************************//**
2012 * Unmounts the micro secure digital card. Other file system functions
2013 * automatically mount the disk by default. This function must be called to
2014 * explictly unmount the disk before removal.
2015 * @return 0 on success and a negative error value on failure.
2016 *******************************************************************************/
2017 int unmountDisk();
2018 
2019 /***************************************************************************//**
2020 * Saves an 80x60 binary bitmap to the disk in BMP file format. The saved binary
2021 * bitmap is the 160x120 segmented color tracking image down-sampled to 80x60.
2022 * @return 0 on success and a negative error value on failure.
2023 *******************************************************************************/
2024 int dumpBitmap();
2025 
2026 /***************************************************************************//**
2027 * Saves an 640:320:160:80x480:240:120:60 image to the disk in BMP file format.
2028 * Use this function to get feedback about what the %CMUcam4 sees.
2029 * @param [in] horizontalResolution The horizontal resolution to save the image
2030 * with: 0=640 pixels, 1=320 pixels, 2=160 pixels, 3=80 pixels.
2031 * @param [in] verticalResolution The vertical resolution to save the image
2032 * with: 0=480 pixels, 1=240 pixels, 2=160 pixels, 3=60 pixels.
2033 * @return 0 on success and a negative error value on failure.
2034 *******************************************************************************/
2035 int dumpFrame(int horizontalResolution, int verticalResolution);
2036 
2037 /***************************************************************************//**
2038 * Receive an 80x60 binary bitmap from the %CMUcam4. The sent binary bitmap is
2039 * the 160x120 segmented color tracking image down-sampled to 80x60.
2040 * @param [out] pointer The address of where to put the received binary bitmap.
2041 * @return 0 on success and a negative error value on failure.
2042 *******************************************************************************/
2043 int sendBitmap(CMUcam4_image_data_t * pointer);
2044 
2045 /***************************************************************************//**
2046 * Receive an 640:320:160:80x480:240:120:60 image from the %CMUcam4. Use this
2047 * function to get feedback about what the %CMUcam4 sees.
2048 * @param [in] horizontalResolution The horizontal resolution to send the image
2049 * in: 0=640 pixels, 1=320 pixels, 2=160 pixels, 3=80 pixels.
2050 * @param [in] verticalResolution The vertical resolution to send the image in:
2051 * 0=480 pixels, 1=240 pixels, 2=160 pixels, 3=60 pixels.
2052 * @param [out] buffer The address of where to put the received RGB565 bitmap.
2053 * @param [in] horizonalSize The horizontal size of the array in 16-bit words.
2054 * @param [in] horizontalOffset A horizontal pixel offset within the image to
2055 * start to store image data from. The @c horizontalOffset plus the array @c
2056 * horizonalSize must be less than or equal the selected horizontal resolution.
2057 * @param [in] verticalSize The vertical size of the array.
2058 * @param [in] verticalOffset A vertical pixel offset within the image to start
2059 * to store image data from. The @c verticalOffset plus the array @c
2060 * verticalSize must be less than or equal the selected vertical resolution.
2061 * @return 0 on success and a negative error value on failure.
2062 *******************************************************************************/
2063 int sendFrame(int horizontalResolution, int verticalResolution,
2064  uint16_t * buffer,
2065  size_t horizonalSize, size_t horizontalOffset,
2066  size_t verticalSize, size_t verticalOffset);
2067 
2068 private:
2069 
2070 /***************************************************************************//**
2071 * Sends a command to the %CMUcam4 and receives a void responce.
2072 * @param [in] command The command string to be sent.
2073 * @param [in] timeout The timeout for the operation in milliseconds.
2074 * @return 0 on success and a negative error value on failure.
2075 *******************************************************************************/
2076 int _voidCommandWrapper(const char * command, unsigned long timeout);
2077 
2078 /***************************************************************************//**
2079 * Sends a command to the %CMUcam4 and receives an integer responce.
2080 * @param [in] command The command string to be sent.
2081 * @param [in] timeout The timeout for the operation in milliseconds.
2082 * @return The integer value on success and a negative error value on failure.
2083 *******************************************************************************/
2084 int _intCommandWrapper(const char * command, unsigned long timeout);
2085 
2086 /***************************************************************************//**
2087 * Generic %CMUcam4 command wrapper. This function wakes the %CMUcam4 up from
2088 * sleep deeply or sleep lightly if not already awake and idles the %CMUcam4 if
2089 * not already idle before sending the passed @c command.
2090 * @param [in] command The command string to be sent.
2091 * @param [in] timeout The timeout for the operation in milliseconds.
2092 * @return 0 on success and a negative error value on failure.
2093 *******************************************************************************/
2094 int _commandWrapper(const char * command, unsigned long timeout);
2095 
2096 /***************************************************************************//**
2097 * Handles receiving and parsing type F, H, S, and T data packets.
2098 * @param [in] responce The type of data packet to look for.
2099 * Either 'F', 'H', 'S', or 'T'.
2100 * @return 0 on success and a negative error value on failure.
2101 *******************************************************************************/
2102 int _responceWrapper(char responce);
2103 
2104 /***************************************************************************//**
2105 * Waits for the %CMUcam4 to respond with the idle character.
2106 *******************************************************************************/
2107 void _waitForIdle();
2108 
2109 /***************************************************************************//**
2110 * Waits for the %CMUcam4 to respond with "ACK" or "NCK".
2111 *******************************************************************************/
2112 void _waitForResponce();
2113 
2114 /***************************************************************************//**
2115 * Receives data and handles "MSG" and "ERR" strings.
2116 *******************************************************************************/
2117 void _receiveData();
2118 
2119 /***************************************************************************//**
2120 * Maps error strings to error numbers.
2121 *******************************************************************************/
2122 void _handleError();
2123 
2124 /***************************************************************************//**
2125 * Checks if the responce buffer starts with a particular string, repeatedly in
2126 * a loop, until timeout.
2127 * @param [in] string The string to check against the responce buffer.
2128 *******************************************************************************/
2129 void _waitForString(const char * string);
2130 
2131 /***************************************************************************//**
2132 * Checks if the responce buffer starts with a particular string.
2133 * @param [in] string The string to check against the responce buffer.
2134 * @return 1 if true and 0 if false.
2135 *******************************************************************************/
2136 int _startsWithString(const char * string);
2137 
2138 /***************************************************************************//**
2139 * Reads binary data from the serial port.
2140 * @param [out] buffer The address of the buffer of where to put the packet.
2141 * @param [in] size The size of the buffer in bytes.
2142 * @param [in] packetSize The size of the binary data packet in bytes.
2143 * @param [in] packetOffset Offset inside of the binary data packet to start
2144 * to read from in bytes.
2145 *******************************************************************************/
2146 void _readBinary(uint8_t * buffer, size_t size,
2147  unsigned long packetSize,
2148  unsigned long packetOffset);
2149 
2150 /***************************************************************************//**
2151 * Reads text data from the serial port terminated by the '@\r' character. This
2152 * function will immediately return if
2153 * ':' is the first character encountered,
2154 * if "F " is the first string encountered,
2155 * if "DAT:" is the first string encountered (for v1.01 and below firmware),
2156 * or if "DAT: " is the first string encountered (for v1.02 and above firmware).
2157 *******************************************************************************/
2158 void _readText();
2159 
2160 /***************************************************************************//**
2161 * Sets the millisecond timeout.
2162 * @param [in] timeout The timeout in milliseconds.
2163 *******************************************************************************/
2164 void _setReadTimeout(unsigned long timeout);
2165 
2166 /***************************************************************************//**
2167 * Reads a byte from the serial port with a timeout.
2168 * @return A byte from the serial port.
2169 *******************************************************************************/
2170 int _readWithTimeout();
2171 
2172 /***************************************************************************//**
2173 * Millisecond timeout storage for use with CMUcam4::_readWithTimeout().
2174 *******************************************************************************/
2175 unsigned long _timeout;
2176 
2177 /***************************************************************************//**
2178 * Millisecond snapshot storage for use with CMUcam4::_readWithTimeout().
2179 *******************************************************************************/
2180 unsigned long _milliseconds;
2181 
2182 /***************************************************************************//**
2183 * Interface library activation state.
2184 *******************************************************************************/
2185 enum _CMUcam4_state
2186 {
2187  DEACTIVATED, ///< The interface library state is deactivated.
2188  ACTIVATED ///< The interface library state is activated.
2189 }
2190 _state; ///< State booking variable.
2191 
2192 /***************************************************************************//**
2193 * Camera board firmware version.
2194 *******************************************************************************/
2195 enum _CMUcam4_version
2196 {
2197  VERSION_100 = CMUCAM4_FIRMWARE_V100, ///< %CMUcam4 firmware version 1.00.
2198  VERSION_101 = CMUCAM4_FIRMWARE_V101, ///< %CMUcam4 firmware version 1.01.
2199  VERSION_102 = CMUCAM4_FIRMWARE_V102, ///< %CMUcam4 firmware version 1.02.
2200  VERSION_103 = CMUCAM4_FIRMWARE_V103 ///< %CMUcam4 firmware version 1.03.
2201 }
2202 _version; ///< Version booking variable.
2203 
2204 /***************************************************************************//**
2205 * Responce (input) storage buffer.
2206 *******************************************************************************/
2207 char _resBuffer[CMUCAM4_RES_BUFFER_SIZE];
2208 
2209 /***************************************************************************//**
2210 * Command (output) storage buffer.
2211 *******************************************************************************/
2212 char _cmdBuffer[CMUCAM4_CMD_BUFFER_SIZE];
2213 
2214 /***************************************************************************//**
2215 * Portable serial and timer wrapper library.
2216 *******************************************************************************/
2217 CMUcom4 _com;
2218 
2219 /***************************************************************************//**
2220 * Stack environment storage for throwing and catching errors.
2221 *******************************************************************************/
2222 jmp_buf _env;
2223 };
2224 
2225 #endif
2226 
2227 /***************************************************************************//**
2228 * @file
2229 * @par MIT License - TERMS OF USE:
2230 * @n Permission is hereby granted, free of charge, to any person obtaining a
2231 * copy of this software and associated documentation files (the "Software"), to
2232 * deal in the Software without restriction, including without limitation the
2233 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
2234 * sell copies of the Software, and to permit persons to whom the Software is
2235 * furnished to do so, subject to the following conditions:
2236 * @n
2237 * @n The above copyright notice and this permission notice shall be included in
2238 * all copies or substantial portions of the Software.
2239 * @n
2240 * @n THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2241 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2242 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2243 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2244 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2245 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2246 * SOFTWARE.
2247 *******************************************************************************/