calculate dallassensor offset

This commit is contained in:
MichaelDvP
2021-07-17 06:33:14 +02:00
parent f8579f7c96
commit d7bc821bbe
2 changed files with 21 additions and 2 deletions

View File

@@ -140,7 +140,11 @@ void DallasSensor::loop() {
bool found = false; bool found = false;
for (auto & sensor : sensors_) { for (auto & sensor : sensors_) {
if (sensor.id() == get_id(addr)) { if (sensor.id() == get_id(addr)) {
changed_ |= (t != sensor.temperature_c); t += sensor.offset();
if (t != sensor.temperature_c) {
sensor.temperature_c = t;
changed_ |= true;
}
sensor.temperature_c = t; sensor.temperature_c = t;
sensor.read = true; sensor.read = true;
found = true; found = true;
@@ -150,7 +154,7 @@ void DallasSensor::loop() {
// add new sensor // add new sensor
if (!found && (sensors_.size() < (MAX_SENSORS - 1))) { if (!found && (sensors_.size() < (MAX_SENSORS - 1))) {
sensors_.emplace_back(addr); sensors_.emplace_back(addr);
sensors_.back().temperature_c = t; sensors_.back().temperature_c = t + sensors_.back().offset();
sensors_.back().read = true; sensors_.back().read = true;
changed_ = true; changed_ = true;
} }
@@ -321,6 +325,20 @@ std::string DallasSensor::Sensor::to_string() const {
return str; return str;
} }
int16_t DallasSensor::Sensor::offset() const {
std::string str = id_string();
int16_t offset = 0;
EMSESP::webSettingsService.read([&](WebSettings & settings) {
for (uint8_t i = 0; i < NUM_SENSOR_NAMES; i++) {
if (strcmp(settings.sensor[i].id.c_str(), str.c_str()) == 0) {
offset = settings.sensor[i].offset;
}
}
});
return offset;
}
void DallasSensor::add_name(const char * id, const char * name, int16_t offset) { void DallasSensor::add_name(const char * id, const char * name, int16_t offset) {
EMSESP::webSettingsService.update([&](WebSettings & settings) { EMSESP::webSettingsService.update([&](WebSettings & settings) {
// check for new name of stored id // check for new name of stored id

View File

@@ -48,6 +48,7 @@ class DallasSensor {
uint64_t id() const; uint64_t id() const;
std::string id_string() const; std::string id_string() const;
std::string to_string() const; std::string to_string() const;
int16_t offset() const;
int16_t temperature_c = EMS_VALUE_SHORT_NOTSET; int16_t temperature_c = EMS_VALUE_SHORT_NOTSET;
bool read = false; bool read = false;