-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainMenuMode.cpp
70 lines (61 loc) · 1.5 KB
/
MainMenuMode.cpp
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
#include "../config.h"
#include "../devices/GhudDevice.hpp"
#include "../modules/ButtonInterface.hpp"
#include "ModeManager.hpp"
#include "MainMenuMode.hpp"
#define MENU_POSITIONS 5
char* menu_items[] = {
"Horizontal",
"Random speed",
"Heading",
"GPS stats",
"Rectangles"
};
byte cursor_position=1;
bool refreshMenuScreen=true;
void MainMenuMode::init(){
refreshMenuScreen = true;
}
void MainMenuMode::processInput(ButtonEvent event){
switch (event) {
case DOWN:
Serial.println(cursor_position);
if (cursor_position < MENU_POSITIONS){
cursor_position++;
} else {
cursor_position=1;
}
refreshMenuScreen=true;
break;
case UP:
if (cursor_position > 1){
cursor_position--;
} else {
cursor_position=MENU_POSITIONS;
}
refreshMenuScreen=true;
break;
case ENTER:
ModeManager::displayMode((Mode)cursor_position);
break;
}
}
void MainMenuMode::display(){
GhudDevice::waitForFrame();
if (refreshMenuScreen){
GhudDevice::clearScreen();
GhudDevice::displayString("Select mode:", 22 , 10);
for (int i=0; i< MENU_POSITIONS; i++){
char buffer[25];
if (i+1==cursor_position){
sprintf(buffer, "* %s", menu_items[i]);
} else {
sprintf(buffer, " %s", menu_items[i]);
}
//Serial.println(buffer);
GhudDevice::displayString(buffer, 20 + MENU_SPACING_X, 10 + (i+1)*MENU_SPACING_Y);
}
refreshMenuScreen=false;
}
//delay(250);
}