From: c vw <dl1ycf@darc.de> Date: Mon, 1 Nov 2021 12:49:46 +0000 (+0100) Subject: Delegate all step size list processing to vfo.c functions. X-Git-Url: https://git.rkrishnan.org/pf/frontends/listings/cyclelanguage?a=commitdiff_plain;h=ab1fc824bb63c50d559df5a9290cd29f08af3e61;p=pihpsdr.git Delegate all step size list processing to vfo.c functions. --- diff --git a/actions.c b/actions.c index 4ba5881..3b019f2 100644 --- a/actions.c +++ b/actions.c @@ -69,8 +69,8 @@ ACTION_TABLE ActionTable[] = { {BAND_902, "BAND 902", "902", MIDI_KEY}, {BAND_AIR, "BAND AIR", "AIR", MIDI_KEY}, {BAND_GEN, "BAND GEN", "GEN", MIDI_KEY}, - {BAND_MINUS, "BAND -", "BND+", MIDI_KEY | CONTROLLER_SWITCH}, - {BAND_PLUS, "BAND +", "BND-", MIDI_KEY | CONTROLLER_SWITCH}, + {BAND_MINUS, "BAND -", "BND-", MIDI_KEY | CONTROLLER_SWITCH}, + {BAND_PLUS, "BAND +", "BND+", MIDI_KEY | CONTROLLER_SWITCH}, {BAND_WWV, "BAND WWV", "WWV", MIDI_KEY}, {BANDSTACK_MINUS, "BANDSTACK -", "BSTK-", MIDI_KEY | CONTROLLER_SWITCH}, {BANDSTACK_PLUS, "BANDSTACK +", "BSTK+", MIDI_KEY | CONTROLLER_SWITCH}, @@ -1048,18 +1048,14 @@ int process_action(void *data) { case VFO_STEP_MINUS: if(a->mode==PRESSED) { i=vfo_get_stepindex(); - i--; - if(i<0) i=STEPS-1; - vfo_set_stepsize(steps[i]); + vfo_set_step_from_index(--i); g_idle_add(ext_vfo_update, NULL); } break; case VFO_STEP_PLUS: if(a->mode==PRESSED) { i=vfo_get_stepindex(); - i++; - if(i>=STEPS) i=0; - vfo_set_stepsize(steps[i]); + vfo_set_step_from_index(++i); g_idle_add(ext_vfo_update, NULL); } break; diff --git a/ext.c b/ext.c index 8cb611f..397234b 100644 --- a/ext.c +++ b/ext.c @@ -75,7 +75,6 @@ // - ctun_update(int id, int state) // set CTUN state of VFO #id // - set_split(int state) // Set split mode to state // - num_pad(int val) // enter VFO frequency -// - update_vfo_step(int direction) // cycle throught VFO step sizes // void set_frequency(int v,long long f) { @@ -189,18 +188,6 @@ void num_pad(int val) { vfo_update(); } -void update_vfo_step(int direction) { - int i = vfo_get_stepindex();; - - if (direction > 0) { - i++; - } else { - i--; - } - vfo_set_step_from_index(i); - vfo_update(); -} - // // Functions to be invoked through the GTK idle queue, // @@ -374,7 +361,12 @@ int ext_tx_set_ps(void *data) { int ext_update_vfo_step(void *data) { int direction=GPOINTER_TO_INT(data); - update_vfo_step(direction); + int i = vfo_get_stepindex(); + + direction > 0 ? i++ : i--; + + vfo_set_step_from_index(i); + g_idle_add(ext_vfo_update, NULL); return 0; } diff --git a/ext.h b/ext.h index 3809182..fee3b22 100644 --- a/ext.h +++ b/ext.h @@ -154,4 +154,3 @@ extern void ctun_update(int id,int state); extern void band_plus(int id); extern void band_minus(int id); extern void num_pad(int num); -extern void update_vfo_step(int direction); diff --git a/rigctl.c b/rigctl.c index 01f8031..76b00d2 100644 --- a/rigctl.c +++ b/rigctl.c @@ -804,6 +804,7 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) { // set the step size int i=atoi(&command[4]) ; vfo_set_step_from_index(i); + vfo_update(); } else { } break; @@ -811,9 +812,8 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) { // move VFO A down by selected step if(command[6]==';') { int step_index=atoi(&command[4]); - if(step_index>=0 && step_index<STEPS) { - vfo_id_move(VFO_A,-steps[step_index],FALSE); - } + long long hz = (long long) vfo_get_step_from_index(step_index); + vfo_id_move(VFO_A,-hz,FALSE); } else { } break; @@ -880,9 +880,8 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) { // move VFO A up by selected step if(command[6]==';') { int step_index=atoi(&command[4]); - if(step_index>=0 && step_index<STEPS) { - vfo_id_move(VFO_A,steps[step_index],FALSE); - } + long long hz = (long long) vfo_get_step_from_index(step_index); + vfo_id_move(VFO_A, hz, FALSE); } else { } break; @@ -940,9 +939,8 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) { // move VFO B down by selected step if(command[6]==';') { int step_index=atoi(&command[4]); - if(step_index>=0 && step_index<STEPS) { - vfo_id_move(VFO_B,-steps[step_index],FALSE); - } + long long hz = (long long) vfo_get_step_from_index(step_index); + vfo_id_move(VFO_B,-hz,FALSE); } else { } @@ -951,9 +949,8 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) { // move VFO B up by selected step if(command[6]==';') { int step_index=atoi(&command[4]); - if(step_index>=0 && step_index<STEPS) { - vfo_id_move(VFO_B,steps[step_index],FALSE); - } + long long hz = (long long) vfo_get_step_from_index(step_index); + vfo_id_move(VFO_B,hz,FALSE); } else { } break; diff --git a/step_menu.c b/step_menu.c index 578452b..da12f03 100644 --- a/step_menu.c +++ b/step_menu.c @@ -53,7 +53,7 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d static void step_select_cb (GtkToggleButton *widget, gpointer data) { int val=GPOINTER_TO_INT(data); if(gtk_toggle_button_get_active(widget)) { - vfo_set_step_from_index(val); + vfo_set_step_from_index(GPOINTER_TO_INT(data)); g_idle_add(ext_vfo_update,NULL); } } @@ -87,6 +87,7 @@ void step_menu(GtkWidget *parent) { gtk_grid_attach(GTK_GRID(grid),close_b,0,0,1,1); GtkWidget *step_rb=NULL; + int index=vfo_get_stepindex(); for (int i=0; i<STEPS; i++) { if(i==0) { step_rb=gtk_radio_button_new_with_label(NULL,step_labels[i]); @@ -94,7 +95,7 @@ void step_menu(GtkWidget *parent) { step_rb=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(step_rb),step_labels[i]); } gtk_widget_override_font(step_rb, pango_font_description_from_string("Sans 16")); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (step_rb), steps[i]==step); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (step_rb), i==index); gtk_widget_show(step_rb); gtk_grid_attach(GTK_GRID(grid),step_rb,i%5,1+(i/5),1,1); g_signal_connect(step_rb,"toggled",G_CALLBACK(step_select_cb),(gpointer)(long)i); diff --git a/vfo.c b/vfo.c index 9cc296d..ed1215f 100644 --- a/vfo.c +++ b/vfo.c @@ -685,21 +685,30 @@ void vfo_a_swap_b() { // get/set the VFO step size // +int vfo_get_step_from_index(int index) { + // + // This function is used for some + // extended CAT commands + // + if (index < 0) index=0; + if (index >= STEPS) index=STEPS-1; + return steps[index]; +} + int vfo_get_stepindex() { // - // return index of current step size in steps[] array, - // or 1 if not found + // return index of current step size in steps[] array // int i; for(i=0;i<STEPS;i++) { if(steps[i]==step) break; } // - // If step size is not found (usually cannot happen) - // report second-smallest step size so that we can - // safely increment and decrement in the caller + // If step size is not found (this should not happen) + // report some "convenient" index at the small end + // (here: index 4 corresponding to 100 Hz) // - if (i >= STEPS) i=1; + if (i >= STEPS) i=4; return i; } @@ -712,7 +721,7 @@ void vfo_set_step_from_index(int index) { vfo_set_stepsize(steps[index]); } -void vfo_set_stepsize(long long newstep) { +void vfo_set_stepsize(int newstep) { // // Set current VFO step size. // and store the value in mode_settings of the current mode diff --git a/vfo.h b/vfo.h index 82b124a..cc31f8a 100644 --- a/vfo.h +++ b/vfo.h @@ -78,13 +78,13 @@ typedef struct _set_frequency { } SET_FREQUENCY; #define STEPS 15 -extern int steps[]; extern char *step_labels[]; extern GtkWidget* vfo_init(int width,int height,GtkWidget *parent); extern int vfo_get_stepindex(); extern void vfo_set_step_from_index(int index); -extern void vfo_set_stepsize(long long newstep); +extern void vfo_set_stepsize(int newstep); +extern int vfo_get_step_from_index(int index); extern void vfo_step(int steps); extern void vfo_id_step(int id, int steps); extern void vfo_move(long long hz,int round); diff --git a/vfo_menu.c b/vfo_menu.c index 284d574..0508a48 100644 --- a/vfo_menu.c +++ b/vfo_menu.c @@ -187,8 +187,7 @@ static void rit_cb(GtkComboBox *widget,gpointer data) { } static void vfo_cb(GtkComboBox *widget,gpointer data) { - int i=gtk_combo_box_get_active(widget); - vfo_set_step_from_index(i); + vfo_set_step_from_index(gtk_combo_box_get_active(widget)); g_idle_add(ext_vfo_update,NULL); } @@ -290,9 +289,10 @@ void vfo_menu(GtkWidget *parent,int vfo) { gtk_grid_attach(GTK_GRID(grid),vfo_label,3,3,1,1); GtkWidget *vfo_b=gtk_combo_box_text_new(); + int index=vfo_get_stepindex(); for (i=0; i<STEPS; i++) { gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(vfo_b),NULL,step_labels[i]); - if(steps[i]==step) { + if(i == index) { gtk_combo_box_set_active (GTK_COMBO_BOX(vfo_b), i); } }