Unable to set value to RangeWidget #309
-
|
Hello, iam doing school project and iam mostly done with LCD screen and control. But for last 5 hours iam trying to find how to save and load default values in/from EEPROM for first WIDGET_RANGE, and WIDGET_RANGE in second line, that are inside ITEM_WIDGET Error from this approach is: Compilation error: invalid use of template-name 'ItemWidget' without an argument list |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I struggled with the same problem. ITEM_WIDGET is a class template and the class should be created with the type in angle brackets. The method to set the values of ITEM_WIDGET is ItemWidget<int>* widget_ptr;
int brightness;
void brightness_callback(const int& value);
MENU_SCREEN(main_screen, main_items,
ITEM_WIDGET(
"Brightness", nullptr,
WIDGET_RANGE(brightness, 16, 0, 256, "%u", 0, true, brightness_callback)));
void setup() {
brightness = 128;
pinMode(LCD_BACKLIGHT, OUTPUT);
analogWrite(LCD_BACKLIGHT, brightness);
renderer.begin();
menu.setScreen(main_screen);
widget_ptr = static_cast<ItemWidget<int>*>(main_screen->getItemAt(0));
widget_ptr->setValues(brightness);
menu.refresh();
}
void brightness_callback(const int& value) {
// the maximum value of PWM is 255
brightness = min(value, 255);
analogWrite(LCD_BACKLIGHT, brightness);
} |
Beta Was this translation helpful? Give feedback.
Hi, you can use assign
ITEM_WIDGETdirectly to variable:Also note that both
ItemandWidgethave callbacks and for this example they have same signature and may be confising.The item's callback behaves as