From 4e122567c15e47b3b4b8f1806b7d26e40e02e278 Mon Sep 17 00:00:00 2001 From: forntoh Date: Tue, 29 Oct 2024 23:50:49 +0100 Subject: [PATCH 1/3] Add Widgets Example Sketch Include various widgets and custom characters for LCD menu. Set up main screen with different item widgets handling input and displaying data. --- examples/Widgets/Widgets.ino | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 examples/Widgets/Widgets.ino diff --git a/examples/Widgets/Widgets.ino b/examples/Widgets/Widgets.ino new file mode 100644 index 00000000..cb2477cb --- /dev/null +++ b/examples/Widgets/Widgets.ino @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LCD_ROWS 2 +#define LCD_COLS 16 + +// Custom characters +byte plusMinus[8] = {B00000, B00100, B01110, B00100, B00000, B01110, B00000, B00000}; // ± +byte euro[8] = {B00111, B01000, B11110, B01000, B11110, B01000, B00111, B00000}; // € + +const char* options[] = {"Buy", "Sell"}; +const char* days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; +const char* pinChars = "123456789ABCDEF"; + +MENU_SCREEN( + mainScreen, + mainItems, + ITEM_WIDGET( + "Auto", + [](const char* option, bool isAuto) { Serial.println(option); Serial.println(isAuto); }, + WIDGET_LIST(options, sizeof(options) / sizeof(options[0]), 0, "%s", 0, true), + WIDGET_BOOL(false, "Yes", "No", ",%s")), + ITEM_WIDGET( + "Price", + [](int price) { Serial.println(price); }, + WIDGET_RANGE(10, 5, 0, 1000, "%.1d\003", 1)), + ITEM_WIDGET( + "Quantity", + [](float quantity, int tollerance) { Serial.println(quantity); Serial.println(tollerance); }, + WIDGET_RANGE(1.0f, 0.1f, 0.1f, 100.0f, "%.1f", 0), + WIDGET_RANGE(10, 1, 0, 100, "\002%d%%", 1)), + ITEM_WIDGET( + "Freq", + [](int hour, int minute, const char* day) { Serial.println(hour); Serial.println(minute); Serial.println(day); }, + WIDGET_RANGE(0, 1, 0, 23, "%02d", 0, true), + WIDGET_RANGE(0, 1, 0, 59, ":%02d", 0, true), + WIDGET_LIST(days, sizeof(days) / sizeof(days[0]), 0, " on %s", 0, true)), + ITEM_WIDGET( + "Start", + [](int day, int month, int year) { Serial.println(day); Serial.println(month); Serial.println(year); }, + WIDGET_RANGE(1, 1, 1, 31, "%02d", 0, true), + WIDGET_RANGE(1, 1, 1, 12, "/%02d", 0, true), + WIDGET_RANGE(2021, 1, 2020, 2050, "/%04d", 0, true)), + ITEM_WIDGET( + "Pin", + [](char d1, char d2, char d3, char d4) { Serial.print(d1); Serial.print(d2); Serial.print(d3); Serial.println(d4); }, + WIDGET_LIST(pinChars, strlen(pinChars), 2, "%c", 0, true), + WIDGET_LIST(pinChars, strlen(pinChars), 6, "%c", 0, true), + WIDGET_LIST(pinChars, strlen(pinChars), 10, "%c", 0, true), + WIDGET_LIST(pinChars, strlen(pinChars), 14, "%c", 0, true))); + +LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +LiquidCrystal_I2CAdapter lcdAdapter(&lcd); +CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS); +LcdMenu menu(renderer); +KeyboardAdapter keyboard(&menu, &Serial); + +void setup() { + Serial.begin(9600); + renderer.begin(); + menu.setScreen(mainScreen); + lcd.createChar(2, plusMinus); + lcd.createChar(3, euro); +} + +void loop() { + keyboard.observe(); +} From bbb33470c6dbe436a2c82666b821c982131a6972 Mon Sep 17 00:00:00 2001 From: forntoh Date: Wed, 30 Oct 2024 00:12:56 +0100 Subject: [PATCH 2/3] Update tolerance widget to display correctly in Widgets example. - Fix tolerance spelling in Quantity widget lambda function - Change Freq widget ranges to not allow wrapping --- examples/Widgets/Widgets.ino | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/Widgets/Widgets.ino b/examples/Widgets/Widgets.ino index cb2477cb..fc2a432e 100644 --- a/examples/Widgets/Widgets.ino +++ b/examples/Widgets/Widgets.ino @@ -10,6 +10,7 @@ #define LCD_ROWS 2 #define LCD_COLS 16 +#define LCD_ADDR 0x27 // Custom characters byte plusMinus[8] = {B00000, B00100, B01110, B00100, B00000, B01110, B00000, B00000}; // ± @@ -17,7 +18,7 @@ byte euro[8] = {B00111, B01000, B11110, B01000, B11110, B01000, B00111, B00000}; const char* options[] = {"Buy", "Sell"}; const char* days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; -const char* pinChars = "123456789ABCDEF"; +const char pinChars[] = "123456789ABCDEF"; MENU_SCREEN( mainScreen, @@ -33,14 +34,14 @@ MENU_SCREEN( WIDGET_RANGE(10, 5, 0, 1000, "%.1d\003", 1)), ITEM_WIDGET( "Quantity", - [](float quantity, int tollerance) { Serial.println(quantity); Serial.println(tollerance); }, + [](float quantity, int tolerance) { Serial.println(quantity); Serial.println(tolerance); }, WIDGET_RANGE(1.0f, 0.1f, 0.1f, 100.0f, "%.1f", 0), WIDGET_RANGE(10, 1, 0, 100, "\002%d%%", 1)), ITEM_WIDGET( "Freq", [](int hour, int minute, const char* day) { Serial.println(hour); Serial.println(minute); Serial.println(day); }, - WIDGET_RANGE(0, 1, 0, 23, "%02d", 0, true), - WIDGET_RANGE(0, 1, 0, 59, ":%02d", 0, true), + WIDGET_RANGE(0, 1, 0, 23, "%02d", 0, false), + WIDGET_RANGE(0, 1, 0, 59, ":%02d", 0, false), WIDGET_LIST(days, sizeof(days) / sizeof(days[0]), 0, " on %s", 0, true)), ITEM_WIDGET( "Start", @@ -56,7 +57,7 @@ MENU_SCREEN( WIDGET_LIST(pinChars, strlen(pinChars), 10, "%c", 0, true), WIDGET_LIST(pinChars, strlen(pinChars), 14, "%c", 0, true))); -LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS); +LiquidCrystal_I2C lcd(LCD_ADDR, LCD_COLS, LCD_ROWS); LiquidCrystal_I2CAdapter lcdAdapter(&lcd); CharacterDisplayRenderer renderer(&lcdAdapter, LCD_COLS, LCD_ROWS); LcdMenu menu(renderer); From b33b2a84baefd4d8ffbddf7ebd7c1b33610897c8 Mon Sep 17 00:00:00 2001 From: forntoh Date: Wed, 30 Oct 2024 00:46:51 +0100 Subject: [PATCH 3/3] Add test steps for widget interactions and edits Added a new test file with detailed steps for simulating various widget interactions and edits. --- test/Widgets.test.yml | 166 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 test/Widgets.test.yml diff --git a/test/Widgets.test.yml b/test/Widgets.test.yml new file mode 100644 index 00000000..19c5a777 --- /dev/null +++ b/test/Widgets.test.yml @@ -0,0 +1,166 @@ +name: Widgets Test +version: 1 +author: Thomas Forntoh +steps: + - wait-serial: "#LOG# LcdMenu::setScreen" + - simulate: enterButton-press + - wait-serial: "#LOG# ItemWidget::enterEditMode=Auto" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=Sell" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=Buy" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetList::previousValue=Sell" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetList::previousValue=Buy" + - simulate: rightButton-press + - wait-serial: "#LOG# ItemWidget::right=1" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetToggle::toggle=1" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetToggle::toggle=0" + - simulate: enterButton-press + - wait-serial: "Buy" + - wait-serial: "0" + - wait-serial: "#LOG# ItemWidget::exitEditMode=Auto" + - simulate: downButton-press + - wait-serial: "#LOG# MenuScreen::down=1" + - simulate: enterButton-press + - wait-serial: "#LOG# ItemWidget::enterEditMode=Price" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=15" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=20" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=25" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=30" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=35" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=40" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetRange::decrement=35" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetRange::decrement=30" + - simulate: enterButton-press + - wait-serial: "30" + - wait-serial: "#LOG# ItemWidget::exitEditMode=Price" + - simulate: downButton-press + - wait-serial: "#LOG# MenuScreen::down=2" + - simulate: enterButton-press + - wait-serial: "#LOG# ItemWidget::enterEditMode=Quantity" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=1.10" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=1.20" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=1.30" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=1.40" + - simulate: rightButton-press + - wait-serial: "#LOG# ItemWidget::right=1" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=11" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=12" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=13" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetRange::decrement=12" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetRange::decrement=11" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetRange::decrement=10" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetRange::decrement=9" + - simulate: leftButton-press + - wait-serial: "#LOG# ItemWidget::left=0" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=1.50" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=1.60" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=1.70" + - simulate: rightButton-press + - wait-serial: "#LOG# ItemWidget::right=1" + - simulate: enterButton-press + - wait-serial: "1.70" + - wait-serial: "9" + - wait-serial: "#LOG# ItemWidget::exitEditMode=Quantity" + - simulate: downButton-press + - wait-serial: "#LOG# MenuScreen::down=3" + - simulate: enterButton-press + - wait-serial: "#LOG# ItemWidget::enterEditMode=Freq" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=1" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=2" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=3" + - simulate: rightButton-press + - wait-serial: "#LOG# ItemWidget::right=1" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=1" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=2" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=3" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=4" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetRange::increment=5" + - simulate: rightButton-press + - wait-serial: "#LOG# ItemWidget::right=2" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=Tue" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=Wed" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=Thu" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=Fri" + - simulate: enterButton-press + - wait-serial: "3" + - wait-serial: "5" + - wait-serial: "Fri" + - wait-serial: "#LOG# ItemWidget::exitEditMode=Freq" + - simulate: downButton-press + - wait-serial: "#LOG# MenuScreen::down=4" + - simulate: downButton-press + - wait-serial: "#LOG# MenuScreen::down=5" + - simulate: enterButton-press + - wait-serial: "#LOG# ItemWidget::enterEditMode=Pin" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=4" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=5" + - simulate: rightButton-press + - wait-serial: "#LOG# ItemWidget::right=1" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetList::previousValue=6" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetList::previousValue=5" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetList::previousValue=4" + - simulate: enterButton-press + - wait-serial: "#LOG# ItemWidget::right=2" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=C" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=D" + - simulate: enterButton-press + - wait-serial: "#LOG# ItemWidget::right=3" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=1" + - simulate: upButton-press + - wait-serial: "#LOG# WidgetList::nextValue=2" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetList::previousValue=1" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetList::previousValue=F" + - simulate: downButton-press + - wait-serial: "#LOG# WidgetList::previousValue=E" + - simulate: enterButton-press + - wait-serial: "54DE" + - wait-serial: "#LOG# ItemWidget::exitEditMode=Pin" \ No newline at end of file