Skip to content

Commit

Permalink
WC: Revamp the event ids and callbacks !
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeg-sfy committed Oct 14, 2021
1 parent d4ea94a commit 61b172d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 18 deletions.
26 changes: 15 additions & 11 deletions examples/window-app/common/include/WindowApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples/window-app/common/src/WindowApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
68 changes: 68 additions & 0 deletions examples/window-app/common/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}


10 changes: 5 additions & 5 deletions examples/window-app/efr32/src/WindowAppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 61b172d

Please sign in to comment.