Changeset 523

Show
Ignore:
Timestamp:
07/02/07 23:25:00 (1 year ago)
Author:
anthony_rowe
Message:

Track Color Line Mode 2 Added to cmucam2 emulation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/projects/cmucam2/cmucam2.c

    r504 r523  
    192192static void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 
    193193                                 bool poll_mode, 
    194                                  bool line_mode, bool auto_led, 
     194                                 int8_t line_mode, bool auto_led, 
    195195                                 cmucam2_servo_t * servo_settings, 
    196196                                 bool buf_mode, uint8_t sw_color_space, bool quiet); 
     
    228228  uint32_t start_time; 
    229229  uint8_t sw_color_space; 
    230   bool error, poll_mode, line_mode, auto_led, demo_mode, buf_mode; 
     230  bool error, poll_mode, auto_led, demo_mode, buf_mode; 
     231  int8_t line_mode; 
    231232  cc3_track_pkt_t t_pkt; 
    232233  cc3_color_info_pkt_t s_pkt; 
     
    280281  auto_led = true; 
    281282  poll_mode = false; 
    282   line_mode = false
     283  line_mode = 0
    283284  buf_mode = false; 
    284285  packet_filter_flag = false; 
     
    614615        if (arg_list[0] == 0) { 
    615616          if (arg_list[1] == 1) 
    616             line_mode = true; 
    617           else 
    618             line_mode = false; 
     617            line_mode = 1; 
     618          else if (arg_list[1] == 2) 
     619                  line_mode=2; 
     620          else 
     621            line_mode = 0; 
    619622        } 
    620623        break; 
     
    12601263void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 
    12611264                          bool poll_mode, 
    1262                           bool line_mode, bool auto_led, 
     1265                          int8_t line_mode, bool auto_led, 
    12631266                          cmucam2_servo_t * servo_settings, bool buf_mode, uint8_t sw_color_space, 
    12641267                          bool quiet) 
     
    12921295      lm_width = 0; 
    12931296      lm_height = 0; 
    1294       if (line_mode) { 
     1297      if (line_mode==1) { 
    12951298        // FIXME: This doesn't make sense 
    12961299        lm = &t_pkt->binary_scanline; 
     
    13091312          putchar (lm_height); 
    13101313      } 
     1314 
     1315    if (line_mode==2) { 
     1316        // FIXME: This still doesn't make sense 
     1317        lm = &t_pkt->binary_scanline; 
     1318        lm_width = img.width / 8; 
     1319        if (img.width % 8 != 0) 
     1320          lm_width++; 
     1321        if (!quiet) 
     1322          putchar (0xFE); 
     1323        if (cc3_g_pixbuf_frame.height > 255) 
     1324          lm_height = 255; 
     1325        else 
     1326          lm_height = cc3_g_pixbuf_frame.height; 
     1327        //if (!quiet) 
     1328          //putchar (img.width); 
     1329        if (!quiet) 
     1330          putchar (lm_height); 
     1331      } 
     1332 
     1333       
    13111334      while (cc3_pixbuf_read_rows (img.pix, 1)) { 
    13121335        if(sw_color_space==HSV_COLOR && img.channels==CC3_CHANNEL_ALL)  cc3_rgb2hsv_row(img.pix,img.width); 
    13131336        cc3_track_color_scanline (&img, t_pkt); 
    1314         if (line_mode) { 
     1337 
     1338        if (line_mode==1) { 
    13151339          // keep this check here if you don't want the CMUcam2 GUI to hang after exiting a command in line mode 
    13161340          while (!cc3_uart_has_data (0)) { 
     
    13311355          } 
    13321356        } 
     1357 
     1358 
     1359        if (line_mode==2) { 
     1360          uint8_t min,max,p_count,conf; 
     1361          uint32_t mean; 
     1362          // keep this check here if you don't want the CMUcam2 GUI to hang after exiting a command in line mode 
     1363          while (!cc3_uart_has_data (0)) { 
     1364            if (getchar () == '\r') { 
     1365              free (img.pix); 
     1366              return; 
     1367            } 
     1368          } 
     1369          mean=0; 
     1370          min=255; 
     1371          max=0; 
     1372          p_count=0; 
     1373          for (int j = 0; j < img.width; j++) { 
     1374                uint8_t block, offset; 
     1375                block = j / 8; 
     1376                offset = j % 8; 
     1377                offset = 7 - offset;     
     1378                if((lm[block] & (1<<offset))!=0)  
     1379                        { 
     1380                        // bit detected 
     1381                        if(j<min) min=j; 
     1382                        if(j>max) max=j; 
     1383                        p_count++; 
     1384                        mean+=j; 
     1385                        } 
     1386          } 
     1387        mean=mean/p_count; 
     1388        conf=((max-min)*100)/p_count; 
     1389        if (!quiet) 
     1390                printf( "%c%c%c%c%c",(uint8_t)mean,min,max,p_count,conf); 
     1391        } 
     1392 
     1393 
     1394         
    13331395      } 
    13341396      // keep this check here if you don't want the CMUcam2 GUI to hang after exiting a command in line mode 
     
    13401402      } 
    13411403      cc3_track_color_scanline_finish (t_pkt); 
    1342       if (line_mode) { 
     1404      if (line_mode==1) { 
    13431405        if (!quiet) 
    13441406          putchar (0xAA); 
     
    13461408          putchar (0xAA); 
    13471409      } 
     1410 
     1411     if (line_mode==2) { 
     1412        if (!quiet) 
     1413          putchar (0xFD); 
     1414      } 
     1415 
    13481416      if (auto_led) { 
    13491417        if (t_pkt->int_density > 2)