Browse Source

sns: fix initialization of _adc_counts (#2471)

pull/2474/head
Matthieu Sprunck 2 years ago
committed by GitHub
parent
commit
9087fcf618
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions
  1. +4
    -0
      code/espurna/config/sensors.h
  2. +1
    -0
      code/espurna/sensor.cpp
  3. +2
    -2
      code/espurna/sensors/BaseAnalogEmonSensor.h

+ 4
- 0
code/espurna/config/sensors.h View File

@ -508,6 +508,10 @@
#define EMON_ANALOG_SUPPORT 0 // Do not build support by default
#endif
#ifndef EMON_ANALOG_RESOLUTION
#define EMON_ANALOG_RESOLUTION 10 // ADC resolution (in bits)
#endif
//------------------------------------------------------------------------------
// Counter sensor
// Enable support by passing EVENTS_SUPPORT=1 build flag


+ 1
- 0
code/espurna/sensor.cpp View File

@ -1926,6 +1926,7 @@ void _sensorLoad() {
auto* sensor = new EmonAnalogSensor();
sensor->setVoltage(EMON_MAINS_VOLTAGE);
sensor->setReferenceVoltage(EMON_REFERENCE_VOLTAGE);
sensor->setResolution(EMON_ANALOG_RESOLUTION);
_sensors.push_back(sensor);
}
#endif


+ 2
- 2
code/espurna/sensors/BaseAnalogEmonSensor.h View File

@ -236,8 +236,8 @@ private:
size_t _samples_max { EMON_MAX_SAMPLES }; // Number of samples, will be adjusted at runtime
size_t _samples { _samples_max }; // based on the maximum value
size_t _resolution { 10 }; // ADC resolution (in bits)
size_t _adc_counts { _resolution << 1 }; // Max count
size_t _resolution { EMON_ANALOG_RESOLUTION }; // ADC resolution (in bits)
size_t _adc_counts { static_cast<size_t>(1) << _resolution }; // Max count
};
// Provide EMON API helper where we don't care about specifics of how the values are stored


Loading…
Cancel
Save