-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.cpp
More file actions
138 lines (113 loc) · 3.51 KB
/
debug.cpp
File metadata and controls
138 lines (113 loc) · 3.51 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
/*
* This file is part of LynxGradProject.
*
* LynxGradProject is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LynxGradProject is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LynxGradProject. If not, see <http://www.gnu.org/licenses/>.
*/
#include "debug.h"
#include <ChibiOS_AVR.h>
bool Debug::s_DebugMode = false;
LEDs Debug::s_LEDs;
Buzzer Debug::s_Buzzer;
Alarm Debug::s_Alarm;
MyKeypad Debug::s_Keypad;
Radio Debug::s_Radio;
Debug::Debug()
{
}
Debug::~Debug()
{
}
void Debug::start()
{
byte param = 0;
char readChar = 0;
s_DebugMode = true;
// Print help
printHelp();
while (s_DebugMode == true) {
readChar = 0;
param = 0;
chThdYield();
// Process data from Serial
if (Serial.available() < 1) {
chThdYield();
continue;
}
byte inChar = Serial.read();
switch (inChar) {
case 'h':
printHelp();
break;
case 'a':
param = Serial.parseInt();
s_Alarm.setLevel((Alarm::AlarmLevel)param);
Serial.print("Setting Alarm to level ");
Serial.println(param);
break;
case 'b':
param = Serial.parseInt();
s_Buzzer.setTone((Buzzer::BuzzerTone)param);
Serial.print("Setting Buzzer to tone ");
Serial.println(param);
break;
case 'r':
param = Serial.parseInt();
s_LEDs.setPattern(LEDs::LEDRed, (LEDs::BlinkType)param);
Serial.println("Setting Red LED to pattern ");
Serial.println(param);
break;
case 'g':
param = Serial.parseInt();
s_LEDs.setPattern(LEDs::LEDGreen, (LEDs::BlinkType)param);
Serial.println("Setting Green LED to pattern ");
Serial.println(param);
break;
case 'k':
Serial.println("Reading Keypad. Press any key on Keypad.");
while (readChar == 0) {
readChar = s_Keypad.getKey();
}
Serial.print("Key pressed is: ");
Serial.println(readChar);
break;
case 's':
param = Serial.parseInt();
Serial.println("Switching comm. system.");
s_Radio.switchCommSystem(param);
break;
case 'q':
Serial.println("Exiting debug mode.");
s_DebugMode = false;
break;
default:
Serial.println("Invalid command");
}
chThdYield();
// Drain buffer before looping.
drainSerial();
}
}
void Debug::printHelp()
{
Serial.println("Debug mode:");
Serial.println("Command\tAction");
Serial.println("h\tPrint help");
Serial.println("a#\tSet Alarm to level #");
Serial.println("b#\tBuzz buzzer using level #");
Serial.println("g#\tBlink Green LED using level #");
Serial.println("r#\tBlink Red LED using level #");
Serial.println("s#\tSwitch comm. system");
Serial.println("k\tRead Keypad");
Serial.println("q\tExit debug mode");
}