it does work with a structure and arrays in it. this is fine
This commit is contained in:
parent
bf1e25d04c
commit
99d598e05d
3 changed files with 67 additions and 55 deletions
|
@ -156,33 +156,33 @@ void loop() {
|
||||||
|
|
||||||
Serial.println(":: [LOOP] save output 0");
|
Serial.println(":: [LOOP] save output 0");
|
||||||
byte i = 0;
|
byte i = 0;
|
||||||
config.system.output_type[i] = 1;
|
config.system.output.type[i] = 1;
|
||||||
strlcpy(config.system.output_name[i], "bla", sizeof("bla"));
|
strlcpy(config.system.output.name[i], "bla", sizeof("bla"));
|
||||||
config.system.output_gpio[i] = 3;
|
config.system.output.gpio[i] = 3;
|
||||||
config.system.output_gpio_invert[i] = false;
|
config.system.output.gpio_invert[i] = false;
|
||||||
config.system.output_gpio_pwm[i] = false;
|
config.system.output.gpio_pwm[i] = false;
|
||||||
strlcpy(config.system.output_i2c[i], "0x3", sizeof("0x3"));
|
strlcpy(config.system.output.i2c[i], "0x3", sizeof("0x3"));
|
||||||
|
|
||||||
for(byte j=0; j < 4 ; j++) {
|
for(byte j=0; j < 4 ; j++) {
|
||||||
config.system.output_ip[i][j] = j + 3;
|
config.system.output.ip[i][j] = j + 3;
|
||||||
}
|
}
|
||||||
strlcpy(config.system.output_ip_path[i], "/asd?foo=lol", sizeof("/asd?foo=lol"));
|
strlcpy(config.system.output.ip_path[i], "/asd?foo=lol", sizeof("/asd?foo=lol"));
|
||||||
config.system.output_enabled[i] = true;
|
config.system.output.enabled[i] = true;
|
||||||
|
|
||||||
Serial.println(":: [LOOP] save output 1");
|
Serial.println(":: [LOOP] save output 1");
|
||||||
i = 1;
|
i = 1;
|
||||||
config.system.output_type[i] = 2;
|
config.system.output.type[i] = 2;
|
||||||
strlcpy(config.system.output_name[i], "lol", sizeof("lol"));
|
strlcpy(config.system.output.name[i], "lol", sizeof("lol"));
|
||||||
config.system.output_gpio[i] = 5;
|
config.system.output.gpio[i] = 5;
|
||||||
config.system.output_gpio_invert[i] = true;
|
config.system.output.gpio_invert[i] = true;
|
||||||
config.system.output_gpio_pwm[i] = true;
|
config.system.output.gpio_pwm[i] = true;
|
||||||
strlcpy(config.system.output_i2c[i], "0x69", sizeof("0x69"));
|
strlcpy(config.system.output.i2c[i], "0x69", sizeof("0x69"));
|
||||||
|
|
||||||
for(byte j=0; j < 4 ; j++) {
|
for(byte j=0; j < 4 ; j++) {
|
||||||
config.system.output_ip[i][j] = j + 23;
|
config.system.output.ip[i][j] = j + 23;
|
||||||
}
|
}
|
||||||
strlcpy(config.system.output_ip_path[i], "/asd?foo=lol", sizeof("/asd?foo=lol"));
|
strlcpy(config.system.output.ip_path[i], "/asd?foo=lol", sizeof("/asd?foo=lol"));
|
||||||
config.system.output_enabled[i] = true;
|
config.system.output.enabled[i] = true;
|
||||||
|
|
||||||
// save config to littlefs as json
|
// save config to littlefs as json
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
|
|
|
@ -100,7 +100,7 @@ struct Config_WiFi {
|
||||||
* Config System
|
* Config System
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//struct Config_System_Outputs {
|
struct Config_System_Output {
|
||||||
//byte type;
|
//byte type;
|
||||||
//char name[32] = "lol";
|
//char name[32] = "lol";
|
||||||
//byte gpio = 15;
|
//byte gpio = 15;
|
||||||
|
@ -110,7 +110,16 @@ struct Config_WiFi {
|
||||||
//byte ip[4];
|
//byte ip[4];
|
||||||
//char ip_path[32];
|
//char ip_path[32];
|
||||||
//bool enabled;
|
//bool enabled;
|
||||||
//};
|
byte type[Max_Outputs];
|
||||||
|
char name[Max_Outputs][32];
|
||||||
|
byte gpio[Max_Outputs];
|
||||||
|
bool gpio_invert[Max_Outputs];
|
||||||
|
bool gpio_pwm[Max_Outputs];
|
||||||
|
char i2c[Max_Outputs][8];
|
||||||
|
byte ip[Max_Outputs][4];
|
||||||
|
char ip_path[Max_Outputs][32];
|
||||||
|
bool enabled[Max_Outputs];
|
||||||
|
};
|
||||||
|
|
||||||
/* main System struct */
|
/* main System struct */
|
||||||
struct Config_System {
|
struct Config_System {
|
||||||
|
@ -138,16 +147,16 @@ struct Config_System {
|
||||||
* - output_enabled: enable output
|
* - output_enabled: enable output
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
byte output_type[Max_Outputs];
|
// byte output_type[Max_Outputs];
|
||||||
char output_name[Max_Outputs][32];
|
// char output_name[Max_Outputs][32];
|
||||||
byte output_gpio[Max_Outputs];
|
// byte output_gpio[Max_Outputs];
|
||||||
bool output_gpio_invert[Max_Outputs];
|
// bool output_gpio_invert[Max_Outputs];
|
||||||
bool output_gpio_pwm[Max_Outputs];
|
// bool output_gpio_pwm[Max_Outputs];
|
||||||
char output_i2c[Max_Outputs][8];
|
// char output_i2c[Max_Outputs][8];
|
||||||
byte output_ip[Max_Outputs][4];
|
// byte output_ip[Max_Outputs][4];
|
||||||
char output_ip_path[Max_Outputs][32];
|
// char output_ip_path[Max_Outputs][32];
|
||||||
bool output_enabled[Max_Outputs];
|
// bool output_enabled[Max_Outputs];
|
||||||
//Config_System_Outputs outputs[Max_Outputs];
|
Config_System_Output output;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -205,19 +205,23 @@ bool LoadConfig() {
|
||||||
config.system.httpLogSerial = objSystem["httpLogSerial"];
|
config.system.httpLogSerial = objSystem["httpLogSerial"];
|
||||||
config.system.schedulerInterval = objSystem["schedulerInterval"];
|
config.system.schedulerInterval = objSystem["schedulerInterval"];
|
||||||
|
|
||||||
|
JsonObject objSystemOutput = objSystem["output"][0];
|
||||||
|
|
||||||
/* System Outputs */
|
/* System Outputs */
|
||||||
for(byte i=0; i < Max_Outputs; i++) {
|
for(byte i=0; i < Max_Outputs; i++) {
|
||||||
config.system.output_type[i] = objSystem["output_type"][i];
|
if(objSystemOutput["type"][i] > 0) {
|
||||||
strlcpy(config.system.output_name[i], objSystem["output_name"][i], sizeof(config.system.output_name[i]));
|
config.system.output.type[i] = objSystemOutput["type"][i];
|
||||||
config.system.output_gpio[i] = objSystem["output_gpio"][i];
|
strlcpy(config.system.output.name[i], objSystemOutput["name"][i], sizeof(config.system.output.name[i]));
|
||||||
config.system.output_gpio_invert[i] = objSystem["output_gpio_invert"][i];
|
config.system.output.gpio[i] = objSystemOutput["gpio"][i];
|
||||||
config.system.output_gpio_pwm[i] = objSystem["output_gpio_pwm"][i];
|
config.system.output.gpio_invert[i] = objSystemOutput["gpio_invert"][i];
|
||||||
strlcpy(config.system.output_i2c[i], objSystem["output_i2c"][i], sizeof(config.system.output_i2c[i]));
|
config.system.output.gpio_pwm[i] = objSystemOutput["gpio_pwm"][i];
|
||||||
for(byte j=0; j < 4 ; j++) {
|
strlcpy(config.system.output.i2c[i], objSystemOutput["i2c"][i], sizeof(config.system.output.i2c[i]));
|
||||||
config.system.output_ip[i][j] = objSystem["output_ip"][i][j];
|
for(byte j=0; j < 4 ; j++) {
|
||||||
|
config.system.output.ip[i][j] = objSystemOutput["ip"][i][j];
|
||||||
|
}
|
||||||
|
strlcpy(config.system.output.ip_path[i], objSystemOutput["ip_path"][i], sizeof(config.system.output.ip_path[i]));
|
||||||
|
config.system.output.enabled[i] = objSystemOutput["enabled"][i];
|
||||||
}
|
}
|
||||||
strlcpy(config.system.output_ip_path[i], objSystem["output_ip_path"][i], sizeof(config.system.output_ip_path[i]));
|
|
||||||
config.system.output_enabled[i] = objSystem["output_enabled"][i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grow */
|
/* Grow */
|
||||||
|
@ -280,23 +284,22 @@ bool SaveConfig(bool writeToSerial = false) {
|
||||||
objSystem["schedulerInterval"] = config.system.schedulerInterval;
|
objSystem["schedulerInterval"] = config.system.schedulerInterval;
|
||||||
|
|
||||||
/* System Outputs */
|
/* System Outputs */
|
||||||
|
JsonObject objSystemOutput = objSystem["output"].add<JsonObject>();
|
||||||
|
|
||||||
for(byte i=0; i < Max_Outputs; i++) {
|
for(byte i=0; i < Max_Outputs; i++) {
|
||||||
|
if(config.system.output.type[i] > 0) {
|
||||||
|
objSystemOutput["type"][i] = config.system.output.type[i];
|
||||||
|
objSystemOutput["name"][i] = config.system.output.name[i];
|
||||||
|
objSystemOutput["gpio"][i] = config.system.output.gpio[i];
|
||||||
|
objSystemOutput["gpio_invert"][i] = config.system.output.gpio_invert[i];
|
||||||
|
objSystemOutput["gpio_pwm"][i] = config.system.output.gpio_pwm[i];
|
||||||
|
objSystemOutput["i2c"][i] = config.system.output.i2c[i];
|
||||||
|
|
||||||
|
for(byte j=0; j < 4 ; j++) {
|
||||||
objSystem["output_type"][i] = config.system.output_type[i];
|
objSystemOutput["ip"][i][j] = config.system.output.ip[i][j];
|
||||||
objSystem["output_name"][i] = config.system.output_name[i];
|
}
|
||||||
objSystem["output_gpio"][i] = config.system.output_gpio[i];
|
objSystemOutput["ip_path"][i] = config.system.output.ip_path[i];
|
||||||
objSystem["output_gpio_invert"][i] = config.system.output_gpio_invert[i];
|
objSystemOutput["enabled"][i] = config.system.output.enabled[i];
|
||||||
objSystem["output_gpio_pwm"][i] = config.system.output_gpio_pwm[i];
|
|
||||||
objSystem["output_i2c"][i] = config.system.output_i2c[i];
|
|
||||||
|
|
||||||
for(byte j=0; j < 4 ; j++) {
|
|
||||||
objSystem["output_ip"][i][j] = config.system.output_ip[i][j];
|
|
||||||
}
|
}
|
||||||
objSystem["output_ip_path"][i] = config.system.output_ip_path[i];
|
|
||||||
objSystem["output_enabled"][i] = config.system.output_enabled[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue