diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index 8258a0e..7f25471 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -156,33 +156,33 @@ void loop() { Serial.println(":: [LOOP] save output 0"); byte i = 0; - config.system.output_type[i] = 1; - strlcpy(config.system.output_name[i], "bla", sizeof("bla")); - config.system.output_gpio[i] = 3; - config.system.output_gpio_invert[i] = false; - config.system.output_gpio_pwm[i] = false; - strlcpy(config.system.output_i2c[i], "0x3", sizeof("0x3")); + config.system.output.type[i] = 1; + strlcpy(config.system.output.name[i], "bla", sizeof("bla")); + config.system.output.gpio[i] = 3; + config.system.output.gpio_invert[i] = false; + config.system.output.gpio_pwm[i] = false; + strlcpy(config.system.output.i2c[i], "0x3", sizeof("0x3")); 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")); - config.system.output_enabled[i] = true; + strlcpy(config.system.output.ip_path[i], "/asd?foo=lol", sizeof("/asd?foo=lol")); + config.system.output.enabled[i] = true; Serial.println(":: [LOOP] save output 1"); i = 1; - config.system.output_type[i] = 2; - strlcpy(config.system.output_name[i], "lol", sizeof("lol")); - config.system.output_gpio[i] = 5; - config.system.output_gpio_invert[i] = true; - config.system.output_gpio_pwm[i] = true; - strlcpy(config.system.output_i2c[i], "0x69", sizeof("0x69")); + config.system.output.type[i] = 2; + strlcpy(config.system.output.name[i], "lol", sizeof("lol")); + config.system.output.gpio[i] = 5; + config.system.output.gpio_invert[i] = true; + config.system.output.gpio_pwm[i] = true; + strlcpy(config.system.output.i2c[i], "0x69", sizeof("0x69")); 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")); - config.system.output_enabled[i] = true; + strlcpy(config.system.output.ip_path[i], "/asd?foo=lol", sizeof("/asd?foo=lol")); + config.system.output.enabled[i] = true; // save config to littlefs as json SaveConfig(); diff --git a/Arduino/CanGrow/include/CanGrow.h b/Arduino/CanGrow/include/CanGrow.h index 8469ec5..d05ef6c 100644 --- a/Arduino/CanGrow/include/CanGrow.h +++ b/Arduino/CanGrow/include/CanGrow.h @@ -100,7 +100,7 @@ struct Config_WiFi { * Config System */ -//struct Config_System_Outputs { +struct Config_System_Output { //byte type; //char name[32] = "lol"; //byte gpio = 15; @@ -110,7 +110,16 @@ struct Config_WiFi { //byte ip[4]; //char ip_path[32]; //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 */ struct Config_System { @@ -138,16 +147,16 @@ struct Config_System { * - output_enabled: enable output * */ - byte output_type[Max_Outputs]; - char output_name[Max_Outputs][32]; - byte output_gpio[Max_Outputs]; - bool output_gpio_invert[Max_Outputs]; - bool output_gpio_pwm[Max_Outputs]; - char output_i2c[Max_Outputs][8]; - byte output_ip[Max_Outputs][4]; - char output_ip_path[Max_Outputs][32]; - bool output_enabled[Max_Outputs]; - //Config_System_Outputs outputs[Max_Outputs]; + // byte output_type[Max_Outputs]; + // char output_name[Max_Outputs][32]; + // byte output_gpio[Max_Outputs]; + // bool output_gpio_invert[Max_Outputs]; + // bool output_gpio_pwm[Max_Outputs]; + // char output_i2c[Max_Outputs][8]; + // byte output_ip[Max_Outputs][4]; + // char output_ip_path[Max_Outputs][32]; + // bool output_enabled[Max_Outputs]; + Config_System_Output output; }; diff --git a/Arduino/CanGrow/include/CanGrow_LittleFS.h b/Arduino/CanGrow/include/CanGrow_LittleFS.h index bbc51a6..032c38a 100644 --- a/Arduino/CanGrow/include/CanGrow_LittleFS.h +++ b/Arduino/CanGrow/include/CanGrow_LittleFS.h @@ -205,19 +205,23 @@ bool LoadConfig() { config.system.httpLogSerial = objSystem["httpLogSerial"]; config.system.schedulerInterval = objSystem["schedulerInterval"]; + JsonObject objSystemOutput = objSystem["output"][0]; + /* System Outputs */ for(byte i=0; i < Max_Outputs; i++) { - config.system.output_type[i] = objSystem["output_type"][i]; - strlcpy(config.system.output_name[i], objSystem["output_name"][i], sizeof(config.system.output_name[i])); - config.system.output_gpio[i] = objSystem["output_gpio"][i]; - config.system.output_gpio_invert[i] = objSystem["output_gpio_invert"][i]; - config.system.output_gpio_pwm[i] = objSystem["output_gpio_pwm"][i]; - strlcpy(config.system.output_i2c[i], objSystem["output_i2c"][i], sizeof(config.system.output_i2c[i])); - for(byte j=0; j < 4 ; j++) { - config.system.output_ip[i][j] = objSystem["output_ip"][i][j]; + if(objSystemOutput["type"][i] > 0) { + config.system.output.type[i] = objSystemOutput["type"][i]; + strlcpy(config.system.output.name[i], objSystemOutput["name"][i], sizeof(config.system.output.name[i])); + config.system.output.gpio[i] = objSystemOutput["gpio"][i]; + config.system.output.gpio_invert[i] = objSystemOutput["gpio_invert"][i]; + config.system.output.gpio_pwm[i] = objSystemOutput["gpio_pwm"][i]; + strlcpy(config.system.output.i2c[i], objSystemOutput["i2c"][i], sizeof(config.system.output.i2c[i])); + 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 */ @@ -280,23 +284,22 @@ bool SaveConfig(bool writeToSerial = false) { objSystem["schedulerInterval"] = config.system.schedulerInterval; /* System Outputs */ - - + JsonObject objSystemOutput = objSystem["output"].add(); for(byte i=0; i < Max_Outputs; i++) { - - - objSystem["output_type"][i] = config.system.output_type[i]; - objSystem["output_name"][i] = config.system.output_name[i]; - objSystem["output_gpio"][i] = config.system.output_gpio[i]; - objSystem["output_gpio_invert"][i] = config.system.output_gpio_invert[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]; + 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++) { + objSystemOutput["ip"][i][j] = config.system.output.ip[i][j]; + } + objSystemOutput["ip_path"][i] = config.system.output.ip_path[i]; + objSystemOutput["enabled"][i] = config.system.output.enabled[i]; } - objSystem["output_ip_path"][i] = config.system.output_ip_path[i]; - objSystem["output_enabled"][i] = config.system.output_enabled[i]; }