diff --git a/Arduino/CanGrow/include/CanGrow_Core.h b/Arduino/CanGrow/include/CanGrow_Core.h index 75c64c2..648b9e6 100644 --- a/Arduino/CanGrow/include/CanGrow_Core.h +++ b/Arduino/CanGrow/include/CanGrow_Core.h @@ -122,6 +122,31 @@ bool Check_GPIOindex_Used(byte gpio) { } } } + + if(used == false) { + for(byte i=0; i < Max_Sensors; i++) { + #ifndef DEBUG + //Serial.printf("DB [Core:Check_GPIOindex_Used] OutputId: %d , type: %d\n", i, config.system.output.type[i]); + #endif + // check if sensor type is gpio + if(config.system.sensor.gpio[i] > 0) { + #ifndef DEBUG + Serial.printf("DB [Core:Check_GPIOindex_Used] SensorId: %d is GPIO (type %d)\n", i, config.system.sensor.gpio[i]); + #endif + // check if gpio id is already in use + if(config.system.sensor.gpio[i] == gpio) { + #ifndef DEBUG + Serial.printf("DB [Core:Check_GPIOindex_Used] sensor.gpio[%d](%d) == GPIO %d\n", i, config.system.sensor.gpio[i], gpio); + #endif + used = true; + break; + } else { + used = false; + } + } + } + } + #ifndef DEBUG Serial.printf("DB [Core:Check_GPIOindex_Used] GPIO: %d, used: %d\n", gpio, used); #endif diff --git a/Arduino/CanGrow/include/Webserver/Page_system.h b/Arduino/CanGrow/include/Webserver/Page_system.h index 2bccc45..e3ebcc5 100644 --- a/Arduino/CanGrow/include/Webserver/Page_system.h +++ b/Arduino/CanGrow/include/Webserver/Page_system.h @@ -340,24 +340,22 @@ String Proc_WebPage_system_output(const String& var) { output_tr_td += ""; output_tr_td += Output_Type_descr[config.system.output.type[i]]; - if((config.system.output.type[i] == OUTPUT_TYPE_GPIO) || (config.system.output.type[i] == OUTPUT_TYPE_I2C)) { + if((config.system.output.type[i] == OUTPUT_TYPE_GPIO) || ( (config.system.output.type[i] == OUTPUT_TYPE_I2C) && (strlen(config.system.output.i2c[i]) > 0) )) { output_tr_td += " ("; - } - switch(config.system.output.type[i]) { - case OUTPUT_TYPE_GPIO: - output_tr_td += GPIOindex[config.system.output.gpio[i]].gpio; - break; - - case OUTPUT_TYPE_I2C: - output_tr_td += config.system.output.i2c[i]; - break; - - default: - break; - } + switch(config.system.output.type[i]) { + case OUTPUT_TYPE_GPIO: + output_tr_td += GPIOindex[config.system.output.gpio[i]].gpio; + break; + + case OUTPUT_TYPE_I2C: + output_tr_td += config.system.output.i2c[i]; + break; + + default: + break; + } - if((config.system.output.type[i] == OUTPUT_TYPE_GPIO) || (config.system.output.type[i] == OUTPUT_TYPE_I2C)) { output_tr_td += ")"; } @@ -828,7 +826,7 @@ String Proc_WebPage_system_sensor(const String& var) { output_tr_td += ""; output_tr_td += SensorIndex[config.system.sensor.type[i]].name; - if((config.system.sensor.i2c_address[i] != "") || (config.system.sensor.gpio[i] > 0)) { + if((strlen(config.system.sensor.i2c_address[i]) > 0) || (config.system.sensor.gpio[i] > 0)) { output_tr_td += " ("; if(config.system.sensor.gpio[i] > 0) { output_tr_td += GPIOindex[config.system.sensor.gpio[i]].gpio;