diff options
author | Jonas Smedegaard <dr@jones.dk> | 2023-10-11 14:35:04 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2023-10-11 15:24:44 +0200 |
commit | 5aafbc43e66cc91747d4d0878de3e1c9f219b27f (patch) | |
tree | c342f890101fc4a412ab09a25371949ecb566af2 | |
parent | 55dbb48c882fe50ecc32ba710414ec4da74eddbb (diff) |
FIXME
-rw-r--r-- | main.ino | 68 |
1 files changed, 68 insertions, 0 deletions
@@ -16,6 +16,8 @@ const int longpress_duration = 2000; // time in milliseconds // dirty hack: assume that any ESP32 board is a Lilygo T5 V2.2 #define LILYGO_T5_V22 #include "boards.h" // source: https://github.com/lewisxhe/GxEPD/blob/master/src/boards.h +#define HAS_DISPLAY + const byte BUTTON_PIN_MOVE = BUTTON_1; const byte BUTTON_PIN_SELECT = BUTTON_2; BlinkControl led(LED_PIN); @@ -31,6 +33,42 @@ BlinkControl led(LED_BUILTIN); // pin 13 is built-in LED on many Arduino boards EasyButton button_move(BUTTON_PIN_MOVE); EasyButton button_select(BUTTON_PIN_SELECT); +#if defined(HAS_DISPLAY) +#define ENABLE_GxEPD2_GFX 1 + +#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 u8g2Fonts; + +#include <GEM_u8g2.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"); + +// Create menu object of class GEM_u8g2. Supply its constructor with reference to u8g2 object we created earlier +GEM_u8g2 menu(u8g2); +#endif + void setup() { Serial.begin(BAUDRATE); while (!Serial) { @@ -46,6 +84,13 @@ void setup() { led.begin(); led.breathe(2000); + + displayEPaper.init(115200, true, 2, false); + u8g2Fonts.begin(display); + + menu.init(); + setupMenu(); + menu.drawMenu(); } void loop() { @@ -77,3 +122,26 @@ 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 + // Note, there might be some problems w/ displaying Cyrillic characters in Serial monitor, + // in which case adjusting baud rate may help + Serial.print("Число: "); + Serial.println(number); + } else { + Serial.println("Печать не разрешена:("); + } +} |