-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserialInterface.ino
More file actions
109 lines (104 loc) · 3.14 KB
/
serialInterface.ino
File metadata and controls
109 lines (104 loc) · 3.14 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
void interface_ASCII() {
/*
Manages the human-readable interactive serial interface.
Just the paramter returns the value of this parameter.
The parameter followed by a value sets the paramter to this value.
Lines need to end with '\n' (newline).
*/
int numInput = 0;
float fnumInput = 0;
if (Serial.available() > 1) { // data is available
char command = Serial.read();
switch (command)
{
case 'b':
if (Serial.available() && Serial.peek() != '\n') {
numInput = Serial.parseInt();
if (numInput > 0) {
ledMetro.reactivate(); // make sure the Metro is running
ledMetro.setInterval(numInput);
if (VERBOSE) {
Serial.print("Setting blink interval to "); Serial.print(numInput); Serial.println(" ms");
}
}
else {
ledMetro.deactivate();
if (VERBOSE) {
Serial.println("Deactivate blinking");
}
}
}
else {
if (VERBOSE) {
Serial.print("Blink interval in ms: "); Serial.println(ledMetro.getInterval());
}
}
break;
case 'g':
if (Serial.available() && Serial.peek() != '\n') {
numInput = Serial.parseInt();
if (numInput > 0) {
generatorMetro.reactivate(); // make sure the Metro is running
generatorMetro.setInterval(numInput);
if (VERBOSE) {
Serial.print("Setting function generator output interval to "); Serial.println(numInput);
}
}
else {
generatorMetro.deactivate();
if (VERBOSE) {
Serial.println("Deactivate function generator output");
}
}
}
else {
if (VERBOSE) {
Serial.println(generatorMetro.getInterval());
}
}
break;
case 'a':
if (Serial.available() && Serial.peek() != '\n') {
fnumInput = Serial.parseFloat();
sine.setAmplitude(fnumInput);
cosine.setAmplitude(fnumInput);
squ.setAmplitude(fnumInput);
if (VERBOSE) {
Serial.print("Setting signal amplitudes to "); Serial.println(fnumInput);
}
}
else {
if (VERBOSE) {
Serial.println("Invlid Input - missing paramter");
}
}
break;
case 'f':
if (Serial.available() && Serial.peek() != '\n') {
fnumInput = Serial.parseFloat();
sine.setFrequency(fnumInput);
cosine.setFrequency(fnumInput);
squ.setFrequency(fnumInput);
if (VERBOSE) {
Serial.print("Setting signal frequencies to "); Serial.println(fnumInput);
}
}
else {
if (VERBOSE) {
Serial.println("Invlid Input - missing paramter");
}
}
break;
default:
if (VERBOSE) {
Serial.println("ERROR: invalid command");
}
break;
}
// clear the input buffer, in case something is left there
while (Serial.available())
{
Serial.read();
}
}
}