Browse Source

sns: always try to load magnitude units from settings

also, drop special builds flags in favour of sane defaults
mcspr-patch-1
Maxim Prokhorov 4 years ago
parent
commit
1f1d6a99d2
4 changed files with 47 additions and 90 deletions
  1. +0
    -6
      code/espurna/config/hardware.h
  2. +0
    -12
      code/espurna/config/sensors.h
  3. +0
    -14
      code/espurna/config/types.h
  4. +47
    -58
      code/espurna/sensor.cpp

+ 0
- 6
code/espurna/config/hardware.h View File

@ -4655,9 +4655,6 @@
#define HLW8012_POWER_RATIO 3414290 #define HLW8012_POWER_RATIO 3414290
#define HLW8012_INTERRUPT_ON FALLING #define HLW8012_INTERRUPT_ON FALLING
#define SENSOR_ENERGY_UNITS ENERGY_KWH
#define SENSOR_POWER_UNITS POWER_WATTS
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Kogan Smarter Home Plug with Energy Meter (Australia) // Kogan Smarter Home Plug with Energy Meter (Australia)
// Product code: KASPEMHA // Product code: KASPEMHA
@ -4703,9 +4700,6 @@
#define HLW8012_POWER_RATIO 3414290 #define HLW8012_POWER_RATIO 3414290
#define HLW8012_INTERRUPT_ON FALLING #define HLW8012_INTERRUPT_ON FALLING
#define SENSOR_ENERGY_UNITS ENERGY_KWH
#define SENSOR_POWER_UNITS POWER_WATTS
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// KINGART_CURTAIN_SWITCH // KINGART_CURTAIN_SWITCH
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


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

@ -69,18 +69,6 @@
#define SENSOR_ADDRESS_TOPIC "address" // Topic to publish sensor addresses #define SENSOR_ADDRESS_TOPIC "address" // Topic to publish sensor addresses
#ifndef SENSOR_TEMPERATURE_UNITS
#define SENSOR_TEMPERATURE_UNITS TMP_CELSIUS // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
#endif
#ifndef SENSOR_ENERGY_UNITS
#define SENSOR_ENERGY_UNITS ENERGY_JOULES // Energy units (ENERGY_JOULES | ENERGY_KWH)
#endif
#ifndef SENSOR_POWER_UNITS
#define SENSOR_POWER_UNITS POWER_WATTS // Power units (POWER_WATTS | POWER_KILOWATTS)
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Magnitude offset correction // Magnitude offset correction
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------


+ 0
- 14
code/espurna/config/types.h View File

@ -275,20 +275,6 @@
#define UV_INDEX_EXTREME 4 // 11 or more means extreme risk of harm from unprotected sun exposure. #define UV_INDEX_EXTREME 4 // 11 or more means extreme risk of harm from unprotected sun exposure.
// Take all precautions because unprotected skin and eyes can burn in minutes. // Take all precautions because unprotected skin and eyes can burn in minutes.
//------------------------------------------------------------------------------
// UNITS
//------------------------------------------------------------------------------
#define POWER_WATTS sensor::Unit::Watt
#define POWER_KILOWATTS sensor::Unit::Kilowatt
#define ENERGY_JOULES sensor::Unit::Joule
#define ENERGY_KWH sensor::Unit::KilowattHour
#define TMP_CELSIUS sensor::Unit::Celcius
#define TMP_FAHRENHEIT sensor::Unit::Farenheit
#define TMP_KELVIN sensor::Unit::Kelvin
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Sensor ID // Sensor ID
// These should remain over time, do not modify them, only add new ones at the end // These should remain over time, do not modify them, only add new ones at the end


+ 47
- 58
code/espurna/sensor.cpp View File

@ -829,40 +829,48 @@ sensor::Unit _magnitudeUnitFilter(const sensor_magnitude_t& magnitude, sensor::U
auto result = magnitude.units; auto result = magnitude.units;
switch (magnitude.type) { switch (magnitude.type) {
case MAGNITUDE_TEMPERATURE: {
switch (updated) {
case sensor::Unit::Celcius:
case sensor::Unit::Farenheit:
case sensor::Unit::Kelvin:
result = updated;
break;
default:
break;
}
case MAGNITUDE_TEMPERATURE: {
switch (updated) {
case sensor::Unit::Celcius:
case sensor::Unit::Farenheit:
case sensor::Unit::Kelvin:
result = updated;
break; break;
}
case MAGNITUDE_POWER_ACTIVE: {
switch (updated) {
case sensor::Unit::Kilowatt:
case sensor::Unit::Watt:
result = updated;
break;
default:
break;
}
default:
break; break;
} }
case MAGNITUDE_ENERGY: {
switch (updated) {
case sensor::Unit::KilowattHour:
case sensor::Unit::Joule:
result = updated;
break;
default:
break;
}
break;
}
case MAGNITUDE_POWER_ACTIVE: {
switch (updated) {
case sensor::Unit::Kilowatt:
case sensor::Unit::Watt:
result = updated;
break;
default:
break; break;
} }
break;
}
case MAGNITUDE_ENERGY: {
switch (updated) {
case sensor::Unit::KilowattHour:
case sensor::Unit::Joule:
result = updated;
break;
default:
break;
}
break;
}
default:
result = updated;
break;
} }
return result; return result;
@ -2396,12 +2404,6 @@ void _sensorConfigure() {
// Update magnitude config, filter sizes and reset energy if needed // Update magnitude config, filter sizes and reset energy if needed
{ {
// TODO: instead of using global enum, have a local mapping?
const auto tmpUnits = getSetting("tmpUnits", SENSOR_TEMPERATURE_UNITS);
const auto pwrUnits = getSetting("pwrUnits", SENSOR_POWER_UNITS);
const auto eneUnits = getSetting("eneUnits", SENSOR_ENERGY_UNITS);
for (unsigned char index = 0; index < _magnitudes.size(); ++index) { for (unsigned char index = 0; index < _magnitudes.size(); ++index) {
auto& magnitude = _magnitudes.at(index); auto& magnitude = _magnitudes.at(index);
@ -2444,29 +2446,16 @@ void _sensorConfigure() {
} }
} }
// adjust type-specific units (TODO: try to adjust settings to use type prefixes?)
switch (magnitude.type) {
case MAGNITUDE_TEMPERATURE:
magnitude.units = _magnitudeUnitFilter(
magnitude,
getSetting({"tmpUnits", magnitude.index_global}, tmpUnits)
);
break;
case MAGNITUDE_POWER_ACTIVE:
magnitude.units = _magnitudeUnitFilter(
magnitude,
getSetting({"pwrUnits", magnitude.index_global}, pwrUnits)
);
break;
case MAGNITUDE_ENERGY:
magnitude.units = _magnitudeUnitFilter(
magnitude,
getSetting({"eneUnits", magnitude.index_global}, eneUnits)
);
break;
default:
magnitude.units = magnitude.sensor->units(magnitude.slot);
break;
// adjust type-specific units
{
const sensor::Unit default_unit { magnitude.sensor->units(magnitude.slot) };
const settings_key_t key {
String(_magnitudeSettingsPrefix(magnitude.type)) + F("Units") + String(magnitude.index_global, 10) };
magnitude.units = _magnitudeUnitFilter(
magnitude,
getSetting(key, default_unit)
);
} }
// some magnitudes allow to be corrected with an offset // some magnitudes allow to be corrected with an offset


Loading…
Cancel
Save