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