From d477b89557e9debda662b1670f7777ec18f3b1c6 Mon Sep 17 00:00:00 2001
From: Malaurie Bernard <mbernard@kinouby>
Date: Thu, 27 Jul 2023 13:24:09 +0200
Subject: [PATCH] Changing serial messages to make them clearer and help
 understand eveything that happen

---
 web.cpp | 185 +++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 137 insertions(+), 48 deletions(-)

diff --git a/web.cpp b/web.cpp
index 67644a8..c22fd09 100644
--- a/web.cpp
+++ b/web.cpp
@@ -131,7 +131,10 @@ void number_callback(Control* sender, int type)
 -Action   : Print the value of the number controller via the serial port.
 ***/
 {
-    Serial.println(sender->value);
+    Serial.println("Type: number");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
 }
 
 
@@ -148,6 +151,10 @@ void stop_syringe_pump_callback (Control* sender, int value, void* param)
 {
     syringe_pump_off();
 
+    Serial.println("Syringe_pump stopped");
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+
 }
 
 void syringe_filled_placement_callback (Control* sender, int value, void* param)
@@ -157,8 +164,6 @@ void syringe_filled_placement_callback (Control* sender, int value, void* param)
 -Action   : Linking the switch of the syringe filled status(placed or not) and the actions.
 ***/
 {
-
-    Serial.println(String("param: ") + String(long(param)));
     switch (value)
     {
     case S_ACTIVE:
@@ -170,8 +175,10 @@ void syringe_filled_placement_callback (Control* sender, int value, void* param)
         break;
     }
 
-    Serial.print(" ");
-    Serial.println(sender->id);
+    Serial.println("Syringe_filled_placement");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
 }
 
 void calibration_callback (Control *sender, int type) 
@@ -182,14 +189,17 @@ void calibration_callback (Control *sender, int type)
 ***/
 {
     if((type == B_UP)) {
-        Serial.printf("Go to zero"); 
+
         syringe_filled.go_to_zero();
-        Serial.print("Active:");
-            
         ESPUI.print(status_syringe_pump, "En marche");
         style (status_syringe_pump, 1);
         style (stop_syringe_pump, 1);
     }
+    
+    Serial.println("Calibration");
+    Serial.println(String("Value: ") + String(sender->type));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
 }
 
 void fast_backward_callback (Control *sender, int type) 
@@ -203,7 +213,6 @@ void fast_backward_callback (Control *sender, int type)
     {
     case B_DOWN:
 
-        Serial.printf("Backward 10 steps"); 
         syringe_filled.reset_position();
         syringe_filled.move_mm(-50);
         syringe_filled.set_speed_mm_per_sec(50);
@@ -217,6 +226,12 @@ void fast_backward_callback (Control *sender, int type)
 
         break;
     }
+
+    Serial.println("Fast_backward");
+    Serial.println(String("Value: ") + String(sender->type));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+
 }
 
 void fast_forward_callback (Control *sender, int type) 
@@ -245,6 +260,12 @@ void fast_forward_callback (Control *sender, int type)
 
         break;
     }
+
+    Serial.println("Fast_forward");
+    Serial.println(String("Value: ") + String(sender->type));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+
 }
 
 void slow_backward_callback (Control *sender, int type) 
@@ -258,7 +279,6 @@ void slow_backward_callback (Control *sender, int type)
     {
     case B_DOWN:
 
-        Serial.printf("Backward 1 step"); 
         syringe_filled.reset_position();
         syringe_filled.move_mm(-50);
         syringe_filled.set_speed_mm_per_sec(0.5);
@@ -272,6 +292,12 @@ void slow_backward_callback (Control *sender, int type)
 
         break;
     }
+
+    Serial.println("Slow_backward");
+    Serial.println(String("Value: ") + String(sender->type));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+
 }
 
 void slow_forward_callback (Control *sender, int type) 
@@ -285,7 +311,6 @@ void slow_forward_callback (Control *sender, int type)
     {
     case B_DOWN:
 
-        Serial.printf("Forward 1 step"); 
         syringe_filled.reset_position();
         syringe_filled.move_mm(50);
         syringe_filled.set_speed_mm_per_sec(0.5);
@@ -299,6 +324,11 @@ void slow_forward_callback (Control *sender, int type)
 
         break;
     }
+    
+    Serial.println("Slow_forward");
+    Serial.println(String("Value: ") + String(sender->type));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
 }
 
 void volume_exchange_mL_callback (Control* sender, int value, void* param)
@@ -308,9 +338,17 @@ void volume_exchange_mL_callback (Control* sender, int value, void* param)
 -Action   : Enable to choose the volume that woud be exchanged.
 ***/
 {
-    Serial.printf("val=%s\n", sender->value.c_str()); 
     syringe_filled.set_exchange_volume_mL(atof(sender->value.c_str()));
     syringe_filled.write_Json ();
+
+    Serial.println("Volume_exchange (sender->value)");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+    Serial.println("Volume_exchange (json value)");
+    Serial.println(String("Value: ") + String(syringe_filled.get_exchange_volume_mL()));
+    Serial.println("");
+    
 }
 
 void exchange_throughtput_uL_per_sec_callback (Control* sender, int value, void* param)
@@ -320,9 +358,17 @@ void exchange_throughtput_uL_per_sec_callback (Control* sender, int value, void*
 -Action   : Enable to choose the volume that woud be exchanged.
 ***/
 {
-    Serial.printf("val=%s\n", sender->value.c_str()); 
     syringe_filled.set_exchange_throughput_uL_per_sec(atof(sender->value.c_str()));
     syringe_filled.write_Json ();
+
+    Serial.println("Exchange_throughtput (sender->value)");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+    Serial.println("Exchange_throughtput (json value)");
+    Serial.println(String("Value: ") + String(syringe_filled.get_exchange_throughput_uL_per_sec()));
+    Serial.println("");
+
 }
 
 
@@ -335,7 +381,6 @@ void switch_push_pull_choice_callback (Control* sender, int value, void* param)
 ***/
 {
 
-    Serial.println(String("param: ") + String(long(param)));
     switch (value)
     {
     case S_ACTIVE:
@@ -343,6 +388,8 @@ void switch_push_pull_choice_callback (Control* sender, int value, void* param)
         
         ESPUI.print(label_push_pull_choice, "Injection");
 
+        style (initial_volume_mL, 1);
+        style (initial_volume_mL_label, 1);
         style (volume_exchange_mL_label, 1);
         style (volume_exchange_mL, 1); 
         style (exchange_throughtput_uL_per_sec_label, 1);
@@ -369,8 +416,14 @@ void switch_push_pull_choice_callback (Control* sender, int value, void* param)
         break;
     }
     syringe_filled.write_Json();
-    Serial.print(" ");
-    Serial.println(sender->id);
+
+    Serial.println("Push_pull_choice (sender->value)");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+    Serial.println("Push_pull_choice (json value)");
+    Serial.println(String("Value: ") + String(syringe_filled.get_push()));
+    Serial.println("");
 }
 
 void remaining_volume_mL_callback (Control* sender, int value, void* param)
@@ -398,6 +451,10 @@ void remaining_time_sec_callback (Control* sender, int value, void* param)
 void start_exchange_callback (Control* sender, int value, void* param)
 {
     syringe_pump_on();
+
+    Serial.println("Exchange start");
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
 }
 
 //configurations  = Configurations
@@ -406,10 +463,16 @@ void start_exchange_callback (Control* sender, int value, void* param)
 void initial_volume_mL_callback (Control* sender, int value, void* param)
 {
     syringe_filled.set_remaining_volume_mL((sender->value).toFloat());
-    Serial.print("Text: ID: ");
-    Serial.print(sender->id);
-    Serial.print(", Value: ");
-    Serial.println(sender->value);
+
+    Serial.println("syringe_initial_volume (sender->value)");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+    Serial.println("syringe_initial_volume (json value)");
+    Serial.println(String("Value: ") + String(syringe_filled.get_remaining_volume_mL()));
+    Serial.println("");
+
+
 }
 
 void choose_syringe_callback (Control* sender, int value, void* param)
@@ -422,7 +485,6 @@ void choose_syringe_callback (Control* sender, int value, void* param)
     switch (value)
     {
     case B_DOWN:
-        Serial.println("Button DOWN");
 
         //syringe_volume_mL_value = 2; //Mettre la valeur associé au nom choisit du select
         syringe_volume_mL_value = syringe.get_syringe_database()[select_value]["total_volume_mL"];
@@ -437,10 +499,24 @@ void choose_syringe_callback (Control* sender, int value, void* param)
         break;
 
     case B_UP:
-        Serial.println("Button UP");
         break;
     }
-    
+
+    Serial.println("choose_syringe");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+    Serial.println("name_new_syringe (json value)");
+    Serial.println(String("Value: ") + syringe_filled.get_name_syringe());
+    Serial.println("");    
+    Serial.println("Volume_total (json value)");
+    Serial.println(String("Value: ") + syringe.get_syringe_database()["AA"]["total_volume_mL"]);
+    //Serial.println(String("Value: ") + syringe.get_syringe_database()[syringe_filled.get_name_syringe()]["total_volume_mL"]);
+   /* Serial.println("");
+    Serial.println("internal_diameter (json value)");
+    Serial.println(String("Value: ") + syringe.get_syringe_database()[syringe_filled.get_name_syringe()]["internal_diameter"]);
+    Serial.println("");*/
+
 }
 
 void name_new_syringe_callback(Control* sender, int type)
@@ -451,10 +527,11 @@ void name_new_syringe_callback(Control* sender, int type)
 ***/
 {
     name_new_syringe_value = sender->value;
-    Serial.print("Text: ID: ");
-    Serial.print(sender->id);
-    Serial.print(", Value: ");
-    Serial.println(sender->value);
+    Serial.println("name_new_syringe (sender->value)");
+    Serial.println(String("Value: ") + String(sender->type));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+
 }
 
 void total_volume_mL_new_syringe_callback(Control* sender, int type)
@@ -465,10 +542,10 @@ void total_volume_mL_new_syringe_callback(Control* sender, int type)
 ***/
 {
     total_volume_mL_new_syringe_value = sender->value;
-    Serial.print("Text: ID: ");
-    Serial.print(sender->id);
-    Serial.print(", Value: ");
-    Serial.println(sender->value);
+    Serial.println("total_volume_new_syringe");
+    Serial.println(String("Value: ") + String(sender->type));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
 }
 
 void internal_diameter_mm_new_syringe_callback(Control* sender, int type)
@@ -479,10 +556,10 @@ void internal_diameter_mm_new_syringe_callback(Control* sender, int type)
 ***/
 {
     internal_diameter_mm_new_syringe_value = sender->value,
-    Serial.print("Text: ID: ");
-    Serial.print(sender->id);
-    Serial.print(", Value: ");
-    Serial.println(sender->value);
+    Serial.println("internal_diameter_new_syringe");
+    Serial.println(String("Value: ") + String(sender->type));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
 }
 
 void add_syringe_callback (Control* sender, int value,  void* param)
@@ -496,8 +573,6 @@ void add_syringe_callback (Control* sender, int value,  void* param)
     switch (value)
     {
     case B_DOWN:
-        Serial.println("Button DOWN");
-
         syringe.set_syringe(name_new_syringe_value, total_volume_mL_new_syringe_value.toFloat(), internal_diameter_mm_new_syringe_value.toFloat());
         syringe.write_Json();
 
@@ -506,10 +581,13 @@ void add_syringe_callback (Control* sender, int value,  void* param)
         break;
 
     case B_UP:
-        Serial.println("Button UP");
         break;
     }
     
+    Serial.println("add_syringe");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
 
 }
 
@@ -524,7 +602,13 @@ void syringe_pump_length_mm_callback(Control* sender, int type)
 -Action   : Print the value of the number controller via the serial port.
 ***/
 {
-    Serial.println(sender->value);
+    Serial.println("syringe_pump_lenggth (sender->value)");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+    //Serial.println("syringe_pump_length (json value)");
+    //Serial.println(String("Value: ") + String(syringe_filled.get_syringe_pump_length()));
+    //Serial.println("");
 }
 
 void clockwise_equals_push_callback(Control* sender, int value)
@@ -538,19 +622,21 @@ void clockwise_equals_push_callback(Control* sender, int value)
     switch (value)
     {
     case S_ACTIVE:
-        Serial.print("Clockwise equals push");
         ESPUI.print(clockwise_equals_push_label, "Horaire = Injection");
         
         break;
 
     case S_INACTIVE:
-        Serial.print("Clockwise equals pull");
         ESPUI.print(clockwise_equals_push_label, "Horaire = Aspiration");
         break;
     }
-
-    Serial.print(" ");
-    Serial.println(sender->id);
+    Serial.println("clockwise_equals_push (sender->value)");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
+    Serial.println("clockwise_equals_push (json value)");
+    Serial.println(String("Value: ") + String(syringe_filled.get_clockwise_equals_push()));
+    Serial.println("");
 }
 
 //
@@ -562,11 +648,14 @@ void syringe_selection_callback(Control* sender, int value)
 -Action   : Print the value of the syringe name chosen via the serial port.
 ***/
 {
-    Serial.print("Select: ID: ");
-    Serial.print(sender->id);
-    Serial.print(", Value: ");
-    Serial.println(sender->value);
+
     select_value = sender->value;
+    syringe_filled.set_name_syringe(select_value);
+
+    Serial.println("syringe_selection (sender->value)");
+    Serial.println(String("Value: ") + String(sender->value));
+    Serial.println(String("ID: ") + sender->id);
+    Serial.println("");
 }
 
 
-- 
GitLab