-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputTerminal.ino
More file actions
159 lines (132 loc) · 3.25 KB
/
InputTerminal.ino
File metadata and controls
159 lines (132 loc) · 3.25 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#if defined (INPUT_TERMINAL)
#include <SerialCommand.h>
SerialCommand sCmd;
void setupInputTerminal(){
Serial.begin(115200);
initSerialCommands();
SERIAL_PRINTLN("*** SETUP COMPLETE ***");
}
void loopInputTerminal(){
sCmd.readSerial();
}
void initSerialCommands(){
sCmd.addCommand("setR", serialSetR);
sCmd.addCommand("setG", serialSetG);
sCmd.addCommand("setB", serialSetB);
sCmd.addCommand("setColor", serialSetColor);
sCmd.addCommand("getColor", serialGetColor);
sCmd.addCommand("printColor", printCurrentColor);
sCmd.addCommand("setConfig", serialSetConfig);
sCmd.addCommand("saveColors", serialSaveColors);
sCmd.addCommand("saveLeds", serialSaveLeds);
sCmd.addCommand("clearEeprom", clearEeprom);
sCmd.addCommand("setArm", serialSetArm);
sCmd.addCommand("setLed", serialSetLed);
sCmd.addCommand("m+", serialNextMode);
sCmd.addCommand("m-", serialPreviousMode);
sCmd.addCommand("d", serialSetDelay);
}
int readIntArg(){
char *arg;
arg = sCmd.next();
if (arg != NULL) return atoi(arg);
return -1;
}
void printCurrentColor(){
SERIAL_PRINT("current RGB color = (");
SERIAL_PRINT(currentRGB.r);
SERIAL_PRINT(", ");
SERIAL_PRINT(currentRGB.g);
SERIAL_PRINT(", ");
SERIAL_PRINT(currentRGB.b);
SERIAL_PRINTLN(")");
}
void serialSetR(){
int newColor = readIntArg();
if (newColor>=0 && newColor<256){
currentRGB.r = newColor;
printCurrentColor();
}
}
void serialSetG(){
int newColor = readIntArg();
if (newColor>=0 && newColor<256){
currentRGB.g = newColor;
printCurrentColor();
}
}
void serialSetB(){
int newColor = readIntArg();
if (newColor>=0 && newColor<256){
currentRGB.b = newColor;
printCurrentColor();
}
}
void serialSetColor(){
int idx = readIntArg()%MAX_EEPROM_COLORS;
if (idx>=0 && idx<MAX_EEPROM_COLORS){
SERIAL_PRINT("Set color ");
SERIAL_PRINT(idx);
SERIAL_PRINTLN(" to current color.");
storedColorsRGB[idx] = currentRGB;
currentColorIdx = idx;
}
}
void serialSetConfig(){
config = readIntArg()%MAX_LED_CONFIGS;
SERIAL_PRINT("new config = ");
SERIAL_PRINTLN(config);
}
void serialGetColor(){
int idx = readIntArg()%MAX_EEPROM_COLORS;
currentRGB = storedColorsRGB[idx];
currentColorIdx = idx;
printCurrentColor();
}
void serialSaveColors(){
writeColors();
SERIAL_PRINTLN("Colors saved to EEPROM.");
}
void serialSaveLeds(){
writeLeds();
SERIAL_PRINTLN("Led colors saved to EEPROM.");
}
void serialSetArm(){
int arm = readIntArg() % NUM_ARMS;
if (arm>=0 && arm<NUM_ARMS){
setArmColor(currentColorIdx, arm, config);
SERIAL_PRINT("Updated arm ");
SERIAL_PRINTLN(arm);
}
}
void serialSetLed(){
int led = readIntArg() % NUM_LEDS;
if (led>=0 && led<NUM_LEDS){
setLedColor(currentColorIdx, led, config);
}
}
void printNewMode(){
SERIAL_PRINT("new mode = ");
SERIAL_PRINTLN(mode);
}
void serialNextMode(){
mode = (mode+1) % NUM_MODES;
printNewMode();
}
void serialPreviousMode(){
mode = (mode+(NUM_MODES-1)) % NUM_MODES;
printNewMode();
}
void serialSetDelay(){
int newDelay = readIntArg();
if (newDelay>0 && newDelay<10000){
DELAY = newDelay;
SERIAL_PRINT("new delay = ");
SERIAL_PRINTLN(DELAY);
}
}
void serialReversed(){
reverse = !reverse;
SERIAL_PRINTLN("reversed");
}
#endif