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 pathScanTableLoader.c
More file actions
108 lines (93 loc) · 2.98 KB
/
ScanTableLoader.c
File metadata and controls
108 lines (93 loc) · 2.98 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
/**
@file ScanTableLoader.c
@brief Generates values for the scan table using either linear or exponential
ramping. A value of -1000 indicates the end of the ramp.
*/
#include "ScanTableLoader.h"
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#include "GUIDesign.h"
#include "ScanTableLoader2.h"
#include "vars.h"
/**
@brief Callback for the Cancel button. Hides the panel without loading anything
to the scan table.
*/
int CVICALLBACK SCAN_LOAD_CANCEL(int panel, int control, int event,
void* callbackData, int eventData1,
int eventData2) {
switch (event) {
case EVENT_COMMIT:
HidePanel(panelHandle8);
break;
}
return 0;
}
/**
@brief Callback for the OK button. Loads values into the scan table based on the
given parameters.
*/
int CVICALLBACK SCAN_LOAD_OK(int panel, int control, int event,
void* callbackData, int eventData1,
int eventData2) {
int steps = 0, mode;
double first, last;
switch (event) {
case EVENT_COMMIT:
GetCtrlVal(panelHandle8, SL_PANEL_SCAN_TYPE, &mode);
GetCtrlVal(panelHandle8, SL_PANEL_ITER_NUM, &steps);
GetCtrlVal(panelHandle8, SL_PANEL_SCAN_INIT, &first);
GetCtrlVal(panelHandle8, SL_PANEL_SCAN_FIN, &last);
if (steps > 30 || steps < 1) {
ConfirmPopup("USER ERROR", "# of Steps must be between 1-30");
HidePanel(panelHandle8);
} else {
switch (mode) {
case 1:
LoadLinearRamp(steps, first, last);
break;
case 2:
LoadExpRamp(steps, first, last);
break;
}
HidePanel(panelHandle8);
}
break;
}
return 0;
}
/**
@brief Loads a linear ramp into the scan table.
@param steps Number of steps to ramp.
@param first The starting value to ramp from.
@param last The final value to ramp to.
*/
void LoadLinearRamp(int steps, double first, double last) {
double slope = (last - first) / steps;
for (int i = 0; i <= steps; i++) {
SetTableCellVal(panelHandle, PANEL_SCAN_TABLE, MakePoint(1, i + 1),
slope * i);
}
SetTableCellVal(panelHandle, PANEL_SCAN_TABLE, MakePoint(1, steps + 2),
-1000.0);
}
/**
@brief Loads an exponential ramp into the scan table.
@param steps Number of steps to ramp.
@param first The starting value to ramp from.
@param last The final value to ramp to.
Creates values using the formula f(x) = last - amplitude * exp(bx) with +/- 1%
accuracy.
*/
void LoadExpRamp(int steps, double first, double last) {
double amplitude = last - first;
double b = log(0.01) / steps;
for (int i = 0; i < steps; i++) {
SetTableCellVal(panelHandle, PANEL_SCAN_TABLE, MakePoint(1, i + 1),
last - amplitude * exp(b * i));
}
SetTableCellVal(panelHandle, PANEL_SCAN_TABLE, MakePoint(1, steps + 1), last);
SetTableCellVal(panelHandle, PANEL_SCAN_TABLE, MakePoint(1, steps + 2),
-1000.0);
}