save i2c sensor addr as char, use it later with strtol()
This commit is contained in:
parent
4b3451c2fa
commit
156849782b
4 changed files with 21 additions and 1 deletions
|
@ -228,6 +228,7 @@ struct Config_System_Sensor {
|
||||||
|
|
||||||
byte type[Max_Sensors];
|
byte type[Max_Sensors];
|
||||||
char name[Max_Sensors][32];
|
char name[Max_Sensors][32];
|
||||||
|
char i2c_address[Max_Sensors][5];
|
||||||
byte gpio[Max_Sensors];
|
byte gpio[Max_Sensors];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -234,6 +234,7 @@ bool LoadConfig() {
|
||||||
if(objSystemSensor["type"][i] > 0) {
|
if(objSystemSensor["type"][i] > 0) {
|
||||||
config.system.sensor.type[i] = objSystemSensor["type"][i];
|
config.system.sensor.type[i] = objSystemSensor["type"][i];
|
||||||
strlcpy(config.system.sensor.name[i], objSystemSensor["name"][i], sizeof(config.system.sensor.name[i]));
|
strlcpy(config.system.sensor.name[i], objSystemSensor["name"][i], sizeof(config.system.sensor.name[i]));
|
||||||
|
strlcpy(config.system.sensor.i2c_address[i], objSystemSensor["i2c_address"][i], sizeof(config.system.sensor.i2c_address[i]));
|
||||||
// gpio
|
// gpio
|
||||||
config.system.sensor.gpio[i] = objSystemSensor["gpio"][i];
|
config.system.sensor.gpio[i] = objSystemSensor["gpio"][i];
|
||||||
|
|
||||||
|
@ -328,6 +329,7 @@ bool SaveConfig(bool writeToSerial = false) {
|
||||||
if(config.system.sensor.type[i] > 0) {
|
if(config.system.sensor.type[i] > 0) {
|
||||||
objSystemSensor["type"][i] = config.system.sensor.type[i];
|
objSystemSensor["type"][i] = config.system.sensor.type[i];
|
||||||
objSystemSensor["name"][i] = config.system.sensor.name[i];
|
objSystemSensor["name"][i] = config.system.sensor.name[i];
|
||||||
|
objSystemSensor["i2c_address"][i] = config.system.sensor.i2c_address[i];
|
||||||
objSystemSensor["gpio"][i] = config.system.sensor.gpio[i];
|
objSystemSensor["gpio"][i] = config.system.sensor.gpio[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -974,6 +974,13 @@ String Proc_WebPage_system_sensor_addEdit(const String& var) {
|
||||||
sensorName.replace("%", "%");
|
sensorName.replace("%", "%");
|
||||||
return sensorName;
|
return sensorName;
|
||||||
|
|
||||||
|
} else if(var == "SENSOR_I2C_ADDRESS") {
|
||||||
|
// "escape" % character, because it would break the template processor.
|
||||||
|
// tasmote webcall for example has percentage char in its path
|
||||||
|
String sensorI2cAddress = config.system.sensor.i2c_address[tmpParam_editSensorId];
|
||||||
|
sensorI2cAddress.replace("%", "%");
|
||||||
|
return sensorI2cAddress;
|
||||||
|
|
||||||
} else if(var == "GPIO_INDEX") {
|
} else if(var == "GPIO_INDEX") {
|
||||||
return Html_SelectOpt_GPIOindex(config.system.sensor.gpio[tmpParam_editSensorId]);
|
return Html_SelectOpt_GPIOindex(config.system.sensor.gpio[tmpParam_editSensorId]);
|
||||||
|
|
||||||
|
@ -1028,6 +1035,12 @@ void WebPage_system_sensor_add(AsyncWebServerRequest *request) {
|
||||||
strlcpy(config.system.sensor.name[sensorId], p_name->value().c_str(), sizeof(config.system.sensor.name[sensorId]));
|
strlcpy(config.system.sensor.name[sensorId], p_name->value().c_str(), sizeof(config.system.sensor.name[sensorId]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(request->hasParam("i2c_address", true)) {
|
||||||
|
const AsyncWebParameter* p_i2c_address = request->getParam("i2c_address", true);
|
||||||
|
Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_i2c_address->name().c_str(), p_i2c_address->value().c_str());
|
||||||
|
strlcpy(config.system.sensor.i2c_address[sensorId], p_i2c_address->value().c_str(), sizeof(config.system.sensor.i2c_address[sensorId]));
|
||||||
|
}
|
||||||
|
|
||||||
if(request->hasParam("gpio", true)) {
|
if(request->hasParam("gpio", true)) {
|
||||||
const AsyncWebParameter* p_gpio = request->getParam("gpio", true);
|
const AsyncWebParameter* p_gpio = request->getParam("gpio", true);
|
||||||
Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_gpio->name().c_str(), p_gpio->value().c_str());
|
Serial.printf(":: [Webserver:system] POST[%s]: %s\n", p_gpio->name().c_str(), p_gpio->value().c_str());
|
||||||
|
|
|
@ -278,7 +278,11 @@ const char* Page_system_sensor_add_HTML PROGMEM = R"(%HEADER%
|
||||||
|
|
||||||
|
|
||||||
<u>Name</u>:<br>
|
<u>Name</u>:<br>
|
||||||
<input type='text' name='name' maxlength='16' value='%SENSOR_NAME%' required><br>
|
<input type='text' name='name' maxlength='32' value='%SENSOR_NAME%' required><br>
|
||||||
|
|
||||||
|
<u>I2C address</u>:<br>
|
||||||
|
<p>leave empty for default</p>
|
||||||
|
<input type='text' name='i2c_address' maxlength='5' value='%SENSOR_I2C_ADDRESS%' required><br>
|
||||||
|
|
||||||
<u>GPIO</u>:<br>
|
<u>GPIO</u>:<br>
|
||||||
<select name='gpio'>
|
<select name='gpio'>
|
||||||
|
|
Loading…
Reference in a new issue