summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2023-10-11 14:35:04 +0200
committerJonas Smedegaard <dr@jones.dk>2023-10-11 18:16:37 +0200
commit3b8b10252d751191eedb2f630f64b6be135f9a5a (patch)
treee64bcdce841ae30bc5f6aa652bc5c6963387fbd0
parent77da0b9468d55246081c8bd3e505cf2ae20406e8 (diff)
FIXME
-rw-r--r--main.ino57
1 files changed, 54 insertions, 3 deletions
diff --git a/main.ino b/main.ino
index 8067cb4..6a1538a 100644
--- a/main.ino
+++ b/main.ino
@@ -38,13 +38,31 @@ EasyButton button_select(BUTTON_PIN_SELECT);
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
-#include <U8g2_for_Adafruit_GFX.h>
// source: https://github.com/ZinggJM/GxEPD2/blob/master/examples/GxEPD2_Example/GxEPD2_display_selection.h#L192
GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> displayEPaper(GxEPD2_290(EPD_CS, EPD_DC, EPD_RSET, EPD_BUSY));
-U8G2_FOR_ADAFRUIT_GFX u8g2;
+#include <GEM_adafruit_gfx.h>
+// Create variables that will be editable through the menu and assign them initial values
+int number = -512;
+boolean enablePrint = false;
+
+// Create two menu item objects of class GEMItem, linked to number and enablePrint variables
+GEMItem menuItemInt("Number:", number);
+GEMItem menuItemBool("Enable print:", enablePrint);
+
+// Create menu button that will trigger printData() function. It will print value of our number variable
+// to Serial monitor if enablePrint is true. We will write (define) this function later. However, we should
+// forward-declare it in order to pass to GEMItem constructor
+void printData(); // Forward declaration
+GEMItem menuItemButton("Print", printData);
+
+// Create menu page object of class GEMPage. Menu page holds menu items (GEMItem) and represents menu level.
+// Menu can have multiple menu pages (linked to each other) with multiple menu items each
+GEMPage menuPageMain("Main Menu");
+
+GEM_adafruit_gfx menu(displayEPaper, GEM_POINTER_ROW, GEM_ITEMS_COUNT_AUTO);
#endif
void setup() {
@@ -64,7 +82,19 @@ void setup() {
led.breathe(2000);
displayEPaper.init(115200, true, 2, false);
- u8g2.begin(displayEPaper);
+ displayEPaper.setTextColor(GxEPD_BLACK);
+ displayEPaper.firstPage();
+ do
+ {
+ displayEPaper.fillScreen(GxEPD_WHITE);
+ // comment out next line to have no or minimal Adafruit_GFX code
+ displayEPaper.print("Hello World!");
+ }
+ while (displayEPaper.nextPage());
+
+ menu.init();
+ setupMenu();
+ menu.drawMenu();
}
void loop() {
@@ -96,3 +126,24 @@ void onButtonSelectPressed() {
Serial.println("button SELECT clicked");
led.on();
}
+
+void setupMenu() {
+ // Add menu items to menu page
+ menuPageMain.addMenuItem(menuItemInt);
+ menuPageMain.addMenuItem(menuItemBool);
+ menuPageMain.addMenuItem(menuItemButton);
+
+ // Add menu page to menu and set it as current
+ menu.setMenuPageCurrent(menuPageMain);
+}
+
+void printData() {
+ // If enablePrint flag is set to true (checkbox on screen is checked)...
+ if (enablePrint) {
+ // ...print the number to Serial
+ Serial.print("Number is: ");
+ Serial.println(number);
+ } else {
+ Serial.println("Printing is disabled, sorry:(");
+ }
+}