Browse Source

ntc: formatting & actually return the value

fixup 4d4b8461dd
(if only the compiler warned about an empty branch...)
pull/2525/head
Maxim Prokhorov 1 year ago
parent
commit
fb31449ed9
2 changed files with 31 additions and 21 deletions
  1. +16
    -9
      code/espurna/sensors/AnalogSensor.h
  2. +15
    -12
      code/espurna/sensors/NTCSensor.h

+ 16
- 9
code/espurna/sensors/AnalogSensor.h View File

@ -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 };


+ 15
- 12
code/espurna/sensors/NTCSensor.h View File

@ -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;


Loading…
Cancel
Save