1#include <ItemWidget.h>
2#include <LcdMenu.h>
3#include <MenuScreen.h>
4#include <display/LiquidCrystal_I2CAdapter.h>
5#include <input/KeyboardAdapter.h>
6#include <renderer/CharacterDisplayRenderer.h>
7#include <widget/WidgetBool.h>
8#include <widget/WidgetList.h>
9#include <widget/WidgetRange.h>
10
11#define LCD_ROWS 2
12#define LCD_COLS 16
13#define LCD_ADDR 0x27
14
15// Custom characters
16byte plusMinus[8] = {B00000, B00100, B01110, B00100, B00000, B01110, B00000, B00000}; // ±
17byte euro[8] = {B00111, B01000, B11110, B01000, B11110, B01000, B00111, B00000}; // €
18
19const char* options[] = {"Buy", "Sell"};
20const char* days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
21const char pinChars[] = "123456789ABCDEF";
22
23MENU_SCREEN(
24 mainScreen,
25 mainItems,
26 ITEM_WIDGET(
27 "Auto",
28 [](const char* option, bool isAuto) { Serial.println(option); Serial.println(isAuto); },
29 WIDGET_LIST(options, sizeof(options) / sizeof(options[0]), 0, "%s", 0, true),
30 WIDGET_BOOL(false, "Yes", "No", ",%s")),
31 ITEM_WIDGET(
32 "Price",
33 [](int price) { Serial.println(price); },
34 WIDGET_RANGE(10, 5, 0, 1000, "%.1d\003", 1)),
35 ITEM_WIDGET(
36 "Quantity",
37 [](float quantity, int tolerance) { Serial.println(quantity); Serial.println(tolerance); },
38 WIDGET_RANGE(1.0f, 0.1f, 0.1f, 100.0f, "%.1f", 0),
39 WIDGET_RANGE(10, 1, 0, 100, "\002%d%%", 1)),
40 ITEM_WIDGET(
41 "Freq",
42 [](int hour, int minute, const char* day) { Serial.println(hour); Serial.println(minute); Serial.println(day); },
43 WIDGET_RANGE(0, 1, 0, 23, "%02d", 0, false),
44 WIDGET_RANGE(0, 1, 0, 59, ":%02d", 0, false),
45 WIDGET_LIST(days, sizeof(days) / sizeof(days[0]), 0, " on %s", 0, true)),
46 ITEM_WIDGET(
47 "Start",
48 [](int day, int month, int year) { Serial.println(day); Serial.println(month); Serial.println(year); },
49 WIDGET_RANGE(1, 1, 1, 31, "%02d", 0, true),
50 WIDGET_RANGE(1, 1, 1, 12, "/%02d", 0, true),
51 WIDGET_RANGE(2021, 1, 2020, 2050, "/%04d", 0, true)),
52 ITEM_WIDGET(
53 "Pin",
54 [](char d1, char d2, char d3, char d4) { Serial.print(d1); Serial.print(d2); Serial.print(d3); Serial.println(d4); },
55 WIDGET_LIST(pinChars, strlen(pinChars), 2, "%c", 0, true),
56 WIDGET_LIST(pinChars, strlen(pinChars), 6, "%c", 0, true),
57 WIDGET_LIST(pinChars, strlen(pinChars), 10, "%c", 0, true),
58 WIDGET_LIST(pinChars, strlen(pinChars), 14, "%c", 0, true)));
59
60LiquidCrystal_I2C lcd(LCD_ADDR, LCD_COLS, LCD_ROWS);
61LiquidCrystal_I2CAdapter lcdAdapter(&lcd);
62CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS);
63LcdMenu menu(renderer);
64KeyboardAdapter keyboard(&menu, &Serial);
65
66void setup() {
67 Serial.begin(9600);
68 renderer.begin();
69 menu.setScreen(mainScreen);
70 lcd.createChar(2, plusMinus);
71 lcd.createChar(3, euro);
72}
73
74void loop() {
75 keyboard.observe();
76}