From 5c00b3af722bc03b323903b55e56263d3f33d7ed Mon Sep 17 00:00:00 2001
From: Malaurie Bernard <mbernard@kinouby>
Date: Thu, 6 Jul 2023 14:46:41 +0200
Subject: [PATCH] Changing id_syringe to name_syringe and also change type from
 Syringe* to String and do all the changes going with it

---
 cli.h             |  1 +
 syringefilled.cpp | 28 ++++++++++++++--------------
 syringefilled.h   | 10 +++++-----
 3 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/cli.h b/cli.h
index b1b1203..fdbb99f 100644
--- a/cli.h
+++ b/cli.h
@@ -3,6 +3,7 @@
 
 #include "common.h"
 #include "syringe.h"
+#include "syringefilled.h"
 
 class Cli
 {
diff --git a/syringefilled.cpp b/syringefilled.cpp
index 7e1a495..9a38a4a 100644
--- a/syringefilled.cpp
+++ b/syringefilled.cpp
@@ -9,7 +9,7 @@ SyringeFilled :: SyringeFilled() : Motor (&ISRStepper) //pb with my motor constr
     set_exchange_volume_mL(1);
     set_remaining_volume_mL(1);
     set_push(true);
-    set_id_syringe("300912");
+    set_name_syringe("300912");
     set_screw_thread_mm(4);
     set_clockwise_equals_push(true);
     set_emergency(false);
@@ -38,8 +38,8 @@ void SyringeFilled :: set_push(bool push)
     SyringeFilledJSON["push"] = push;
 }
 
-void SyringeFilled :: set_id_syringe(Syringe* id_syringe){
-    SyringeFilledJSON["id_syringe"] = id_syringe;
+void SyringeFilled :: set_name_syringe(Syringe* name_syringe){
+    SyringeFilledJSON["name_syringe"] = name_syringe;
 }
 
 void SyringeFilled :: set_screw_thread_mm(float screw_thread_mm)
@@ -79,9 +79,9 @@ bool SyringeFilled :: get_push()
     return SyringeFilledJSON["push"].as<bool>();
 }
 
-Syringe* SyringeFilled :: get_id_syringe()
+String SyringeFilled :: get_name_syringe()
 {
-    return SyringeFilledJSON["id_syringe"].as<Syringe*>();
+    return SyringeFilledJSON["name_syringe"].as<String>();
 }
 
 float SyringeFilled :: get_screw_thread_mm()
@@ -102,7 +102,7 @@ bool SyringeFilled :: get_emergency()
 
 //CONVERSIONS
     
-float SyringeFilled::volume_to_distance(float volume_mL, Syringe* id_syringe)
+float SyringeFilled::volume_to_distance(float volume_mL)
 /***
 -Argument : Volume in mL.
 -Return   : The distance to cover associated in mm.
@@ -111,21 +111,21 @@ float SyringeFilled::volume_to_distance(float volume_mL, Syringe* id_syringe)
 {
     float volume_mm3 = 1000*volume_mL; //mL->mm3
 
-    float piston_surface_mm2 = id_syringe->get_internal_diameter_mm();
+    float piston_surface_mm2 = SyringeJSON[SyringeFilledJSON["name_syringe"]]["internal_diameter"];
 
     float distance_mm = volume_mm3/piston_surface_mm2;
 
     return distance_mm;
 }
 
-float SyringeFilled::distance_to_volume(float distance_mm, Syringe* id_syringe)
+float SyringeFilled::distance_to_volume(float distance_mm)
 /***
 -Argument : distance in mm.
 -Return   : The volume associated in mL.
 -Action   : /
 ***/
 {
-    float piston_surface_mm2 = id_syringe->get_internal_diameter_mm();
+    float piston_surface_mm2 = SyringeJSON[SyringeFilledJSON["name_syringe"]]["internal_diameter"];
 
     float volume_mm3 = distance_mm*piston_surface_mm2;
 
@@ -147,7 +147,7 @@ float SyringeFilled :: move()
     float exchange_volume_mm3 = get_exchange_volume_mL()*1000;
 
     //Find the section
-    float radius = get_id_syringe()->get_internal_diameter_mm();
+    float radius = SyringeJSON[SyringeFilledJSON["name_syringe"]]["internal_diameter"];
     float section_mm2 = M_PI*radius*radius;
 
 
@@ -252,7 +252,7 @@ bool SyringeFilled :: check_configuration()
 -Action   : Check if the values are correct.
 ***/
 {
-    if (get_id_syringe()->get_internal_diameter_mm() <= 0)
+    if (SyringeJSON[SyringeFilledJSON["name_syringe"]]["internal_diameter"] <= 0)
         return false;
 
     if (get_exchange_volume_mL() < 0)
@@ -289,10 +289,10 @@ void SyringeFilled :: show_configuration()
                   "#     emergency: %d\n"
                   "#     current position: %g mm\n",
                   get_clockwise_equals_push()? "yes": "no",
-                  get_id_syringe()->get_internal_diameter_mm(),
-                  get_id_syringe()->get_total_volume_mL(),
+                  SyringeJSON[SyringeFilledJSON["name_syringe"]]["internal_diameter"],
+                  SyringeJSON[SyringeFilledJSON["name_syringe"]]["total_volume_mL"],
                   get_exchange_throughput_uL_per_sec(),
-                  volume_to_distance(get_exchange_throughput_uL_per_sec(), get_id_syringe()),
+                  volume_to_distance(get_exchange_throughput_uL_per_sec()),
                   get_remaining_volume_mL(),
                   get_push()? "infuse": "withdraw",
                   get_emergency(),
diff --git a/syringefilled.h b/syringefilled.h
index 98934aa..488f478 100644
--- a/syringefilled.h
+++ b/syringefilled.h
@@ -29,7 +29,7 @@ class SyringeFilled : public Motor
     bool _push;  //false means pull
 
     //Syringe
-    Syringe* _id_syringe; //Not sure how to manage it
+    String _name_syringe; //Not sure how to manage it
 
     //Syringe_Pump
     float _screw_thread_mm;
@@ -49,7 +49,7 @@ class SyringeFilled : public Motor
     void set_exchange_volume_mL(float exchange_volume_mL);
     void set_remaining_volume_mL(float remaining_volume_mL);
     void set_push(bool push);
-    void set_id_syringe(Syringe* id_syringe);
+    void set_name_syringe(Syringe* name_syringe);
     void set_screw_thread_mm(float screw_thread_mm);
     void set_clockwise_equals_push(bool clockwise_equals_push);
     void set_emergency(bool emergency);
@@ -60,7 +60,7 @@ class SyringeFilled : public Motor
     float get_exchange_volume_mL();
     float get_remaining_volume_mL();
     bool get_push();
-    Syringe* get_id_syringe();
+    String get_name_syringe();
     float get_screw_thread_mm();
     bool get_clockwise_equals_push();
     bool get_emergency();
@@ -71,8 +71,8 @@ class SyringeFilled : public Motor
 
 
     //CONVERSIONS
-    float volume_to_distance(float volume_mL, Syringe* id_syringe);
-    float distance_to_volume(float distance_mm, Syringe* id_syringe); //CLI
+    float volume_to_distance(float volume_mL);
+    float distance_to_volume(float distance_mm); //CLI
 
     //MOVEMENTS
     float move();
-- 
GitLab