refactor(server): ♻️ reduce code complexity
This commit is contained in:
parent
1e5fc119ad
commit
455d6d6bce
|
@ -87,25 +87,34 @@ void serverConfig()
|
|||
{
|
||||
String command;
|
||||
float value;
|
||||
if (request->hasParam("command")) {
|
||||
command = request->getParam("command")->value();
|
||||
if (request->hasParam("value")){
|
||||
value = request->getParam("value")->value().toFloat();
|
||||
}
|
||||
else{
|
||||
value = 0;
|
||||
}
|
||||
requestCheck(command,value);
|
||||
}
|
||||
else {
|
||||
command = "Not the good command";
|
||||
}
|
||||
|
||||
// Parse request params and update command and value
|
||||
parseRequestParams(request, command, value);
|
||||
|
||||
Serial.print(command);
|
||||
Serial.print(": ");
|
||||
Serial.println(value);
|
||||
request->send(200, "text/plain", command); });
|
||||
}
|
||||
|
||||
void parseRequestParams(AsyncWebServerRequest &request, String &command, int &value)
|
||||
{
|
||||
// Stop here with error message if wrong command
|
||||
if (!request->hasParam("command"))
|
||||
{
|
||||
command = "Not the good command";
|
||||
return;
|
||||
}
|
||||
|
||||
// Update command from params
|
||||
command = request->getParam("command")->value();
|
||||
|
||||
// Update value from params and use "0" as default
|
||||
value = request->hasParam("value") ? request->getParam("value")->value().toFloat() : 0;
|
||||
|
||||
requestCheck(command, value);
|
||||
}
|
||||
|
||||
// Fonction pour convertir une longueur en cm vers un nombre de pas moteur.
|
||||
int convertLengthToSteps(float length)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue