diff --git a/syringe.cpp b/syringe.cpp index e2e3a56d5c30c7213f4b9dcbecb194e1bab17d95..0fe5407e01d835881a74fd48ce6fb19dc7710704 100644 --- a/syringe.cpp +++ b/syringe.cpp @@ -38,6 +38,36 @@ string Syringe :: get_id() } +//Example : File f = ({ InterruptLock lock; filesystem->open(filename, "w"); }); and the f becomes the argument output_stream +//useful in web.cpp via a button to save data +void Syringe :: write_Json (Stream& output_stream) +{ +/*** +-Argument : output_stream (= serial or a file) +-Return : / +-Action : Save the Json structure in a file (convert it to text) +***/ + +InterruptLock lock; //useful thanks to its constructor (so a is not visible in the code) +serializeJson(SyringeJSON, output_stream); + +} + + +//useful in setup of pousse-seringue.cpp(to check at the begining what has already been saved) and web.cpp via a button to recover data +void Syringe :: read_Json (Stream& input_stream) +{ +/*** +-Argument : input_stream (= serial or a file) +-Return : / +-Action : Check if a Json Document alredy exist or not +***/ + +InterruptLock lock; //useful thanks to its constructor (so a is not visible in the code) +deserializeJson(SyringeJSON, input_stream); + +} + diff --git a/syringe.h b/syringe.h index 0536ac8713c4ec55aadd0823b1bcde5a58f30ff0..614777ae32faf42a54cddee35e5f5739b7dc3395 100644 --- a/syringe.h +++ b/syringe.h @@ -4,6 +4,12 @@ #include "motor.h" #include <ArduinoJson.h> +#include <interrupts.h> // InterruptLock +using InterruptLock = esp8266::InterruptLock; + +#include <iostream> +using namespace std; + class Syringe { @@ -27,6 +33,9 @@ class Syringe //JSON DOCUMENT StaticJsonDocument<200> SyringeJSON; //200 = RAM allocated to this document + //JSON METHODS + void write_Json (Stream& output_stream); + void read_Json (Stream& input_stream); }; diff --git a/syringefilled.cpp b/syringefilled.cpp index 17f42b7401bb84089c4e033fa61123929f3f6a31..b2e116fd9b52f5714273bd8ee0c25a9f900e35fa 100644 --- a/syringefilled.cpp +++ b/syringefilled.cpp @@ -288,3 +288,33 @@ void SyringeFilled :: show_configuration() stepToMm(step)); } +//Example : File f = ({ InterruptLock lock; filesystem->open(filename, "w"); }); and the f becomes the argument output_stream +//useful in web.cpp via a button to save data +void SyringeFilled :: write_Json (Stream& output_stream) //file_name sera le nom du fichier Json, doc sera la structure Json qu'on veut transformer en fichier +{ +/*** +-Argument : output_stream (= serial or a file) +-Return : / +-Action : Save the Json structure in a file (convert it to text) +***/ + +InterruptLock lock; //useful thanks to its constructor (so a is not visible in the code) +serializeJson(SyringeFilledJSON, output_stream); + +} + + +//useful in setup of pousse-seringue.cpp(to check at the begining what has already been saved) and web.cpp via a button to recover data +void SyringeFilled :: read_Json (Stream& input_stream) //file_name sera le nom du fichier Json, doc sera la structure Json qu'on veut transformer en fichier +{ +/*** +-Argument : input_stream (= serial or a file) +-Return : / +-Action : Check if a Json Document alredy exist or not +***/ + +InterruptLock lock; //useful thanks to its constructor (so a is not visible in the code) +deserializeJson(SyringeFilledJSON, input_stream); + + +} diff --git a/syringefilled.h b/syringefilled.h index 4724fd7765f7d6573bc58fbba75e5b13d7585f65..31167bd1181420f88f3e645967fb55d1014ca4a0 100644 --- a/syringefilled.h +++ b/syringefilled.h @@ -3,6 +3,9 @@ #include "syringe.h" #include <ArduinoJson.h> #include "math.h" +#include <interrupts.h> // InterruptLock +using InterruptLock = esp8266::InterruptLock; + #define syringe_pump_length_mm 50 @@ -83,6 +86,13 @@ class SyringeFilled : public Motor bool check_configuration(); //CLI void show_configuration(); //CLI + //JSON + void write_Json (Stream& output_stream); + void read_Json (Stream& input_stream); + + + + }; extern SyringeFilled syringe_filled; \ No newline at end of file