mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-27 17:19:08 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev
This commit is contained in:
@@ -57,10 +57,12 @@ void AnalogSensor::reload(bool get_nvs) {
|
||||
remove_ha_topic(sensor.type(), sensor.gpio());
|
||||
sensor.ha_registered = false;
|
||||
}
|
||||
|
||||
if (!analog_enabled_) {
|
||||
sensors_.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// load the list of analog sensors from the customization service
|
||||
// and store them locally and then activate them
|
||||
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
||||
@@ -68,8 +70,8 @@ void AnalogSensor::reload(bool get_nvs) {
|
||||
for (auto & sensor_ : sensors_) {
|
||||
// update existing sensors
|
||||
bool found = false;
|
||||
for (const auto & sensor : settings.analogCustomizations) { //search customlist
|
||||
if (System::is_valid_gpio(sensor.gpio) && sensor_.gpio() == sensor.gpio) {
|
||||
for (const auto & sensor : settings.analogCustomizations) { // search customlist
|
||||
if (sensor_.gpio() == sensor.gpio) {
|
||||
// for output sensors set value to new start-value
|
||||
if ((sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT)
|
||||
&& (sensor_.type() != sensor.type || sensor_.offset() != sensor.offset || sensor_.factor() != sensor.factor)) {
|
||||
@@ -94,14 +96,14 @@ void AnalogSensor::reload(bool get_nvs) {
|
||||
for (const auto & sensor : settings.analogCustomizations) {
|
||||
bool found = false;
|
||||
for (const auto & sensor_ : sensors_) {
|
||||
if (System::is_valid_gpio(sensor.gpio) && sensor_.gpio() == sensor.gpio) {
|
||||
if (sensor_.gpio() == sensor.gpio) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
if (!System::is_valid_gpio(sensor.gpio)) {
|
||||
continue;
|
||||
}
|
||||
// if (!System::is_valid_gpio(sensor.gpio)) {
|
||||
// continue;
|
||||
// }
|
||||
sensors_.emplace_back(sensor.gpio, sensor.name, sensor.offset, sensor.factor, sensor.uom, sensor.type);
|
||||
sensors_.back().ha_registered = false; // this will trigger recreate of the HA config
|
||||
if (sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT) {
|
||||
@@ -130,6 +132,14 @@ void AnalogSensor::reload(bool get_nvs) {
|
||||
// activate each sensor
|
||||
for (auto & sensor : sensors_) {
|
||||
sensor.ha_registered = false; // force HA configs to be re-created
|
||||
|
||||
// first check if the GPIO is valid. If not, force set it to disabled
|
||||
if (!System::is_valid_gpio(sensor.gpio())) {
|
||||
LOG_WARNING("Bad GPIO %d for Sensor %s", sensor.gpio(), sensor.name().c_str());
|
||||
sensor.set_type(AnalogType::NOTUSED);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sensor.type() == AnalogType::ADC) {
|
||||
LOG_DEBUG("ADC Sensor on GPIO %02d", sensor.gpio());
|
||||
// analogSetPinAttenuation does not work with analogReadMilliVolts
|
||||
@@ -261,6 +271,7 @@ void AnalogSensor::measure() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// poll digital io every time with debounce
|
||||
// go through the list of digital sensors
|
||||
for (auto & sensor : sensors_) {
|
||||
|
||||
@@ -101,7 +101,7 @@ class AnalogSensor {
|
||||
double factor_;
|
||||
uint8_t uom_;
|
||||
double value_; // double because of the factor is a double
|
||||
int8_t type_;
|
||||
int8_t type_; // one of the AnalogType enum
|
||||
};
|
||||
|
||||
AnalogSensor() = default;
|
||||
|
||||
@@ -266,7 +266,7 @@ MAKE_ENUM_FIXED(list_syslog_level, "off", "emerg", "alert", "crit", "error", "wa
|
||||
// sensors
|
||||
MAKE_ENUM_FIXED(counter, "counter")
|
||||
MAKE_ENUM_FIXED(digital_out, "digital_out")
|
||||
MAKE_ENUM_FIXED(list_sensortype, "none", "digital in", "counter", "adc", "timer", "rate", "digital out", "pwm 0", "pwm 1", "pwm 2")
|
||||
MAKE_ENUM_FIXED(list_sensortype, "disabled", "digital in", "counter", "adc", "timer", "rate", "digital out", "pwm 0", "pwm 1", "pwm 2")
|
||||
|
||||
// watch
|
||||
MAKE_ENUM_FIXED(list_watch, "off", "on", "raw", "unknown")
|
||||
|
||||
@@ -440,6 +440,11 @@ bool System::is_valid_gpio(uint8_t pin, bool has_psram) {
|
||||
#endif
|
||||
return false; // bad pin
|
||||
}
|
||||
|
||||
// extra check for pins 21 and 22 (I2C) when ethernet is enabled
|
||||
if ((EMSESP::system_.ethernet_connected()) && (pin >= 21 && pin <= 22)) {
|
||||
return false; // bad pin
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user