diff --git a/code/espurna/compat.h b/code/espurna/compat.h index 61799849..67595d1b 100644 --- a/code/espurna/compat.h +++ b/code/espurna/compat.h @@ -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 // ----------------------------------------------------------------------------- diff --git a/code/espurna/curtain_kingart.cpp b/code/espurna/curtain_kingart.cpp index b173790d..42aaea0b 100644 --- a/code/espurna/curtain_kingart.cpp +++ b/code/espurna/curtain_kingart.cpp @@ -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() { diff --git a/code/espurna/light.cpp b/code/espurna/light.cpp index b9ac83ee..ea7d94e8 100644 --- a/code/espurna/light.cpp +++ b/code/espurna/light.cpp @@ -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(1000000L / mireds), _light_warm_kelvin, _light_cold_kelvin); + return std::clamp(static_cast(1000000L / mireds), _light_warm_kelvin, _light_cold_kelvin); } long _toMireds(long kelvin) { - return constrain(static_cast(lround(1000000L / kelvin)), _light_cold_mireds, _light_warm_mireds); + return std::clamp(static_cast(lround(1000000L / kelvin)), _light_cold_mireds, _light_warm_mireds); } void _lightMireds(long kelvin) { diff --git a/code/espurna/sensor.cpp b/code/espurna/sensor.cpp index 6e8f9722..2810c43d 100644 --- a/code/espurna/sensor.cpp +++ b/code/espurna/sensor.cpp @@ -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 diff --git a/code/espurna/sensors/HDC1080Sensor.h b/code/espurna/sensors/HDC1080Sensor.h index ddc455b3..255aca5f 100644 --- a/code/espurna/sensors/HDC1080Sensor.h +++ b/code/espurna/sensors/HDC1080Sensor.h @@ -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