Browse Source

sns: constrain only works on a single type

make sure we use clamp instead of constrain
pull/2516/head
Maxim Prokhorov 2 years ago
parent
commit
c9e3cd65f4
5 changed files with 9 additions and 5 deletions
  1. +3
    -0
      code/espurna/compat.h
  2. +1
    -1
      code/espurna/curtain_kingart.cpp
  3. +2
    -2
      code/espurna/light.cpp
  4. +2
    -1
      code/espurna/sensor.cpp
  5. +1
    -1
      code/espurna/sensors/HDC1080Sensor.h

+ 3
- 0
code/espurna/compat.h View File

@ -133,6 +133,9 @@ constexpr size_t size(const T& value) {
} // namespace std
// Same as min and max, force same type arguments
#undef constrain
#endif
// -----------------------------------------------------------------------------


+ 1
- 1
code/espurna/curtain_kingart.cpp View File

@ -496,7 +496,7 @@ void kingartCurtainSetup() {
//------------------------------------------------------------------------------
void curtainSetPosition(unsigned char id, long value) {
if (id > 1) return;
_KACurtainSet(CURTAIN_BUTTON_UNKNOWN, constrain(value, 0, 100));
_KACurtainSet(CURTAIN_BUTTON_UNKNOWN, std::clamp(value, 0, 100));
}
unsigned char curtainCount() {


+ 2
- 2
code/espurna/light.cpp View File

@ -1091,11 +1091,11 @@ void _lightFromHsvPayload(const char* hsv) {
// https://github.com/stelgenhof/AiLight
// Color temperature is measured in mireds (kelvin = 1e6/mired)
long _toKelvin(long mireds) {
return constrain(static_cast<long>(1000000L / mireds), _light_warm_kelvin, _light_cold_kelvin);
return std::clamp(static_cast<long>(1000000L / mireds), _light_warm_kelvin, _light_cold_kelvin);
}
long _toMireds(long kelvin) {
return constrain(static_cast<long>(lround(1000000L / kelvin)), _light_cold_mireds, _light_warm_mireds);
return std::clamp(static_cast<long>(lround(1000000L / kelvin)), _light_cold_mireds, _light_warm_mireds);
}
void _lightMireds(long kelvin) {


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

@ -2596,8 +2596,9 @@ void _sensorLoad() {
#if BMX280_SUPPORT
{
// TODO: bmx280AddressN, do some migrate code based on number?
// Support up to two sensors with full auto-discovery.
const unsigned char number = constrain(getSetting("bmx280Number", BMX280_NUMBER), 1, 2);
const auto number = std::clamp(getSetting("bmx280Number", BMX280_NUMBER), 1, 2);
// For second sensor, if BMX280_ADDRESS is 0x00 then auto-discover
// otherwise choose the other unnamed sensor address


+ 1
- 1
code/espurna/sensors/HDC1080Sensor.h View File

@ -83,7 +83,7 @@ class HDC1080Sensor : public I2CSensor<> {
}
value = (value / 65536) * 100;
_humidity = std::clamp(value, 0, 100);
_humidity = std::clamp(value, 0.0, 100.0);
}
// Current value for slot # index


Loading…
Cancel
Save