From 61b172d23d8f6a51b6756add9e3cc3de403882a0 Mon Sep 17 00:00:00 2001 From: Jonathan Megevand Date: Mon, 20 Sep 2021 17:42:30 +0200 Subject: [PATCH] WC: Revamp the event ids and callbacks ! --- .../window-app/common/include/WindowApp.h | 26 ++++--- examples/window-app/common/src/WindowApp.cpp | 4 +- .../window-app/common/src/ZclCallbacks.cpp | 68 +++++++++++++++++++ .../window-app/efr32/src/WindowAppImpl.cpp | 10 +-- 4 files changed, 90 insertions(+), 18 deletions(-) diff --git a/examples/window-app/common/include/WindowApp.h b/examples/window-app/common/include/WindowApp.h index 1a53237facfc6c..0ea463edb8d0c8 100644 --- a/examples/window-app/common/include/WindowApp.h +++ b/examples/window-app/common/include/WindowApp.h @@ -72,17 +72,21 @@ class WindowApp UpReleased, DownPressed, DownReleased, - // Cover events - CoverChange, - CoverTypeChange, - TiltModeChange, - LiftUp, - LiftDown, - LiftChanged, - TiltUp, - TiltDown, - TiltChanged, - StopMotion, + BtnCycleType, + BtnCycleActuator, + + // Cover Attribute update events + Type, + ConfigStatus, + OperationalStatus, + EndProductType, + Mode, + SafetyStatus, + LiftCurrentPosition, + TiltCurrentPosition, + LiftTargetPosition, + TiltTargetPosition, + // Provisioning events ProvisionedStateChanged, ConnectivityStateChanged, diff --git a/examples/window-app/common/src/WindowApp.cpp b/examples/window-app/common/src/WindowApp.cpp index 1dafdbbab10f26..b1f86a273bce1d 100644 --- a/examples/window-app/common/src/WindowApp.cpp +++ b/examples/window-app/common/src/WindowApp.cpp @@ -195,7 +195,7 @@ void WindowApp::DispatchEvent(const WindowApp::Event & event) mButtonCtrlMode = ButtonCtrlMode::Tilt; mUpSuppressed = mDownSuppressed = true; - PostEvent(EventId::TiltModeChange); + PostEvent(EventId::BtnCycleActuator); } else if (mTiltMode) { @@ -303,7 +303,7 @@ void WindowApp::HandleLongPress() // Long press both buttons: Cycle between window coverings mUpSuppressed = mDownSuppressed = true; mCurrentCover = mCurrentCover < WINDOW_COVER_COUNT - 1 ? mCurrentCover + 1 : 0; - PostEvent(EventId::CoverChange); + PostEvent(EventId::BtnCycleType); } else if (mUpPressed) { diff --git a/examples/window-app/common/src/ZclCallbacks.cpp b/examples/window-app/common/src/ZclCallbacks.cpp index d102d1c87ff3a1..d213588fd59026 100644 --- a/examples/window-app/common/src/ZclCallbacks.cpp +++ b/examples/window-app/common/src/ZclCallbacks.cpp @@ -95,3 +95,71 @@ void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attrib } + +void emberAfPostAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId, + uint8_t mask, uint16_t manufacturerCode, uint8_t type, uint16_t size, uint8_t * value) +{ + if (ZCL_WINDOW_COVERING_CLUSTER_ID == clusterId) + { + WindowApp & app = WindowApp::Instance(); + uint16_t current; + uint16_t target; + + switch (attributeId) + { + /* RO Type: Cycling Window Covering Demo */ + case ZCL_WC_TYPE_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::Type, endpoint)); + break; + /* RO ConfigStatus */ + case ZCL_WC_CONFIG_STATUS_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::ConfigStatus, endpoint)); + break; + /* RO OperationalStatus */ + case ZCL_WC_OPERATIONAL_STATUS_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::OperationalStatus, endpoint)); + break; + /* RO EndProductType */ + case ZCL_WC_END_PRODUCT_TYPE_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::EndProductType, endpoint)); + break; + /* RW Mode */ + case ZCL_WC_MODE_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::Mode, endpoint)); + break; + /* RO SafetyStatus */ + case ZCL_WC_SAFETY_STATUS_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::SafetyStatus, endpoint)); + break; + + + /* ============= Positions for Position Aware ============= */ + case ZCL_WC_CURRENT_POSITION_LIFT_PERCENT100_THS_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::LiftCurrentPosition, endpoint)); + break; + + case ZCL_WC_CURRENT_POSITION_TILT_PERCENT100_THS_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::TiltCurrentPosition, endpoint)); + break; + + /* Changing the Target triggers motions on the real or simulated device */ + case ZCL_WC_TARGET_POSITION_LIFT_PERCENT100_THS_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::LiftTargetPosition, endpoint)); + break; + + /* Changing the Target triggers motions on the real or simulated device */ + case ZCL_WC_TARGET_POSITION_TILT_PERCENT100_THS_ATTRIBUTE_ID: + app.PostEvent(WindowApp::Event(WindowApp::EventId::TiltTargetPosition, endpoint)); + break; + + default: + break; + } + } + else + { + ChipLogProgress(Zcl, "Unknown cluster ID: %ld", clusterId); + } +} + + diff --git a/examples/window-app/efr32/src/WindowAppImpl.cpp b/examples/window-app/efr32/src/WindowAppImpl.cpp index fe4b6f81d20587..2c7bcab028afe7 100644 --- a/examples/window-app/efr32/src/WindowAppImpl.cpp +++ b/examples/window-app/efr32/src/WindowAppImpl.cpp @@ -265,17 +265,17 @@ void WindowAppImpl::DispatchEvent(const WindowApp::Event & event) case EventId::BLEConnectionsChanged: UpdateLEDs(); break; - case EventId::CoverTypeChange: - case EventId::LiftChanged: - case EventId::TiltChanged: + case EventId::Type: + case EventId::LiftCurrentPosition: + case EventId::TiltCurrentPosition: UpdateLCD(); break; - case EventId::CoverChange: + case EventId::BtnCycleType: mIconTimer.Start(); mIcon = (GetCover().mEndpoint == 1) ? LcdIcon::One : LcdIcon::Two; UpdateLCD(); break; - case EventId::TiltModeChange: + case EventId::BtnCycleActuator: mIconTimer.Start(); switch (mButtonCtrlMode) {