refactor(server): ♻️ refactor code to reduce complexity
This commit is contained in:
parent
f1a70e6cfb
commit
704a352724
|
@ -132,46 +132,36 @@ int convertRotToSteps(int rotation)
|
||||||
// Lorsqu'une commande arrive au serveur, cette fonction permet
|
// Lorsqu'une commande arrive au serveur, cette fonction permet
|
||||||
void requestCheck(String command, float value)
|
void requestCheck(String command, float value)
|
||||||
{
|
{
|
||||||
if (command == "forward")
|
if (command == "stop")
|
||||||
{
|
|
||||||
globalCommand = "forward";
|
|
||||||
commandRunning = true;
|
|
||||||
stopCommand = false;
|
|
||||||
globalValue = convertLengthToSteps(value);
|
|
||||||
}
|
|
||||||
else if (command == "backward")
|
|
||||||
{
|
|
||||||
globalCommand = "backward";
|
|
||||||
commandRunning = true;
|
|
||||||
stopCommand = false;
|
|
||||||
globalValue = convertLengthToSteps(value);
|
|
||||||
}
|
|
||||||
else if (command == "left")
|
|
||||||
{
|
|
||||||
globalCommand = "left";
|
|
||||||
commandRunning = true;
|
|
||||||
stopCommand = false;
|
|
||||||
globalValue = convertRotToSteps(value);
|
|
||||||
}
|
|
||||||
else if (command == "right")
|
|
||||||
{
|
|
||||||
globalCommand = "right";
|
|
||||||
commandRunning = true;
|
|
||||||
stopCommand = false;
|
|
||||||
globalValue = convertRotToSteps(value);
|
|
||||||
}
|
|
||||||
else if (command == "stop")
|
|
||||||
{
|
{
|
||||||
globalCommand = "stop";
|
globalCommand = "stop";
|
||||||
commandRunning = true;
|
commandRunning = true;
|
||||||
stopCommand = true;
|
stopCommand = true;
|
||||||
}
|
}
|
||||||
|
else if setGlobals (command, value)
|
||||||
|
;
|
||||||
|
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
{
|
{
|
||||||
globalValue = 474;
|
globalValue = 474;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setGlobals(String command, float value)
|
||||||
|
{
|
||||||
|
// Assert command before updating globals
|
||||||
|
if (command != "forward" && command != "backward" && command != "left" && command != "right")
|
||||||
|
{
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update globals
|
||||||
|
globalCommand = command;
|
||||||
|
commandRunning = true;
|
||||||
|
stopCommand = false;
|
||||||
|
globalValue = convertLengthToSteps(value);
|
||||||
|
}
|
||||||
|
|
||||||
void connectWiFi()
|
void connectWiFi()
|
||||||
{
|
{
|
||||||
WiFi.mode(WIFI_AP);
|
WiFi.mode(WIFI_AP);
|
||||||
|
|
Loading…
Reference in a new issue