Radio Buttons (2)

radiofrq

Radio buttons for preset frequencies.

void set_freq (double frq) { /* freq in kHz */
  int outputcount = 11;
  static unsigned char command[11] /* set frequency command */
   = {0xfe, 0xfe, 0x80, 0xe0, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfd};
  int ifrq, idigit[8];

  ifrq = frq * 1000; /* freq in Hz */
  for(int i=0; i<8; i++) {
   idigit[i] = ifrq % 10;
   ifrq /= 10;
  }
  command[5] = 16*idigit[1] + idigit[0];
  command[6] = 16*idigit[3] + idigit[2];
  command[7] = 16*idigit[5] + idigit[4];
  command[8] = 16*idigit[7] + idigit[6];
  write(fd, &command1, outputcount);
}

I always wonder if I should use a for loop for the lines like command[5] through [8]. I suppose repeating the lines is more explicit and more readable.

/* main */
    int nfrq = 8;
    char *strfrq[] = {" 3501.000kHz", " 7026.000kHz", "10118.000kHz", "14058.000kHz",
                      "18085.000kHz", "21058.000kHz", "24908.000kHz", "28058.000kHz"};

    for(int i=0;i<nfrq;i++) {
     if(i == 0) {
      button = gtk_radio_button_new_with_label (NULL, strfrq[i]);
     } else {
      button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)), strfrq[i]);
     }
     gtk_signal_connect (GTK_OBJECT (button), "toggled", GTK_SIGNAL_FUNC (callback3), (gpointer) strfrq[i]);
     gtk_box_pack_start (GTK_BOX (box6), button, TRUE, TRUE, 0);
     gtk_widget_show (button);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *