1
0
mirror of https://github.com/s00500/ESPUI.git synced 2025-07-03 19:50:20 +00:00

Add "autoupdate value" option for input controls

This commit is contained in:
Nikola Kirov
2023-11-30 14:54:50 +02:00
parent 8b64b185a4
commit 31911b3969
5 changed files with 83 additions and 69 deletions

View File

@ -3,8 +3,8 @@
static uint16_t idCounter = 0;
static const String ControlError = "*** ESPUI ERROR: Could not transfer control ***";
Control::Control(ControlType type, const char* label, std::function<void(Control*, int)> callback,
const String& value, ControlColor color, bool visible, uint16_t parentControl)
Control::Control(ControlType type, const char* label, std::function<void(Control*, int)> callback, const String& value,
ControlColor color, bool visible, uint16_t parentControl)
: type(type),
label(label),
callback(callback),
@ -14,6 +14,7 @@ Control::Control(ControlType type, const char* label, std::function<void(Control
wide(false),
vertical(false),
enabled(true),
auto_update_value(false),
parentControl(parentControl),
next(nullptr)
{
@ -154,129 +155,128 @@ void Control::onWsEvent(String & cmd, String& data)
{
// Serial.println(String(F("Control::onWsEvent")));
SetControlChangedId(ESPUI.GetNextControlChangeId());
if (!HasCallback())
{
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.println(String(F("Control::onWsEvent:No callback found for ID ")) + String(id));
}
#endif
break;
}
// Serial.println("Control::onWsEvent:Generating callback");
int arg = 0;
if (cmd.equals(F("bdown")))
{
SendCallback(B_DOWN);
break;
arg = B_DOWN;
}
if (cmd.equals(F("bup")))
else if (cmd.equals(F("bup")))
{
SendCallback(B_UP);
break;
arg = B_UP;
}
if (cmd.equals(F("pfdown")))
else if (cmd.equals(F("pfdown")))
{
SendCallback(P_FOR_DOWN);
break;
arg = P_FOR_DOWN;
}
if (cmd.equals(F("pfup")))
else if (cmd.equals(F("pfup")))
{
SendCallback(P_FOR_UP);
break;
arg = P_FOR_UP;
}
if (cmd.equals(F("pldown")))
else if (cmd.equals(F("pldown")))
{
SendCallback(P_LEFT_DOWN);
break;
arg = P_LEFT_DOWN;
}
else if (cmd.equals(F("plup")))
{
SendCallback(P_LEFT_UP);
arg = P_LEFT_UP;
}
else if (cmd.equals(F("prdown")))
{
SendCallback(P_RIGHT_DOWN);
arg = P_RIGHT_DOWN;
}
else if (cmd.equals(F("prup")))
{
SendCallback(P_RIGHT_UP);
arg = P_RIGHT_UP;
}
else if (cmd.equals(F("pbdown")))
{
SendCallback(P_BACK_DOWN);
arg = P_BACK_DOWN;
}
else if (cmd.equals(F("pbup")))
{
SendCallback(P_BACK_UP);
arg = P_BACK_UP;
}
else if (cmd.equals(F("pcdown")))
{
SendCallback(P_CENTER_DOWN);
arg = P_CENTER_DOWN;
}
else if (cmd.equals(F("pcup")))
{
SendCallback(P_CENTER_UP);
arg = P_CENTER_UP;
}
else if (cmd.equals(F("sactive")))
{
value = "1";
SendCallback(S_ACTIVE);
if (auto_update_value)
value = "1";
arg = S_ACTIVE;
}
else if (cmd.equals(F("sinactive")))
{
value = "0";
// updateControl(c, client->id());
SendCallback(S_INACTIVE);
if (auto_update_value)
value = "0";
arg = S_INACTIVE;
}
else if (cmd.equals(F("slvalue")))
{
value = data;
// updateControl(c, client->id());
SendCallback(SL_VALUE);
if (auto_update_value)
value = data;
arg = SL_VALUE;
}
else if (cmd.equals(F("nvalue")))
{
value = data;
// updateControl(c, client->id());
SendCallback(N_VALUE);
if (auto_update_value)
value = data;
arg = N_VALUE;
}
else if (cmd.equals(F("tvalue")))
{
value = data;
// updateControl(c, client->id());
SendCallback(T_VALUE);
if (auto_update_value)
value = data;
arg = T_VALUE;
}
else if (cmd.equals(F("tabvalue")))
{
SendCallback(0);
arg = 0;
}
else if (cmd.equals(F("svalue")))
{
value = data;
// updateControl(c, client->id());
SendCallback(S_VALUE);
if (auto_update_value)
value = data;
arg = S_VALUE;
}
else if (cmd.equals(F("time")))
{
value = data;
// updateControl(c, client->id());
SendCallback(TM_VALUE);
if (auto_update_value)
value = data;
arg = TM_VALUE;
}
else
{
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.println(F("Control::onWsEvent:Malformed message from the websocket"));
}
#endif
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.println(F("Control::onWsEvent:Malformed message from the websocket"));
}
#endif
break;
}
if (!HasCallback())
{
#if defined(DEBUG_ESPUI)
if (ESPUI.verbosity)
{
Serial.println(String(F("Control::onWsEvent:No callback found for ID ")) + String(id));
}
#endif
}
else
{
// Serial.println("Control::onWsEvent:Generating callback");
SendCallback(arg);
}
} while (false);
}