Skip to content

Commit 5235a84

Browse files
committed
Merge branch '2.9'
2 parents 59697b0 + c7b37d0 commit 5235a84

3 files changed

Lines changed: 66 additions & 7 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
component radiobutton "Select one from several outputs with momentary switches";
2+
3+
description """This component creates \\fBpersonality\\fR inputs to select
4+
one of several outputs. When \\fBsel-N\\fR is momentarily set high then the
5+
corresponding bit output \\fBout-N\\fR will be set high and other outputs will
6+
be set low. Simultaneously the value on the pin \\fBinput-N\\fR will be copied
7+
to the \\fBvalue\\fR pin.
8+
The \\fBselected\\fR pin will indicate which set of outputs is currently
9+
active.
10+
Note that channel-0 should be used to provide the default values.""";
11+
12+
pin in bit sel-##[32:personality] "Inputs to select a channel";
13+
pin out bit out-##[32:personality] "output selected";
14+
pin out signed selected = 0 "indicates which output is currently active";
15+
pin in float input-##[32:personality] "Possible output values";
16+
pin out float value "currently-selected output value";
17+
18+
function _;
19+
license "GPL 2+";
20+
author "Andy Pugh";
21+
22+
;;
23+
24+
FUNCTION(_){
25+
int i;
26+
for(i = 0; i < personality; i++){
27+
if(sel(i) !=0){
28+
selected = i;
29+
}
30+
}
31+
for(i = 0; i < personality; i++){
32+
if(i == selected){
33+
out(i) = 1;
34+
value = input(i);
35+
} else {
36+
out(i) = 0;
37+
}
38+
}
39+
}

src/hal/utils/scope_usr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ typedef struct {
9393
hal_type_t data_type; /* data type */
9494
int data_len; /* data length */
9595
double vert_offset; /* offset to be applied */
96+
double saved_vert_offset; /* saved offset when AC coupling is enabled */
9697
int ac_offset; /* TRUE if the signal should be AC-coupled */
9798
int scale_index; /* scaling (slider setting) */
9899
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
@@ -276,6 +276,7 @@ int set_channel_source(int chan_num, int type, char *name)
276276
vert->data_offset[chan_num - 1] = -1;
277277
/* set scale and offset to nominal values */
278278
chan->vert_offset = 0.0;
279+
chan->saved_vert_offset = 0.0;
279280
chan->scale_index = 0;
280281
/* return success */
281282
return 0;
@@ -390,6 +391,8 @@ int set_vert_offset(double setting, int ac_coupled)
390391
/* set the new offset */
391392
chan->vert_offset = setting;
392393
chan->ac_offset = ac_coupled;
394+
/* copy the offset to restore when toggling AC coupling */
395+
chan->saved_vert_offset = chan->vert_offset;
393396
/* update the offset display */
394397
if (chan->data_type == HAL_BIT) {
395398
snprintf(buf1, BUFLEN, "----");
@@ -716,15 +719,23 @@ static gboolean dialog_set_offset(int chan_num)
716719
vert->offset_entry, FALSE, TRUE, 0);
717720

718721
/* update elements */
719-
snprintf(data.buf, BUFLEN, "%f", chan->vert_offset);
722+
snprintf(data.buf, BUFLEN, "%f", chan->saved_vert_offset);
723+
/* get AC coupling setting from channel */
724+
data.ac_coupled = chan->ac_offset;
725+
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vert->offset_ac), data.ac_coupled);
726+
gtk_widget_set_sensitive(GTK_WIDGET(vert->offset_entry), !data.ac_coupled);
727+
720728
gtk_entry_set_text(GTK_ENTRY(vert->offset_entry), data.buf);
721729
gtk_entry_set_max_length(GTK_ENTRY(vert->offset_entry), BUFLEN-1);
722-
/* point at first char */
723-
gtk_editable_set_position(GTK_EDITABLE(vert->offset_entry), 0);
724-
/* select all chars, so if the user types the original value goes away */
725-
gtk_editable_select_region(GTK_EDITABLE(vert->offset_entry), 0, strlen(data.buf));
726-
/* make it active so user doesn't have to click on it */
727-
gtk_widget_grab_focus(GTK_WIDGET(vert->offset_entry));
730+
731+
if (!data.ac_coupled) {
732+
/* point at first char */
733+
gtk_editable_set_position(GTK_EDITABLE(vert->offset_entry), 0);
734+
/* select all chars, so if the user types the original value goes away */
735+
gtk_editable_select_region(GTK_EDITABLE(vert->offset_entry), 0, strlen(data.buf));
736+
/* make it active so user doesn't have to click on it */
737+
gtk_widget_grab_focus(GTK_WIDGET(vert->offset_entry));
738+
}
728739

729740
/* signals */
730741
g_signal_connect(vert->offset_ac, "toggled",
@@ -758,6 +769,14 @@ static void offset_changed(GtkEditable * editable, struct offset_data *data)
758769
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ctrl_usr->vert.offset_ac));
759770
gtk_widget_set_sensitive(ctrl_usr->vert.offset_entry, !data->ac_coupled);
760771

772+
if (!data->ac_coupled) {
773+
/* select all chars, so if the user types the original value goes away */
774+
gtk_editable_select_region(
775+
GTK_EDITABLE(ctrl_usr->vert.offset_entry), 0, strlen(data->buf));
776+
/* make it active so user doesn't have to click on it */
777+
gtk_widget_grab_focus(GTK_WIDGET(ctrl_usr->vert.offset_entry));
778+
}
779+
761780
/* maybe user typed something, save it in the buffer */
762781
text = gtk_entry_get_text(GTK_ENTRY(ctrl_usr->vert.offset_entry));
763782
snprintf(data->buf, BUFLEN, "%s", text);

0 commit comments

Comments
 (0)