Changeset 415
- Timestamp:
- 02/17/07 15:37:54 (2 years ago)
- Files:
-
- trunk/lib/cc3-ilp/cc3_ilp.c (modified) (1 diff)
- trunk/lib/cc3-ilp/cc3_ilp.h (modified) (1 diff)
- trunk/projects/cmucam2/cmucam2.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/cc3-ilp/cc3_ilp.c
r399 r415 22 22 #include <stdio.h> 23 23 #include <stdlib.h> 24 25 void cc3_send_image_direct (void)26 {27 cc3_pixbuf_load ();28 29 uint32_t x, y;30 uint32_t size_x, size_y;31 uint8_t *row = cc3_malloc_rows(1);32 uint8_t num_channels = cc3_g_pixbuf_frame.coi == CC3_CHANNEL_ALL ? 3 : 1;33 34 35 size_x = cc3_g_pixbuf_frame.width;36 size_y = cc3_g_pixbuf_frame.height;37 38 putchar (1);39 putchar (size_x);40 if (size_y > 255)41 size_y = 255;42 putchar (size_y);43 for (y = 0; y < size_y; y++) {44 putchar (2);45 46 cc3_pixbuf_read_rows(row, 1);47 for (x = 0; x < size_x * num_channels; x++) {48 uint8_t p = row[x];49 putchar (p);50 }51 }52 putchar (3);53 54 free(row);55 }56 24 57 25 uint8_t cc3_load_img_rows (cc3_image_t * img, uint16_t rows) trunk/lib/cc3-ilp/cc3_ilp.h
r367 r415 31 31 32 32 33 void cc3_send_image_direct(void);34 33 void cc3_get_pixel(cc3_image_t *img, uint16_t x, uint16_t y, cc3_pixel_t *out_pix); 35 34 void cc3_set_pixel(cc3_image_t *img, uint16_t x, uint16_t y, cc3_pixel_t *in_pix); trunk/projects/cmucam2/cmucam2.c
r413 r415 25 25 26 26 27 static const int MAX_ARGS = 1 1;27 static const int MAX_ARGS = 12; 28 28 static const int MAX_LINE = 128; 29 29 … … 49 49 TRACK_WINDOW, 50 50 GET_WINDOW, 51 LED_0, 51 52 CMUCAM2_CMD_END // Must be last entry so array sizes are correct 52 53 } cmucam2_command_t; … … 60 61 static void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 61 62 bool poll_mode, 62 bool line_mode, bool quite);63 bool line_mode, bool auto_led, bool quite); 63 64 static int32_t cmucam2_get_command (int32_t * cmd, int32_t * arg_list); 64 65 static void set_cmucam2_commands (void); … … 66 67 static void print_NCK (void); 67 68 static void cmucam2_write_t_packet (cc3_track_pkt_t * pkt); 69 void cmucam2_send_image_direct (bool auto_led); 68 70 69 71 int main (void) … … 72 74 int32_t val, n; 73 75 uint32_t arg_list[MAX_ARGS]; 74 bool error, poll_mode, line_mode ;76 bool error, poll_mode, line_mode,auto_led; 75 77 cc3_track_pkt_t t_pkt; 76 78 cc3_color_info_pkt_t s_pkt; … … 79 81 80 82 cmucam2_start: 83 auto_led= true; 81 84 poll_mode = false; 82 85 line_mode = false; 86 t_pkt.lower_bound.channel[0] = 16; 87 t_pkt.upper_bound.channel[0] = 240; 88 t_pkt.lower_bound.channel[1] = 16; 89 t_pkt.upper_bound.channel[1] = 240; 90 t_pkt.lower_bound.channel[2] = 16; 91 t_pkt.upper_bound.channel[2] = 240; 83 92 cc3_system_setup (); 84 93 … … 134 143 break; 135 144 145 case LED_0: 146 if (n != 1 && arg_list[0]>2 ) { 147 error = true; 148 break; 149 } 150 else 151 print_ACK (); 152 auto_led=false; 153 if (arg_list[0] == 0) 154 cc3_clr_led(0); 155 if (arg_list[0] == 1) 156 cc3_set_led(0); 157 if (arg_list[0] == 2) 158 auto_led=true; 159 break; 136 160 137 161 case POLL_MODE: … … 214 238 else 215 239 print_ACK (); 216 c c3_send_image_direct ();240 cmucam2_send_image_direct (auto_led); 217 241 cc3_pixbuf_set_coi(old_coi); 218 242 break; … … 281 305 t_pkt.upper_bound.channel[2] = arg_list[5]; 282 306 } 283 cmucam2_track_color (&t_pkt, poll_mode, line_mode, 0);307 cmucam2_track_color (&t_pkt, poll_mode, line_mode,auto_led,0); 284 308 break; 285 309 … … 317 341 tmp= s_pkt.mean.channel[2]-threshold; if(tmp<16) tmp=16; if(tmp>240) tmp=240;t_pkt.lower_bound.channel[2] = tmp; 318 342 tmp= s_pkt.mean.channel[2]+threshold; if(tmp<16) tmp=16; if(tmp>240) tmp=240; t_pkt.upper_bound.channel[2] = tmp; 319 cmucam2_track_color (&t_pkt, poll_mode, line_mode,0);343 cmucam2_track_color (&t_pkt, poll_mode, line_mode,auto_led,0); 320 344 } 321 345 break; … … 404 428 405 429 430 void cmucam2_send_image_direct (bool auto_led) 431 { 432 cc3_pixbuf_load (); 433 434 uint32_t x, y; 435 uint32_t size_x, size_y; 436 uint8_t *row = cc3_malloc_rows(1); 437 uint8_t num_channels = cc3_g_pixbuf_frame.coi == CC3_CHANNEL_ALL ? 3 : 1; 438 439 440 size_x = cc3_g_pixbuf_frame.width; 441 size_y = cc3_g_pixbuf_frame.height; 442 443 putchar (1); 444 putchar (size_x); 445 if (size_y > 255) 446 size_y = 255; 447 putchar (size_y); 448 for (y = 0; y < size_y; y++) { 449 putchar (2); 450 if(auto_led) 451 { 452 if(y%4==0) cc3_set_led(0); 453 else cc3_clr_led(0); 454 } 455 cc3_pixbuf_read_rows(row, 1); 456 for (x = 0; x < size_x * num_channels; x++) { 457 uint8_t p = row[x]; 458 putchar (p); 459 } 460 } 461 putchar (3); 462 463 cc3_clr_led(0); 464 free(row); 465 } 466 406 467 void cmucam2_get_mean (cc3_color_info_pkt_t * s_pkt, 407 468 bool poll_mode, … … 420 481 } 421 482 cc3_color_info_scanline_finish (s_pkt); 483 while (!cc3_uart_has_data (0)) { if(fgetc(stdin)=='\r' ) free(img.pix); return; } 422 484 if(!quite) cmucam2_write_s_packet (s_pkt); 423 485 } … … 434 496 void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 435 497 bool poll_mode, 436 bool line_mode, bool quite)498 bool line_mode, bool auto_led, bool quite) 437 499 { 438 500 cc3_image_t img; … … 469 531 cc3_track_color_scanline (&img, t_pkt); 470 532 if (line_mode) { 471 472 for (int j = 0; j < lm_width; j++) { 533 // keep this check here if you don't want the CMUcam2 GUI to hang after exiting a command in line mode 534 while (!cc3_uart_has_data (0)) { if(fgetc(stdin)=='\r' ) free(img.pix); return; } 535 for (int j = 0; j < lm_width; j++) { 473 536 if (lm[j] == 0xAA) 474 537 { … … 481 544 } 482 545 } 546 // keep this check here if you don't want the CMUcam2 GUI to hang after exiting a command in line mode 547 while (!cc3_uart_has_data (0)) { if(fgetc(stdin)=='\r' ) free(img.pix); return; } 483 548 cc3_track_color_scanline_finish (t_pkt); 484 549 if (line_mode) { … … 486 551 if(!quite) putchar (0xAA); 487 552 } 553 if(auto_led) { 554 if(t_pkt->int_density>2 ) cc3_set_led(0); 555 else cc3_clr_led(0); 556 } 488 557 if(!quite) cmucam2_write_t_packet (t_pkt); 489 } 490 if(!cc3_uart_has_data (0))558 } else return 0; 559 while (!cc3_uart_has_data (0)) 491 560 { 492 561 if(fgetc(stdin)=='\r' ) … … 494 563 } 495 564 } while (!poll_mode); 496 497 565 free (img.pix); 566 return 1; 498 567 } 499 568 … … 566 635 cmucam2_cmds[TRACK_WINDOW] = "TW"; 567 636 cmucam2_cmds[GET_WINDOW] = "GW"; 637 cmucam2_cmds[LED_0] = "L0"; 568 638 } 569 639
