Changeset 342
- Timestamp:
- 01/16/07 23:53:30 (2 years ago)
- Files:
-
- trunk/projects/cmucam2/cmucam2.c (modified) (31 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/projects/cmucam2/cmucam2.c
r335 r342 24 24 25 25 26 #define MAX_ARGS 10 27 #define MAX_LINE 128 28 #define VERSION_BANNER "CMUcam2 v1.00 c6" 26 static const int MAX_ARGS = 10; 27 static const int MAX_LINE = 128; 28 29 static const char *VERSION_BANNER = "CMUcam2 v1.00 c6"; 29 30 30 31 typedef enum { … … 50 51 char *cmucam2_cmds[CMUCAM2_CMD_END]; 51 52 52 void cmucam2_get_mean (cc3_color_info_pkt_t * t_pkt, uint8_t poll_mode, 53 uint8_t line_mode); 54 void cmucam2_write_s_packet (cc3_color_info_pkt_t * pkt); 55 void cmucam2_track_color (cc3_track_pkt_t * t_pkt, uint8_t poll_mode, 56 uint8_t line_mode); 57 int32_t cmucam2_get_command (int32_t * cmd, int32_t * arg_list); 58 void set_cmucam2_commands (void); 59 void print_ACK (void); 60 void print_NCK (void); 61 void cmucam2_write_t_packet (cc3_track_pkt_t * pkt); 53 static void cmucam2_get_mean (cc3_color_info_pkt_t * t_pkt, 54 bool poll_mode, 55 bool line_mode); 56 static void cmucam2_write_s_packet (cc3_color_info_pkt_t * pkt); 57 static void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 58 bool poll_mode, 59 bool line_mode); 60 static int32_t cmucam2_get_command (int32_t * cmd, int32_t * arg_list); 61 static void set_cmucam2_commands (void); 62 static void print_ACK (void); 63 static void print_NCK (void); 64 static void cmucam2_write_t_packet (cc3_track_pkt_t * pkt); 62 65 63 66 int main (void) … … 66 69 int32_t val, n; 67 70 uint32_t arg_list[MAX_ARGS]; 68 uint8_terror, poll_mode, line_mode;71 bool error, poll_mode, line_mode; 69 72 cc3_track_pkt_t t_pkt; 70 73 cc3_color_info_pkt_t s_pkt; … … 73 76 74 77 cmucam2_start: 75 poll_mode = 0;76 line_mode = 0;78 poll_mode = false; 79 line_mode = false; 77 80 cc3_system_setup (); 78 81 … … 92 95 cc3_pixbuf_set_subsample (CC3_NEAREST, 2, 1); 93 96 94 while ( 1) {97 while (true) { 95 98 cc3_channel_t old_coi; 96 99 97 100 printf (":"); 98 error = 0;101 error = false; 99 102 n = cmucam2_get_command (&command, arg_list); 100 103 if (n != -1) { … … 103 106 case RESET: 104 107 if (n != 0) { 105 error = 1;108 error = true; 106 109 break; 107 110 } … … 115 118 case GET_VERSION: 116 119 if (n != 0) { 117 error = 1;120 error = true; 118 121 break; 119 122 } … … 126 129 case POLL_MODE: 127 130 if (n != 1) { 128 error = 1;131 error = true; 129 132 break; 130 133 } … … 132 135 print_ACK (); 133 136 if (arg_list[0] == 1) 134 poll_mode = 1;135 else 136 poll_mode = 0;137 poll_mode = true; 138 else 139 poll_mode = false; 137 140 break; 138 141 … … 140 143 case HI_RES: 141 144 if (n != 1) { 142 error = 1;145 error = true; 143 146 break; 144 147 } … … 154 157 case LINE_MODE: 155 158 if (n != 2) { 156 error = 1;159 error = true; 157 160 break; 158 161 } … … 162 165 if (arg_list[0] == 0) { 163 166 if (arg_list[1] == 1) 164 line_mode = 1;167 line_mode = true; 165 168 else 166 line_mode = 0;169 line_mode = false; 167 170 } 168 171 break; … … 171 174 case SEND_JPEG: 172 175 if (n != 0 && n != 1) { 173 error = 1;176 error = true; 174 177 break; 175 178 } … … 189 192 if (n == 1) { 190 193 if (arg_list[0] > 4) { 191 error = 1;194 error = true; 192 195 break; 193 196 } … … 195 198 } 196 199 else if (n > 1) { 197 error = 1;200 error = true; 198 201 break; 199 202 } … … 207 210 case CAMERA_REG: 208 211 if (n % 2 != 0 || n < 2) { 209 error = 1;212 error = true; 210 213 break; 211 214 } … … 219 222 case VIRTUAL_WINDOW: 220 223 if (n != 4) { 221 error = 1;224 error = true; 222 225 break; 223 226 } … … 233 236 case DOWN_SAMPLE: 234 237 if (n != 2) { 235 error = 1;238 error = true; 236 239 break; 237 240 } … … 244 247 case TRACK_COLOR: 245 248 if (n != 0 && n != 6) { 246 error = 1;249 error = true; 247 250 break; 248 251 } … … 262 265 case GET_POLLY: 263 266 if (n != 5 ) { 264 error = 1;267 error = true; 265 268 break; 266 269 } … … 277 280 if (!cc3_uart_has_data (0)) 278 281 break; 279 } while ( poll_mode != 1);282 } while (!poll_mode); 280 283 break; 281 284 … … 283 286 case GET_MEAN: 284 287 if (n != 0) { 285 error = 1;288 error = true; 286 289 break; 287 290 } … … 294 297 case SET_SERVO: 295 298 if (n != 2) { 296 error = 1;299 error = true; 297 300 break; 298 301 } … … 309 312 } 310 313 else 311 error = 1;312 313 if (error == 1)314 error = true; 315 316 if (error) 314 317 print_NCK (); 315 318 } … … 320 323 321 324 322 void cmucam2_get_mean (cc3_color_info_pkt_t * s_pkt, uint8_t poll_mode, 323 uint8_t line_mode) 325 void cmucam2_get_mean (cc3_color_info_pkt_t * s_pkt, 326 bool poll_mode, 327 bool line_mode) 324 328 { 325 329 cc3_image_t img; … … 339 343 if (!cc3_uart_has_data (0)) 340 344 break; 341 } while ( poll_mode != 1);345 } while (!poll_mode); 342 346 343 347 free (img.pix); 344 348 } 345 349 346 void cmucam2_track_color (cc3_track_pkt_t * t_pkt, uint8_t poll_mode, 347 uint8_t line_mode) 350 void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 351 bool poll_mode, 352 bool line_mode) 348 353 { 349 354 cc3_image_t img; … … 361 366 lm_width = 0; 362 367 lm_height = 0; 363 if (line_mode == 1) {368 if (line_mode) { 364 369 lm = &t_pkt->binary_scanline; 365 370 lm_width = img.width / 8; … … 379 384 while (cc3_pixbuf_read_rows (img.pix, 1)) { 380 385 cc3_track_color_scanline (&img, t_pkt); 381 if (line_mode == 1) {386 if (line_mode) { 382 387 383 388 for (int j = 0; j < lm_width; j++) { … … 391 396 } 392 397 cc3_track_color_scanline_finish (t_pkt); 393 if (line_mode == 1) {398 if (line_mode) { 394 399 putchar (0xAA); 395 400 putchar (0xAA); … … 400 405 if (!cc3_uart_has_data (0)) 401 406 break; 402 } while ( poll_mode != 1);407 } while (!poll_mode); 403 408 404 409 free (img.pix); … … 523 528 return -1; 524 529 argc = 0; 525 while ( 1) {530 while (true) { 526 531 /* extract string from string sequence */ 527 532 token = strtok (NULL, " \r\n");
