1#include <ItemCommand.h>
2#include <ItemInput.h>
3#include <ItemInputCharset.h>
4#include <ItemSubMenu.h>
5#include <LcdMenu.h>
6#include <MenuScreen.h>
7#include <SimpleRotary.h>
8#include <display/LiquidCrystal_I2CAdapter.h>
9#include <input/SimpleRotaryAdapter.h>
10#include <renderer/CharacterDisplayRenderer.h>
11
12#define LCD_ROWS 2
13#define LCD_COLS 16
14
15// Create your charset
16const char* charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
17
18// Declare the call back functions
19void inputCallback(char* value);
20void clearInput();
21
22extern MenuScreen* userScreen;
23
24// clang-format off
25MENU_SCREEN(mainScreen, mainItems,
26 ITEM_SUBMENU("Set user", userScreen),
27 ITEM_BASIC("Settings"),
28 ITEM_BASIC("More Settings"),
29 ITEM_BASIC("And more Settings"));
30
31MENU_SCREEN(userScreen, userItems,
32 ITEM_INPUT_CHARSET("User", charset, inputCallback),
33 ITEM_COMMAND("Clear", clearInput));
34// clang-format on
35
36LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
37CharacterDisplayRenderer renderer(new LiquidCrystal_I2CAdapter(&lcd), LCD_COLS, LCD_ROWS);
38LcdMenu menu(renderer);
39SimpleRotary encoder(2, 3, 4);
40SimpleRotaryAdapter rotaryInput(&menu, &encoder);
41
42void setup() {
43 Serial.begin(9600);
44 renderer.begin();
45 menu.setScreen(mainScreen);
46}
47
48void loop() { rotaryInput.observe(); }
49
50// Define the callbacks
51void inputCallback(char* value) {
52 // Do stuff with value
53 Serial.print(F("# "));
54 Serial.println(value);
55}
56
57void clearInput() {
58 if ((static_cast<ItemInput*>(userItems[0]))->setValue((char*)"")) {
59 menu.refresh();
60 }
61}