-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.c
326 lines (279 loc) · 7.92 KB
/
test.c
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
* @file test.c
*
* @date May 24, 2017
* @author hamster
*
* @brief Test Routines
*
* This file contains routines to test all the parts of the badge
* The tests are run if the right button is held down during power up.
* The user is then presented with a menu to run the tests
*
*/
#include "system.h"
#include "test.h"
/**
* @brief Toggle all the helmet wing LEDs on and off
*/
void test_wing_leds(void){
wing_leds(ON);
nrf_delay_ms(500);
wing_leds(OFF);
nrf_delay_ms(500);
wing_leds(ON);
nrf_delay_ms(500);
wing_leds(OFF);
nrf_delay_ms(500);
}
/**
* @brief Toggle all the helmet LEDs on and off
*/
void test_helmet_leds(void){
helmet_leds(ON);
nrf_delay_ms(500);
helmet_leds(OFF);
nrf_delay_ms(500);
helmet_leds(ON);
nrf_delay_ms(500);
helmet_leds(OFF);
nrf_delay_ms(500);
}
/**
* @brief Test the eyes by running through all the defined eye colors
*/
void test_eye_leds(void){
for(int i = 0; i < NUM_EYE_COLORS; i++){
set_eye_color(eye_side_both, i);
nrf_delay_ms(500);
}
set_eye_color(eye_side_both, eye_color_none);
nrf_delay_ms(500);
}
/**
* @brief Fill the screen with solid colors
*/
void test_lcd(void){
for(int j = 0; j < LCD_COLOR_NUMBER; j++){
nrf_gfx_screen_fill(p_lcd, lcd_color_list[j]);
nrf_delay_ms(100);
}
nrf_delay_ms(500);
}
/**
* @brief Play a tone through the speaker
*/
void test_speaker(void){
for(int i = 0; i < 50; i++){
beep(25, 600 + (i * 10));
}
}
/**
* @brief Test the buttons
*/
void test_buttons(void){
uint8_t keep_testing = true;
char *new_button = " ", *old_button = " ";
// Clear the screen
nrf_gfx_screen_fill(p_lcd, LCD_COLOR_BLACK);
nrf_gfx_point_t banner_start = NRF_GFX_POINT(20, 0);
nrf_gfx_print(p_lcd, &banner_start, LCD_COLOR_WHITE, "DC801", font_16_point, true);
nrf_gfx_point_t banner_2 = NRF_GFX_POINT(15, 25);
nrf_gfx_print(p_lcd, &banner_2, LCD_COLOR_WHITE, "Press a button", font_8_point, true);
nrf_gfx_point_t banner_3 = NRF_GFX_POINT(15, 40);
nrf_gfx_print(p_lcd, &banner_3, LCD_COLOR_WHITE, "1+4 to exit", font_8_point, true);
nrf_gfx_point_t banner_4 = NRF_GFX_POINT(15, 65);
nrf_gfx_rect_t box = NRF_GFX_RECT(0, 65, 128, 25);
while(keep_testing){
if(isButtonDown(USER_BUTTON_1) &&
isButtonDown(USER_BUTTON_4)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(USER_BUTTON_1) &&
isButtonDown(USER_BUTTON_4)){
// Test is over
keep_testing = false;
}
}
if(isButtonDown(USER_BUTTON_1)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(USER_BUTTON_1)){
new_button = "B1";
}
}
if(isButtonDown(USER_BUTTON_2)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(USER_BUTTON_2)){
new_button = "B2";
}
}
if(isButtonDown(USER_BUTTON_3)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(USER_BUTTON_3)){
new_button = "B3";
}
}
if(isButtonDown(USER_BUTTON_4)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(USER_BUTTON_4)){
new_button = "B4";
}
}
if(isButtonDown(TAIL_TOUCH)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(TAIL_TOUCH)){
new_button = "TAIL";
}
}
if(isButtonDown(EAR_TOUCH)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(EAR_TOUCH)){
new_button = "EAR";
}
}
if(new_button != old_button){
nrf_gfx_rect_draw(p_lcd, &box, 1, LCD_COLOR_BLACK, true);
nrf_gfx_print(p_lcd, &banner_4, LCD_COLOR_RED, new_button, font_16_point, true);
old_button = new_button;
}
nrf_delay_ms(10);
}
nrf_delay_ms(500);
}
/**
* @brief This is the test mode, for testing parts of the badge
* @note You must reboot the badge to exit - button 4 will do this
*/
void run_test_mode(void){
uint8_t test_mode = test_mode_none;
uint8_t run_mode = run_mode_none;
nrf_gfx_point_t status_line = NRF_GFX_POINT(5, 100);
nrf_gfx_rect_t box = NRF_GFX_RECT(0, 100, 128, 14);
draw_menu();
while(isButtonDown(USER_BUTTON_4)){
// Wait for the user to let go of button 4 so we don't go right to button 4 test
nrf_delay_ms(10);
}
while (true){
// Scan for button changes
if(isButtonDown(USER_BUTTON_1)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(USER_BUTTON_1)){
// Button is pressed, advance to the next test
if(test_mode < test_mode_lcd){
// Skip the button test
test_mode++;
}
else{
// All tests have been run
test_mode = test_mode_eyes;
}
run_mode = run_mode_single;
}
}
if(isButtonDown(USER_BUTTON_2)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(USER_BUTTON_2)){
// Button is pressed, run all the tests
test_mode = test_mode_eyes;
run_mode = run_mode_all;
}
}
if(isButtonDown(USER_BUTTON_3)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(USER_BUTTON_3)){
// Button is pressed, run the button test
test_mode = test_mode_button;
run_mode = run_mode_single;
}
}
if(isButtonDown(USER_BUTTON_4)){
// Debounce
nrf_delay_ms(15);
if(isButtonDown(USER_BUTTON_4)){
// Button is pressed, reboot
NVIC_SystemReset();
}
}
if(run_mode == run_mode_single || run_mode == run_mode_all){
switch(test_mode){
case test_mode_none:
default:
break;
case test_mode_eyes:
nrf_gfx_print(p_lcd, &status_line, LCD_COLOR_RED, "Eye LED Test", font_8_point, true);
test_eye_leds();
break;
case test_mode_helmet:
nrf_gfx_print(p_lcd, &status_line, LCD_COLOR_RED, "Helmet LED Test", font_8_point, true);
test_helmet_leds();
break;
case test_mode_wingss:
nrf_gfx_print(p_lcd, &status_line, LCD_COLOR_RED, "Wing LED Test", font_8_point, true);
test_wing_leds();
break;
case test_mode_speaker:
nrf_gfx_print(p_lcd, &status_line, LCD_COLOR_RED, "Speaker Test", font_8_point, true);
test_speaker();
break;
case test_mode_lcd:
nrf_gfx_print(p_lcd, &status_line, LCD_COLOR_RED, "LCD Test", font_8_point, true);
test_lcd();
break;
case test_mode_button:
nrf_gfx_print(p_lcd, &status_line, LCD_COLOR_RED, "Button Test", font_8_point, true);
test_buttons();
break;
}
if(run_mode == run_mode_all){
// Advance to the next test
if(test_mode < test_mode_lcd){
// Skip the button test
test_mode++;
nrf_gfx_rect_draw(p_lcd, &box, 1, LCD_COLOR_BLACK, true);
}
else{
// All tests have been run
run_mode = run_mode_none;
draw_menu();
}
}
else{
// Single test mode, cancel running again
run_mode = run_mode_none;
draw_menu();
}
}
nrf_delay_ms(10);
}
}
/**
* @brief Draw the test menu. This also clears any text at the bottom
*/
void draw_menu(void){
nrf_gfx_screen_fill(p_lcd, LCD_COLOR_BLACK);
// Print the test menu
nrf_gfx_point_t banner_start = NRF_GFX_POINT(20, 0);
nrf_gfx_print(p_lcd, &banner_start, LCD_COLOR_WHITE, "DC801", font_16_point, true);
nrf_gfx_point_t banner_2 = NRF_GFX_POINT(28, 25);
nrf_gfx_print(p_lcd, &banner_2, LCD_COLOR_BLUE, "Test Mode", font_8_point, true);
nrf_gfx_point_t menu_line_1 = NRF_GFX_POINT(15, 40);
nrf_gfx_print(p_lcd, &menu_line_1, LCD_COLOR_WHITE, "B1: Next Test", font_8_point, true);
nrf_gfx_point_t menu_line_2 = NRF_GFX_POINT(15, 54);
nrf_gfx_print(p_lcd, &menu_line_2, LCD_COLOR_WHITE, "B2: All Tests", font_8_point, true);
nrf_gfx_point_t menu_line_3 = NRF_GFX_POINT(15, 68);
nrf_gfx_print(p_lcd, &menu_line_3, LCD_COLOR_WHITE, "B3: Button Test", font_8_point, true);
nrf_gfx_point_t menu_line_4 = NRF_GFX_POINT(15, 82);
nrf_gfx_print(p_lcd, &menu_line_4, LCD_COLOR_WHITE, "B4: Reboot", font_8_point, true);
nrf_gfx_rect_t box = NRF_GFX_RECT(0, 100, 14, 128);
nrf_gfx_rect_draw(p_lcd, &box, 0, LCD_COLOR_BLACK, true);
}