1#define VAR_NAME(name) #name
3#include <ArduinoJson.h>
11#define DebugPrint(x) DBG_OUTPUT_PORT.print(x)
12#define DebugPrintln(x) DBG_OUTPUT_PORT.println(x)
13#define DebugPrintf(fmt, ...) DBG_OUTPUT_PORT.printf(fmt, ##__VA_ARGS__)
14#define DebugPrintf_P(fmt, ...) DBG_OUTPUT_PORT.printf_P(fmt, ##__VA_ARGS__)
17#define DebugPrintln(x)
18#define DebugPrintf(x, ...)
19#define DebugPrintf_P(x, ...)
23enum {
CHAR,
UCHAR,
CHAR_PT,
BOOL,
INT,
LONG,
UINT,
ULONG,
FLOAT,
DOUBLE,
STRING};
52 if (first ==
nullptr) {
64 while ( current !=
nullptr )
66 if (strcmp(current->
key, key) == 0) {
69 current = current->
next;
76 File file = fs->open(
"/config.json",
"w");
77 int sz = file.size() * 1.33;
78 int docSize = max(sz, 2048);
79 DynamicJsonDocument root((
size_t)docSize);
82 DebugPrintln(F(
"File not found, will be created new configuration file"));
87 while ( current !=
nullptr )
89 switch (current->
type) {
90 case BOOL: root[current->
key] = *(
bool*)current->
var;
break;
91 case CHAR: root[current->
key] = *(
signed char*)current->
var;
break;
92 case INT: root[current->
key] = *(
int*)current->
var;
break;
93 case LONG: root[current->
key] = *(
long*)current->
var;
break;
94 case UCHAR: root[current->
key] = *(
unsigned char*)current->
var;
break;
95 case UINT: root[current->
key] = *(
unsigned int*)current->
var;
break;
96 case ULONG: root[current->
key] = *(
unsigned long*)current->
var;
break;
97 case CHAR_PT: root[current->
key] = (
unsigned char*)current->
var;
break;
98 case FLOAT: root[current->
key] = *(
float*)current->
var;
break;
99 case DOUBLE: root[current->
key] = *(
double*)current->
var;
break;
100 case STRING: root[current->
key] = *(String*)current->
var;
break;
102 current = current->
next;
105 serializeJson(root, file);
111 File file = fs->open(
"/config.json",
"r");
112 DynamicJsonDocument doc(file.size() * 1.33);
115 DeserializationError error = deserializeJson(doc, file);
118 DebugPrintln(F(
"Failed to deserialize file, may be corrupted"));
129 while ( current !=
nullptr )
131 switch (current->
type) {
132 case BOOL: *(
bool*)current->
var = doc[current->
key];
break;
133 case CHAR: *(
signed char*)current->
var = doc[current->
key];
break;
134 case INT: *(
int*)current->
var = doc[current->
key];
break;
135 case LONG: *(
long*)current->
var = doc[current->
key];
break;
136 case UCHAR: *(
unsigned char*)current->
var = doc[current->
key];
break;
137 case UINT: *(
unsigned int*)current->
var = doc[current->
key];
break;
138 case ULONG: *(
unsigned long*)current->
var = doc[current->
key];
break;
139 case CHAR_PT: strcpy((
char*)current->
var, doc[current->
key]);
break;
140 case FLOAT: *(
float*)current->
var = doc[current->
key];
break;
141 case DOUBLE: *(
double*)current->
var = doc[current->
key];
break;
142 case STRING: *(String*)current->
var = doc[current->
key].as<String>();
break;
144 current = current->
next;
156 virtual inline uint8_t
TypeOf(
const int&) {
return INT; }
157 virtual inline uint8_t
TypeOf(
const unsigned int&) {
return UINT; }
158 virtual inline uint8_t
TypeOf(
const unsigned long&) {
return ULONG; }
159 virtual inline uint8_t
TypeOf(
const unsigned char&) {
return UCHAR; }
VarNode * getNode(const char *key)
bool loadValues(fs::FS *fs, const char *filename)
virtual uint8_t TypeOf(const String &)
virtual uint8_t TypeOf(const char *)
virtual uint8_t TypeOf(const double &)
virtual uint8_t TypeOf(const float &)
virtual uint8_t TypeOf(const unsigned long &)
void addItem(T &var, const char *key)
virtual uint8_t TypeOf(const char &)
virtual uint8_t TypeOf(const bool &)
virtual uint8_t TypeOf(const int &)
virtual uint8_t TypeOf(const unsigned char &)
bool saveValues(fs::FS *fs, const char *filename)
virtual uint8_t TypeOf(const unsigned int &)