-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
46 lines (42 loc) · 1.04 KB
/
Menu.cpp
File metadata and controls
46 lines (42 loc) · 1.04 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
#include "Menu.h"
Menu::Menu(Adafruit_SSD1306 *display) {
this->display = display;
}
void Menu::configure(MenuItem *menuItems, byte menuItemsCount) {
this->menuItems = menuItems;
this->menuItemsCount = menuItemsCount;
}
void Menu::next() {
selection++;
if (selection == menuItemsCount) {
selection = 0;
}
}
void Menu::show() {
if (!display || !menuItems) {
return;
}
display->clearDisplay();
display->setTextColor(SSD1306_WHITE);
display->cp437(true);
display->setCursor(0, 0);
MenuItem menuItem = menuItems[selection];
display->setTextSize(1);
display->println(menuItem.header1);
display->println(menuItem.header2);
display->setTextSize(2);
if (menuItem.displayValueFn) {
display->setTextSize(2);
menuItem.displayValueFn();
}
if (selection > 0) {
display->setTextSize(1);
display->setCursor(display->width() - 12, 0);
display->setTextColor(SSD1306_BLACK, SSD1306_WHITE);
if (selection < 10) {
display->print(0);
}
display->print(selection);
}
display->display();
}