added button action configuration and handling for reset and restart

This commit is contained in:
RaffaelW 2024-12-21 21:28:35 +01:00
parent 5870182507
commit 3aeb8ffe5b
4 changed files with 62 additions and 0 deletions

View file

@ -70,6 +70,16 @@ Direction parseDirection(uint8_t direction)
throw ::std::invalid_argument("Invalid direction value: " + direction);
}
ButtonAction parseButtonAction(uint8_t buttonAction)
{
if (buttonAction > 0 || buttonAction < BUTTON_ACTION_SIZE)
{
return static_cast<ButtonAction>(buttonAction);
}
throw ::std::invalid_argument("Invalid value for button action: " + buttonAction);
}
#pragma endregion
void onGetConfig(AsyncWebServerRequest *request)
@ -93,6 +103,7 @@ void onGetConfig(AsyncWebServerRequest *request)
doc["universe-2"] = config.getUInt("universe-2", DEFAULT_UNIVERSE2);
doc["direction-2"] = config.getUInt("direction-2", DEFAULT_DIRECTION2);
doc["led-brightness"] = config.getUInt("led-brightness", DEFAULT_LED_BRIGHTNESS);
doc["button-action"] = config.getUInt("button-action", DEFAULT_BUTTON_ACTION);
config.end();
@ -151,6 +162,9 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
config.putUInt("led-brightness", doc["led-brightness"]);
ButtonAction buttonAction = parseButtonAction(doc["button-action"].as<uint8_t>());
config.putUInt("button-action", buttonAction);
config.end();
request->send(200);

View file

@ -29,6 +29,14 @@ enum Direction
};
const uint8_t DIRECTION_SIZE = 2;
enum ButtonAction
{
None,
ResetConfig,
Restart
};
const uint8_t BUTTON_ACTION_SIZE = 3;
const Connection DEFAULT_CONNECTION = WiFiAP;
const IpMethod DEFAULT_IP_METHOD = DHCP;
extern String DEFAULT_SSID; // initialized in setup because it depends on the mac address
@ -43,6 +51,7 @@ const uint8_t DEFAULT_UNIVERSE1 = 1;
const uint8_t DEFAULT_UNIVERSE2 = 2;
const uint8_t DEFAULT_LED_BRIGHTNESS = 25;
const ButtonAction DEFAULT_BUTTON_ACTION = Restart;
void onGetConfig(AsyncWebServerRequest *request);