Skip to content

Commit c7b37d0

Browse files
authored
Merge pull request #4128 from hansu/halscope-fix-ac-setting-2.9
Halscope: Fix setting for AC coupling (2.9)
2 parents ec4e777 + 84fe499 commit c7b37d0

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

src/hal/utils/scope_usr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ typedef struct {
9090
hal_type_t data_type; /* data type */
9191
int data_len; /* data length */
9292
double vert_offset; /* offset to be applied */
93+
double saved_vert_offset; /* saved offset when AC coupling is enabled */
9394
int ac_offset; /* TRUE if the signal should be AC-coupled */
9495
int scale_index; /* scaling (slider setting) */
9596
int max_index; /* limits of scale slider */

src/hal/utils/scope_vert.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ int set_channel_source(int chan_num, int type, char *name)
287287
vert->data_offset[chan_num - 1] = -1;
288288
/* set scale and offset to nominal values */
289289
chan->vert_offset = 0.0;
290+
chan->saved_vert_offset = 0.0;
290291
chan->scale_index = 0;
291292
/* return success */
292293
return 0;
@@ -401,6 +402,8 @@ int set_vert_offset(double setting, int ac_coupled)
401402
/* set the new offset */
402403
chan->vert_offset = setting;
403404
chan->ac_offset = ac_coupled;
405+
/* copy the offset to restore when toggling AC coupling */
406+
chan->saved_vert_offset = chan->vert_offset;
404407
/* update the offset display */
405408
if (chan->data_type == HAL_BIT) {
406409
snprintf(buf1, BUFLEN, "----");
@@ -723,15 +726,23 @@ static gboolean dialog_set_offset(int chan_num)
723726
vert->offset_entry, FALSE, TRUE, 0);
724727

725728
/* update elements */
726-
snprintf(data.buf, BUFLEN, "%f", chan->vert_offset);
729+
snprintf(data.buf, BUFLEN, "%f", chan->saved_vert_offset);
730+
/* get AC coupling setting from channel */
731+
data.ac_coupled = chan->ac_offset;
732+
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vert->offset_ac), data.ac_coupled);
733+
gtk_widget_set_sensitive(GTK_WIDGET(vert->offset_entry), !data.ac_coupled);
734+
727735
gtk_entry_set_text(GTK_ENTRY(vert->offset_entry), data.buf);
728736
gtk_entry_set_max_length(GTK_ENTRY(vert->offset_entry), BUFLEN-1);
729-
/* point at first char */
730-
gtk_editable_set_position(GTK_EDITABLE(vert->offset_entry), 0);
731-
/* select all chars, so if the user types the original value goes away */
732-
gtk_editable_select_region(GTK_EDITABLE(vert->offset_entry), 0, strlen(data.buf));
733-
/* make it active so user doesn't have to click on it */
734-
gtk_widget_grab_focus(GTK_WIDGET(vert->offset_entry));
737+
738+
if (!data.ac_coupled) {
739+
/* point at first char */
740+
gtk_editable_set_position(GTK_EDITABLE(vert->offset_entry), 0);
741+
/* select all chars, so if the user types the original value goes away */
742+
gtk_editable_select_region(GTK_EDITABLE(vert->offset_entry), 0, strlen(data.buf));
743+
/* make it active so user doesn't have to click on it */
744+
gtk_widget_grab_focus(GTK_WIDGET(vert->offset_entry));
745+
}
735746

736747
/* signals */
737748
g_signal_connect(vert->offset_ac, "toggled",
@@ -764,6 +775,14 @@ static void offset_changed(GtkEditable * editable, struct offset_data *data)
764775
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ctrl_usr->vert.offset_ac));
765776
gtk_widget_set_sensitive(ctrl_usr->vert.offset_entry, !data->ac_coupled);
766777

778+
if (!data->ac_coupled) {
779+
/* select all chars, so if the user types the original value goes away */
780+
gtk_editable_select_region(
781+
GTK_EDITABLE(ctrl_usr->vert.offset_entry), 0, strlen(data->buf));
782+
/* make it active so user doesn't have to click on it */
783+
gtk_widget_grab_focus(GTK_WIDGET(ctrl_usr->vert.offset_entry));
784+
}
785+
767786
/* maybe user typed something, save it in the buffer */
768787
text = gtk_entry_get_text(GTK_ENTRY(ctrl_usr->vert.offset_entry));
769788
snprintf(data->buf, BUFLEN, "%s", text);

0 commit comments

Comments
 (0)