From d7bc821bbe3b5e8ad63b9aea848473dfaa1e1808 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sat, 17 Jul 2021 06:33:14 +0200 Subject: [PATCH] calculate dallassensor offset --- src/dallassensor.cpp | 22 ++++++++++++++++++++-- src/dallassensor.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index ba3192c2d..b23eb898f 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -140,7 +140,11 @@ void DallasSensor::loop() { bool found = false; for (auto & sensor : sensors_) { 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.read = true; found = true; @@ -150,7 +154,7 @@ void DallasSensor::loop() { // add new sensor if (!found && (sensors_.size() < (MAX_SENSORS - 1))) { sensors_.emplace_back(addr); - sensors_.back().temperature_c = t; + sensors_.back().temperature_c = t + sensors_.back().offset(); sensors_.back().read = true; changed_ = true; } @@ -321,6 +325,20 @@ std::string DallasSensor::Sensor::to_string() const { 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) { EMSESP::webSettingsService.update([&](WebSettings & settings) { // check for new name of stored id diff --git a/src/dallassensor.h b/src/dallassensor.h index 092eded07..ec410d0e8 100644 --- a/src/dallassensor.h +++ b/src/dallassensor.h @@ -48,6 +48,7 @@ class DallasSensor { uint64_t id() const; std::string id_string() const; std::string to_string() const; + int16_t offset() const; int16_t temperature_c = EMS_VALUE_SHORT_NOTSET; bool read = false;