From fb31449ed9929bdd7d19da822a87ec0988a53455 Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Mon, 13 Jun 2022 02:10:18 +0300 Subject: [PATCH] ntc: formatting & actually return the value fixup 4d4b8461dd26b8381802402d248441de7bd74b2a (if only the compiler warned about an empty branch...) --- code/espurna/sensors/AnalogSensor.h | 25 ++++++++++++++++--------- code/espurna/sensors/NTCSensor.h | 27 +++++++++++++++------------ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/code/espurna/sensors/AnalogSensor.h b/code/espurna/sensors/AnalogSensor.h index 98778c9b..c8ccbd63 100644 --- a/code/espurna/sensors/AnalogSensor.h +++ b/code/espurna/sensors/AnalogSensor.h @@ -18,13 +18,19 @@ class AnalogSensor : public BaseAnalogSensor { public: - using Delay = espurna::duration::critical::Microseconds; - static constexpr int RawBits { 10 }; static constexpr double RawMax { (1 << RawBits) - 1 }; static constexpr double RawMin { 0.0 }; + static constexpr size_t SamplesMin { 1 }; + static constexpr size_t SamplesMax { 16 }; + + using Delay = espurna::duration::critical::Microseconds; + + static constexpr auto DelayMin = Delay{ 200 }; + static constexpr auto DelayMax = Delay::max(); + unsigned char id() const override { return SENSOR_ANALOG_ID; } @@ -92,13 +98,19 @@ class AnalogSensor : public BaseAnalogSensor { // Type for slot # index unsigned char type(unsigned char index) const override { - if (index == 0) return MAGNITUDE_ANALOG; + if (index == 0) { + return MAGNITUDE_ANALOG; + } + return MAGNITUDE_NONE; } // Current value for slot # index double value(unsigned char index) override { - if (index == 0) return this->analogRead(); + if (index == 0) { + return this->analogRead(); + } + return 0; } @@ -141,12 +153,7 @@ class AnalogSensor : public BaseAnalogSensor { return _withFactor(RawMax); } - static constexpr Delay DelayMin { 200 }; - static constexpr Delay DelayMax { Delay::max() }; Delay _delay { DelayMin }; - - static constexpr size_t SamplesMin { 1 }; - static constexpr size_t SamplesMax { 16 }; size_t _samples { SamplesMin }; double _factor { 1.0 }; diff --git a/code/espurna/sensors/NTCSensor.h b/code/espurna/sensors/NTCSensor.h index bd425e31..9e92841f 100644 --- a/code/espurna/sensors/NTCSensor.h +++ b/code/espurna/sensors/NTCSensor.h @@ -20,7 +20,9 @@ class NTCSensor : public AnalogSensor { // --------------------------------------------------------------------- void setBeta(unsigned long beta) { - if (beta > 0) _beta = beta; + if (beta > 0) { + _beta = beta; + } } void setUpstreamResistor(unsigned long resistance) { @@ -32,15 +34,17 @@ class NTCSensor : public AnalogSensor { } void setR0(unsigned long resistance) override { - if (resistance > 0) _R0 = resistance; + if (resistance > 0) { + _R0 = resistance; + } } void setT0(double temperature) { - if (temperature > 0) _T0 = temperature; + if (temperature > 0) { + _T0 = temperature; + } } - // --------------------------------------------------------------------- - // --------------------------------------------------------------------- // Sensor API // --------------------------------------------------------------------- @@ -58,14 +62,12 @@ class NTCSensor : public AnalogSensor { return F("NTC @ TOUT"); } - // Address of the sensor (it could be the GPIO or I2C address) - String address(unsigned char index) const override { - return F("0"); - } - // Type for slot # index unsigned char type(unsigned char index) const override { - if (index == 0) return MAGNITUDE_TEMPERATURE; + if (index == 0) { + return MAGNITUDE_TEMPERATURE; + } + return MAGNITUDE_NONE; } @@ -75,7 +77,7 @@ class NTCSensor : public AnalogSensor { return sensor::Unit::Kelvin; } - return BaseSensor::units(index); + return sensor::Unit::None; } // Previous version happened to use AnalogSensor readings with factor and offset applied @@ -101,6 +103,7 @@ class NTCSensor : public AnalogSensor { // Current value for slot # index double value(unsigned char index) override { if (index == 0) { + return _value; } return 0.0;