Changeset 342

Show
Ignore:
Timestamp:
01/16/07 23:53:30 (2 years ago)
Author:
goodea
Message:

boolify

Files:

Legend:

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

    r335 r342  
    2424 
    2525 
    26 #define MAX_ARGS     10 
    27 #define MAX_LINE     128 
    28 #define VERSION_BANNER "CMUcam2 v1.00 c6" 
     26static const int MAX_ARGS = 10; 
     27static const int MAX_LINE = 128; 
     28 
     29static const char *VERSION_BANNER = "CMUcam2 v1.00 c6"; 
    2930 
    3031typedef enum { 
     
    5051char *cmucam2_cmds[CMUCAM2_CMD_END]; 
    5152 
    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); 
     53static void cmucam2_get_mean (cc3_color_info_pkt_t * t_pkt, 
     54                              bool poll_mode, 
     55                              bool line_mode); 
     56static void cmucam2_write_s_packet (cc3_color_info_pkt_t * pkt); 
     57static void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 
     58                                 bool poll_mode, 
     59                                 bool line_mode); 
     60static int32_t cmucam2_get_command (int32_t * cmd, int32_t * arg_list); 
     61static void set_cmucam2_commands (void); 
     62static void print_ACK (void); 
     63static void print_NCK (void); 
     64static void cmucam2_write_t_packet (cc3_track_pkt_t * pkt); 
    6265 
    6366int main (void) 
     
    6669  int32_t val, n; 
    6770  uint32_t arg_list[MAX_ARGS]; 
    68   uint8_t error, poll_mode, line_mode; 
     71  bool error, poll_mode, line_mode; 
    6972  cc3_track_pkt_t t_pkt; 
    7073  cc3_color_info_pkt_t s_pkt; 
     
    7376 
    7477cmucam2_start: 
    75   poll_mode = 0
    76   line_mode = 0
     78  poll_mode = false
     79  line_mode = false
    7780  cc3_system_setup (); 
    7881 
     
    9295  cc3_pixbuf_set_subsample (CC3_NEAREST, 2, 1); 
    9396 
    94   while (1) { 
     97  while (true) { 
    9598    cc3_channel_t old_coi; 
    9699 
    97100    printf (":"); 
    98     error = 0
     101    error = false
    99102    n = cmucam2_get_command (&command, arg_list); 
    100103    if (n != -1) { 
     
    103106      case RESET: 
    104107        if (n != 0) { 
    105           error = 1
     108          error = true
    106109          break; 
    107110        } 
     
    115118      case GET_VERSION: 
    116119        if (n != 0) { 
    117           error = 1
     120          error = true
    118121          break; 
    119122        } 
     
    126129      case POLL_MODE: 
    127130        if (n != 1) { 
    128           error = 1
     131          error = true
    129132          break; 
    130133        } 
     
    132135          print_ACK (); 
    133136        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
    137140        break; 
    138141 
     
    140143        case HI_RES: 
    141144        if (n != 1) { 
    142           error = 1
     145          error = true
    143146          break; 
    144147        } 
     
    154157      case LINE_MODE: 
    155158        if (n != 2) { 
    156           error = 1
     159          error = true
    157160          break; 
    158161        } 
     
    162165        if (arg_list[0] == 0) { 
    163166          if (arg_list[1] == 1) 
    164             line_mode = 1
     167            line_mode = true
    165168          else 
    166             line_mode = 0
     169            line_mode = false
    167170        } 
    168171        break; 
     
    171174      case SEND_JPEG: 
    172175        if (n != 0 && n != 1) { 
    173           error = 1
     176          error = true
    174177          break; 
    175178        } 
     
    189192        if (n == 1) { 
    190193          if (arg_list[0] > 4) { 
    191             error = 1
     194            error = true
    192195            break; 
    193196          } 
     
    195198        } 
    196199        else if (n > 1) { 
    197           error = 1
     200          error = true
    198201          break; 
    199202        } 
     
    207210      case CAMERA_REG: 
    208211        if (n % 2 != 0 || n < 2) { 
    209           error = 1
     212          error = true
    210213          break; 
    211214        } 
     
    219222      case VIRTUAL_WINDOW: 
    220223        if (n != 4) { 
    221           error = 1
     224          error = true
    222225          break; 
    223226        } 
     
    233236      case DOWN_SAMPLE: 
    234237        if (n != 2) { 
    235           error = 1
     238          error = true
    236239          break; 
    237240        } 
     
    244247      case TRACK_COLOR: 
    245248        if (n != 0 && n != 6) { 
    246           error = 1
     249          error = true
    247250          break; 
    248251        } 
     
    262265      case GET_POLLY: 
    263266        if (n != 5 ) { 
    264           error = 1
     267          error = true
    265268          break; 
    266269        } 
     
    277280                if (!cc3_uart_has_data (0)) 
    278281                        break; 
    279             } while (poll_mode != 1); 
     282            } while (!poll_mode); 
    280283        break; 
    281284 
     
    283286      case GET_MEAN: 
    284287        if (n != 0) { 
    285           error = 1
     288          error = true
    286289          break; 
    287290        } 
     
    294297      case SET_SERVO: 
    295298        if (n != 2) { 
    296           error = 1
     299          error = true
    297300          break; 
    298301        } 
     
    309312    } 
    310313    else 
    311       error = 1
    312  
    313     if (error == 1
     314      error = true
     315 
     316    if (error
    314317      print_NCK (); 
    315318  } 
     
    320323 
    321324 
    322 void cmucam2_get_mean (cc3_color_info_pkt_t * s_pkt, uint8_t poll_mode, 
    323                        uint8_t line_mode) 
     325void cmucam2_get_mean (cc3_color_info_pkt_t * s_pkt, 
     326                       bool poll_mode, 
     327                       bool line_mode) 
    324328{ 
    325329  cc3_image_t img; 
     
    339343    if (!cc3_uart_has_data (0)) 
    340344      break; 
    341   } while (poll_mode != 1); 
     345  } while (!poll_mode); 
    342346 
    343347  free (img.pix); 
    344348} 
    345349 
    346 void cmucam2_track_color (cc3_track_pkt_t * t_pkt, uint8_t poll_mode, 
    347                           uint8_t line_mode) 
     350void cmucam2_track_color (cc3_track_pkt_t * t_pkt, 
     351                          bool poll_mode, 
     352                          bool line_mode) 
    348353{ 
    349354  cc3_image_t img; 
     
    361366      lm_width = 0; 
    362367      lm_height = 0; 
    363       if (line_mode == 1) { 
     368      if (line_mode) { 
    364369        lm = &t_pkt->binary_scanline; 
    365370        lm_width = img.width / 8; 
     
    379384      while (cc3_pixbuf_read_rows (img.pix, 1)) { 
    380385        cc3_track_color_scanline (&img, t_pkt); 
    381         if (line_mode == 1) { 
     386        if (line_mode) { 
    382387 
    383388          for (int j = 0; j < lm_width; j++) { 
     
    391396      } 
    392397      cc3_track_color_scanline_finish (t_pkt); 
    393       if (line_mode == 1) { 
     398      if (line_mode) { 
    394399        putchar (0xAA); 
    395400        putchar (0xAA); 
     
    400405    if (!cc3_uart_has_data (0)) 
    401406      break; 
    402   } while (poll_mode != 1); 
     407  } while (!poll_mode); 
    403408 
    404409  free (img.pix); 
     
    523528    return -1; 
    524529  argc = 0; 
    525   while (1) { 
     530  while (true) { 
    526531    /* extract string from string sequence */ 
    527532    token = strtok (NULL, " \r\n");