1
0
mirror of https://github.com/s00500/ESPUI.git synced 2025-06-14 02:30:41 +00:00

Proper wrappers

- update order of params of create functions to be simillar
- changed all numbers to be numbers
- split pad creation function
- updated examples
This commit is contained in:
2019-03-24 19:18:53 +01:00
parent 650411bac4
commit 3c69f013fc
5 changed files with 319 additions and 307 deletions

View File

@ -407,35 +407,41 @@ uint16_t ESPUIClass::addControl(ControlType type, const char *label, String valu
return control->id;
}
int ESPUIClass::label(const char *label, ControlColor color, String value) { return addControl(ControlType::Label, label, value, color); }
uint16_t ESPUIClass::label(const char *label, ControlColor color, String value) { return addControl(ControlType::Label, label, value, color); }
int ESPUIClass::graph(const char *label, ControlColor color) { return addControl(ControlType::Graph, label, "", color); }
uint16_t ESPUIClass::graph(const char *label, ControlColor color) { return addControl(ControlType::Graph, label, "", color); }
int ESPUIClass::slider(const char *label, void (*callback)(Control *, int), ControlColor color, String value) {
return addControl(ControlType::Slider, label, "", color, Control::noParent, callback);
uint16_t ESPUIClass::slider(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);
addControl(ControlType::Min, label, String(min), ControlColor::None, sliderId);
addControl(ControlType::Max, label, String(max), ControlColor::None, sliderId);
return sliderId;
}
int ESPUIClass::button(const char *label, void (*callback)(Control *, int), ControlColor color, String value) {
uint16_t ESPUIClass::button(const char *label, void (*callback)(Control *, int), ControlColor color, String value) {
return addControl(ControlType::Button, label, value, color, Control::noParent, callback);
}
int ESPUIClass::switcher(const char *label, bool startState, void (*callback)(Control *, int), ControlColor color) {
return addControl(ControlType::Switcher, label, "", color, Control::noParent, callback);
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);
}
int ESPUIClass::pad(const char *label, bool center, void (*callback)(Control *, int), ControlColor color) {
if (center) {
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback);
} else {
return addControl(ControlType::Pad, label, "", color, Control::noParent, callback);
}
uint16_t ESPUIClass::pad(const char *label, void (*callback)(Control *, int), ControlColor color) {
return addControl(ControlType::Pad, label, "", color, Control::noParent, callback);
}
uint16_t ESPUIClass::padWithCenter(const char *label, void (*callback)(Control *, int), ControlColor color) {
return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback);
}
int ESPUIClass::number(const char *label, void (*callback)(Control *, int), ControlColor color, int number, int min, int max) {
return addControl(ControlType::Number, label, String(number), color, Control::noParent, callback);
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);
addControl(ControlType::Min, label, String(min), ControlColor::None, numberId);
addControl(ControlType::Max, label, String(max), ControlColor::None, numberId);
return numberId;
}
int ESPUIClass::text(const char *label, void (*callback)(Control *, int), ControlColor color, String value) {
uint16_t ESPUIClass::text(const char *label, void (*callback)(Control *, int), ControlColor color, String value) {
return addControl(ControlType::Text, label, value, color, Control::noParent, callback);
}
@ -522,7 +528,7 @@ void ESPUIClass::updateControlValue(uint16_t id, String value, int clientId) {
Control *control = getControl(id);
if (control) {
updateControl(control, value, clientId);
updateControlValue(control, value, clientId);
} else {
if (this->verbosity) {
Serial.println(String("Error: There is no control with ID ") + String(id));

View File

@ -174,16 +174,20 @@ public:
uint16_t parentControl = Control::noParent, void (*callback)(Control *, int) = nullptr);
// create Elements
int button(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create Event Button
int switcher(const char *label, bool startState, void (*callback)(Control *, int), ControlColor color); // Create Toggle Button
int pad(const char *label, bool centerButton, void (*callback)(Control *, int), ControlColor color); // Create Pad Control
int slider(const char *label, void (*callback)(Control *, int), ControlColor color, String value); // Create Slider Control
int number(const char *label, void (*callback)(Control *, int), ControlColor color, int number, int min, int max); // Create a Number Input Control
int text(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create a Text Input Control
uint16_t button(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create Event Button
uint16_t switcher(const char *label, void (*callback)(Control *, int), ControlColor color, 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,
int max = 100); // 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 text(const char *label, void (*callback)(Control *, int), ControlColor color, String value = ""); // Create a Text Input Control
// Output only
int label(const char *label, ControlColor color, String value = ""); // Create Label
int graph(const char *label, ControlColor color); // Create Graph display
uint16_t label(const char *label, ControlColor color, String value = ""); // Create Label
uint16_t graph(const char *label, ControlColor color); // Create Graph display
// Update Elements
@ -191,7 +195,6 @@ public:
// Update Elements
void updateControlValue(uint16_t id, String value, int clientId = -1);
void updateControlValue(uint16_t id, String value, int clientId = -1);
void updateControlValue(Control *control, String value, int clientId = -1);
void updateControl(uint16_t id, int clientId = -1);