Skip to content

Commit fdc74b5

Browse files
committed
Workaround Fan PercentSetting float error (2nd)
Use integer multiply & devide to workaround floating point precision error which causes incorrect Fan PercentSetting value after ceil calculation.
1 parent 0040b88 commit fdc74b5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/app/clusters/fan-control-server/fan-control-server.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ void MatterFanControlClusterServerAttributeChangedCallback(const app::ConcreteAt
346346
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status,
347347
ChipLogError(Zcl, "Failed to get SpeedSetting with error: 0x%02x", status));
348348

349-
float percent = percentSetting.Value();
350-
// Minus insignificant number 0.00000001 before ceil() to avoid floating point precision error
351-
uint8_t speedSetting = static_cast<uint8_t>(ceil(speedMax * (percent * 0.01) - 0.00000001));
349+
uint16_t percent = percentSetting.Value();
350+
// Plus 99 then devide by 100 instead of multiplying 0.01 to workaround floating point precision error
351+
uint8_t speedSetting = static_cast<uint8_t>(ceil((speedMax * percent + 99) / 100));
352352

353353
if (currentSpeedSetting.IsNull() || speedSetting != currentSpeedSetting.Value())
354354
{

0 commit comments

Comments
 (0)