2
0
Files
lpsarii/main.cpp
2026-01-14 23:52:06 +01:00

124 lines
2.4 KiB
C++

#include "main.hpp"
#include "autom.cpp"
#include <thread>
#include <atomic>
int marche_precedent = 0;
int marche_frontmontant = 0;
int arret_precedent = 1;
int arret_frontdescedant = 0;
int bouton_precedent[8];
int bouton_frontmontant[8];
int bouton_frontdescendant[8];
int cycle = 0;
long unsigned tempo = 0;
int compteur = 0;
int sens = 1;
int ci = 0;
int mode_auto = 0;
int mode_manu = 0;
int etape = 0;
int etape_2 = 0;
int c7_frontdescendant = 0;
int c7_precedent = 0;
int main()
{
mqtt_open(&client);
std::atomic<bool> running{true};
while (running)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
mqtt_close();
return 0;
}
void process() {
// Détection des fronts
// front montant (état courant supérieur à l'état précédent)
// front descendant (état courant inférieur à l'état précédent)
// ****************************************************************
marche_frontmontant = marche > marche_precedent;
arret_frontdescedant = arret < arret_precedent;
for(int i = 0; i < 8 ; i++) {
bouton_frontmontant[i] = bouton[i] > bouton_precedent[i];
bouton_frontdescendant[i] = bouton[i] < bouton_precedent[i];
}
/* ****************************************************************
**************************************************************** */
c7_frontdescendant = capteur[7] < c7_precedent;
ci = (capteur[0] == 1 && capteur[2] == 1 && capteur[3] == 0 && capteur[5] == 0 && capteur[6] == 0 && capteur[7] == 0);
if (ci == 1 && marche_frontmontant == 1)
{
mode_auto = 1;
etape = 1;
}
if (etape == 1 && capteur[0] == 0 && capteur[6] == 1)
{
etape = 2;
}
if (etape == 2 && capteur[3] == 1)
{
etape = 3;
}
if (etape == 3 && tempo == 0)
{
tempo = millis();
}
if (etape == 3 && millis() > tempo + 3000)
{
etape = 4;
tempo = 0;
}
if (etape == 4 && capteur[2] == 1)
{
etape = 5;
}
if (etape == 5 && capteur[5] == 1)
{
etape = 6;
}
if (etape == 6 && c7_frontdescendant == 1)
{
etape = 1;
}
sortie[10] = etape;
sortie[11] = ci;
actionneur[0] = (etape == 1);
actionneur[1] = (etape == 2 || etape == 3);
actionneur[2] = (etape == 5);
actionneur[3] = (etape == 6);
// Prêt pour un nouveau cycle
// L'état courant devient l'état précédent
marche_precedent = marche;
arret_precedent = arret;
for (int i = 0; i < 8; i++) {
bouton_precedent[i] = bouton[i];
}
c7_precedent = capteur[7];
}