This repository was archived by the owner on Jun 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalogControl.c
More file actions
172 lines (156 loc) · 5.67 KB
/
AnalogControl.c
File metadata and controls
172 lines (156 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
@file AnalogControl.c
@brief This panel is used to set the value of an AnalogTableValues in
AnalogTable. It is called by double-clicking on an analog table cell.
*/
#include "AnalogControl.h"
#include <ansi_c.h>
#include <toolbox.h>
#include <userint.h>
#include "AnalogControl2.h"
#include "GUIDesign2.h"
#include "vars.h"
/**
@brief Set button callback. On commit, reads data off of
the panel controls and update the entry in the AnalogTable array.
@todo If timescale exceeds the time column, update the following cells
as well until total timescale is used.
*/
int CVICALLBACK CMD_SETANALAOG_CALLBACK(int panel, int control, int event,
void* callbackData, int eventData1,
int eventData2) {
int itemp = 0; // variables for reading/writing the control mode
double dtemp, ttemp;
switch (event) {
case EVENT_COMMIT:
// Retrieve Control/Data Values from Panel
GetCtrlVal(panelHandle4, CTRL_PANEL_RING_CTRLMODE, &itemp);
GetCtrlVal(panelHandle4, CTRL_PANEL_NUMFINALVAL, &dtemp);
GetCtrlVal(panelHandle4, CTRL_PANEL_NUMTIMESCALE, &ttemp);
AnalogTable[currentx][currenty][currentpage].fcn = itemp;
if (itemp != 6) {
AnalogTable[currentx][currenty][currentpage].fval = dtemp;
AnalogTable[currentx][currenty][currentpage].tscale = ttemp;
}
GetCtrlVal(panelHandle4, CTRL_PANEL_NUMFINALVAL, &dtemp);
AnalogTable[currentx][currenty][currentpage].fval = dtemp;
GetCtrlVal(panelHandle4, CTRL_PANEL_NUMTIMESCALE, &dtemp);
AnalogTable[currentx][currenty][currentpage].tscale = dtemp;
HidePanel(panelHandle4);
DrawNewTable(0);
break;
}
return 0;
}
/**
@brief Fill in indicators on the panel.
*/
void SetControlPanel(void) {
SetCtrlVal(panelHandle4, CTRL_PANEL_STRUNITS, AChName[currenty].units);
SetCtrlVal(panelHandle4, CTRL_PANEL_STR_CHNAME, AChName[currenty].chname);
SetCtrlVal(panelHandle4, CTRL_PANEL_NUMFINALVAL,
AnalogTable[currentx][currenty][currentpage].fval);
SetCtrlVal(panelHandle4, CTRL_PANEL_NUMTIMESCALE,
AnalogTable[currentx][currenty][currentpage].tscale);
SetCtrlVal(panelHandle4, CTRL_PANEL_RING_CTRLMODE,
AnalogTable[currentx][currenty][currentpage].fcn);
// find the last value
// This loop can perform better if it starts from the current cell and
// searches backwards instead of starting from the beginning and searching
// forwards
BOOL FOUNDVAL = 0;
int cx = 1;
int cz = 1;
double lastvalue = 0;
while (!FOUNDVAL) {
if (cz > NUMBEROFPAGES) {
break; // didn't find it, end the loop
}
if (TimeArray[cx][cz] == 0) {
cz++; // if you see a 0 time, go to next page
cx = 1;
} else if (TimeArray[cx][cz] < 0) {
// if you see a negative time, skip to next value
cx++;
if (cx >= NUMBEROFCOLUMNS) {
cx = 1;
cz++;
}
} else {
// if positive time, record current val
if ((cx >= currentx) && (cz >= currentpage)) {
FOUNDVAL = TRUE; // found current value
} else {
lastvalue = AnalogTable[cx][currenty][cz].fval;
}
cx++;
if (cx >= NUMBEROFCOLUMNS) {
cx = 1;
cz++;
}
}
}
SetCtrlVal(panelHandle4, CTRL_PANEL_NUMINITVAL, lastvalue);
}
/**
@brief Callback for the Control Mode ring control.
Cycles between the different control modes and changes the timescale of the ramp
to an appropriate value for the mode.
If adding another function, just add another case, modify the ring control
on the AnalogControl.uir file, and add function handling in CalcFcnVal() in
GUIDesign.c
*/
int CVICALLBACK RING_CTRLMODE_CALLBACK(int panel, int control, int event,
void* callbackData, int eventData1,
int eventData2) {
int ctrlmode = 0;
double timescales = 0, ctrlvfinal;
GetCtrlVal(panelHandle4, CTRL_PANEL_RING_CTRLMODE, &ctrlmode);
GetCtrlVal(panelHandle4, CTRL_PANEL_NUMFINALVAL, &ctrlvfinal);
timescales = TimeArray[currentx][currentpage];
double Vdiff =
ctrlvfinal - AnalogTable[currentx - 1][currenty][currentpage].fval;
SetCtrlAttribute(panelHandle4, CTRL_PANEL_NUMFINALVAL, ATTR_LABEL_TEXT,
"Final Value");
SetCtrlAttribute(panelHandle4, CTRL_PANEL_NUMTIMESCALE, ATTR_LABEL_TEXT,
"Time Scale");
switch (ctrlmode) {
case 1: // Step
SetCtrlVal(panelHandle4, CTRL_PANEL_NUMTIMESCALE, 0.0);
break;
case 2: // Linear ramp
SetCtrlVal(panelHandle4, CTRL_PANEL_NUMTIMESCALE, timescales);
break;
case 3: // Exponential ramp
SetCtrlVal(panelHandle4, CTRL_PANEL_NUMTIMESCALE, timescales);
if (FloatCompare(&Vdiff, &(float){0.}) != 0) {
double newtime = timescales / fabs(log(fabs(Vdiff)) - log(0.001));
// newtime=fabs(timescales/(log(0.001/Vdiff)));
SetCtrlVal(panelHandle4, CTRL_PANEL_NUMTIMESCALE, newtime);
}
break;
case 4: // S curve
SetCtrlVal(panelHandle4, CTRL_PANEL_NUMTIMESCALE, timescales);
break;
case 5: // Sine wave
SetCtrlAttribute(panelHandle4, CTRL_PANEL_NUMFINALVAL, ATTR_LABEL_TEXT,
"Amplitude");
SetCtrlAttribute(panelHandle4, CTRL_PANEL_NUMTIMESCALE, ATTR_LABEL_TEXT,
"Frequency");
break;
}
return 0;
}
/**
@brief Callback for the Cancel button.
*/
int CVICALLBACK CMD_ANCANCEL_CALLBACK(int panel, int control, int event,
void* callbackData, int eventData1,
int eventData2) {
switch (event) {
case EVENT_COMMIT:
HidePanel(panelHandle4);
break;
}
return 0;
}