diff --git a/examples/window-app/common/include/WindowApp.h b/examples/window-app/common/include/WindowApp.h index 210af1bf1a5b71..92ddf52e96fa6e 100644 --- a/examples/window-app/common/include/WindowApp.h +++ b/examples/window-app/common/include/WindowApp.h @@ -121,6 +121,7 @@ class WindowApp void TiltSchedulePositionSet(chip::Percent100ths position) { SchedulePositionSet(position, true); } void TiltScheduleOperationalStateSet(OperationalState opState) { ScheduleOperationalStateSet(opState, true); } + void UpdateTargetPosition(OperationalState direction, bool isTilt); void StepToward(OperationalState direction, bool isTilt); Type CycleType(); diff --git a/examples/window-app/common/src/WindowApp.cpp b/examples/window-app/common/src/WindowApp.cpp index 0c7b28a0bd1415..9adafad1e28357 100644 --- a/examples/window-app/common/src/WindowApp.cpp +++ b/examples/window-app/common/src/WindowApp.cpp @@ -242,7 +242,7 @@ void WindowApp::DispatchEvent(const WindowApp::Event & event) } else { - GetCover().StepToward(OperationalState::MovingUpOrOpen, mTiltMode); + GetCover().UpdateTargetPosition(OperationalState::MovingUpOrOpen, mTiltMode); } break; @@ -276,7 +276,7 @@ void WindowApp::DispatchEvent(const WindowApp::Event & event) } else { - GetCover().StepToward(OperationalState::MovingDownOrClose, mTiltMode); + GetCover().UpdateTargetPosition(OperationalState::MovingDownOrClose, mTiltMode); } break; case EventId::AttributeChange: @@ -594,6 +594,37 @@ void WindowApp::Cover::StepToward(OperationalState direction, bool isTilt) } } +void WindowApp::Cover::UpdateTargetPosition(OperationalState direction, bool isTilt) +{ + EmberAfStatus status; + NPercent100ths current; + chip::Percent100ths target; + + chip::DeviceLayer::PlatformMgr().LockChipStack(); + + if (isTilt) + { + status = Attributes::CurrentPositionTiltPercent100ths::Get(mEndpoint, current); + if ((status == EMBER_ZCL_STATUS_SUCCESS) && !current.IsNull()) + { + + target = ComputePercent100thsStep(direction, current.Value(), TILT_DELTA); + (void) Attributes::TargetPositionTiltPercent100ths::Set(mEndpoint, target); + } + } + else + { + status = Attributes::CurrentPositionLiftPercent100ths::Get(mEndpoint, current); + if ((status == EMBER_ZCL_STATUS_SUCCESS) && !current.IsNull()) + { + + target = ComputePercent100thsStep(direction, current.Value(), LIFT_DELTA); + (void) Attributes::TargetPositionLiftPercent100ths::Set(mEndpoint, target); + } + } + chip::DeviceLayer::PlatformMgr().UnlockChipStack(); +} + Type WindowApp::Cover::CycleType() { chip::DeviceLayer::PlatformMgr().LockChipStack();