From ed8b1816cafc474c131210d4ebde741bf2af8209 Mon Sep 17 00:00:00 2001
From: David Gauchard <gauchard@laas.fr>
Date: Fri, 16 Jun 2023 14:47:58 +0200
Subject: [PATCH] reenabling wifi

---
 pousseseringue-arduino.cpp | 35 ++++++++++-------------------------
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/pousseseringue-arduino.cpp b/pousseseringue-arduino.cpp
index 14b00b6..c8718b7 100644
--- a/pousseseringue-arduino.cpp
+++ b/pousseseringue-arduino.cpp
@@ -78,7 +78,6 @@ DNSServer dnsServer;
 char ssid[65];
 
 Modes mode = Modes::RPM;
-bool stepperMoving = false;
 
 int move = 0;
 
@@ -245,27 +244,10 @@ void buttons (int shortp, int longp)
 
 #if !CORE_MOCK
 
-IRAM_ATTR
-void stepperRunOLD ()
-{
-//    if (syringe.locked())
-//        return;
-//    cli();
-#if 0
-    if (rpming)
-        stepperMoving = stepper.runSpeed();
-    else
-        stepperMoving = stepper.run();
-#else
-    stepperMoving = stepper.runSpeed();
-#endif
-//    sei();
-}
-
 IRAM_ATTR
 void stepperRun ()
 {
-    stepperMoving = stepper.runSpeed();
+    stepper.runSpeed();
 }
 
 #endif // !CORE_MOCK
@@ -299,12 +281,12 @@ void setup()
     digitalWrite(SLEEP, 0);
 #endif // !CORE_MOCK
 
-#if 0
+#if 1
 
     uint8_t mac[6];
     WiFi.macAddress(mac);
     sprintf(ssid, NAME "-%02x%02x%02x", mac[3], mac[4], mac[5]);
-#if 0
+#if 1
     if (strlen(STASSID) > 0)
     {
         WiFi.setPhyMode(WIFI_PHY_MODE_11G);
@@ -346,7 +328,7 @@ void setup()
     timer1_enable(TIM_DIV1, TIM_EDGE, TIM_LOOP);
     timer1_attachInterrupt(stepperRun);
     timer1_write(microsecondsToClockCycles(100));
-    schedule_recurrent_function_us([](){ if (stepperMoving) { InterruptLock lock; stepper.computeNewSpeed(); } return true; }, 1);
+    schedule_recurrent_function_us([](){ if (stepper.distanceToGo()) { InterruptLock lock; stepper.computeNewSpeed(); } return true; }, 1);
 #else
     #warning ===================================================================================================
     #warning "Please use the ISR version of AccelStepper (git clone -b isr https://github.com/d-a-v/AccelStepper)"
@@ -374,7 +356,10 @@ void setup()
 void loop()
 {
     if (bEmergency.update(digitalRead(COURSE)))
-        syringe.manageEmergency(bEmergency.pressed(), stepperMoving);
+    {
+        syringe.manageEmergency(bEmergency.pressed(), !!stepper.distanceToGo());
+        Serial.printf("%sEmergency=%u (remaining steps = %lu)\n", msgHeader, bEmergency.pressed(), stepper.distanceToGo());
+    }
 
   #if CORE_MOCK
     bool changeA = false;
@@ -416,6 +401,6 @@ void loop()
     }
 
     console.loop(Serial);
-    //webLoop();
-    //dnsServer.processNextRequest(); // access-point redirection
+    webLoop();
+    dnsServer.processNextRequest(); // access-point redirection
 }
-- 
GitLab