Skip to content
Snippets Groups Projects
Commit b49fa079 authored by Malaurie Bernard's avatar Malaurie Bernard
Browse files

Creation of the read_json and write_json methods in syringe and syringefilled class.

parent 501d3b84
No related branches found
No related tags found
1 merge request!17Malaurie's work on UI + CLI interface + AccelStepper interface
...@@ -38,6 +38,36 @@ string Syringe :: get_id() ...@@ -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);
}
......
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
#include "motor.h" #include "motor.h"
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <interrupts.h> // InterruptLock
using InterruptLock = esp8266::InterruptLock;
#include <iostream>
using namespace std;
class Syringe class Syringe
{ {
...@@ -27,6 +33,9 @@ class Syringe ...@@ -27,6 +33,9 @@ class Syringe
//JSON DOCUMENT //JSON DOCUMENT
StaticJsonDocument<200> SyringeJSON; //200 = RAM allocated to this document StaticJsonDocument<200> SyringeJSON; //200 = RAM allocated to this document
//JSON METHODS
void write_Json (Stream& output_stream);
void read_Json (Stream& input_stream);
}; };
......
...@@ -288,3 +288,33 @@ void SyringeFilled :: show_configuration() ...@@ -288,3 +288,33 @@ void SyringeFilled :: show_configuration()
stepToMm(step)); 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);
}
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
#include "syringe.h" #include "syringe.h"
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "math.h" #include "math.h"
#include <interrupts.h> // InterruptLock
using InterruptLock = esp8266::InterruptLock;
#define syringe_pump_length_mm 50 #define syringe_pump_length_mm 50
...@@ -83,6 +86,13 @@ class SyringeFilled : public Motor ...@@ -83,6 +86,13 @@ class SyringeFilled : public Motor
bool check_configuration(); //CLI bool check_configuration(); //CLI
void show_configuration(); //CLI void show_configuration(); //CLI
//JSON
void write_Json (Stream& output_stream);
void read_Json (Stream& input_stream);
}; };
extern SyringeFilled syringe_filled; extern SyringeFilled syringe_filled;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment