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

Use const String& to reduce IROM usage

This commit is contained in:
Moritz Wirger 2020-09-14 11:59:35 +02:00
parent 99cf344d93
commit bfd645d7a1
2 changed files with 21 additions and 21 deletions

View File

@ -500,7 +500,7 @@ void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventTyp
} }
} }
uint16_t ESPUIClass::addControl(ControlType type, const char *label, String value, ControlColor color, uint16_t parentControl, uint16_t ESPUIClass::addControl(ControlType type, const char *label, const String& value, ControlColor color, uint16_t parentControl,
void (*callback)(Control *, int)) void (*callback)(Control *, int))
{ {
Control *control = new Control(type, label, callback, value, color, parentControl); Control *control = new Control(type, label, callback, value, color, parentControl);
@ -571,7 +571,7 @@ bool ESPUIClass::removeControl(uint16_t id, bool force_reload_ui)
return false; return false;
} }
uint16_t 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, const String& value) { return addControl(ControlType::Label, label, value, color); }
uint16_t 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); }
@ -584,7 +584,7 @@ uint16_t ESPUIClass::slider(const char *label, void (*callback)(Control *, int),
return sliderId; return sliderId;
} }
uint16_t 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, const String& value)
{ {
return addControl(ControlType::Button, label, value, color, Control::noParent, callback); return addControl(ControlType::Button, label, value, color, Control::noParent, callback);
} }
@ -624,7 +624,7 @@ 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::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, const String& value)
{ {
return addControl(ControlType::Text, label, value, color, Control::noParent, callback); return addControl(ControlType::Text, label, value, color, Control::noParent, callback);
} }
@ -713,7 +713,7 @@ void ESPUIClass::updateControl(uint16_t id, int clientId)
updateControl(control, clientId); updateControl(control, clientId);
} }
void ESPUIClass::updateControlValue(Control *control, String value, int clientId) void ESPUIClass::updateControlValue(Control *control, const String& value, int clientId)
{ {
if (!control) if (!control)
{ {
@ -724,7 +724,7 @@ void ESPUIClass::updateControlValue(Control *control, String value, int clientId
updateControl(control, clientId); updateControl(control, clientId);
} }
void ESPUIClass::updateControlValue(uint16_t id, String value, int clientId) void ESPUIClass::updateControlValue(uint16_t id, const String& value, int clientId)
{ {
Control *control = getControl(id); Control *control = getControl(id);
@ -740,9 +740,9 @@ void ESPUIClass::updateControlValue(uint16_t id, String value, int clientId)
updateControlValue(control, value, clientId); updateControlValue(control, value, clientId);
} }
void ESPUIClass::print(uint16_t id, String value) { updateControlValue(id, value); } void ESPUIClass::print(uint16_t id, const String& value) { updateControlValue(id, value); }
void ESPUIClass::updateLabel(uint16_t id, String value) { updateControlValue(id, value); } void ESPUIClass::updateLabel(uint16_t id, const String& value) { updateControlValue(id, value); }
void ESPUIClass::updateSlider(uint16_t id, int nValue, int clientId) { updateControlValue(id, String(nValue), clientId); } void ESPUIClass::updateSlider(uint16_t id, int nValue, int clientId) { updateControlValue(id, String(nValue), clientId); }
@ -750,9 +750,9 @@ void ESPUIClass::updateSwitcher(uint16_t id, bool nValue, int clientId) { update
void ESPUIClass::updateNumber(uint16_t id, int number, int clientId) { updateControlValue(id, String(number), clientId); } void ESPUIClass::updateNumber(uint16_t id, int number, int clientId) { updateControlValue(id, String(number), clientId); }
void ESPUIClass::updateText(uint16_t id, String text, int clientId) { updateControlValue(id, text, clientId); } void ESPUIClass::updateText(uint16_t id, const String& text, int clientId) { updateControlValue(id, text, clientId); }
void ESPUIClass::updateSelect(uint16_t id, String text, int clientId) { updateControlValue(id, text, clientId); } void ESPUIClass::updateSelect(uint16_t id, const String& text, int clientId) { updateControlValue(id, text, clientId); }
void ESPUIClass::updateGauge(uint16_t id, int number, int clientId) { updateControlValue(id, String(number), clientId); } void ESPUIClass::updateGauge(uint16_t id, int number, int clientId) { updateControlValue(id, String(number), clientId); }

View File

@ -140,7 +140,7 @@ public:
static constexpr uint16_t noParent = 0xffff; static constexpr uint16_t noParent = 0xffff;
Control(ControlType type, const char *label, void (*callback)(Control *, int), String value, ControlColor color, Control(ControlType type, const char *label, void (*callback)(Control *, int), const String& value, ControlColor color,
uint16_t parentControl = Control::noParent) uint16_t parentControl = Control::noParent)
: type(type), label(label), callback(callback), value(value), color(color), parentControl(parentControl), next(nullptr) : type(type), label(label), callback(callback), value(value), color(color), parentControl(parentControl), next(nullptr)
{ {
@ -206,11 +206,11 @@ public:
void prepareFileSystem(); // Initially preps the filesystem and loads a lot of stuff into SPIFFS void prepareFileSystem(); // Initially preps the filesystem and loads a lot of stuff into SPIFFS
void list(); // Lists SPIFFS directory void list(); // Lists SPIFFS directory
uint16_t addControl(ControlType type, const char *label, String value = String(""), ControlColor color = ControlColor::Turquoise, uint16_t parentControl = Control::noParent, void (*callback)(Control *, int) = nullptr); uint16_t addControl(ControlType type, const char *label, const String& value = String(""), ControlColor color = ControlColor::Turquoise, uint16_t parentControl = Control::noParent, void (*callback)(Control *, int) = nullptr);
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, String value = ""); // Create Event Button uint16_t button(const char *label, void (*callback)(Control *, int), ControlColor color, const 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 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 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 padWithCenter(const char *label, void (*callback)(Control *, int), ControlColor color); // Create Pad Control with Centerbutton
@ -219,10 +219,10 @@ public:
int max = 100); // Create Slider Control int max = 100); // Create Slider Control
uint16_t number(const char *label, void (*callback)(Control *, int), ControlColor color, int value, int min = 0, 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 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 uint16_t text(const char *label, void (*callback)(Control *, int), ControlColor color, const String& value = ""); // Create a Text Input Control
// Output only // Output only
uint16_t label(const char *label, ControlColor color, String value = ""); // Create Label uint16_t label(const char *label, ControlColor color, const String& value = ""); // Create Label
uint16_t graph(const char *label, ControlColor color); // Create Graph display uint16_t graph(const char *label, ControlColor color); // Create Graph display
uint16_t gauge(const char *label, ControlColor color, int value, int min = 0, int max = 100); // Create Gauge display uint16_t gauge(const char *label, ControlColor color, int value, int min = 0, int max = 100); // Create Gauge display
@ -234,19 +234,19 @@ public:
Control *getControl(uint16_t id); Control *getControl(uint16_t id);
// Update Elements // Update Elements
void updateControlValue(uint16_t id, String value, int clientId = -1); void updateControlValue(uint16_t id, const String& value, int clientId = -1);
void updateControlValue(Control *control, String value, int clientId = -1); void updateControlValue(Control *control, const String& value, int clientId = -1);
void updateControl(uint16_t id, int clientId = -1); void updateControl(uint16_t id, int clientId = -1);
void updateControl(Control *control, int clientId = -1); void updateControl(Control *control, int clientId = -1);
void print(uint16_t id, String value); void print(uint16_t id, const String& value);
void updateLabel(uint16_t id, String value); void updateLabel(uint16_t id, const String& value);
void updateSwitcher(uint16_t id, bool nValue, int clientId = -1); void updateSwitcher(uint16_t id, bool nValue, int clientId = -1);
void updateSlider(uint16_t id, int nValue, int clientId = -1); void updateSlider(uint16_t id, int nValue, int clientId = -1);
void updateNumber(uint16_t id, int nValue, int clientId = -1); void updateNumber(uint16_t id, int nValue, int clientId = -1);
void updateText(uint16_t id, String nValue, int clientId = -1); void updateText(uint16_t id, const String& nValue, int clientId = -1);
void updateSelect(uint16_t id, String nValue, int clientId = -1); void updateSelect(uint16_t id, const String& nValue, int clientId = -1);
void updateGauge(uint16_t id, int number, int clientId); void updateGauge(uint16_t id, int number, int clientId);
void clearGraph(uint16_t id, int clientId = -1); void clearGraph(uint16_t id, int clientId = -1);