From 6a5e29bf37fc01885837b2a9f839b509a35a73a1 Mon Sep 17 00:00:00 2001
From: Malaurie Bernard <mbernard@kinouby>
Date: Fri, 4 Aug 2023 17:06:01 +0200
Subject: [PATCH] Add a few new attrubutes of the syringe pump to the
 sringe_filled class

---
 syringefilled.cpp | 47 +++++++++++++++++++++++++++++----------
 syringefilled.h   |  3 +++
 web.cpp           | 56 ++++++++++++++++++++++++++++++++++++++++++++++-
 web.h             |  4 +++-
 4 files changed, 96 insertions(+), 14 deletions(-)

diff --git a/syringefilled.cpp b/syringefilled.cpp
index 3750fd9..29b3fec 100644
--- a/syringefilled.cpp
+++ b/syringefilled.cpp
@@ -16,9 +16,11 @@ SyringeFilled :: SyringeFilled (MotorHardware_t& stepper): Motor(stepper)
     set_remaining_volume_mL(1);
     set_push(true);
     set_name_syringe("BD_10mL");
-    set_screw_thread_mm(4);
     set_clockwise_equals_push(true);
+    set_lead_screw_pitch_mm(0.7);
     set_syringe_pump_length_mm(50);
+    set_microstep_configuration(16);
+    set_motor_steps(200);
     set_emergency(false);
 
 }
@@ -45,13 +47,9 @@ void SyringeFilled :: set_push(bool push)
     syringe_filled_json["push"] = push;
 }
 
-void SyringeFilled :: set_name_syringe(String name_syringe){
-    syringe_filled_json["name_syringe"] = name_syringe;
-}
-
-void SyringeFilled :: set_screw_thread_mm(float screw_thread_mm)
+void SyringeFilled :: set_name_syringe(String name_syringe)
 {
-    syringe_filled_json["screw_thread_mm"] = screw_thread_mm;
+    syringe_filled_json["name_syringe"] = name_syringe;
 }
 
 void SyringeFilled :: set_clockwise_equals_push(bool clockwise_equals_push)
@@ -64,6 +62,21 @@ void SyringeFilled :: set_syringe_pump_length_mm(float syringe_pump_length_mm)
     syringe_filled_json["syringe_pump_length_mm"] = syringe_pump_length_mm;
 }
 
+void SyringeFilled :: set_lead_screw_pitch_mm(float lead_screw_pitch_mm)
+{
+    syringe_filled_json["lead_screw_pitch_mm"] = lead_screw_pitch_mm;
+}
+
+void SyringeFilled :: set_microstep_configuration(int microstep_configuration)
+{
+    syringe_filled_json["microstep_configuration"] = microstep_configuration;
+}
+
+void SyringeFilled :: set_motor_steps(int motor_steps)
+{
+    syringe_filled_json["motor_steps"] = motor_steps;
+}
+
 void SyringeFilled :: set_emergency(bool emergency)
 {
     syringe_filled_json["emergency"] = emergency;
@@ -96,11 +109,6 @@ String SyringeFilled :: get_name_syringe()
     return syringe_filled_json["name_syringe"].as<String>();
 }
 
-float SyringeFilled :: get_screw_thread_mm()
-{
-    return syringe_filled_json["screw_thread_mm"].as<float>();
-}
-
 bool SyringeFilled :: get_clockwise_equals_push()
 {
     return syringe_filled_json["clockwise_equals_push"].as<bool>();
@@ -111,6 +119,21 @@ float SyringeFilled :: get_syringe_pump_length_mm()
     return syringe_filled_json["syringe_pump_length_mm"].as<float>();
 }
 
+float SyringeFilled :: get_lead_screw_pitch_mm()
+{
+    return syringe_filled_json["lead_screw_pitch_mm"].as<float>();
+}
+
+int SyringeFilled :: get_microstep_configuration()
+{
+    return syringe_filled_json["microstep_configuration"].as<int>();
+}
+
+int SyringeFilled :: get_motor_steps()
+{
+    return syringe_filled_json["motor_steps"].as<int>();
+}
+
 bool SyringeFilled :: get_emergency()
 {
     return syringe_filled_json["emergency"].as<bool>();
diff --git a/syringefilled.h b/syringefilled.h
index 82b6c23..8bef682 100644
--- a/syringefilled.h
+++ b/syringefilled.h
@@ -37,6 +37,9 @@ class SyringeFilled : public Motor
     float _screw_thread_mm;
     bool _clockwise_equals_push;
     float _syringe_pump_length_mm;
+    float _lead_screw_pitch_mm;
+    int _microstep_configuration;
+    int _motor_steps;
 
     //Limit_Switch
     bool _emergency;
diff --git a/web.cpp b/web.cpp
index a06ab42..db4c0e3 100644
--- a/web.cpp
+++ b/web.cpp
@@ -130,6 +130,10 @@ void web_setup ()
     clockwise_equals_push = ESPUI.addControl(ControlType::Switcher, "Sens de rotation du moteur", "Horaire =", ControlColor::None, clockwise_equals_push_label, clockwise_equals_push_callback);
     ESPUI.updateSwitcher(clockwise_equals_push, true); //set "Horaire = Injection" at the beginning
 
+    microstep_configuration = ESPUI.addControl(ControlType::Number, "Configuration Hardware des microsteps", "16", ControlColor::None, features, microstep_configuration_callback);
+
+    motor_steps = ESPUI.addControl(ControlType::Number, "Caractéristique du moteur (nombre de pas possibles ?)", "2000", ControlColor::None, features, motor_steps_callback);
+
 
     
 
@@ -636,6 +640,44 @@ void clockwise_equals_push_callback(Control* sender, int value)
     Serial.println("");
 }
 
+void microstep_configuration_callback(Control* sender, int type)
+/***
+-Argument : Pointer to the controller calling the function, integer according to the controller type.
+-Return   : /
+-Action   : Print the value of the number controller via the serial port.
+            Change the microstep_configuration value.
+***/
+{
+    syringe_filled.set_microstep_configuration(sender->type);
+    syringe_filled.write_Json();
+
+    serial_print ("microstep_configuration (sender->value)", sender);
+
+    Serial.println("microstep_configuration (json value)");
+    Serial.println(String("Value: ") + String(syringe_filled.get_microstep_configuration()));
+    Serial.println("");
+}
+
+void motor_steps_callback(Control* sender, int type)
+/***
+-Argument : Pointer to the controller calling the function, integer according to the controller type.
+-Return   : /
+-Action   : Print the value of the number controller via the serial port.
+            Change the motor_steps value.
+***/
+{
+    syringe_filled.set_motor_steps(sender->type);
+    syringe_filled.write_Json();
+
+    serial_print ("motor_steps (sender->value)", sender);
+
+    Serial.println("motor_steps (json value)");
+    Serial.println(String("Value: ") + String(syringe_filled.get_motor_steps()));
+    Serial.println("");
+}
+
+
+
 //
 
 void syringe_selection_callback(Control* sender, int value)
@@ -763,7 +805,8 @@ void set_initial_style()
     style (lead_screw_pitch_mm, 3);
     style (clockwise_equals_push_label, 3);
     style (clockwise_equals_push, 3);
-
+    style (microstep_configuration, 3);
+    style (motor_steps, 3);
 
 
     //
@@ -950,6 +993,17 @@ void web_loop ()
         else
         style_syringe_pump_off();
 
+        if (syringe_filled.get_emergency())
+        {
+            ESPUI.print(status_syringe_pump, "On");
+            style (status_limit_switch, 1);
+        }
+        else
+        {
+            ESPUI.print(status_syringe_pump, "Off");
+            style (status_limit_switch, 2);
+        }
+        
 	}
 
 }
diff --git a/web.h b/web.h
index a796389..e5d3d14 100644
--- a/web.h
+++ b/web.h
@@ -46,7 +46,7 @@ String name_new_syringe_value, total_volume_mL_new_syringe_value, internal_diame
 
 //Features
 uint16_t syringe_pump_length_mm_value;
-uint16_t lead_screw_pitch_mm, clockwise_equals_push_label, clockwise_equals_push;
+uint16_t lead_screw_pitch_mm, clockwise_equals_push_label, clockwise_equals_push, microstep_configuration, motor_steps;
 
 
 //Other
@@ -109,6 +109,8 @@ void add_syringe_callback (Control* sender, int value, void* param);
 //features : Configurations avancées
 void syringe_pump_length_mm_callback(Control* sender, int type);
 void clockwise_equals_push_callback(Control* sender, int value);
+void microstep_configuration_callback(Control* sender, int type);
+void motor_steps_callback(Control* sender, int type);
 
 //
 void syringe_selection_callback(Control* sender, int value);
-- 
GitLab