1
0
mirror of https://github.com/s00500/ESPUI.git synced 2024-11-21 22:50:55 +00:00

Updated the rest of the callback functions to support the new UserData parameter

This commit is contained in:
Martin Mueller 2022-06-11 01:20:25 -04:00
parent 02e847a31e
commit 1419b2dec0
2 changed files with 72 additions and 25 deletions

View File

@ -704,10 +704,16 @@ uint16_t ESPUIClass::graph(const char* label, ControlColor color)
return addControl(ControlType::Graph, label, "", color); return addControl(ControlType::Graph, label, "", color);
} }
uint16_t ESPUIClass::slider( uint16_t ESPUIClass::slider(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min, int max)
const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min, int max)
{ {
uint16_t sliderId = addControl(ControlType::Slider, label, String(value), color, Control::noParent, callback); uint16_t id = slider(label, nullptr, color, value, min, max, nullptr);
getControl(id)->callback = callback;
return id;
}
uint16_t ESPUIClass::slider(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int value, int min, int max, void* userData)
{
uint16_t sliderId = addControl(ControlType::Slider, label, String(value), color, Control::noParent, callback, userData);
addControl(ControlType::Min, label, String(min), ControlColor::None, sliderId); addControl(ControlType::Min, label, String(min), ControlColor::None, sliderId);
addControl(ControlType::Max, label, String(max), ControlColor::None, sliderId); addControl(ControlType::Max, label, String(max), ControlColor::None, sliderId);
@ -719,22 +725,42 @@ uint16_t ESPUIClass::button(const char* label, void (*callback)(Control*, int),
return addControl(ControlType::Button, label, value, color, Control::noParent, callback); return addControl(ControlType::Button, label, value, color, Control::noParent, callback);
} }
uint16_t ESPUIClass::button(const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData)
{
return addControl(ControlType::Button, label, value, color, Control::noParent, callback, UserData);
}
uint16_t ESPUIClass::switcher(const char* label, void (*callback)(Control*, int), ControlColor color, bool startState) uint16_t ESPUIClass::switcher(const char* label, void (*callback)(Control*, int), ControlColor color, bool startState)
{ {
return addControl(ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback); return addControl(ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback);
} }
uint16_t ESPUIClass::switcher(const char* label, void (*callback)(Control*, int, void*), ControlColor color, bool startState, void* UserData)
{
return addControl(ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback, UserData);
}
uint16_t ESPUIClass::pad(const char* label, void (*callback)(Control*, int), ControlColor color) uint16_t ESPUIClass::pad(const char* label, void (*callback)(Control*, int), ControlColor color)
{ {
return addControl(ControlType::Pad, label, "", color, Control::noParent, callback); return addControl(ControlType::Pad, label, "", color, Control::noParent, callback);
} }
uint16_t ESPUIClass::pad(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
{
return addControl(ControlType::Pad, label, "", color, Control::noParent, callback, UserData);
}
uint16_t ESPUIClass::padWithCenter(const char* label, void (*callback)(Control*, int), ControlColor color) uint16_t ESPUIClass::padWithCenter(const char* label, void (*callback)(Control*, int), ControlColor color)
{ {
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback); return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback);
} }
uint16_t ESPUIClass::number( uint16_t ESPUIClass::padWithCenter(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
const char* label, void (*callback)(Control*, int), ControlColor color, int number, int min, int max) {
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback, UserData);
}
uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int), ControlColor color, int number, int min, int max)
{ {
uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback); uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback);
addControl(ControlType::Min, label, String(min), ControlColor::None, numberId); addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);
@ -742,6 +768,14 @@ uint16_t ESPUIClass::number(
return numberId; return numberId;
} }
uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int number, int min, int max, void* UserData)
{
uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback, UserData);
addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);
addControl(ControlType::Max, label, String(max), ControlColor::None, numberId);
return numberId;
}
uint16_t ESPUIClass::gauge(const char* label, ControlColor color, int number, int min, int max) uint16_t ESPUIClass::gauge(const char* label, ControlColor color, int number, int min, int max)
{ {
uint16_t numberId = addControl(ControlType::Gauge, label, String(number), color, Control::noParent); uint16_t numberId = addControl(ControlType::Gauge, label, String(number), color, Control::noParent);
@ -759,11 +793,21 @@ uint16_t ESPUIClass::accelerometer(const char* label, void (*callback)(Control*,
return addControl(ControlType::Accel, label, "", color, Control::noParent, callback); return addControl(ControlType::Accel, label, "", color, Control::noParent, callback);
} }
uint16_t ESPUIClass::accelerometer(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData)
{
return addControl(ControlType::Accel, label, "", color, Control::noParent, callback, UserData);
}
uint16_t ESPUIClass::text(const char* label, void (*callback)(Control*, int), ControlColor color, const String& value) uint16_t ESPUIClass::text(const char* label, void (*callback)(Control*, int), ControlColor color, const String& value)
{ {
return addControl(ControlType::Text, label, value, color, Control::noParent, callback); return addControl(ControlType::Text, label, value, color, Control::noParent, callback);
} }
uint16_t ESPUIClass::text(const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData)
{
return addControl(ControlType::Text, label, value, color, Control::noParent, callback, UserData);
}
Control* ESPUIClass::getControl(uint16_t id) Control* ESPUIClass::getControl(uint16_t id)
{ {
Control* control = this->controls; Control* control = this->controls;
@ -897,7 +941,6 @@ void ESPUIClass::setEnabled(uint16_t id, bool enabled, int clientId) {
} }
} }
void ESPUIClass::setVertical(uint16_t id, bool vert) { void ESPUIClass::setVertical(uint16_t id, bool vert) {
Control* control = getControl(id); Control* control = getControl(id);
if (control) if (control)

View File

@ -153,11 +153,8 @@ public:
static constexpr uint16_t noParent = 0xffff; static constexpr uint16_t noParent = 0xffff;
Control( Control(ControlType type, const char* label, void (*callback)(Control*, int, void*), void* UserData,
ControlType type, const String& value, ControlColor color, bool visible, uint16_t parentControl)
const char* label,
void (*callback)(Control*, int, void*),
void* UserData, const String& value, ControlColor color, bool visible, uint16_t parentControl)
: type(type), : type(type),
label(label), label(label),
callback(nullptr), callback(nullptr),
@ -262,21 +259,27 @@ public:
bool removeControl(uint16_t id, bool force_reload_ui = false); bool removeControl(uint16_t id, bool force_reload_ui = false);
// create Elements // create Elements
uint16_t button(const char* label, void (*callback)(Control*, int), ControlColor color, // Create Event Button
const String& value = ""); // Create Event Button uint16_t button(const char* label, void (*callback)(Control*, int), ControlColor color, const String& value = "");
uint16_t switcher(const char* label, void (*callback)(Control*, int), ControlColor color, uint16_t button(const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData);
bool startState = false); // Create Toggle Button
uint16_t pad(const char* label, void (*callback)(Control*, int),
ControlColor color); // Create Pad Control
uint16_t padWithCenter(const char* label, void (*callback)(Control*, int),
ControlColor color); // Create Pad Control with Centerbutton
uint16_t slider(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min = 0, uint16_t switcher(const char* label, void (*callback)(Control*, int), ControlColor color, bool startState = false); // Create Toggle Button
int max = 100); // Create Slider Control uint16_t switcher(const char* label, void (*callback)(Control*, int, void*), ControlColor color, bool startState, void* UserData); // Create Toggle Button
uint16_t number(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min = 0,
int max = 100); // Create a Number Input Control uint16_t pad(const char* label, void (*callback)(Control*, int), ControlColor color); // Create Pad Control
uint16_t text(const char* label, void (*callback)(Control*, int), ControlColor color, uint16_t pad(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData); // Create Pad Control
const String& value = ""); // Create a Text Input Control
uint16_t padWithCenter(const char* label, void (*callback)(Control*, int), ControlColor color); // Create Pad Control with Centerbutton
uint16_t padWithCenter(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData); // Create Pad Control with Centerbutton
uint16_t slider(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min = 0, int max = 100); // Create Slider Control
uint16_t slider(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int value, int min, int max, void* UserData); // Create Slider Control
uint16_t number(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min = 0, int max = 100); // Create a Number Input Control
uint16_t number(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int value, int min, int max, void* UserData); // Create a Number Input Control
uint16_t text(const char* label, void (*callback)(Control*, int), ControlColor color, const String& value = ""); // Create a Text Input Control
uint16_t text(const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData); // Create a Text Input Control
// Output only // Output only
uint16_t label(const char* label, ControlColor color, uint16_t label(const char* label, ControlColor color,
@ -288,6 +291,7 @@ public:
// Input only // Input only
uint16_t accelerometer(const char* label, void (*callback)(Control*, int), ControlColor color); uint16_t accelerometer(const char* label, void (*callback)(Control*, int), ControlColor color);
uint16_t accelerometer(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData);
// Update Elements // Update Elements