refactor(server): ♻️ reduce code complexity

This commit is contained in:
Julien Oculi 2024-06-25 17:32:09 +02:00
parent c1cdd646e2
commit bf3ea49e13

View file

@ -54,10 +54,21 @@ void setup()
// Code exécuté en boucle jusqu'à l'extinction du robot // Code exécuté en boucle jusqu'à l'extinction du robot
void loop() void loop()
{ {
if (commandRunning) // Ne rien faire si aucune commande en cours
{ if (!commandRunning)
if (!stopCommand) return;
// Arrêter le robot si une commande est interrompue
if (stopCommand)
{ {
Serial.println("stop");
commandRunning = false;
stopCommand = false;
stopMotors();
return;
}
// Sinon executer la commande en cours
chooseCommand(); // Appeler la fonction "chooseCommand()" chooseCommand(); // Appeler la fonction "chooseCommand()"
if (globalValue > 0) if (globalValue > 0)
{ // S'il reste des pas à effectuer alors on l'affiche et on enlève un pas { // S'il reste des pas à effectuer alors on l'affiche et on enlève un pas
@ -73,15 +84,6 @@ void loop()
stopCommand = false; stopCommand = false;
stopMotors(); stopMotors();
} }
}
else
{
Serial.println("stop");
commandRunning = false;
stopCommand = false;
stopMotors();
}
}
} }
// Configuration du serveur asynchrone // Configuration du serveur asynchrone