annotate Plot.c @ 121:f48e8ff21f0f

Update Sr data logger IP address
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 12 Dec 2013 16:26:20 +0100
parents 381da7b34cd8
children bd28161e5ac2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2 #include <ansi_c.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 #include <userint.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5 #include "YLCStuff.h"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6 #include "FXAnalyse.h"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8 #include "FXPlot.h" // Auto generated panel definitions and protypes
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 #include "Plot.h" // My own .h file, containing prototypes and definitions for the class Plot...
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
10
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
11
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 // ******************* Member functions : constructor and destructor **********************
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 int Plot_InitPanel(Plot_Data * Instance, char * title, double PlotMin, double PlotMax, void (*OnCloseFunc)(int) ) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 if ((Instance->PlotPanel = LoadPanel (0, "FXPlot.uir", PLOTPANEL)) < 0)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
19 SetPanelAttribute(Instance->PlotPanel, ATTR_TITLE, title) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 SetPanelAttribute (Instance->PlotPanel, ATTR_CALLBACK_DATA, (void *)Instance); // the panel callback therefore knows which data structure it is associated to
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
21 Instance->OnClosePanel = OnCloseFunc ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
22 Instance->IndexPoint = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
23 Instance->Mean = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 Instance->Slope = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 Instance->ADev = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26 Instance->Frequencies = calloc(MAXPOINTSNUMBER, sizeof(double)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27 DisplayPanel (Instance->PlotPanel);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, PlotMin) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, PlotMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
30 SetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, PlotMin, PlotMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
31 return 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
32 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
33
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
34
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
35
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
36 int Plot_ClosePanel(Plot_Data * Instance) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
37 free(Instance->Frequencies) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
38 Instance->OnClosePanel(Instance->PlotPanel) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
39 DiscardPanel (Instance->PlotPanel);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
40 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
41 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
42
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
43
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
44
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
45 // ******************** Member functions, callbacks (private) *******************************
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
46
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
47 int CVICALLBACK CB_PlotEvent(int panel, int event, void *callbackData, int eventData1, int eventData2) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
48
21
381da7b34cd8 Unused variable
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 0
diff changeset
49 int VirtualKeyCode;
381da7b34cd8 Unused variable
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 0
diff changeset
50 int StepIndex;
381da7b34cd8 Unused variable
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 0
diff changeset
51 double Step;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
52
21
381da7b34cd8 Unused variable
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 0
diff changeset
53 Plot_Data * Instance = NULL;
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
54
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
55 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
56 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
57 case EVENT_CLOSE:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
58 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
59 Plot_ClosePanel(Instance) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
60 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
61
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
62 case EVENT_KEYPRESS:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
63 VirtualKeyCode = GetKeyPressEventVirtualKey(eventData2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
64 switch (VirtualKeyCode)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
65 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
66 case 2304: //ie right arrow
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
67 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &StepIndex);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
68 if (StepIndex<10){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
69 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, ++StepIndex) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
70 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &Step);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
71 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, Step) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
72 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, Step) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
73 };
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
74 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
75 case 2048: //ie left arrow
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
76 GetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, &StepIndex);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
77 if (StepIndex>0){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
78 SetCtrlIndex(panel, PLOTPANEL_SCALINGSTEP, --StepIndex) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
79 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &Step);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
80 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, Step) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
81 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, Step) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
82 };
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
83 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
84 };
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
85 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
86 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
87 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
88 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
89
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
90 int CVICALLBACK Plot_CB_ChangeMax (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
91 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
92 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
93 double YMin, YMax ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
94
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
95 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
96 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
97 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
98 GetCtrlVal(panel, PLOTPANEL_MIN, &YMin) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
99 GetCtrlVal(panel, PLOTPANEL_MAX, &YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
100 if (YMin<YMax) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
101 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, YMin, YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
102 SetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, FALSE) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
103 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
104 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
105 case EVENT_RIGHT_CLICK:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
106
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
107 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
108 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
109 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
110 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
111
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
112 int CVICALLBACK Plot_CB_ChangeMin (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
113 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
114 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
115 double YMin, YMax ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
116
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
117 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
118 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
119 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
120 GetCtrlVal(panel, PLOTPANEL_MIN, &YMin) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
121 GetCtrlVal(panel, PLOTPANEL_MAX, &YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
122 if (YMin<YMax ) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
123 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, YMin, YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
124 SetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, FALSE) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
125 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
126 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
127 case EVENT_RIGHT_CLICK:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
128
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
129 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
130 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
131 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
132 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
133
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
134
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
135 int CVICALLBACK Plot_CB_ChangeAutoScale (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
136 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
137 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
138 bool AutoScale = FALSE;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
139 int NotCare = 20000000 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
140 double YMin = 10000000 , YMax = 64000000 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
141
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
142 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
143 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
144 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
145 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_AUTOSCALE, &AutoScale) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
146 if (AutoScale) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
147 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_AUTOSCALE, YMin, YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
148 GetAxisScalingMode(panel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, &NotCare, &YMin, &YMax ) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
149 SetCtrlVal(panel, PLOTPANEL_MIN, YMin);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
150 SetCtrlVal(panel, PLOTPANEL_MAX, YMax);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
151 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
152 else {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
153 GetCtrlVal(panel, PLOTPANEL_MIN, &YMin);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
154 GetCtrlVal(panel, PLOTPANEL_MAX, &YMax);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
155 SetAxisScalingMode(panel, PLOTPANEL_FREQPLOT, VAL_LEFT_YAXIS, VAL_MANUAL, YMin, YMax) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
156 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
157 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
158 case EVENT_RIGHT_CLICK:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
159
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
160 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
161 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
162 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
163 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
164
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
165 int CVICALLBACK Plot_CB_ChangeScalingStep(int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
166 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
167 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
168 double ScalingStep ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
169
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
170 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
171 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
172 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
173 GetCtrlVal(panel, PLOTPANEL_SCALINGSTEP, &ScalingStep) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
174 SetCtrlAttribute(panel, PLOTPANEL_MIN, ATTR_INCR_VALUE, ScalingStep) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
175 SetCtrlAttribute(panel, PLOTPANEL_MAX, ATTR_INCR_VALUE, ScalingStep) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
176 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
177 case EVENT_RIGHT_CLICK:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
178 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
179 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
180 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
181 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
182
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
183
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
184 // ******************** Member functions, public *******************************************
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
185
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
186 int Plot_AddFrequency(Plot_Data * Instance, double Freq) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
187
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
188 double YMin = 10000000, YMax = 64000000, Mean = 0, ADev = 0 , Slope = 0 , Drift = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
189 bool AutoScale, DeDrift ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
190 int N = 0, NotCare ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
191
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
192 // Retrieve previous values for mean, adev and slope
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
193 Mean = Instance->Mean ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
194 Slope = Instance->Slope;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
195 ADev = Instance->ADev;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
196
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
197 // Correct Freq with drift (feed forward) if dedrift is on
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
198 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_DEDRIFT, &DeDrift) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
199 if(DeDrift) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
200 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_DEDRIFT, &Drift) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
201 Freq -= ((double) Instance->IndexPoint)*Drift ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
202 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
203
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
204 // Add Freq to graph plot
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
205 Instance->Frequencies[Instance->IndexPoint++] = Freq ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
206 N = Instance->IndexPoint ; // N is now the new number of points in the graph
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
207
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
208
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
209 if (N > 1) { // ADEV and SLOPE need at least 2 values !
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
210 Instance->Slope = (Slope*(N-2) + 6*(Freq-Mean)/N)/(N+1) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
211 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_SLOPE, Instance->Slope ) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
212 Instance->ADev = sqrt( ( ADev*ADev*(N-2) + 0.5*pow(Freq-Instance->Frequencies[N-2],2) ) / (N-1) ) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
213 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_ADEV, Instance->ADev ) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
214 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
215 Instance->Mean = (Mean*(N-1)+Freq)/N ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
216 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MEAN, Instance->Mean);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
217
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
218 if (N > MAXPOINTSNUMBER - 2) { // If too many points recorded, restart new plot with new values of Mean, Slope and Adev
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
219 Instance->IndexPoint = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
220 Instance->Mean = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
221 Instance->Slope = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
222 Instance->ADev = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
223 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_MEAN, 0.) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
224 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_SLOPE, 0.) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
225 SetCtrlVal(Instance->PlotPanel,PLOTPANEL_ADEV, 0.) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
226 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
227
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
228 DeleteGraphPlot(Instance->PlotPanel, PLOTPANEL_FREQPLOT, -1,VAL_IMMEDIATE_DRAW) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
229 PlotY(Instance->PlotPanel, PLOTPANEL_FREQPLOT, Instance->Frequencies, Instance->IndexPoint, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
230 GetCtrlVal(Instance->PlotPanel, PLOTPANEL_CHECKBOX_AUTOSCALE, &AutoScale) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
231 if (AutoScale) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
232 GetAxisScalingMode(Instance->PlotPanel, PLOTPANEL_FREQPLOT,VAL_LEFT_YAXIS, &NotCare, &YMin, &YMax ) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
233 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MIN, YMin);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
234 SetCtrlVal(Instance->PlotPanel, PLOTPANEL_MAX, YMax);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
235 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
236 return 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
237 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
238
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
239
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
240
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
241
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
242 int CVICALLBACK Plot_CB_Reset (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
243 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
244 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
245 Plot_Data * Instance = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
246
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
247 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
248 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
249 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
250 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
251 Instance->IndexPoint = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
252 Instance->Mean = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
253 Instance->Slope = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
254 Instance->ADev = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
255
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
256 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
257 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
258 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
259 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
260
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
261
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
262 int CVICALLBACK Plot_CB_GetDrift (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
263 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
264 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
265 Plot_Data * Instance = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
266 bool DeDrift ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
267 double Drift ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
268
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
269 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
270 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
271 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
272
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
273 //Instance = ThisPlot(panel) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
274 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
275 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &DeDrift) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
276
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
277 if (!DeDrift) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
278 SetCtrlVal(panel,PLOTPANEL_DEDRIFT,Instance->Slope) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
279 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
280 else {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
281 GetCtrlVal(panel, PLOTPANEL_DEDRIFT, &Drift) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
282 Drift += Instance->Slope ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
283 SetCtrlVal(panel, PLOTPANEL_DEDRIFT, Drift) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
284
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
285 Instance->IndexPoint = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
286 Instance->Mean = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
287 Instance->Slope = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
288 Instance->ADev = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
289
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
290 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
291
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
292
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
293 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
294 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
295 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
296 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
297
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
298 int CVICALLBACK Plot_CB_ChangeDrift (int panel, int control, int event,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
299 void *callbackData, int eventData1, int eventData2)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
300 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
301 bool DeDrift ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
302 Plot_Data * Instance = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
303
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
304 switch (event)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
305 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
306 case EVENT_COMMIT:
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
307 GetCtrlVal(panel, PLOTPANEL_CHECKBOX_DEDRIFT, &DeDrift) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
308 if(DeDrift) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
309
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
310 //Instance = ThisPlot(panel) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
311 GetPanelAttribute (panel, ATTR_CALLBACK_DATA, &Instance);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
312
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
313 Instance->IndexPoint = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
314 Instance->Mean = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
315 Instance->Slope = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
316 Instance->ADev = 0 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
317
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
318 } ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
319
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
320 break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
321 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
322 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
323 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
324