From d765081b11a082e3967771cf28e40b40063c2887 Mon Sep 17 00:00:00 2001
From: Maximilien Naveau <maximilien.naveau@gmail.com>
Date: Mon, 9 May 2022 15:53:43 +0200
Subject: [PATCH] Create a make.sh inorder to build the web server app locally

---
 README.md                  | 17 ++++++++++++++++-
 host_gui/clean             |  3 +++
 host_gui/make.sh           |  4 ++++
 pousseseringue-arduino.cpp | 20 ++++++++++++++++++--
 pousseseringue-arduino.ino |  6 ++++++
 5 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100755 host_gui/clean
 create mode 100755 host_gui/make.sh

diff --git a/README.md b/README.md
index bff8223..3461142 100644
--- a/README.md
+++ b/README.md
@@ -87,4 +87,19 @@ firefox localhost:9080
 
 ### ESP
 
-@todo
\ No newline at end of file
+@todo
+
+## Some code details explanation
+
+### CORE_MOCK
+
+Ce `CORE_MOCK` permet d'ignorer les ligne qui sont spécifique au micro-controller
+afin de compiler le driver sur le PC local. Cela permet notamment de visualiser
+le gui sans avoir la carte éléctronique physiquement et de la flasher.
+```
+#if !CORE_MOCK
+  // on the target
+#else // !CORE_MOCK
+  // on host
+#endif // !CORE_MOCK
+```
\ No newline at end of file
diff --git a/host_gui/clean b/host_gui/clean
new file mode 100755
index 0000000..54ab358
--- /dev/null
+++ b/host_gui/clean
@@ -0,0 +1,3 @@
+#!/bin/sh -ex
+cd ${ESP8266ARDUINO}/tests/host
+make clean
diff --git a/host_gui/make.sh b/host_gui/make.sh
new file mode 100755
index 0000000..ee9b4e7
--- /dev/null
+++ b/host_gui/make.sh
@@ -0,0 +1,4 @@
+#!/bin/sh -ex
+cd ${ESP8266ARDUINO}/tests/host
+make FORCE32=0 ssl
+make -j 10 FORCE32=0 D=1 USERCFLAGS="-I ${ARDUINOLIB}/emuAsync/replacement" ULIBDIRS=${ARDUINOLIB}/emuAsync:${ARDUINOLIB}/ESPUI:${ARDUINOLIB}/ArduinoJson:${ARDUINOLIB}/arduinoWebSockets ${ARDUINOLIB}/pousseseringue-arduino/pousseseringue-arduino
\ No newline at end of file
diff --git a/pousseseringue-arduino.cpp b/pousseseringue-arduino.cpp
index f50c850..0f4b23d 100644
--- a/pousseseringue-arduino.cpp
+++ b/pousseseringue-arduino.cpp
@@ -3,7 +3,6 @@
 // Feather LCD
 // Feather motor controler
 
-
 #if 0
 #define STASSID         "laas-capture"
 #define STAPSK          ""
@@ -53,9 +52,10 @@
 
 #include <ESP8266WiFi.h>        // internal, wifi library
 #include <DNSServer.h>          // internal, access point mode
+#if !CORE_MOCK
 #include <SSD1306AsciiWire.h>   // https://github.com/greiman/SSD1306Ascii
 #include <A4988.h>              // https://github.com/laurb9/StepperDriver
-
+#endif // !CORE_MOCK
 #include "Debouncer.h"          // local, debouncer, short counter, long detector
 #include "common.h"
 
@@ -69,8 +69,10 @@ enum class Modes { TURN, TURNSetup, RPM, RPMSetup, INFO };
 millis_t nowMs; // to update on main loop(): "nowMs = millis();"
 
 Debouncer<nowMs> bA, bB, bC;
+#if !CORE_MOCK
 A4988 a4988(MOTOR_STEPS, DIR, STEP, SLEEP);
 SSD1306AsciiWire oled;
+#endif // !CORE_MOCK
 constexpr int DNS_PORT = 53;
 DNSServer dnsServer;
 
@@ -106,11 +108,14 @@ const char* oledMode ()
 
 void oledPrintMode ()
 {
+#if !CORE_MOCK
     oled.printf("\n mode: %s", oledMode());
+#endif // !CORE_MOCK
 }
 
 void oledRedisplay ()
 {
+#if !CORE_MOCK
     oled.clear();
 
     switch (mode)
@@ -151,6 +156,7 @@ void oledRedisplay ()
     default:
         oled.printf("?");
     }
+#endif // !CORE_MOCK
 }
 
 void changeMode ()
@@ -212,20 +218,26 @@ void setup()
 {
     Serial.begin(74880);
     Serial.setDebugOutput(true);
+#if !CORE_MOCK
     Wire.begin();
     Wire.setClock(400000L);
+#endif // !CORE_MOCK
     delay(500);
 
+#if !CORE_MOCK
     oled.begin(&OLED_HW, OLED_I2C);
     oled.setFont(System5x7);
     oled.setScrollMode(SCROLL_MODE_AUTO);
     oled.clear();
     oled.println("Booting...\n");
+#endif // !CORE_MOCK
     
+#if !CORE_MOCK
     a4988.begin(STEPPER_RPM); // some value is necessary
     a4988.setEnableActiveState(LOW);
     a4988.setMicrostep(MICROSTEPS_CONF);
     a4988.enable();
+#endif // !CORE_MOCK
 
     uint8_t mac[6];
     WiFi.macAddress(mac);
@@ -309,12 +321,16 @@ void loop()
         if (move >= stepsPerDuration)
         {
             move -= stepsPerDuration;
+#if !CORE_MOCK
             a4988.move(stepsPerDuration);    // forward revolution
+#endif // !CORE_MOCK
         }
         if (move <= -stepsPerDuration)
         {
             move += stepsPerDuration;
+#if !CORE_MOCK
             a4988.move(-stepsPerDuration);   // backward revolution
+#endif // !CORE_MOCK
         }
 
         lastMoveMs += stepDurationMs;
diff --git a/pousseseringue-arduino.ino b/pousseseringue-arduino.ino
index 6d5ef8a..9207b33 100644
--- a/pousseseringue-arduino.ino
+++ b/pousseseringue-arduino.ino
@@ -1,2 +1,8 @@
 
 // please edit this file: pousseseringue-arduino.cpp
+
+// Pour la compilation local sur le PC
+#if CORE_MOCK
+  #include "pousseseringue-arduino.cpp"
+  #include "web.cpp"
+#endif // !CORE_MOCK
-- 
GitLab