16 #include "../camera.h"
29 static char LK_RESOLUTION_1600[] = {0x56, 0x00, 0x54, 0x01, 0x21};
30 static char LK_RESOLUTION_RE[] = {0x76, 0x00, 0x54, 0x00, 0x00};
32 static char LK_COMPRESSION[] = {0x56, 0x00, 0x31, 0x05, 0x01, 0x01, 0x12, 0x04, 0x00};
33 static char LK_COMPRESSION_RE[] = {0x76, 0x00, 0x31, 0x00, 0x00};
35 static char LK_RESET[] = {0x56, 0x00, 0x26, 0x00};
38 static char LK_RESET_RE[] = {0x0d, 0x0a, 0x49, 0x6e, 0x69, 0x74, 0x20, 0x65, 0x6e, 0x64, 0x0d, 0x0a};
40 static char LK_PICTURE[] = {0x56, 0x00, 0x36, 0x01, 0x00};
41 static char LK_PICTURE_RE[] = {0x76, 0x00, 0x36, 0x00, 0x00};
42 static char LK_JPEGSIZE[] = {0x56, 0x00, 0x34, 0x01, 0x00};
43 static char LK_JPEGSIZE_RE[] = {0x76, 0x00, 0x34, 0x00, 0x04};
47 static char LK_READPICTURE[] = {0x56, 0x00, 0x32, 0x0C, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
48 static char LK_PICTURE_TIME_dot1ms[] = {0x00, 0x0A};
49 static char LK_READPICTURE_RE[] = {0x76, 0x00, 0x32, 0x00, 0x00};
51 static char JPEG_END[] = {0xFF, 0xD9};
53 #define CAMWRITE(a) UART_putb(UART_CAMERA,a,sizeof(a)); // send this message
55 static bool UART_waitmatch(
char *
string, uint32_t string_length, uint32_t timeout)
59 uint64_t start_timestamp;
67 if(c ==
string[index])
70 if(index == string_length)
84 static uint32_t UART_getw4(uint8_t serial)
87 return (uint32_t)((c1 << 24) | (c2 << 16) | (c3 << 8) | (c4 << 0));
90 static bool Camera_command(
char *command, uint32_t command_length,
char *response, uint32_t response_length)
92 uint32_t attempts = 1;
94 UART_putb(UART_CAMERA,command,command_length);
95 while(!UART_waitmatch(response, response_length, 3000))
102 UART_putb(UART_CAMERA,command,command_length);
109 uint32_t jpegsize, i=0, j=0, endfoundcount = 0;
110 uint8_t page_buffer[page_size];
113 if(!Camera_command(LK_RESET,
sizeof(LK_RESET), LK_RESET_RE,
sizeof(LK_RESET_RE)))
121 if(!Camera_command(LK_RESOLUTION_1600,
sizeof(LK_RESOLUTION_1600), LK_RESOLUTION_RE,
sizeof(LK_RESOLUTION_RE)))
127 LK_COMPRESSION[8] = 0x10;
128 if(!Camera_command(LK_COMPRESSION,
sizeof(LK_COMPRESSION), LK_COMPRESSION_RE,
sizeof(LK_COMPRESSION_RE)))
134 if(!Camera_command(LK_PICTURE,
sizeof(LK_PICTURE), LK_PICTURE_RE,
sizeof(LK_PICTURE_RE)))
140 if(!Camera_command(LK_JPEGSIZE,
sizeof(LK_JPEGSIZE), LK_JPEGSIZE_RE,
sizeof(LK_JPEGSIZE_RE)))
144 jpegsize = UART_getw4(UART_CAMERA);
147 LK_READPICTURE[6] = 0x00;
148 LK_READPICTURE[7] = 0x00;
150 LK_READPICTURE[8] = 0x00;
151 LK_READPICTURE[9] = 0x00;
154 LK_READPICTURE[10] = (char)((jpegsize >> 24) & 0xFF);
155 LK_READPICTURE[11] = (char)((jpegsize >> 16) & 0xFF);
156 LK_READPICTURE[12] = (char)((jpegsize >> 8) & 0xFF);
157 LK_READPICTURE[13] = (char)(jpegsize & 0xFF);
160 LK_READPICTURE[14] = LK_PICTURE_TIME_dot1ms[0];
161 LK_READPICTURE[15] = LK_PICTURE_TIME_dot1ms[1];
163 if(!Camera_command(LK_READPICTURE,
sizeof(LK_READPICTURE), LK_READPICTURE_RE,
sizeof(LK_READPICTURE_RE)))
168 for(i=0; i<jpegsize && endfoundcount<2;i++)
172 if(page_buffer[j] == JPEG_END[endfoundcount])
182 if(j==page_size || endfoundcount==2)
184 page_store(page_buffer, j);
void Delay_ms(uint32_t milliseconds)
bool Camera_capture(uint32_t page_size, void(*page_store)(uint8_t *, uint32_t))
bool UART_getc_nonblocking(uint8_t uart_num, char *c)
char UART_getc(uint8_t uart_num)
bool RTC_timerElapsed_ms(uint64_t start_time_ms, uint64_t period_ms)
void RTC_getTime_ms(uint64_t *time_ms)
void UART_putb(uint8_t uart_num, char *str, uint32_t len)