35 #define CMUCAM4_FIRMWARE_V100 100
40 #define CMUCAM4_FIRMWARE_V101 101
45 #define CMUCAM4_FIRMWARE_V102 102
50 #define CMUCAM4_FIRMWARE_V103 103
55 #define CMUCAM4_NATIVE_H_RES 160
60 #define CMUCAM4_NATIVE_V_RES 120
65 #define CMUCAM4_BINARY_H_RES (CMUCAM4_NATIVE_H_RES / 2)
70 #define CMUCAM4_BINARY_V_RES (CMUCAM4_NATIVE_V_RES / 2)
75 #define CMUCAM4_MIN_NATIVE_ROW 0
80 #define CMUCAM4_MIN_NATIVE_COLUMN 0
85 #define CMUCAM4_MAX_NATIVE_ROW (CMUCAM4_NATIVE_V_RES - 1)
90 #define CMUCAM4_MAX_NATIVE_COLUMN (CMUCAM4_NATIVE_H_RES - 1)
95 #define CMUCAM4_MIN_BINARY_ROW 0
100 #define CMUCAM4_MIN_BINARY_COLUMN 0
105 #define CMUCAM4_MAX_BINARY_ROW (CMUCAM4_BINARY_V_RES - 1)
110 #define CMUCAM4_MAX_BINARY_COLUMN (CMUCAM4_BINARY_H_RES - 1)
117 #define CMUCAM4_IN_TP_LL 0
124 #define CMUCAM4_IN_TP_LH 1
131 #define CMUCAM4_IN_TP_HL 2
138 #define CMUCAM4_IN_TP_HH 3
145 #define CMUCAM4_DIR_TP_II 0
152 #define CMUCAM4_DIR_TP_IO 1
159 #define CMUCAM4_DIR_TP_OI 2
166 #define CMUCAM4_DIR_TP_OO 3
173 #define CMUCAM4_OUT_TP_LL 0
180 #define CMUCAM4_OUT_TP_LH 1
187 #define CMUCAM4_OUT_TP_HL 2
194 #define CMUCAM4_OUT_TP_HH 3
201 #define CMUCAM4_LED_OFF -1
208 #define CMUCAM4_LED_ON 0
215 #define CMUCAM4_PAN_SERVO 0
222 #define CMUCAM4_TILT_SERVO 1
228 #define CMUCAM4_RED_CHANNEL 0
234 #define CMUCAM4_GREEN_CHANNEL 1
240 #define CMUCAM4_BLUE_CHANNEL 2
246 #define CMUCAM4_H1_BINS 0
252 #define CMUCAM4_H2_BINS 1
258 #define CMUCAM4_H4_BINS 2
264 #define CMUCAM4_H8_BINS 3
270 #define CMUCAM4_H16_BINS 4
276 #define CMUCAM4_H32_BINS 5
282 #define CMUCAM4_H64_BINS 6
288 #define CMUCAM4_HR_640 0
294 #define CMUCAM4_HR_320 1
300 #define CMUCAM4_HR_160 2
306 #define CMUCAM4_HR_80 3
312 #define CMUCAM4_VR_480 0
318 #define CMUCAM4_VR_240 1
324 #define CMUCAM4_VR_120 2
330 #define CMUCAM4_VR_60 3
335 #define CMUCAM4_ID_T_R CMUCAM4_BINARY_V_RES
340 #define CMUCAM4_ID_T_C (CMUCAM4_BINARY_H_RES / 8)
346 #define CMUCAM4_ID_T_LENGTH (CMUCAM4_ID_T_R * CMUCAM4_ID_T_C)
352 #define CMUCAM4_HD_1_T_LENGTH (1 << CMUCAM4_H1_BINS)
358 #define CMUCAM4_HD_2_T_LENGTH (1 << CMUCAM4_H2_BINS)
364 #define CMUCAM4_HD_4_T_LENGTH (1 << CMUCAM4_H4_BINS)
370 #define CMUCAM4_HD_8_T_LENGTH (1 << CMUCAM4_H8_BINS)
376 #define CMUCAM4_HD_16_T_LENGTH (1 << CMUCAM4_H16_BINS)
382 #define CMUCAM4_HD_32_T_LENGTH (1 << CMUCAM4_H32_BINS)
388 #define CMUCAM4_HD_64_T_LENGTH (1 << CMUCAM4_H64_BINS)
393 #define CMUCAM4_VL_LENGTH 11
398 #define CMUCAM4_FST_LENGTH 8
403 #define CMUCAM4_NAME_LENGTH 12
408 #define CMUCAM4_ATTR_LENGTH 6
413 #define CMUCAM4_RETURN_SUCCESS 0
418 #define CMUCAM4_RETURN_FAILURE -1
423 #define CMUCAM4_NOT_ACTIVATED -2
428 #define CMUCAM4_NCK_RESPONCE -3
433 #define CMUCAM4_UNSUPPORTED_VERSION -4
438 #define CMUCAM4_UNEXPECTED_RESPONCE -5
444 #define CMUCAM4_COMMAND_OVERFLOW -6
452 #define CMUCAM4_RESPONCE_OVERFLOW -7
457 #define CMUCAM4_STREAM_END -8
462 #define CMUCAM4_SERIAL_TIMEOUT -9
467 #define CMUCAM4_CAMERA_TIMEOUT_ERROR -10
472 #define CMUCAM4_CAMERA_CONNECTION_ERROR -11
477 #define CMUCAM4_DISK_IO_ERROR -12
482 #define CMUCAM4_FILE_SYSTEM_CORRUPTED -13
487 #define CMUCAM4_FILE_SYSTEM_UNSUPPORTED -14
492 #define CMUCAM4_CARD_NOT_DETECTED -15
498 #define CMUCAM4_DISK_MAY_BE_FULL -16
504 #define CMUCAM4_DIRECTORY_FULL -17
509 #define CMUCAM4_EXPECTED_AN_ENTRY -18
514 #define CMUCAM4_EXPECTED_A_DIRECTORY -19
519 #define CMUCAM4_ENTRY_NOT_ACCESSIBLE -20
524 #define CMUCAM4_ENTRY_NOT_MODIFIABLE -21
529 #define CMUCAM4_ENTRY_NOT_FOUND -22
534 #define CMUCAM4_ENTRY_ALREADY_EXISTS -23
539 #define CMUCAM4_DIRECTORY_LINK_MISSING -24
544 #define CMUCAM4_DIRECTORY_NOT_EMPTY -25
549 #define CMUCAM4_NOT_A_DIRECTORY -26
554 #define CMUCAM4_NOT_A_FILE -27
561 #define CMUCAM4_VL_LENGTH_STR CMUCOM4_V_TO_S(CMUCAM4_VL_LENGTH)
566 #define CMUCAM4_FST_LENGTH_STR CMUCOM4_V_TO_S(CMUCAM4_FST_LENGTH)
571 #define CMUCAM4_NAME_LENGTH_STR CMUCOM4_V_TO_S(CMUCAM4_NAME_LENGTH)
576 #define CMUCAM4_ATTR_LENGTH_STR CMUCOM4_V_TO_S(CMUCAM4_ATTR_LENGTH)
581 #define CMUCAM4_CAMERA_TIMEOUT_ERROR_SUM ('E'+'R'+'R'+':'+' '+\
582 'C'+'a'+'m'+'e'+'r'+'a'+' '+\
583 'T'+'i'+'m'+'e'+'o'+'u'+'t'+' '+\
589 #define CMUCAM4_CAMERA_CONNECTION_ERROR_SUM ('E'+'R'+'R'+':'+' '+\
590 'C'+'a'+'m'+'e'+'r'+'a'+' '+\
591 'C'+'o'+'n'+'n'+'e'+'c'+'t'+'i'+'o'+'n'+' '+\
597 #define CMUCAM4_DISK_IO_ERROR_SUM ('E'+'R'+'R'+':'+' '+\
598 'D'+'i'+'s'+'k'+' '+\
605 #define CMUCAM4_FILE_SYSTEM_CORRUPTED_SUM ('E'+'R'+'R'+':'+' '+\
606 'F'+'i'+'l'+'e'+' '+\
607 'S'+'y'+'s'+'t'+'e'+'m'+' '+\
608 'C'+'o'+'r'+'r'+'u'+'p'+'t'+'e'+'d')
613 #define CMUCAM4_FILE_SYSTEM_UNSUPPORTED_SUM ('E'+'R'+'R'+':'+' '+\
614 'F'+'i'+'l'+'e'+' '+\
615 'S'+'y'+'s'+'t'+'e'+'m'+' '+\
616 'U'+'n'+'s'+'u'+'p'+'p'+'o'+'r'+'t'+'e'+'d')
621 #define CMUCAM4_CARD_NOT_DETECTED_SUM ('E'+'R'+'R'+':'+' '+\
622 'C'+'a'+'r'+'d'+' '+\
624 'D'+'e'+'t'+'e'+'c'+'t'+'e'+'d')
629 #define CMUCAM4_DISK_MAY_BE_FULL_SUM ('E'+'R'+'R'+':'+' '+\
630 'D'+'i'+'s'+'k'+' '+\
638 #define CMUCAM4_DIRECTORY_FULL_SUM ('E'+'R'+'R'+':'+' '+\
639 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y'+' '+\
645 #define CMUCAM4_EXPECTED_AN_ENTRY_SUM ('E'+'R'+'R'+':'+' '+\
646 'E'+'x'+'p'+'e'+'c'+'t'+'e'+'d'+' '+\
653 #define CMUCAM4_EXPECTED_A_DIRECTORY_SUM ('E'+'R'+'R'+':'+' '+\
654 'E'+'x'+'p'+'e'+'c'+'t'+'e'+'d'+' '+\
656 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y')
661 #define CMUCAM4_ENTRY_NOT_ACCESSIBLE_SUM ('E'+'R'+'R'+':'+' '+\
662 'E'+'n'+'t'+'r'+'y'+' '+\
664 'A'+'c'+'c'+'e'+'s'+'s'+'i'+'b'+'l'+'e')
669 #define CMUCAM4_ENTRY_NOT_MODIFIABLE_SUM ('E'+'R'+'R'+':'+' '+\
670 'E'+'n'+'t'+'r'+'y'+' '+\
672 'M'+'o'+'d'+'i'+'f'+'i'+'a'+'b'+'l'+'e')
677 #define CMUCAM4_ENTRY_NOT_FOUND_SUM ('E'+'R'+'R'+':'+' '+\
678 'E'+'n'+'t'+'r'+'y'+' '+\
685 #define CMUCAM4_ENTRY_ALREADY_EXISTS_SUM ('E'+'R'+'R'+':'+' '+\
686 'E'+'n'+'t'+'r'+'y'+' '+\
687 'A'+'l'+'r'+'e'+'a'+'d'+'y'+' '+\
688 'E'+'x'+'i'+'s'+'t'+'s')
693 #define CMUCAM4_DIRECTORY_LINK_MISSING_SUM ('E'+'R'+'R'+':'+' '+\
694 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y'+' '+\
695 'L'+'i'+'n'+'k'+' '+\
696 'M'+'i'+'s'+'s'+'i'+'n'+'g')
701 #define CMUCAM4_DIRECTORY_NOT_EMPTY_SUM ('E'+'R'+'R'+':'+' '+\
702 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y'+' '+\
709 #define CMUCAM4_NOT_A_DIRECTORY_SUM ('E'+'R'+'R'+':'+' '+\
712 'D'+'i'+'r'+'e'+'c'+'t'+'o'+'r'+'y')
717 #define CMUCAM4_NOT_A_FILE_SUM ('E'+'R'+'R'+':'+' '+\
725 #define CMUCAM4_RES_BUFFER_SIZE CMUCOM4_INPUT_BUFFER_SIZE
726 #if (CMUCAM4_RES_BUFFER_SIZE < 1) // Responce buffer size limit.
727 #error "Error: The responce (input) buffer size is too small!"
733 #define CMUCAM4_CMD_BUFFER_SIZE CMUCOM4_OUTPUT_BUFFER_SIZE
734 #if (CMUCAM4_CMD_BUFFER_SIZE < 1) // Command buffer size limit.
735 #error "Error: The command (output) buffer size is too small!"
741 #define CMUCAM4_RESET_TRIES 4
746 #define CMUCAM4_RESET_TIMEOUT 2250
751 #define CMUCAM4_IDLE_TRIES 4
756 #define CMUCAM4_IDLE_TIMEOUT 750
761 #define CMUCAM4_NON_FS_TIMEOUT 1000
766 #define CMUCAM4_FS_TIMEOUT 3600000
771 #define CMUCAM4_IC_STRING ":ACK\rCMUcam4 v%d.%02d\r:"
776 #define CMUCAM4_IC_LENGTH sizeof(CMUCAM4_IC_STRING)
781 #define CMUCAM4_FRAME_H_RES 640
786 #define CMUCAM4_FRAME_V_RES 480
1126 #define CMUCAM4_GET_PIXEL(pointer, row, column) \
1128 (((pointer)->pixels[((row) * CMUCAM4_ID_T_C) + ((column) / 8)] \
1129 >> (7 - ((column) & 7))) & 1)
1157 #define CMUCAM4_SET_PIXEL(pointer, row, column, value) \
1159 int bitIndex = (7 - ((column) & 7)); \
1160 int byteIndex = (((row) * CMUCAM4_ID_T_C) + ((column) / 8)); \
1162 (pointer)->pixels[byteIndex] = \
1163 (((~(1<<bitIndex))&((pointer)->pixels[byteIndex]))|(((value)?1:0)<<bitIndex)) \
1428 int panOutput(
int direction,
int output);
1474 int LEDOn(
long frequency);
1592 int greenMin,
int greenMax,
1593 int blueMin,
int blueMax);
1613 int bottomRightX,
int bottomRightY);
1650 int greenMin,
int greenMax,
1651 int blueMin,
int blueMax);
1671 int trackWindow(
int redRange,
int greenRange,
int blueRange);
1926 const char * attributes);
1966 size_t size,
unsigned long offset);
1981 int moveEntry(
const char * oldEntryPathAndName,
1982 const char * newEntryPathAndName);
1990 int printLine(
const char * filePathAndName,
const char * textToAppend);
2001 long filePrint(
const char * filePathAndName, uint8_t * buffer,
2002 size_t size,
unsigned long offset);
2009 int removeEntry(
const char * fileOrDirectoryPathAndName);
2035 int dumpFrame(
int horizontalResolution,
int verticalResolution);
2063 int sendFrame(
int horizontalResolution,
int verticalResolution,
2065 size_t horizonalSize,
size_t horizontalOffset,
2066 size_t verticalSize,
size_t verticalOffset);
2076 int _voidCommandWrapper(
const char * command,
unsigned long timeout);
2084 int _intCommandWrapper(
const char * command,
unsigned long timeout);
2094 int _commandWrapper(
const char * command,
unsigned long timeout);
2102 int _responceWrapper(
char responce);
2107 void _waitForIdle();
2112 void _waitForResponce();
2117 void _receiveData();
2122 void _handleError();
2129 void _waitForString(
const char *
string);
2136 int _startsWithString(
const char *
string);
2146 void _readBinary(uint8_t * buffer,
size_t size,
2147 unsigned long packetSize,
2148 unsigned long packetOffset);
2164 void _setReadTimeout(
unsigned long timeout);
2170 int _readWithTimeout();
2175 unsigned long _timeout;
2180 unsigned long _milliseconds;
2195 enum _CMUcam4_version
2207 char _resBuffer[CMUCAM4_RES_BUFFER_SIZE];
2212 char _cmdBuffer[CMUCAM4_CMD_BUFFER_SIZE];