Skip to content

Commit

Permalink
Update color and number lists to dynamically determine array sizes.
Browse files Browse the repository at this point in the history
- Define constants for the count of colors and numbers in each list.
- Modify code to use these constants for array sizes instead of hardcoding values.
  • Loading branch information
forntoh committed Oct 28, 2024
1 parent 7dcb67f commit 1959101
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/ButtonWithRotaryAdapter/ButtonWithRotaryAdapter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ void toggleBacklight(bool isOn);
void inputCallback(char* value);

const char* colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
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_WIDGET(
"Color",
[](const char* color) { Serial.println(color); },
WIDGET_LIST(colors, 8, 0, "%s")),
WIDGET_LIST(colors, COLORS_COUNT, 0, "%s")),
ITEM_TOGGLE("Backlight", toggleBacklight),
ITEM_BASIC("Placeholder 1"),
ITEM_BASIC("Placeholder 2"));
Expand Down
7 changes: 5 additions & 2 deletions examples/List/List.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@
const char* colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
const char* nums[] = {"5", "7", "9", "12", "32"};

const uint8_t NUMS_COUNT = sizeof(nums) / sizeof(nums[0]);
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_WIDGET(
"Color",
[](const char* color) { Serial.println(color); },
WIDGET_LIST(colors, 8, 0, "%s")),
WIDGET_LIST(colors, COLORS_COUNT, 0, "%s")),
ITEM_WIDGET(
"Num",
[](const char* num) { Serial.println(num); },
WIDGET_LIST(nums, 5, 0, "%s")),
WIDGET_LIST(nums, NUMS_COUNT, 0, "%s")),
ITEM_BASIC("Example"));
// clang-format on

Expand Down
3 changes: 2 additions & 1 deletion examples/SimpleRotary/SimpleRotary.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ void callback(int pos);
void toggleBacklight(bool isOn);

const char* colors[] = {"Red", "Green", "Blue", "Orange", "Aqua", "Yellow", "Purple", "Pink"};
const uint8_t COLORS_COUNT = sizeof(colors) / sizeof(colors[0]);

// clang-format off
MENU_SCREEN(mainScreen, mainItems,
ITEM_BASIC("Connect to WiFi"),
ITEM_WIDGET(
"Color",
[](const char* color) { Serial.println(color); },
WIDGET_LIST(colors, 8, 0, "%s")),
WIDGET_LIST(colors, COLORS_COUNT, 0, "%s")),
ITEM_BASIC("Blink SOS"),
ITEM_INT_RANGE("Dist", 0, 50, 0, callback, "%dm"),
ITEM_TOGGLE("Backlight", toggleBacklight),
Expand Down

0 comments on commit 1959101

Please sign in to comment.