diff --git a/examples/ButtonWithRotaryAdapter/ButtonWithRotaryAdapter.ino b/examples/ButtonWithRotaryAdapter/ButtonWithRotaryAdapter.ino index 789d2978..235a47ef 100644 --- a/examples/ButtonWithRotaryAdapter/ButtonWithRotaryAdapter.ino +++ b/examples/ButtonWithRotaryAdapter/ButtonWithRotaryAdapter.ino @@ -3,8 +3,8 @@ #include #include -#include #include +#include #include #include #include @@ -12,21 +12,25 @@ #include #include #include +#include #define LCD_ROWS 2 #define LCD_COLS 16 // Declare the callbacks -void colorsCallback(uint8_t pos); void toggleBacklight(bool isOn); void inputCallback(char* value); -String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; +static const char* colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; +static const uint8_t COLORS_COUNT = sizeof(colors) / sizeof(colors[0]); // clang-format off MENU_SCREEN(mainScreen, mainItems, ITEM_INPUT_CHARSET("User", (const char*)"ABCDEFGHIJKLMNOPQRSTUVWXYZ", inputCallback), - ITEM_STRING_LIST("Color", colors, 8, colorsCallback), + ITEM_WIDGET( + "Color", + [](const char* color) { Serial.println(color); }, + WIDGET_LIST(colors, COLORS_COUNT, 0, "%s")), ITEM_TOGGLE("Backlight", toggleBacklight), ITEM_BASIC("Placeholder 1"), ITEM_BASIC("Placeholder 2")); @@ -58,10 +62,6 @@ void toggleBacklight(bool isOn) { lcdAdapter.setBacklight(isOn); } -void colorsCallback(uint8_t pos) { - Serial.println(colors[pos]); -} - void inputCallback(char* value) { Serial.println(value); } \ No newline at end of file diff --git a/examples/IntFloatValues/IntFloatValues.ino b/examples/IntFloatValues/IntFloatValues.ino index 765c8ff3..f49198a1 100644 --- a/examples/IntFloatValues/IntFloatValues.ino +++ b/examples/IntFloatValues/IntFloatValues.ino @@ -1,10 +1,10 @@ -#include -#include +#include #include #include #include #include #include +#include #define LCD_ROWS 2 #define LCD_COLS 16 @@ -17,8 +17,14 @@ void callbackFloat(float value); // clang-format off MENU_SCREEN(mainScreen, mainItems, ITEM_BASIC("Con"), - ITEM_INT_RANGE("Dist", 100, 200, 100, callbackInt, "%02dm"), - ITEM_FLOAT_RANGE("Curr", -1.0f, 1.0f, -1.0f, callbackFloat, "%.2fmA", 0.01f), + ITEM_WIDGET( + "Dist", + callbackInt, + WIDGET_RANGE(100, 1, 100, 200, "%dm", 1)), + ITEM_WIDGET( + "Curr", + callbackFloat, + WIDGET_RANGE(-1.0f, 0.01f, -1.0f, 1.0f, "%.2fmA", 2)), ITEM_BASIC("Blink SOS"), ITEM_BASIC("Blink random")); // clang-format on diff --git a/examples/List/List.ino b/examples/List/List.ino index cd1fe327..3d90027c 100644 --- a/examples/List/List.ino +++ b/examples/List/List.ino @@ -1,33 +1,32 @@ -#include +#include #include #include #include #include #include +#include #define LCD_ROWS 2 #define LCD_COLS 16 -// Declare the callbacks -void colorsCallback(uint8_t pos); -void numsCallback(uint8_t pos); +static const char* colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; +static const uint8_t nums[] = {5, 7, 9, 12, 32}; -// Declare the array -extern String colors[]; -// Initialize the array -String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; - -// Declare the array -extern String nums[]; -// Initialize the array -String nums[] = {"5", "7", "9", "12", "32"}; +static const uint8_t NUMS_COUNT = sizeof(nums) / sizeof(nums[0]); +static const uint8_t COLORS_COUNT = sizeof(colors) / sizeof(colors[0]); // Initialize the main menu items // clang-format off MENU_SCREEN(mainScreen, mainItems, ITEM_BASIC("List demo"), - ITEM_STRING_LIST("Col", colors, 8, colorsCallback), - ITEM_STRING_LIST("Num", nums, 5, numsCallback), + ITEM_WIDGET( + "Color", + [](const char* color) { Serial.println(color); }, + WIDGET_LIST(colors, COLORS_COUNT, 0, "%s", 0, true)), + ITEM_WIDGET( + "Num", + [](const uint8_t num) { Serial.println(num); }, + WIDGET_LIST(nums, NUMS_COUNT, 0, "%d", 0, true)), ITEM_BASIC("Example")); // clang-format on @@ -45,15 +44,4 @@ void setup() { void loop() { keyboard.observe(); -} - -// Define the callbacks -void colorsCallback(uint8_t pos) { - // do something with the index - Serial.println(colors[pos]); -} - -void numsCallback(uint8_t pos) { - // do something with the index - Serial.println(nums[pos]); } \ No newline at end of file diff --git a/examples/SimpleRotary/SimpleRotary.ino b/examples/SimpleRotary/SimpleRotary.ino index 0719311a..b411f1c8 100644 --- a/examples/SimpleRotary/SimpleRotary.ino +++ b/examples/SimpleRotary/SimpleRotary.ino @@ -1,29 +1,37 @@ -#include #include #include +#include #include #include #include #include #include #include +#include +#include #define LCD_ROWS 2 #define LCD_COLS 16 // Declare the callbacks void callback(int pos); -void colorsCallback(uint8_t pos); void toggleBacklight(bool isOn); -String colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; +static const char* colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"}; +static const uint8_t COLORS_COUNT = sizeof(colors) / sizeof(colors[0]); // clang-format off MENU_SCREEN(mainScreen, mainItems, ITEM_BASIC("Connect to WiFi"), - ITEM_STRING_LIST("Color", colors, 8, colorsCallback), + ITEM_WIDGET( + "Color", + [](const char* color) { Serial.println(color); }, + WIDGET_LIST(colors, COLORS_COUNT, 0, "%s")), ITEM_BASIC("Blink SOS"), - ITEM_INT_RANGE("Dist", 0, 50, 0, callback, "%dm"), + ITEM_WIDGET( + "Dist", + callback, + WIDGET_RANGE(0, 1, 0, 50, "%dm", 1, true)), ITEM_TOGGLE("Backlight", toggleBacklight), ITEM_BASIC("Blink random")); // clang-format on @@ -51,7 +59,3 @@ void toggleBacklight(bool isOn) { void callback(int pos) { Serial.println(pos); } - -void colorsCallback(uint8_t pos) { - Serial.println(colors[pos]); -} \ No newline at end of file diff --git a/src/ItemList.h b/src/ItemList.h index ab306e80..b0666973 100644 --- a/src/ItemList.h +++ b/src/ItemList.h @@ -3,6 +3,8 @@ #include "LcdMenu.h" #include "MenuItem.h" +// clang-format off + /** * @class ItemList * @brief A class representing a list of items in a menu. @@ -29,6 +31,7 @@ class ItemList : public MenuItem { * @param callback A pointer to the callback function to execute when * this menu item is selected. */ + [[deprecated("ItemList is deprecated and will be removed in future versions. Please use ITEM_WIDGET with WIDGET_LIST")]] ItemList(const char* key, String* items, const uint8_t itemCount, fptruInt callback) : MenuItem(key), callback(callback), items(items), itemCount(itemCount) {} diff --git a/src/ItemRangeBase.h b/src/ItemRangeBase.h index 6015e10b..f7747bb6 100644 --- a/src/ItemRangeBase.h +++ b/src/ItemRangeBase.h @@ -5,6 +5,8 @@ #include "MenuItem.h" #include +// clang-format off + template /** * @brief Item that allows user to select a value from a range. @@ -44,6 +46,7 @@ class ItemRangeBase : public MenuItem { * @param step The step value for increment/decrement. * @param commitOnChange If true, the callback will be called every time the value changes. */ + [[deprecated("ItemRangeBase is deprecated and will be removed in future versions. Please use ITEM_WIDGET with WIDGET_RANGE")]] ItemRangeBase( const char* text, const T min, diff --git a/test/IntFloatValues.test.yml b/test/IntFloatValues.test.yml index beddc022..97775b76 100644 --- a/test/IntFloatValues.test.yml +++ b/test/IntFloatValues.test.yml @@ -1,4 +1,4 @@ -name: ItemRangeBase Test +name: WidgetRange Test version: 1 author: Thomas Forntoh steps: @@ -6,36 +6,36 @@ steps: - simulate: downButton-press - wait-serial: "#LOG# MenuScreen::down=1" - simulate: enterButton-press - - wait-serial: "#LOG# ItemRangeBase::enterEditMode=100" + - wait-serial: "#LOG# ItemWidget::enterEditMode=Dist" - simulate: upButton-press - - wait-serial: "#LOG# ItemRangeBase::increment=101" + - wait-serial: "#LOG# WidgetRange::increment=101" - simulate: upButton-press - - wait-serial: "#LOG# ItemRangeBase::increment=102" + - wait-serial: "#LOG# WidgetRange::increment=102" - simulate: upButton-press - - wait-serial: "#LOG# ItemRangeBase::increment=103" + - wait-serial: "#LOG# WidgetRange::increment=103" - simulate: downButton-press - - wait-serial: "#LOG# ItemRangeBase::decrement=102" + - wait-serial: "#LOG# WidgetRange::decrement=102" - simulate: downButton-press - - wait-serial: "#LOG# ItemRangeBase::decrement=101" + - wait-serial: "#LOG# WidgetRange::decrement=101" - simulate: backButton-press - - wait-serial: "#LOG# ItemRangeBase::exitEditMode=101" + - wait-serial: "#LOG# ItemWidget::exitEditMode=Dist" - simulate: downButton-press - wait-serial: "#LOG# MenuScreen::down=2" - simulate: enterButton-press - - wait-serial: "#LOG# ItemRangeBase::enterEditMode=-1.00" + - wait-serial: "#LOG# ItemWidget::enterEditMode=Curr" - simulate: upButton-press - - wait-serial: "#LOG# ItemRangeBase::increment=-0.99" + - wait-serial: "#LOG# WidgetRange::increment=-0.99" - simulate: upButton-press - - wait-serial: "#LOG# ItemRangeBase::increment=-0.98" + - wait-serial: "#LOG# WidgetRange::increment=-0.98" - simulate: upButton-press - - wait-serial: "#LOG# ItemRangeBase::increment=-0.97" + - wait-serial: "#LOG# WidgetRange::increment=-0.97" - simulate: upButton-press - - wait-serial: "#LOG# ItemRangeBase::increment=-0.96" + - wait-serial: "#LOG# WidgetRange::increment=-0.96" - simulate: downButton-press - - wait-serial: "#LOG# ItemRangeBase::decrement=-0.97" + - wait-serial: "#LOG# WidgetRange::decrement=-0.97" - simulate: downButton-press - - wait-serial: "#LOG# ItemRangeBase::decrement=-0.98" + - wait-serial: "#LOG# WidgetRange::decrement=-0.98" - simulate: backButton-press - - wait-serial: "#LOG# ItemRangeBase::exitEditMode=-0.98" + - wait-serial: "#LOG# ItemWidget::exitEditMode=Curr" - simulate: downButton-press - wait-serial: "#LOG# MenuScreen::down=3" diff --git a/test/List.test.yml b/test/List.test.yml index 78ce0b93..2eaf1236 100644 --- a/test/List.test.yml +++ b/test/List.test.yml @@ -6,28 +6,28 @@ steps: - simulate: downButton-press - wait-serial: "#LOG# MenuScreen::down=1" - simulate: enterButton-press - - wait-serial: "#LOG# ItemList::enterEditMode=Red" + - wait-serial: "#LOG# ItemWidget::enterEditMode=Color" - simulate: upButton-press - - wait-serial: "#LOG# ItemList::selectNext=Green" + - wait-serial: "#LOG# WidgetList::nextValue=Green" - simulate: upButton-press - - wait-serial: "#LOG# ItemList::selectNext=Blue" + - wait-serial: "#LOG# WidgetList::nextValue=Blue" - simulate: upButton-press - - wait-serial: "#LOG# ItemList::selectNext=Orange" + - wait-serial: "#LOG# WidgetList::nextValue=Orange" - simulate: backButton-press - - wait-serial: "#LOG# ItemList::exitEditMode=Orange" + - wait-serial: "#LOG# ItemWidget::exitEditMode=Color" - simulate: downButton-press - wait-serial: "#LOG# MenuScreen::down=2" - simulate: enterButton-press - - wait-serial: "#LOG# ItemList::enterEditMode=5" + - wait-serial: "#LOG# ItemWidget::enterEditMode=Num" - simulate: downButton-press - - wait-serial: "#LOG# ItemList::selectPrevious=32" + - wait-serial: "#LOG# WidgetList::previousValue=32" - simulate: downButton-press - - wait-serial: "#LOG# ItemList::selectPrevious=12" + - wait-serial: "#LOG# WidgetList::previousValue=12" - simulate: upButton-press - - wait-serial: "#LOG# ItemList::selectNext=32" + - wait-serial: "#LOG# WidgetList::nextValue=32" - simulate: upButton-press - - wait-serial: "#LOG# ItemList::selectNext=5" + - wait-serial: "#LOG# WidgetList::nextValue=5" - simulate: upButton-press - - wait-serial: "#LOG# ItemList::selectNext=7" + - wait-serial: "#LOG# WidgetList::nextValue=7" - simulate: backButton-press - - wait-serial: "#LOG# ItemList::exitEditMode=7" + - wait-serial: "#LOG# ItemWidget::exitEditMode=Num"