Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Widgets Example Sketch #262

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions examples/Widgets/Widgets.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <ItemWidget.h>
#include <LcdMenu.h>
#include <MenuScreen.h>
#include <display/LiquidCrystal_I2CAdapter.h>
#include <input/KeyboardAdapter.h>
#include <renderer/CharacterDisplayRenderer.h>
#include <widget/WidgetBool.h>
#include <widget/WidgetList.h>
#include <widget/WidgetRange.h>

#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}; // ±
byte euro[8] = {B00111, B01000, B11110, B01000, B11110, B01000, B00111, B00000}; // €

forntoh marked this conversation as resolved.
Show resolved Hide resolved
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)),
forntoh marked this conversation as resolved.
Show resolved Hide resolved
ITEM_WIDGET(
"Quantity",
[](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, 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",
[](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)));
forntoh marked this conversation as resolved.
Show resolved Hide resolved

LiquidCrystal_I2C lcd(LCD_ADDR, 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();
}
166 changes: 166 additions & 0 deletions test/Widgets.test.yml
Original file line number Diff line number Diff line change
@@ -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"
forntoh marked this conversation as resolved.
Show resolved Hide resolved
- 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"
forntoh marked this conversation as resolved.
Show resolved Hide resolved
- 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"
forntoh marked this conversation as resolved.
Show resolved Hide resolved
- 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"
forntoh marked this conversation as resolved.
Show resolved Hide resolved
forntoh marked this conversation as resolved.
Show resolved Hide resolved
Loading