From ce523660614e8760518c5bc0d0eb003be5a3ce72 Mon Sep 17 00:00:00 2001 From: c vw Date: Fri, 29 Oct 2021 15:21:14 +0200 Subject: [PATCH] Access to step size list now through function calls in vfo.c --- actions.c | 18 +++---------- ext.c | 22 +++------------- rigctl.c | 75 +++++++++++++++++++++-------------------------------- step_menu.c | 5 ++-- vfo.c | 53 +++++++++++++++++++++++++++++++++++++ vfo.h | 5 +++- vfo_menu.c | 5 ++-- 7 files changed, 100 insertions(+), 83 deletions(-) diff --git a/actions.c b/actions.c index 1e73ac21..e382e54d 100644 --- a/actions.c +++ b/actions.c @@ -1158,25 +1158,15 @@ int process_action(void *data) { break; case VFO_STEP_MINUS: if(a->mode==PRESSED) { - for(i=0;i=STEPS) i=0; - i--; - if(i<0) i=STEPS-1; - step=steps[i]; + i=vfo_get_stepindex(); + vfo_set_step_from_index(--i); g_idle_add(ext_vfo_update, NULL); } break; case VFO_STEP_PLUS: if(a->mode==PRESSED) { - for(i=0;i=STEPS) i=0; - i++; - if(i>=STEPS) i=0; - step=steps[i]; + i=vfo_get_stepindex(); + vfo_set_step_from_index(++i); g_idle_add(ext_vfo_update, NULL); } break; diff --git a/ext.c b/ext.c index d94efa2f..0d0524fa 100644 --- a/ext.c +++ b/ext.c @@ -264,25 +264,11 @@ int ext_tx_set_ps(void *data) { int ext_update_vfo_step(void *data) { int direction=GPOINTER_TO_INT(data); - int i; - for(i=0;i=STEPS) i=0; + int i = vfo_get_stepindex(); - if(steps[i]!=0) { - if(direction>0) { - i++; - if(steps[i]!=0) { - step=steps[i]; - } - } else { - i--; - if(i>=0) { - step=steps[i]; - } - } - } + direction > 0 ? i++ : i--; + + vfo_set_step_from_index(i); g_idle_add(ext_vfo_update, NULL); return 0; } diff --git a/rigctl.c b/rigctl.c index 3cc2695c..2065b2fa 100644 --- a/rigctl.c +++ b/rigctl.c @@ -540,12 +540,24 @@ long long rigctl_getFrequency() { void send_resp (int fd,char * msg) { if(rigctl_debug) g_print("RIGCTL: RESP=%s\n",msg); int length=strlen(msg); - int written=0; - - while(written0) { + rc=write(fd,msg,length); + if (rc < 0) return; + if (rc == 0) { + count++; + if (count > 10) return; + } + length -= rc; + msg += rc; } - } // @@ -765,22 +777,13 @@ gboolean parse_extended_cmd (char *command,CLIENT *client) { // sets or reads the Step Size if(command[4]==';') { // read the step size - int i=0; - for(i=0;i<=14;i++) { - if(steps[i]==step) break; - } - if(i<=14) { - // send reply back - sprintf(reply,"ZZAC%02d;",i); - send_resp(client->fd,reply) ; - } + sprintf(reply,"ZZAC%02d;",vfo_get_stepindex()); + send_resp(client->fd,reply) ; } else if(command[6]==';') { // set the step size int i=atoi(&command[4]) ; - if(i>=0 && i<=14) { - step=steps[i]; - vfo_update(); - } + vfo_set_step_from_index(i); + vfo_update(); } else { } break; @@ -788,13 +791,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]); - long long hz=0; - if(step_index>=0 && step_index<=14) { - hz=(long long)steps[step_index]; - } - if(hz!=0LL) { - vfo_id_move(VFO_A,-hz,FALSE); - } + long long hz = (long long) vfo_get_step_from_index(step_index); + vfo_id_move(VFO_A,-hz,FALSE); } else { } break; @@ -861,13 +859,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]); - long long hz=0; - if(step_index>=0 && step_index<=14) { - hz=(long long)steps[step_index]; - } - if(hz!=0LL) { - vfo_id_move(VFO_A,hz,FALSE); - } + long long hz = (long long) vfo_get_step_from_index(step_index); + vfo_id_move(VFO_A, hz, FALSE); } else { } break; @@ -925,13 +918,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]); - long long hz=0; - if(step_index>=0 && step_index<=14) { - hz=(long long)steps[step_index]; - } - if(hz!=0LL) { - vfo_id_move(VFO_B,-hz,FALSE); - } + long long hz = (long long) vfo_get_step_from_index(step_index); + vfo_id_move(VFO_B,-hz,FALSE); } else { } @@ -940,13 +928,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]); - long long hz=0; - if(step_index>=0 && step_index<=14) { - hz=(long long)steps[step_index]; - } - if(hz!=0LL) { - vfo_id_move(VFO_B,hz,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 6069ef7f..8644e8dd 100644 --- a/step_menu.c +++ b/step_menu.c @@ -52,7 +52,7 @@ static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_d static void step_select_cb (GtkToggleButton *widget, gpointer data) { if(gtk_toggle_button_get_active(widget)) { - step=steps[GPOINTER_TO_INT(data)]; + vfo_set_step_from_index(GPOINTER_TO_INT(data)); g_idle_add(ext_vfo_update,NULL); } } @@ -86,6 +86,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) index=STEPS-1; + return steps[index]; +} + +int vfo_get_stepindex() { + // + // return index of current step size in steps[] array, + // + int i; + for(i=0;i= STEPS) i=4; + return i; +} + +void vfo_set_step_from_index(int index) { + // + // Set VFO step size to steps[index], with range checking + // + if (index < 0) index=0; + if (index >= STEPS) index = STEPS-1; + vfo_set_stepsize(steps[index]); +} + +void vfo_set_stepsize(int newstep) { + // + // Set current VFO step size. + // and store the value in mode_settings of the current mode + // + int id=active_receiver->id; + int m=vfo[id].mode; + + step=newstep; + //mode_settings[m].step=newstep; +} + void vfo_step(int steps) { int id=active_receiver->id; long long delta; diff --git a/vfo.h b/vfo.h index 41240c1a..3e84bda5 100644 --- a/vfo.h +++ b/vfo.h @@ -72,10 +72,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(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 2b4da08f..8455876c 100644 --- a/vfo_menu.c +++ b/vfo_menu.c @@ -186,7 +186,7 @@ static void rit_cb(GtkComboBox *widget,gpointer data) { } static void vfo_cb(GtkComboBox *widget,gpointer data) { - step=steps[gtk_combo_box_get_active(widget)]; + vfo_set_step_from_index(gtk_combo_box_get_active(widget)); g_idle_add(ext_vfo_update,NULL); } @@ -291,9 +291,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<15;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); } }