forked from dpavlin/DLO-138
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.ino
125 lines (104 loc) · 2.35 KB
/
control.ino
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
enum { TRIGGER_AUTO, TRIGGER_NORM, TRIGGER_SINGLE };
uint8_t triggerType;
// ------------------------
void setTriggerType(uint8_t tType) {
// ------------------------
triggerType = tType;
// break any running capture loop
keepSampling = false;
}
// ------------------------
void controlLoop() {
// ------------------------
// start by reading the state of analog system
readInpSwitches();
if(triggerType == TRIGGER_AUTO) {
captureDisplayCycle(true);
}
else if(triggerType == TRIGGER_NORM) {
captureDisplayCycle(false);
}
else {
// single trigger
clearWaves();
indicateCapturing();
// blocking call - until trigger
sampleWaves(false);
indicateCapturingDone();
hold = true;
// request repainting of screen labels in next draw cycle
repaintLabels();
// draw the waveform
drawWaves();
blinkLED();
// dump captured data on serial port
dumpSamples();
// freeze display
while(hold);
// update display indicating hold released
drawLabels();
}
processSerial();
}
void processSerial() {
// process any long pending operations which cannot be serviced in ISR
if ( Serial.available() ) {
int serial = Serial.read();
switch(serial) {
case 10:
break; // ignore enter
case '?':
Serial.println("# commandss: [d]umpSamples, print[s]tats, [hjkl] - encoder emulation, [p]eersistence");
break;
case 's':
changeStats();
break;
case 'd':
dumpSamples();
break;
// keyboard emulation of encoder for testing
case 'h':
hold = ! hold;
repaintLabels();
DBG_PRINT("hold ");
DBG_PRINTLN(hold);
break;
case 'j':
encoderChanged(1);
break;
case 'k':
encoderChanged(-1);
break;
case 'l':
readESwitchISR();
break;
// config
case 'p':
togglePersistence();
break;
default:
Serial.print(serial, HEX);
}
}
}
// ------------------------
void captureDisplayCycle(boolean wTimeOut) {
// ------------------------
indicateCapturing();
// blocking call - until timeout or trigger
sampleWaves(wTimeOut);
// draw the waveform
indicateCapturingDone();
drawWaves();
// inter wait before next sampling
if(triggered)
blinkLED();
if(hold) {
// update UI labels
drawLabels();
// dump captured data on serial port
dumpSamples();
}
// freeze display if requested
while(hold) processSerial(); // buttons are in ISR, serial is not
}