From 8cc8a0136ece329eb9b2749df12a7f69ba91abad Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 30 Jul 2024 09:33:29 -0400 Subject: [PATCH 1/4] Fix int promotion compile errors --- examples/thermostat/linux/thermostat-delegate-impl.cpp | 4 ++-- examples/thermostat/linux/thermostat-manager.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/thermostat/linux/thermostat-delegate-impl.cpp b/examples/thermostat/linux/thermostat-delegate-impl.cpp index fa7bd9a259a475..d5481b7ea09ff6 100644 --- a/examples/thermostat/linux/thermostat-delegate-impl.cpp +++ b/examples/thermostat/linux/thermostat-delegate-impl.cpp @@ -96,10 +96,10 @@ void ThermostatDelegate::InitializePresets() const uint8_t handle[] = { static_cast(presetScenario) }; mPresets[index].SetPresetHandle(DataModel::MakeNullable(ByteSpan(handle))); mPresets[index].SetName(NullOptional); - int16_t coolingSetpointValue = 2500 + index * 100; + int16_t coolingSetpointValue = static_cast(2500 + index * 100); mPresets[index].SetCoolingSetpoint(MakeOptional(coolingSetpointValue)); - int16_t heatingSetpointValue = 2100 - index * 100; + int16_t heatingSetpointValue = static_cast(2100 - index * 100); mPresets[index].SetHeatingSetpoint(MakeOptional(heatingSetpointValue)); mPresets[index].SetBuiltIn(DataModel::MakeNullable(true)); index++; diff --git a/examples/thermostat/linux/thermostat-manager.cpp b/examples/thermostat/linux/thermostat-manager.cpp index 00266161007d59..a32df2f092bebe 100644 --- a/examples/thermostat/linux/thermostat-manager.cpp +++ b/examples/thermostat/linux/thermostat-manager.cpp @@ -398,8 +398,8 @@ void ThermostatManager::EvalThermostatState() void ThermostatManager::UpdateRunningModeForHeating() { - const int16_t heatingOnThreshold = mOccupiedHeatingSetpoint - mOccupiedSetback * 10; - const int16_t heatingOffThreshold = mOccupiedHeatingSetpoint + mOccupiedSetback * 10; + const int16_t heatingOnThreshold = static_cast(mOccupiedHeatingSetpoint - mOccupiedSetback * 10); + const int16_t heatingOffThreshold = static_cast(mOccupiedHeatingSetpoint + mOccupiedSetback * 10); if (mRunningMode == ThermostatRunningModeEnum::kHeat) { @@ -429,8 +429,8 @@ void ThermostatManager::UpdateRunningModeForHeating() void ThermostatManager::UpdateRunningModeForCooling() { - const int16_t coolingOffThreshold = mOccupiedCoolingSetpoint - mOccupiedSetback * 10; - const int16_t coolingOnThreshold = mOccupiedCoolingSetpoint + mOccupiedSetback * 10; + const int16_t coolingOffThreshold = static_cast(mOccupiedCoolingSetpoint - mOccupiedSetback * 10); + const int16_t coolingOnThreshold = static_cast(mOccupiedCoolingSetpoint + mOccupiedSetback * 10); if (mRunningMode == ThermostatRunningModeEnum::kCool) { From 61cbc74ee28a27f26a53bd6d01831ed9a1acea36 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 30 Jul 2024 09:36:27 -0400 Subject: [PATCH 2/4] Fix cast types --- examples/thermostat/linux/thermostat-manager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/thermostat/linux/thermostat-manager.cpp b/examples/thermostat/linux/thermostat-manager.cpp index a32df2f092bebe..43e64d491e9e7c 100644 --- a/examples/thermostat/linux/thermostat-manager.cpp +++ b/examples/thermostat/linux/thermostat-manager.cpp @@ -398,8 +398,8 @@ void ThermostatManager::EvalThermostatState() void ThermostatManager::UpdateRunningModeForHeating() { - const int16_t heatingOnThreshold = static_cast(mOccupiedHeatingSetpoint - mOccupiedSetback * 10); - const int16_t heatingOffThreshold = static_cast(mOccupiedHeatingSetpoint + mOccupiedSetback * 10); + const int16_t heatingOnThreshold = static_cast(mOccupiedHeatingSetpoint - mOccupiedSetback * 10); + const int16_t heatingOffThreshold = static_cast(mOccupiedHeatingSetpoint + mOccupiedSetback * 10); if (mRunningMode == ThermostatRunningModeEnum::kHeat) { @@ -429,8 +429,8 @@ void ThermostatManager::UpdateRunningModeForHeating() void ThermostatManager::UpdateRunningModeForCooling() { - const int16_t coolingOffThreshold = static_cast(mOccupiedCoolingSetpoint - mOccupiedSetback * 10); - const int16_t coolingOnThreshold = static_cast(mOccupiedCoolingSetpoint + mOccupiedSetback * 10); + const int16_t coolingOffThreshold = static_cast(mOccupiedCoolingSetpoint - mOccupiedSetback * 10); + const int16_t coolingOnThreshold = static_cast(mOccupiedCoolingSetpoint + mOccupiedSetback * 10); if (mRunningMode == ThermostatRunningModeEnum::kCool) { From 9f1f9721c8fafbb7fc7bbeebf31a5b0486ec5141 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 30 Jul 2024 09:38:35 -0400 Subject: [PATCH 3/4] Minimize cast size --- examples/thermostat/linux/thermostat-delegate-impl.cpp | 4 ++-- examples/thermostat/linux/thermostat-manager.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/thermostat/linux/thermostat-delegate-impl.cpp b/examples/thermostat/linux/thermostat-delegate-impl.cpp index d5481b7ea09ff6..491e44a311c3e8 100644 --- a/examples/thermostat/linux/thermostat-delegate-impl.cpp +++ b/examples/thermostat/linux/thermostat-delegate-impl.cpp @@ -96,10 +96,10 @@ void ThermostatDelegate::InitializePresets() const uint8_t handle[] = { static_cast(presetScenario) }; mPresets[index].SetPresetHandle(DataModel::MakeNullable(ByteSpan(handle))); mPresets[index].SetName(NullOptional); - int16_t coolingSetpointValue = static_cast(2500 + index * 100); + int16_t coolingSetpointValue = static_cast(2500 + (index * 100)); mPresets[index].SetCoolingSetpoint(MakeOptional(coolingSetpointValue)); - int16_t heatingSetpointValue = static_cast(2100 - index * 100); + int16_t heatingSetpointValue = static_cast(2100 - (index * 100)); mPresets[index].SetHeatingSetpoint(MakeOptional(heatingSetpointValue)); mPresets[index].SetBuiltIn(DataModel::MakeNullable(true)); index++; diff --git a/examples/thermostat/linux/thermostat-manager.cpp b/examples/thermostat/linux/thermostat-manager.cpp index 43e64d491e9e7c..28130e87896cc7 100644 --- a/examples/thermostat/linux/thermostat-manager.cpp +++ b/examples/thermostat/linux/thermostat-manager.cpp @@ -398,8 +398,8 @@ void ThermostatManager::EvalThermostatState() void ThermostatManager::UpdateRunningModeForHeating() { - const int16_t heatingOnThreshold = static_cast(mOccupiedHeatingSetpoint - mOccupiedSetback * 10); - const int16_t heatingOffThreshold = static_cast(mOccupiedHeatingSetpoint + mOccupiedSetback * 10); + const int16_t heatingOnThreshold = mOccupiedHeatingSetpoint - static_cast(mOccupiedSetback * 10); + const int16_t heatingOffThreshold = mOccupiedHeatingSetpoint - static_cast(mOccupiedSetback * 10); if (mRunningMode == ThermostatRunningModeEnum::kHeat) { @@ -429,8 +429,8 @@ void ThermostatManager::UpdateRunningModeForHeating() void ThermostatManager::UpdateRunningModeForCooling() { - const int16_t coolingOffThreshold = static_cast(mOccupiedCoolingSetpoint - mOccupiedSetback * 10); - const int16_t coolingOnThreshold = static_cast(mOccupiedCoolingSetpoint + mOccupiedSetback * 10); + const int16_t coolingOffThreshold = mOccupiedCoolingSetpoint - static_cast(mOccupiedSetback * 10); + const int16_t coolingOnThreshold = mOccupiedCoolingSetpoint + static_cast(mOccupiedSetback * 10); if (mRunningMode == ThermostatRunningModeEnum::kCool) { From 98cb9988ed79093fabd7a5a9b5d8d4d5201bde80 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 30 Jul 2024 09:42:14 -0400 Subject: [PATCH 4/4] Fix typo --- examples/thermostat/linux/thermostat-manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/thermostat/linux/thermostat-manager.cpp b/examples/thermostat/linux/thermostat-manager.cpp index 28130e87896cc7..e96f04a78d49e9 100644 --- a/examples/thermostat/linux/thermostat-manager.cpp +++ b/examples/thermostat/linux/thermostat-manager.cpp @@ -399,7 +399,7 @@ void ThermostatManager::EvalThermostatState() void ThermostatManager::UpdateRunningModeForHeating() { const int16_t heatingOnThreshold = mOccupiedHeatingSetpoint - static_cast(mOccupiedSetback * 10); - const int16_t heatingOffThreshold = mOccupiedHeatingSetpoint - static_cast(mOccupiedSetback * 10); + const int16_t heatingOffThreshold = mOccupiedHeatingSetpoint + static_cast(mOccupiedSetback * 10); if (mRunningMode == ThermostatRunningModeEnum::kHeat) {