Mercurial > hg > fxanalyse
annotate Plot.c @ 180:8faada7e4faf
Remove DDS frequency +10 kHz and -10 kHz buttons
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 21 Feb 2014 18:42:16 +0100 |
parents | be87c8e78266 |
children | a3494d2806ee |
rev | line source |
---|---|
0 | 1 #include <ansi_c.h> |
2 #include <userint.h> | |
3 | |
144 | 4 #include "utils.h" |
135 | 5 #include "FXPlot.h" |
6 #include "Plot.h" | |
0 | 7 |
135 | 8 void Plot_InitPanel(Plot_Data *Instance, const char *title, double ymin, double ymax, int parent, int control) |
9 { | |
0 | 10 if ((Instance->PlotPanel = LoadPanel (0, "FXPlot.uir", PLOTPANEL)) < 0) |
135 | 11 return; |
12 | |
13 SetPanelAttribute(Instance->PlotPanel, ATTR_TITLE, title); | |
14 SetPanelAttribute(Instance->PlotPanel, ATTR_CALLBACK_DATA, (void *)Instance); | |
134
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
15 Instance->active = TRUE; |
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
16 Instance->parent = parent; |
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
17 Instance->control = control; |
135 | 18 Instance->IndexPoint = 0; |
19 Instance->Mean = 0; | |
0 | 20 Instance->Slope = 0; |
135 | 21 Instance->ADev = 0; |
22 Instance->Frequencies = calloc(MAXPOINTSNUMBER, sizeof(double)); | |
23 DisplayPanel(Instance->PlotPanel); | |
24 | |
25 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, ymin); | |
26 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, ymax); | |
27 | |
28 if ((ymin != 0.0) && (ymax != 0.0)) { | |
29 /* manual scaling */ | |
30 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, ymin); | |
31 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, ymax); | |
32 SetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, ymin, ymax); | |
33 } else { | |
34 /* auto scaling */ | |
35 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_AUTOSCALE, TRUE); | |
36 SetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_AUTOSCALE, 0, 0); | |
0 | 37 } |
135 | 38 } |
0 | 39 |
40 | |
135 | 41 void Plot_ClosePanel(Plot_Data * Instance) |
42 { | |
134
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
43 Instance->active = FALSE; |
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
44 free(Instance->Frequencies); |
bd28161e5ac2
Major code cleanup
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
21
diff
changeset
|
45 SetCtrlVal(Instance->parent, Instance->control, FALSE); |
135 | 46 DiscardPanel(Instance->PlotPanel); |
47 } | |
48 | |
0 | 49 |
135 | 50 void Plot_AddFrequency(Plot_Data * Instance, double Freq) |
51 { | |
52 double Drift = 0; | |
53 int DeDrift; | |
54 int N = 0; | |
0 | 55 |
135 | 56 double Mean = Instance->Mean; |
57 double Slope = Instance->Slope; | |
58 double ADev = Instance->ADev; | |
59 | |
60 /* Correct Freq with drift (feed forward) if dedrift is on */ | |
61 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_DEDRIFT, &DeDrift); | |
62 if (DeDrift) { | |
63 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_DEDRIFT, &Drift); | |
64 Freq -= ((double) Instance->IndexPoint)*Drift; | |
65 } | |
66 | |
67 /* Add Freq to graph plot */ | |
68 Instance->Frequencies[Instance->IndexPoint++] = Freq; | |
69 N = Instance->IndexPoint; | |
70 | |
71 if (N > 1) { | |
72 /* adev and slope computation need at least 2 data points */ | |
73 Instance->Slope = (Slope*(N-2) + 6*(Freq-Mean)/N)/(N+1); | |
74 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_SLOPE, Instance->Slope); | |
75 Instance->ADev = sqrt( ( ADev*ADev*(N-2) + 0.5*pow(Freq-Instance->Frequencies[N-2],2) ) / (N-1)); | |
76 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_ADEV, Instance->ADev); | |
77 } | |
78 Instance->Mean = (Mean*(N-1)+Freq)/N; | |
79 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MEAN, Instance->Mean); | |
0 | 80 |
135 | 81 /* if too many points recorded restart */ |
82 if (N > MAXPOINTSNUMBER - 2) { | |
83 Instance->IndexPoint = 0; | |
84 Instance->Mean = 0; | |
85 Instance->Slope = 0; | |
86 Instance->ADev = 0; | |
87 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_MEAN, 0.0); | |
88 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_SLOPE, 0.0); | |
89 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_ADEV, 0.0); | |
90 } | |
91 | |
92 DeleteGraphPlot(Instance->PlotPanel, PLOTPANEL_FREQPLOT, -1, VAL_IMMEDIATE_DRAW); | |
93 PlotY(Instance->PlotPanel, PLOTPANEL_FREQPLOT, Instance->Frequencies, Instance->IndexPoint, | |
94 VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE); | |
0 | 95 |
135 | 96 int autoscale; |
97 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_AUTOSCALE, &autoscale); | |
98 if (autoscale) { | |
99 /* update plot limits */ | |
100 double ymin, ymax; | |
101 GetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, NULL, &ymin, &ymax); | |
102 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, ymin); | |
103 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, ymax); | |
104 /* adjust control limits */ | |
105 SetCtrlAttribute(Instance->PlotPanel, PLOTPANEL_MIN, ATTR_MAX_VALUE, ymax); | |
106 SetCtrlAttribute(Instance->PlotPanel, PLOTPANEL_MAX, ATTR_MIN_VALUE, ymin); | |
107 } | |
108 } | |
109 | |
110 | |
111 /* callbacks */ | |
112 | |
113 int CVICALLBACK CB_PlotEvent(int panel, int event, | |
114 void *callbackData, int eventData1, int eventData2) | |
115 { | |
0 | 116 switch (event) |
117 { | |
135 | 118 case EVENT_CLOSE: |
119 Plot_Data *data; | |
120 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &data); | |
121 Plot_ClosePanel(data); | |
122 break; | |
0 | 123 |
135 | 124 case EVENT_KEYPRESS: |
125 int keycode = GetKeyPressEventVirtualKey(eventData2); | |
126 int index; | |
127 double step; | |
128 switch (keycode) | |
129 { | |
130 case 2304: /* right arrow */ | |
131 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &index); | |
132 if (index < 10) { | |
133 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, ++index); | |
134 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &step); | |
135 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, step); | |
136 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, step); | |
137 } | |
138 break; | |
139 case 2048: /* left arrow */ | |
140 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &index); | |
141 if (index > 0) { | |
142 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, --index); | |
143 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &step); | |
144 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, step); | |
145 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, step); | |
146 } | |
147 break; | |
148 } | |
0 | 149 break; |
150 } | |
151 return 0; | |
152 } | |
153 | |
135 | 154 |
155 int CVICALLBACK Plot_CB_ChangeYLim (int panel, int control, int event, | |
0 | 156 void *callbackData, int eventData1, int eventData2) |
157 { | |
135 | 158 double ymin, ymax; |
0 | 159 |
160 switch (event) | |
135 | 161 { |
0 | 162 case EVENT_COMMIT: |
135 | 163 GetCtrlVal(panel, PLOTPANEL_MIN, &ymin); |
164 GetCtrlVal(panel, PLOTPANEL_MAX, &ymax); | |
165 /* adjust control limits */ | |
166 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_MAX_VALUE, ymax); | |
167 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_MIN_VALUE, ymin); | |
168 /* disable autoscaling */ | |
169 SetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, FALSE); | |
170 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, ymin, ymax); | |
0 | 171 break; |
135 | 172 } |
0 | 173 return 0; |
174 } | |
175 | |
176 | |
177 int CVICALLBACK Plot_CB_ChangeAutoScale (int panel, int control, int event, | |
178 void *callbackData, int eventData1, int eventData2) | |
179 { | |
135 | 180 int autoscale = FALSE; |
181 double ymin, ymax; | |
0 | 182 |
183 switch (event) | |
135 | 184 { |
0 | 185 case EVENT_COMMIT: |
135 | 186 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, &autoscale); |
187 if (autoscale) { | |
188 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_AUTOSCALE, 0, 0); | |
189 GetAxisScalingMode(panel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, NULL, &ymin, &ymax); | |
190 SetCtrlVal(panel, PLOTPANEL_MIN, ymin); | |
191 SetCtrlVal(panel, PLOTPANEL_MAX, ymax); | |
192 /* adjust control limits */ | |
193 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_MAX_VALUE, ymax); | |
194 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_MIN_VALUE, ymin); | |
195 } else { | |
196 GetCtrlVal(panel, PLOTPANEL_MIN, &ymin); | |
197 GetCtrlVal(panel, PLOTPANEL_MAX, &ymax); | |
198 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, ymin, ymax); | |
199 } | |
0 | 200 break; |
135 | 201 } |
0 | 202 return 0; |
203 } | |
204 | |
135 | 205 |
0 | 206 int CVICALLBACK Plot_CB_ChangeScalingStep(int panel, int control, int event, |
207 void *callbackData, int eventData1, int eventData2) | |
208 { | |
135 | 209 double step; |
0 | 210 |
211 switch (event) | |
135 | 212 { |
0 | 213 case EVENT_COMMIT: |
135 | 214 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &step); |
215 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, step); | |
216 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, step); | |
0 | 217 break; |
135 | 218 } |
0 | 219 return 0; |
220 } | |
221 | |
222 | |
223 int CVICALLBACK Plot_CB_Reset (int panel, int control, int event, | |
224 void *callbackData, int eventData1, int eventData2) | |
225 { | |
135 | 226 Plot_Data *data; |
0 | 227 switch (event) |
135 | 228 { |
0 | 229 case EVENT_COMMIT: |
135 | 230 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &data); |
231 data->IndexPoint = 0; | |
232 data->Mean = 0; | |
233 data->Slope = 0; | |
234 data->ADev = 0; | |
0 | 235 break; |
135 | 236 } |
0 | 237 return 0; |
238 } | |
239 | |
240 | |
241 int CVICALLBACK Plot_CB_GetDrift (int panel, int control, int event, | |
242 void *callbackData, int eventData1, int eventData2) | |
243 { | |
135 | 244 Plot_Data *data; |
245 int dedrift; | |
246 double drift; | |
0 | 247 |
248 switch (event) | |
135 | 249 { |
0 | 250 case EVENT_COMMIT: |
135 | 251 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &data); |
252 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &dedrift); | |
253 if (dedrift) { | |
254 GetCtrlVal(panel, PLOTPANEL_DEDRIFT, &drift); | |
255 drift += data->Slope; | |
256 SetCtrlVal(panel, PLOTPANEL_DEDRIFT, drift); | |
257 data->IndexPoint = 0; | |
258 data->Mean = 0; | |
259 data->Slope = 0; | |
260 data->ADev = 0; | |
261 } else | |
262 SetCtrlVal(panel,PLOTPANEL_DEDRIFT, data->Slope); | |
0 | 263 break; |
135 | 264 } |
0 | 265 return 0; |
266 } | |
267 | |
135 | 268 |
0 | 269 int CVICALLBACK Plot_CB_ChangeDrift (int panel, int control, int event, |
270 void *callbackData, int eventData1, int eventData2) | |
271 { | |
135 | 272 int dedrift; |
273 Plot_Data *data; | |
0 | 274 |
275 switch (event) | |
135 | 276 { |
0 | 277 case EVENT_COMMIT: |
135 | 278 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &dedrift); |
279 if (dedrift) { | |
280 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &data); | |
281 data->IndexPoint = 0; | |
282 data->Mean = 0; | |
283 data->Slope = 0; | |
284 data->ADev = 0; | |
285 } | |
0 | 286 break; |
135 | 287 } |
0 | 288 return 0; |
289 } | |
290 |