Skip to content

Commit

Permalink
[nrfconnect] Fixed setting tilt/lift for window covering (#25108)
Browse files Browse the repository at this point in the history
Window covering sample has a bug that allows to set only
lift/tilt positions that are multiple of 5% (step value).

It was fixed by adding a logic that compares the next step
value with the target value.
  • Loading branch information
kkasperczyk-no authored and pull[bot] committed Nov 15, 2023
1 parent a4db8e7 commit 3255093
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions examples/window-app/nrfconnect/main/WindowCovering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3255093

Please sign in to comment.