-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate_mainmenu.cpp
More file actions
158 lines (139 loc) · 4.16 KB
/
state_mainmenu.cpp
File metadata and controls
158 lines (139 loc) · 4.16 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* state_mainmenu.cpp
*
* Created on: 29 dec. 2017
* Author: MisterCavespider
*/
#include "state_mainmenu.h"
#define TIME_TILL_SLEEP 7777
// This should be declared somewhere else
#define ibe_med_width 64
#define ibe_med_height 34
static const uint8_t ibe_med_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0xfc, 0xff, 0x03, 0xfc, 0xff, 0x0f,
0xf0, 0x3f, 0xfc, 0xff, 0x03, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf0, 0x3f, 0xfc, 0xff, 0x0f, 0xfc, 0xff, 0x0f, 0xf0, 0x3f, 0xfc, 0xff,
0x0f, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0xf0, 0xc3,
0x0f, 0xf0, 0x03, 0x00, 0xc0, 0x0f, 0xf0, 0xc3, 0x0f, 0xf0, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0xf0, 0xff, 0x03, 0xf0, 0xff, 0x03,
0xc0, 0x0f, 0xf0, 0xff, 0x03, 0xf0, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x0f, 0xf0, 0xff, 0x03, 0xf0, 0xff, 0x03, 0xc0, 0x0f, 0xf0, 0xff,
0x03, 0xf0, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0xf0, 0xc3,
0x0f, 0xf0, 0x03, 0x00, 0xc0, 0x0f, 0xf0, 0xc3, 0x0f, 0xf0, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0xfc, 0xff, 0x0f, 0xfc, 0xff, 0x0f,
0xf0, 0x3f, 0xfc, 0xff, 0x0f, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xf0, 0x3f, 0xfc, 0xff, 0x03, 0xfc, 0xff, 0x0f, 0xf0, 0x3f, 0xfc, 0xff,
0x03, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Name of project + formatting
#define PROJECT_STRING "-==[ModBox]==-"
bool logo = true;
void MainMenuState::setup()
{
encc1->r.write(0);
encc2->r.write(0);
encc3->r.write(0);
if(logo)
{
u8g2->drawXBMP(32, 8, ibe_med_width, ibe_med_height, ibe_med_bits);
uint8_t w = u8g2->getStrWidth(PROJECT_STRING);
u8g2->setCursor((128-(w+1))/2, 50);
u8g2->print(PROJECT_STRING);
}
else
{
uint8_t n = 14;
uint8_t i;
uint8_t w = u8g2->getStrWidth(PROJECT_STRING);
u8g2->setCursor((128-w)/2, 6);
u8g2->print(PROJECT_STRING);
u8g2->drawHLine((128-w)/2-1, 8, w+2);
for(i = 1; i < stateManager->size; i++)
{
u8g2->setCursor(1, n+=6);
u8g2->print(stateManager->states[i]->title);
}
}
currselect = -1;
lastselect = -1;
}
void MainMenuState::loop()
{
if(logo)
{
if(PRESSEDP(encc1) || PRESSEDP(encc2) || PRESSEDP(encc3)
|| encc1->r.read() || encc2->r.read() || encc3->r.read())
{
logo = false;
u8g2->clearBuffer();
time = 0; // Reset timer
setup();
}
}
else
{
currselect = -1; // Invalidate
int32_t read = encc3->r.read()/4;
if(read >= 0 && read < stateManager->size - 1) // -1 because MainMenu
{
currselect = read;
}
else if(read >= stateManager->size - 1)
{
encc3->r.write(stateManager->size - 2);
}
else
{
encc3->r.write(0);
}
// Check if pressed
if(PRESSEDP(encc3) > 0)
{
u8g2->clearBuffer();
time = 0; // Reset timer
stateManager->setCurrentState(currselect+1); // +1 because MainMenu
stateManager->setup();
return;
}
// Not pressed? update the screen
if(currselect != lastselect)
{
// Remove last select
if(lastselect >= 0 && lastselect < stateManager->size - 1)
{
u8g2->setDrawColor(2);
u8g2->drawBox(0, 14 + 6*lastselect, 128, 7);
u8g2->setDrawColor(1);
}
// Set new select
if(currselect >= 0 && currselect < stateManager->size - 1)
{
u8g2->setDrawColor(2);
u8g2->drawBox(0, 14 + 6*currselect, 128, 7);
u8g2->setDrawColor(1);
}
time = 0; // Reset timer
}
// No changes? Has it fallen asleep?
if(time > TIME_TILL_SLEEP)
{
logo = true;
u8g2->clearBuffer();
time = 0; // Reset timer
setup();
}
lastselect = currselect;
}
}
MainMenuState::~MainMenuState()
{
}