-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.ino
More file actions
121 lines (103 loc) · 3 KB
/
Console.ino
File metadata and controls
121 lines (103 loc) · 3 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
// ===================== CONSOLE SERIE =====================
// ENTER (\r\n ou \n) quand debug tourne => console + stop debug
// Q/q => resume debug
static char lineBuf[24];
static uint8_t lineLen = 0;
#define DEBUG_LEVEL 1
static void printConsoleHelp() {
Serial.println();
Serial.println(F("=== Help ==="));
Serial.println(F("M <val> : Input Mode (1=CPPM, 2=SBUS, 3=IBUS, 4=SUMD, 5=JETI, 6=SRXL, 7=SRXL2, 8=CRSF)"));
Serial.println(F("C <val> : Channel (1..16)"));
Serial.println(F("S : Print configuration"));
Serial.println(F("Q/q : Quit Console + Restart debug"));
Serial.println();
}
static void enterConsoleMode() {
consoleMode = true;
dbgRun = false;
lineLen = 0;
printConsoleHelp();
}
static void exitConsoleMode() {
consoleMode = false;
dbgRun = true;
lineLen = 0;
Serial.println(F("\n[Debug resumed]\n"));
}
// ===================== EEPROM load/save =====================
void cfgLoad() {
EEPROM.get(0, Nv);
}
void cfgSave() {
EEPROM.put(0, Nv);
}
static void handleConsoleLine(char *s) {
while (*s == ' ' || *s == '\t') s++;
if (*s == 0) { Serial.print(F("> ")); return; }
if ((s[0] == 'Q' || s[0] == 'q') && s[1] == 0) { exitConsoleMode(); return; }
if ((s[0] == 'S' || s[0] == 's') && s[1] == 0) {
PRINTF("\r\nInput Mode: %s\r\n", INPUT_MODE_STR[Nv.InputType]);
PRINTF("Channel : %d\r\n", Nv.Channel);
return;
}
if (s[0] == 'M' || s[0] == 'm') {
while (*s && *s != ' ' && *s != '\t') s++;
while (*s == ' ' || *s == '\t') s++;
uint8_t h = atoi(s);
if (h >= 1 && h <= 16) {
Nv.InputType = h;
cfgSave();
PRINTF("\r\nOK Input Mode = %s saved\r\n", INPUT_MODE_STR[Nv.InputType]);
} else {
Serial.println(F("\r\nERR Channel (1..8)\r\n"));
}
return;
}
if (s[0] == 'C' || s[0] == 'c') {
while (*s && *s != ' ' && *s != '\t') s++;
while (*s == ' ' || *s == '\t') s++;
uint8_t h = atoi(s);
if (h >= 1 && h <= 16) {
Nv.Channel = h;
cfgSave();
Serial.print(F("\r\nOK Channel=saved\r\n"));
} else {
Serial.println(F("\r\nERR Channel (1..16)\r\n"));
}
return;
}
// float sp = atof(s);
// if (sp >= -20.0f && sp <= 120.0f) {
// //TEMP_SET_C = sp;
// cfgSave();
// //Serial.print(F("OK Set=")); Serial.print(TEMP_SET_C, 1); Serial.println(F("C (saved)"));
// } else {
// Serial.println(F("ERR setpoint (-20..120)"));
// }
// Serial.print(F("> "));
}
static void serialService() {
#if DEBUG_LEVEL == 0
return;
#else
while (Serial.available() > 0) {
char c = (char)Serial.read();
if (!consoleMode) {
// entrée console sur ENTER
if (c == '\n') { enterConsoleMode(); continue; }
// ignore tout le reste
continue;
}
if (c == '\r') continue;
if (c == '\n') {
lineBuf[lineLen] = 0;
handleConsoleLine(lineBuf);
lineLen = 0;
continue;
}
if (c == 8 || c == 127) { if (lineLen > 0) lineLen--; continue; }
if (lineLen < sizeof(lineBuf) - 1) lineBuf[lineLen++] = c;
}
#endif
}