-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patha_TerminalCommand.ino
79 lines (75 loc) · 1.9 KB
/
a_TerminalCommand.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
void __emptyInputBuffer()
{
while (SERIAL.available()) {
if (SERIAL.read() == '\n') {
return;
}
}
fifo_readindex = fifo_writeindex = 0;
}
void checkTerminalCommands()
{
while (SERIAL.available() || fifo_readindex != fifo_writeindex) {
static boolean shiftable;
char c;
if (fifo_readindex != fifo_writeindex) {
c = command_buf[fifo_readindex];
++fifo_readindex %= MEWPRO_BUFFER_LENGTH;
WRITE_CHAR(c);
} else {
c = SERIAL.read();
if (startupSession == STARTUP_HALT) { // suspend sending bulk setting commands too quickly
WRITE_CHAR(c);
}
}
switch (c) {
case ' ':
shiftable = false;
continue;
case '\r':
case '\n':
if (bufp != 6) {
buf[0] = bufp - 1;
buf[1] = 5; buf[2] = 2;
buf[3] = bufp - 4;
buf[4] = buf[6]; buf[5] = buf[7];
buf[6] = ++session;
buf[7] = buf[4] == 'Y' ? 6 : 4;
bufp = 6;
parseSerialWrite();
updateLCD();
}
return;
case '@':
bufp = 6;
session = 0xFF;
DEBUG_println(F("\ncamera power on"));
__emptyInputBuffer();
WRITE_CHAR('\n'); // this is required because the buffer is made empty
startupSession = 0; // emit power on sequence
disp_state = MENU_MAIN;
setting.p.mode = setting.p.setup.default_app_mode;
updateLCD();
return;
default:
if (bufp >= 8 && isxdigit(c)) {
c -= '0';
if (c >= 10) {
c = (c & 0x0f) + 9;
}
}
if (bufp < 9) {
shiftable = true;
buf[bufp++] = c;
} else {
if (shiftable) {
buf[bufp-1] = (buf[bufp-1] << 4) + c;
} else {
buf[bufp++] = c;
}
shiftable = !shiftable;
}
break;
}
}
}