From 2ab919d77049d2e82ff4fa9792a5db660e03b33d Mon Sep 17 00:00:00 2001
From: David Gauchard <gauchard@laas.fr>
Date: Thu, 19 May 2022 17:00:43 +0200
Subject: [PATCH] fix running on host, automatically starts firefox

---
 host_gui/make.sh           | 18 +++++++++++++++++-
 motor.h                    |  3 +--
 pousseseringue-arduino.cpp | 10 +++++++++-
 pousseseringue-arduino.ino |  4 +++-
 syringe.cpp                |  6 ------
 syringe.h                  |  7 ++++---
 web.cpp                    |  2 ++
 7 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/host_gui/make.sh b/host_gui/make.sh
index 56fb9f7..36a876f 100755
--- a/host_gui/make.sh
+++ b/host_gui/make.sh
@@ -1,5 +1,21 @@
 #!/bin/sh -ex
+
 pwd=$(pwd)
 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 ${pwd}/../pousseseringue-arduino
\ No newline at end of file
+make -j 10 FORCE32=0 D=1 USERCFLAGS="-I ${ARDUINOLIB}/emuAsync/replacement" ULIBDIRS=${ARDUINOLIB}/emuAsync:${ARDUINOLIB}/ESPUI:${ARDUINOLIB}/ArduinoJson:${ARDUINOLIB}/arduinoWebSockets ${pwd}/../pousseseringue-arduino
+
+(./bin/pousseseringue-arduino/pousseseringue-arduino -b "$@" 2>&1 | grep -v '^http-server loop: conn=') & pid=$!
+trap "kill ${pid}" EXIT INT
+
+sleep 1
+true '----------------------------------------'
+true '----------- starting firefox -----------'
+true '----------------------------------------'
+sleep 4
+firefox -new-window http://localhost:9080
+
+while true; do
+    true '^C to quit'
+    read junk
+done
diff --git a/motor.h b/motor.h
index 5d72027..4b0b65f 100644
--- a/motor.h
+++ b/motor.h
@@ -1,4 +1,5 @@
 
+#pragma once
 
 class Motor
 {
@@ -10,5 +11,3 @@ private:
 	int current_step_count = 0;
 };
 
-// Global object
-extern Motor motor;
diff --git a/pousseseringue-arduino.cpp b/pousseseringue-arduino.cpp
index 22bd1e1..ed4a1eb 100644
--- a/pousseseringue-arduino.cpp
+++ b/pousseseringue-arduino.cpp
@@ -55,6 +55,7 @@
 #include <AccelStepper.h>
 #endif // !CORE_MOCK
 #include "Debouncer.h"          // local, debouncer, short counter, long detector
+#include "syringe.h"
 #include "common.h"
 
 
@@ -90,7 +91,8 @@ int stepDurationMs = STEP_DURATION_DEFAULT_MS;
 float stepsPerDuration2rpm () { return 60.0 * stepsPerDuration / ((MOTOR_STEPS * MICROSTEPS_CONF) * (stepDurationMs / 1000.0)); }
 int rpming = 0; // -1, 0 or +1
 
-
+// single syringe global instance
+Syringe syringe;
 
 const char* oledMode ()
 {
@@ -268,10 +270,16 @@ void loop()
 {
     nowMs = millis();
    
+  #if CORE_MOCK
+    bool changeA = false;
+    bool changeB = false;
+    bool changeC = false;
+  #else
     // button management (nowMs must be updated)
     bool changeA = bA.update(!digitalRead(BTNA));
     bool changeB = bB.update(!digitalRead(BTNB));
     bool changeC = bC.update(!digitalRead(BTNC));
+  #endif
 
     if (changeA)
     {
diff --git a/pousseseringue-arduino.ino b/pousseseringue-arduino.ino
index 9207b33..e70951c 100644
--- a/pousseseringue-arduino.ino
+++ b/pousseseringue-arduino.ino
@@ -1,8 +1,10 @@
 
 // please edit this file: pousseseringue-arduino.cpp
 
-// Pour la compilation local sur le PC
+// Pour la compilation locale sur le PC
 #if CORE_MOCK
   #include "pousseseringue-arduino.cpp"
   #include "web.cpp"
+  #include "syringe.cpp"
+  #include "motor.cpp"
 #endif // !CORE_MOCK
diff --git a/syringe.cpp b/syringe.cpp
index efdf0a6..7a831b3 100644
--- a/syringe.cpp
+++ b/syringe.cpp
@@ -1,12 +1,6 @@
 #include <math.h>
 
 #include "syringe.h"
-#include "motor.h"
-
-// Global object
-Syringe syringe;
-
-// Members definitions
 
 float Syringe::volumeToDistance(float volume)
 {
diff --git a/syringe.h b/syringe.h
index f28710f..49dea57 100644
--- a/syringe.h
+++ b/syringe.h
@@ -1,5 +1,7 @@
 
+#pragma once
 
+#include "motor.h"
 
 class Syringe
 {
@@ -41,7 +43,6 @@ private:
 	bool is_configured = false;
 	float remaining_volume = 0;
 	float piston_surface = 0;
+	
+	Motor motor;
 };
-
-// Global object
-extern Syringe syringe;
diff --git a/web.cpp b/web.cpp
index 48e8c24..b2b0794 100644
--- a/web.cpp
+++ b/web.cpp
@@ -12,6 +12,8 @@ uint16_t button1;
 uint16_t millisLabelId;
 uint16_t switchOne;
 
+extern Syringe syringe;
+
 
 void numberCall( Control* sender, int type ) {
   Serial.println( sender->value );
-- 
GitLab