Changeset 415

Show
Ignore:
Timestamp:
02/17/07 15:37:54 (2 years ago)
Author:
anthony_rowe
Message:

no more GUI hang leaving line mode

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/cc3-ilp/cc3_ilp.c

    r399 r415  
    2222#include <stdio.h> 
    2323#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 } 
    5624 
    5725uint8_t cc3_load_img_rows (cc3_image_t * img, uint16_t rows) 
  • trunk/lib/cc3-ilp/cc3_ilp.h

    r367 r415  
    3131 
    3232 
    33 void cc3_send_image_direct(void); 
    3433void cc3_get_pixel(cc3_image_t *img, uint16_t x, uint16_t y, cc3_pixel_t *out_pix); 
    3534void 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  
    2525 
    2626 
    27 static const int MAX_ARGS = 11
     27static const int MAX_ARGS = 12
    2828static const int MAX_LINE = 128; 
    2929 
     
    4949  TRACK_WINDOW, 
    5050  GET_WINDOW, 
     51  LED_0, 
    5152  CMUCAM2_CMD_END               // Must be last entry so array sizes are correct 
    5253} cmucam2_command_t; 
     
    6061static void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 
    6162                                 bool poll_mode, 
    62                                  bool line_mode, bool quite); 
     63                                 bool line_mode, bool auto_led, bool quite); 
    6364static int32_t cmucam2_get_command (int32_t * cmd, int32_t * arg_list); 
    6465static void set_cmucam2_commands (void); 
     
    6667static void print_NCK (void); 
    6768static void cmucam2_write_t_packet (cc3_track_pkt_t * pkt); 
     69void cmucam2_send_image_direct (bool auto_led); 
    6870 
    6971int main (void) 
     
    7274  int32_t val, n; 
    7375  uint32_t arg_list[MAX_ARGS]; 
    74   bool error, poll_mode, line_mode
     76  bool error, poll_mode, line_mode,auto_led
    7577  cc3_track_pkt_t t_pkt; 
    7678  cc3_color_info_pkt_t s_pkt; 
     
    7981 
    8082cmucam2_start: 
     83  auto_led= true;  
    8184  poll_mode = false; 
    8285  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; 
    8392  cc3_system_setup (); 
    8493 
     
    134143        break; 
    135144 
     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; 
    136160 
    137161      case POLL_MODE: 
     
    214238        else 
    215239          print_ACK (); 
    216         cc3_send_image_direct (); 
     240        cmucam2_send_image_direct (auto_led); 
    217241        cc3_pixbuf_set_coi(old_coi); 
    218242        break; 
     
    281305          t_pkt.upper_bound.channel[2] = arg_list[5]; 
    282306        } 
    283         cmucam2_track_color (&t_pkt, poll_mode, line_mode,0); 
     307        cmucam2_track_color (&t_pkt, poll_mode, line_mode,auto_led,0); 
    284308        break; 
    285309 
     
    317341          tmp= s_pkt.mean.channel[2]-threshold; if(tmp<16) tmp=16; if(tmp>240) tmp=240;t_pkt.lower_bound.channel[2] = tmp; 
    318342          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); 
    320344        } 
    321345        break; 
     
    404428 
    405429 
     430void 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 
    406467void cmucam2_get_mean (cc3_color_info_pkt_t * s_pkt, 
    407468                       bool poll_mode, 
     
    420481      } 
    421482      cc3_color_info_scanline_finish (s_pkt); 
     483      while (!cc3_uart_has_data (0)) { if(fgetc(stdin)=='\r' ) free(img.pix); return; } 
    422484      if(!quite) cmucam2_write_s_packet (s_pkt); 
    423485    } 
     
    434496void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 
    435497                          bool poll_mode, 
    436                           bool line_mode, bool quite) 
     498                          bool line_mode, bool auto_led, bool quite) 
    437499{ 
    438500  cc3_image_t img; 
     
    469531        cc3_track_color_scanline (&img, t_pkt); 
    470532        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++) { 
    473536            if (lm[j] == 0xAA) 
    474537            { 
     
    481544        } 
    482545      } 
     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; } 
    483548      cc3_track_color_scanline_finish (t_pkt); 
    484549      if (line_mode) { 
     
    486551        if(!quite) putchar (0xAA); 
    487552      } 
     553      if(auto_led) { 
     554        if(t_pkt->int_density>2 ) cc3_set_led(0); 
     555        else cc3_clr_led(0); 
     556      } 
    488557      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)) 
    491560    { 
    492561      if(fgetc(stdin)=='\r' ) 
     
    494563    } 
    495564  } while (!poll_mode); 
    496  
    497565  free (img.pix); 
     566  return 1; 
    498567} 
    499568 
     
    566635  cmucam2_cmds[TRACK_WINDOW] = "TW"; 
    567636  cmucam2_cmds[GET_WINDOW] = "GW"; 
     637  cmucam2_cmds[LED_0] = "L0"; 
    568638} 
    569639