Skip to content

Commit

Permalink
Access to step size list now through function calls in vfo.c
Browse files Browse the repository at this point in the history
  • Loading branch information
dl1ycf committed Oct 29, 2021
1 parent e9da187 commit ce52366
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 83 deletions.
18 changes: 4 additions & 14 deletions actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,25 +1158,15 @@ int process_action(void *data) {
break;
case VFO_STEP_MINUS:
if(a->mode==PRESSED) {
for(i=0;i<STEPS;i++) {
if(steps[i]==step) break;
}
if(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++) {
if(steps[i]==step) break;
}
if(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;
Expand Down
22 changes: 4 additions & 18 deletions ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
if(steps[i]==step) break;
}
if(step>=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;
}
Expand Down
75 changes: 29 additions & 46 deletions rigctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(written<length) {
written+=write(fd,&msg[written],length-written);
int rc;
int count=0;

//
// Possibly, the channel is already closed. In this case
// give up (rc < 0) or at most try a few times (rc == 0)
// since we are in the GTK idle loop
//
while(length>0) {
rc=write(fd,msg,length);
if (rc < 0) return;
if (rc == 0) {
count++;
if (count > 10) return;
}
length -= rc;
msg += rc;
}

}

//
Expand Down Expand Up @@ -765,36 +777,22 @@ 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;
case 'D': //ZZAD
// 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
}

Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions step_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -86,14 +86,15 @@ 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]);
} else {
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);
Expand Down
53 changes: 53 additions & 0 deletions vfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,59 @@ void vfo_a_swap_b() {
g_idle_add(ext_vfo_update,NULL);
}

//
// here we collect various functions to
// 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,
//
int i;
for(i=0;i<STEPS;i++) {
if(steps[i]==step) break;
}
//
// 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=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;
Expand Down
5 changes: 4 additions & 1 deletion vfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions vfo_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit ce52366

Please sign in to comment.