From 173939356d6a3876af4a4bdcee1ae5e61e806a56 Mon Sep 17 00:00:00 2001 From: Hussein Elsherbini <36723549+HusseinElsherbini@users.noreply.github.com> Date: Fri, 17 Mar 2023 00:41:16 -0400 Subject: [PATCH] modified window app button press behavior (#25701) * modified window app button press behaviour to update the TargetPositionLiftPercent attribute * added check for tilt mode change * fixed minor error * created WindowApp::Cover::UpdateTargetPosition() function that updates respective TargetPosition attributes * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io --- .../window-app/common/include/WindowApp.h | 1 + examples/window-app/common/src/WindowApp.cpp | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) 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();