diff --git a/examples/window-app/nrfconnect/main/WindowCovering.cpp b/examples/window-app/nrfconnect/main/WindowCovering.cpp index 13f22ad848a16f..430670a6f06265 100644 --- a/examples/window-app/nrfconnect/main/WindowCovering.cpp +++ b/examples/window-app/nrfconnect/main/WindowCovering.cpp @@ -62,9 +62,20 @@ void WindowCovering::DriveCurrentLiftPosition(intptr_t) VerifyOrReturn(Attributes::CurrentPositionLiftPercent100ths::Get(Endpoint(), current) == EMBER_ZCL_STATUS_SUCCESS); VerifyOrReturn(Attributes::TargetPositionLiftPercent100ths::Get(Endpoint(), target) == EMBER_ZCL_STATUS_SUCCESS); - UpdateOperationalStatus(MoveType::LIFT, ComputeOperationalState(target, current)); + OperationalState state = ComputeOperationalState(target, current); + UpdateOperationalStatus(MoveType::LIFT, state); + + chip::Percent100ths step = CalculateSingleStep(MoveType::LIFT); + + if (state == OperationalState::MovingUpOrOpen) + { + positionToSet.SetNonNull(step > target.Value() ? step : target.Value()); + } + else if (state == OperationalState::MovingDownOrClose) + { + positionToSet.SetNonNull(step < target.Value() ? step : target.Value()); + } - positionToSet.SetNonNull(CalculateSingleStep(MoveType::LIFT)); LiftPositionSet(Endpoint(), positionToSet); // assume single move completed @@ -156,9 +167,20 @@ void WindowCovering::DriveCurrentTiltPosition(intptr_t) VerifyOrReturn(Attributes::CurrentPositionTiltPercent100ths::Get(Endpoint(), current) == EMBER_ZCL_STATUS_SUCCESS); VerifyOrReturn(Attributes::TargetPositionTiltPercent100ths::Get(Endpoint(), target) == EMBER_ZCL_STATUS_SUCCESS); - UpdateOperationalStatus(MoveType::TILT, ComputeOperationalState(target, current)); + OperationalState state = ComputeOperationalState(target, current); + UpdateOperationalStatus(MoveType::TILT, state); + + chip::Percent100ths step = CalculateSingleStep(MoveType::TILT); + + if (state == OperationalState::MovingUpOrOpen) + { + positionToSet.SetNonNull(step > target.Value() ? step : target.Value()); + } + else if (state == OperationalState::MovingDownOrClose) + { + positionToSet.SetNonNull(step < target.Value() ? step : target.Value()); + } - positionToSet.SetNonNull(CalculateSingleStep(MoveType::TILT)); TiltPositionSet(Endpoint(), positionToSet); // assume single move completed