Skip to content

Commit

Permalink
[Telink] Event struct cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
s07641069 committed May 13, 2024
1 parent 1622e71 commit 20dbba8
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 135 deletions.
64 changes: 0 additions & 64 deletions examples/bridge-app/telink/include/AppEvent.h

This file was deleted.

8 changes: 4 additions & 4 deletions examples/bridge-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2023-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -539,10 +539,10 @@ void AppTask::LightingActionEventHandler(AppEvent * aEvent)
Action_t action = INVALID_ACTION;
int32_t actor = 0;

if (aEvent->Type == AppEvent::kEventType_Lighting)
if (aEvent->Type == AppEvent::kEventType_DeviceAction)
{
action = static_cast<Action_t>(aEvent->LightingEvent.Action);
actor = aEvent->LightingEvent.Actor;
action = static_cast<Action_t>(aEvent->DeviceEvent.Action);
actor = aEvent->DeviceEvent.Actor;
}
else if (aEvent->Type == AppEvent::kEventType_Button)
{
Expand Down
12 changes: 6 additions & 6 deletions examples/contact-sensor-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2022-2023 Project CHIP Authors
* Copyright (c) 2022-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -67,9 +67,9 @@ void AppTask::OnStateChanged(ContactSensorManager::State aState)
void AppTask::PostContactActionRequest(ContactSensorManager::Action aAction)
{
AppEvent event;
event.Type = AppEvent::kEventType_Contact;
event.ContactEvent.Action = static_cast<uint8_t>(aAction);
event.Handler = ContactActionEventHandler;
event.Type = AppEvent::kEventType_DeviceAction;
event.DeviceEvent.Action = static_cast<uint8_t>(aAction);
event.Handler = ContactActionEventHandler;

sAppTask.PostEvent(&event);
}
Expand All @@ -95,9 +95,9 @@ void AppTask::ContactActionEventHandler(AppEvent * aEvent)

ChipLogProgress(NotSpecified, "ContactActionEventHandler");

if (aEvent->Type == AppEvent::kEventType_Contact)
if (aEvent->Type == AppEvent::kEventType_DeviceAction)
{
action = static_cast<ContactSensorManager::Action>(aEvent->ContactEvent.Action);
action = static_cast<ContactSensorManager::Action>(aEvent->DeviceEvent.Action);
}
else if (aEvent->Type == AppEvent::kEventType_Button)
{
Expand Down
10 changes: 5 additions & 5 deletions examples/contact-sensor-app/telink/src/ContactSensorManager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2022-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -54,15 +54,15 @@ bool ContactSensorManager::IsContactClosed()
void ContactSensorManager::InitiateAction(Action aAction)
{
AppEvent event;
event.Type = AppEvent::kEventType_Contact;
event.ContactEvent.Action = static_cast<uint8_t>(aAction);
event.Handler = HandleAction;
event.Type = AppEvent::kEventType_DeviceAction;
event.DeviceEvent.Action = static_cast<uint8_t>(aAction);
event.Handler = HandleAction;
GetAppTask().PostEvent(&event);
}

void ContactSensorManager::HandleAction(AppEvent * aEvent)
{
Action action = static_cast<Action>(aEvent->ContactEvent.Action);
Action action = static_cast<Action>(aEvent->DeviceEvent.Action);
// Change current state based on action:
// - if state is closed and action is signal lost, change state to opened
// - if state is opened and action is signal detected, change state to closed
Expand Down
12 changes: 6 additions & 6 deletions examples/lighting-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2022-2023 Project CHIP Authors
* Copyright (c) 2022-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -48,7 +48,7 @@ void AppTask::PowerOnFactoryReset(void)
{
LOG_INF("Lighting App Power On Factory Reset");
AppEvent event;
event.Type = AppEvent::kEventType_Lighting;
event.Type = AppEvent::kEventType_DeviceAction;
event.Handler = PowerOnFactoryResetEventHandler;
GetAppTask().PostEvent(&event);
}
Expand Down Expand Up @@ -77,7 +77,7 @@ CHIP_ERROR AppTask::Init(void)
if (status == Protocols::InteractionModel::Status::Success)
{
// Set actual state to stored before reboot
SetInitiateAction(storedValue ? ON_ACTION : OFF_ACTION, static_cast<int32_t>(AppEvent::kEventType_Lighting), nullptr);
SetInitiateAction(storedValue ? ON_ACTION : OFF_ACTION, static_cast<int32_t>(AppEvent::kEventType_DeviceAction), nullptr);
}

return CHIP_NO_ERROR;
Expand All @@ -88,10 +88,10 @@ void AppTask::LightingActionEventHandler(AppEvent * aEvent)
Fixture_Action action = INVALID_ACTION;
int32_t actor = 0;

if (aEvent->Type == AppEvent::kEventType_Lighting)
if (aEvent->Type == AppEvent::kEventType_DeviceAction)
{
action = static_cast<Fixture_Action>(aEvent->LightingEvent.Action);
actor = aEvent->LightingEvent.Actor;
action = static_cast<Fixture_Action>(aEvent->DeviceEvent.Action);
actor = aEvent->DeviceEvent.Actor;
}
else if (aEvent->Type == AppEvent::kEventType_Button)
{
Expand Down
12 changes: 6 additions & 6 deletions examples/lighting-app/telink/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2022-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -42,14 +42,14 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
{
ChipLogDetail(Zcl, "Cluster OnOff: attribute OnOff set to %u", *value);
GetAppTask().SetInitiateAction(*value ? AppTask::ON_ACTION : AppTask::OFF_ACTION,
static_cast<int32_t>(AppEvent::kEventType_Lighting), value);
static_cast<int32_t>(AppEvent::kEventType_DeviceAction), value);
}
else if (clusterId == LevelControl::Id && attributeId == LevelControl::Attributes::CurrentLevel::Id)
{
if (GetAppTask().IsTurnedOn())
{
ChipLogDetail(Zcl, "Cluster LevelControl: attribute CurrentLevel set to %u", *value);
GetAppTask().SetInitiateAction(AppTask::LEVEL_ACTION, static_cast<int32_t>(AppEvent::kEventType_Lighting), value);
GetAppTask().SetInitiateAction(AppTask::LEVEL_ACTION, static_cast<int32_t>(AppEvent::kEventType_DeviceAction), value);
}
else
{
Expand Down Expand Up @@ -79,7 +79,7 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
}

ChipLogDetail(Zcl, "New XY color: %u|%u", xy.x, xy.y);
GetAppTask().SetInitiateAction(AppTask::COLOR_ACTION_XY, static_cast<int32_t>(AppEvent::kEventType_Lighting),
GetAppTask().SetInitiateAction(AppTask::COLOR_ACTION_XY, static_cast<int32_t>(AppEvent::kEventType_DeviceAction),
(uint8_t *) &xy);
}
/* HSV color space */
Expand All @@ -101,14 +101,14 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath &
hsv.s = *value;
}
ChipLogDetail(Zcl, "New HSV color: hue = %u| saturation = %u", hsv.h, hsv.s);
GetAppTask().SetInitiateAction(AppTask::COLOR_ACTION_HSV, static_cast<int32_t>(AppEvent::kEventType_Lighting),
GetAppTask().SetInitiateAction(AppTask::COLOR_ACTION_HSV, static_cast<int32_t>(AppEvent::kEventType_DeviceAction),
(uint8_t *) &hsv);
}
/* Temperature Mireds color space */
else if (attributeId == ColorControl::Attributes::ColorTemperatureMireds::Id)
{
ChipLogDetail(Zcl, "New Temperature Mireds color = %u", *(uint16_t *) value);
GetAppTask().SetInitiateAction(AppTask::COLOR_ACTION_CT, static_cast<int32_t>(AppEvent::kEventType_Lighting), value);
GetAppTask().SetInitiateAction(AppTask::COLOR_ACTION_CT, static_cast<int32_t>(AppEvent::kEventType_DeviceAction), value);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions examples/lock-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2023-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -130,11 +130,11 @@ void AppTask::LockActionEventHandler(AppEvent * aEvent)
{
case LockManager::kState_NotFulyLocked:
case LockManager::kState_LockCompleted:
LockMgr().LockAction(AppEvent::kEventType_Lock, LockManager::UNLOCK_ACTION, LockManager::OperationSource::kButton,
LockMgr().LockAction(AppEvent::kEventType_DeviceAction, LockManager::UNLOCK_ACTION, LockManager::OperationSource::kButton,
kExampleEndpointId);
break;
case LockManager::kState_UnlockCompleted:
LockMgr().LockAction(AppEvent::kEventType_Lock, LockManager::LOCK_ACTION, LockManager::OperationSource::kButton,
LockMgr().LockAction(AppEvent::kEventType_DeviceAction, LockManager::LOCK_ACTION, LockManager::OperationSource::kButton,
kExampleEndpointId);
break;
default:
Expand Down
10 changes: 5 additions & 5 deletions examples/lock-app/telink/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2023-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -75,7 +75,7 @@ bool emberAfPluginDoorLockOnDoorLockCommand(chip::EndpointId endpointId, const N
{
ChipLogProgress(Zcl, "Door Lock App: Lock Command endpoint=%d", endpointId);

return LockMgr().LockAction(AppEvent::kEventType_Lock, LockManager::LOCK_ACTION, LockManager::OperationSource::kRemote,
return LockMgr().LockAction(AppEvent::kEventType_DeviceAction, LockManager::LOCK_ACTION, LockManager::OperationSource::kRemote,
endpointId, err, fabricIdx, nodeId, pinCode);
}

Expand All @@ -85,7 +85,7 @@ bool emberAfPluginDoorLockOnDoorUnlockCommand(chip::EndpointId endpointId, const
{
ChipLogProgress(Zcl, "Door Lock App: Unlock Command endpoint=%d", endpointId);

return LockMgr().LockAction(AppEvent::kEventType_Lock, LockManager::UNLOCK_ACTION, LockManager::OperationSource::kRemote,
return LockMgr().LockAction(AppEvent::kEventType_DeviceAction, LockManager::UNLOCK_ACTION, LockManager::OperationSource::kRemote,
endpointId, err, fabricIdx, nodeId, pinCode);
}

Expand All @@ -96,7 +96,7 @@ bool emberAfPluginDoorLockOnDoorUnboltCommand(chip::EndpointId endpointId, const
{
ChipLogProgress(Zcl, "Door Lock App: Unbolt Command endpoint=%d", endpointId);

return LockMgr().LockAction(AppEvent::kEventType_Lock, LockManager::UNBOLT_ACTION, LockManager::OperationSource::kRemote,
return LockMgr().LockAction(AppEvent::kEventType_DeviceAction, LockManager::UNBOLT_ACTION, LockManager::OperationSource::kRemote,
endpointId, err, fabricIdx, nodeId, pinCode);
}

Expand Down Expand Up @@ -170,5 +170,5 @@ DlStatus emberAfPluginDoorLockSetSchedule(chip::EndpointId endpointId, uint8_t h
void emberAfPluginDoorLockOnAutoRelock(chip::EndpointId endpointId)
{
// Apply the relock state in the application control
LockMgr().LockAction(AppEvent::kEventType_Lock, LockManager::LOCK_ACTION, LockManager::OperationSource::kRemote, endpointId);
LockMgr().LockAction(AppEvent::kEventType_DeviceAction, LockManager::LOCK_ACTION, LockManager::OperationSource::kRemote, endpointId);
}
25 changes: 3 additions & 22 deletions examples/platform/telink/common/include/AppEventCommon.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2022 Project CHIP Authors
* Copyright (c) 2022-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -31,15 +31,9 @@ struct AppEvent
{
kEventType_Button = 0,
kEventType_Timer,
kEventType_UpdateLedState,
kEventType_IdentifyStart,
kEventType_IdentifyStop,
kEventType_Lighting,
kEventType_Thermostat,
kEventType_Install,
kEventType_Contact,
kEventType_Start,
kEventType_Lock
kEventType_DeviceAction
};

uint16_t Type;
Expand All @@ -58,20 +52,7 @@ struct AppEvent
{
uint8_t Action;
int32_t Actor;
} LightingEvent;
struct
{
uint8_t Action;
} ContactEvent;
struct
{
uint8_t Action;
int32_t Actor;
} StartEvent;
struct
{
LEDWidget * LedWidget;
} UpdateLedStateEvent;
} DeviceEvent;
};

EventHandler Handler;
Expand Down
14 changes: 7 additions & 7 deletions examples/pump-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* Copyright (c) 2023-2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -85,9 +85,9 @@ void AppTask::ActionCompleted(PumpManager::Action_t action, int32_t actor)
void AppTask::PostStartActionRequest(int32_t actor, PumpManager::Action_t action)
{
AppEvent event;
event.Type = AppEvent::kEventType_Start;
event.StartEvent.Actor = actor;
event.StartEvent.Action = action;
event.Type = AppEvent::kEventType_DeviceAction;
event.DeviceEvent.Actor = actor;
event.DeviceEvent.Action = action;
event.Handler = StartActionEventHandler;
sAppTask.PostEvent(&event);
}
Expand All @@ -97,10 +97,10 @@ void AppTask::StartActionEventHandler(AppEvent * aEvent)
PumpManager::Action_t action = PumpManager::INVALID_ACTION;
int32_t actor = 0;

if (aEvent->Type == AppEvent::kEventType_Start)
if (aEvent->Type == AppEvent::kEventType_DeviceAction)
{
action = static_cast<PumpManager::Action_t>(aEvent->StartEvent.Action);
actor = aEvent->StartEvent.Actor;
action = static_cast<PumpManager::Action_t>(aEvent->DeviceEvent.Action);
actor = aEvent->DeviceEvent.Actor;
}
else if (aEvent->Type == AppEvent::kEventType_Button)
{
Expand Down
Loading

0 comments on commit 20dbba8

Please sign in to comment.