Skip to content

Commit 84fe499

Browse files
committed
halscope: save offset when enabling AC coupling
The offset was reset to zero when AC coupling was enabled. This adds a data field to restore the previous offset value when disabling AC coupling.
1 parent 87d8760 commit 84fe499

2 files changed

Lines changed: 13 additions & 1 deletion

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: 12 additions & 1 deletion
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,7 +726,7 @@ 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);
727730
/* get AC coupling setting from channel */
728731
data.ac_coupled = chan->ac_offset;
729732
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vert->offset_ac), data.ac_coupled);
@@ -772,6 +775,14 @@ static void offset_changed(GtkEditable * editable, struct offset_data *data)
772775
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ctrl_usr->vert.offset_ac));
773776
gtk_widget_set_sensitive(ctrl_usr->vert.offset_entry, !data->ac_coupled);
774777

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+
775786
/* maybe user typed something, save it in the buffer */
776787
text = gtk_entry_get_text(GTK_ENTRY(ctrl_usr->vert.offset_entry));
777788
snprintf(data->buf, BUFLEN, "%s", text);

0 commit comments

Comments
 (0)