mirror of
https://github.com/AquaMorph/Droplets.git
synced 2025-04-30 01:35:34 +00:00
Menu selection
This commit is contained in:
parent
57b92cad75
commit
d1ca954388
36
src/main.cpp
36
src/main.cpp
@ -26,6 +26,7 @@ const int MAX_CHAR_LENGTH = 15;
|
|||||||
const int MENU_X[] = {0, 5, 10, 5, 0};
|
const int MENU_X[] = {0, 5, 10, 5, 0};
|
||||||
const int MENU_Y[] = {0, 11, 22, 41, 52};
|
const int MENU_Y[] = {0, 11, 22, 41, 52};
|
||||||
int selectedMenuItem = 0;
|
int selectedMenuItem = 0;
|
||||||
|
bool inMenu = false;
|
||||||
|
|
||||||
void DrawSolidRect(uint8_t x1,
|
void DrawSolidRect(uint8_t x1,
|
||||||
uint8_t y1,
|
uint8_t y1,
|
||||||
@ -37,6 +38,12 @@ void DrawSolidRect(uint8_t x1,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteString(int x, int y, std::string text) {
|
||||||
|
patch.display.SetCursor(x, y);
|
||||||
|
char* cstr = &text[0];
|
||||||
|
patch.display.WriteString(cstr, Font_6x8, true);
|
||||||
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
patch.Init();
|
patch.Init();
|
||||||
patch.StartAdc();
|
patch.StartAdc();
|
||||||
@ -65,8 +72,20 @@ std::string FilterMenuText(int position) {
|
|||||||
void ProcessControls() {
|
void ProcessControls() {
|
||||||
patch.UpdateAnalogControls();
|
patch.UpdateAnalogControls();
|
||||||
patch.DebounceControls();
|
patch.DebounceControls();
|
||||||
selectedMenuItem -= patch.encoder.Increment();
|
|
||||||
FilterMenuSelection();
|
if (inMenu) {
|
||||||
|
selectedMenuItem -= patch.encoder.Increment();
|
||||||
|
FilterMenuSelection();
|
||||||
|
if (patch.encoder.RisingEdge()) {
|
||||||
|
inMenu = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (patch.encoder.Pressed()) {
|
||||||
|
if (patch.encoder.TimeHeldMs() > 500 && patch.encoder.TimeHeldMs() < 505) {
|
||||||
|
inMenu = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessOutputs() {}
|
void ProcessOutputs() {}
|
||||||
@ -83,14 +102,21 @@ void CreateMenuItem(std::string text, int position, bool highlighted) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessOled() {
|
void ProcessMenuOled() {
|
||||||
patch.display.Fill(false);
|
|
||||||
|
|
||||||
CreateMenuItem(FilterMenuText(selectedMenuItem-2), 1, false);
|
CreateMenuItem(FilterMenuText(selectedMenuItem-2), 1, false);
|
||||||
CreateMenuItem(FilterMenuText(selectedMenuItem-1), 2, false);
|
CreateMenuItem(FilterMenuText(selectedMenuItem-1), 2, false);
|
||||||
CreateMenuItem(FilterMenuText(selectedMenuItem), 3, true);
|
CreateMenuItem(FilterMenuText(selectedMenuItem), 3, true);
|
||||||
CreateMenuItem(FilterMenuText(selectedMenuItem+1), 4, false);
|
CreateMenuItem(FilterMenuText(selectedMenuItem+1), 4, false);
|
||||||
CreateMenuItem(FilterMenuText(selectedMenuItem+2), 5, false);
|
CreateMenuItem(FilterMenuText(selectedMenuItem+2), 5, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessOled() {
|
||||||
|
patch.display.Fill(false);
|
||||||
|
|
||||||
|
if (inMenu) {
|
||||||
|
ProcessMenuOled();
|
||||||
|
} else {
|
||||||
|
WriteString(0, 0, MENU_ITEMS[selectedMenuItem]);
|
||||||
|
}
|
||||||
patch.display.Update();
|
patch.display.Update();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user