From e32aadb3af75570cf8962a7fb2c3789b77cbae5d Mon Sep 17 00:00:00 2001 From: Bill Waters <65681039+billwatersiii@users.noreply.github.com> Date: Fri, 21 Oct 2022 22:18:47 -0700 Subject: [PATCH] reworking example code to avoid compiler warning (#23297) * reworking example code to avoid compiler warning * Restyled by clang-format Co-authored-by: Restyled.io --- .../infineon/psoc6/src/AppTask.cpp | 29 +++++++++---------- .../lock-app/infineon/psoc6/src/AppTask.cpp | 27 ++++++++--------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/examples/lighting-app/infineon/psoc6/src/AppTask.cpp b/examples/lighting-app/infineon/psoc6/src/AppTask.cpp index 64bd0c189fb377..89605fc8a9c6e6 100644 --- a/examples/lighting-app/infineon/psoc6/src/AppTask.cpp +++ b/examples/lighting-app/infineon/psoc6/src/AppTask.cpp @@ -305,18 +305,18 @@ void AppTask::AppTaskMain(void * pvParameter) void AppTask::LightActionEventHandler(AppEvent * event) { - bool initiated = false; LightingManager::Action_t action; - int32_t actor = 0; - CHIP_ERROR err = CHIP_NO_ERROR; + int32_t actor; - if (event->Type == AppEvent::kEventType_Light) + switch (event->Type) { + case AppEvent::kEventType_Light: { action = static_cast(event->LightEvent.Action); actor = event->LightEvent.Actor; + break; } - else if (event->Type == AppEvent::kEventType_Button) - { + + case AppEvent::kEventType_Button: { if (LightMgr().IsLightOn()) { action = LightingManager::OFF_ACTION; @@ -325,21 +325,18 @@ void AppTask::LightActionEventHandler(AppEvent * event) { action = LightingManager::ON_ACTION; } + actor = AppEvent::kEventType_Button; + break; } - else - { - err = APP_ERROR_UNHANDLED_EVENT; + + default: + return; } - if (err == CHIP_NO_ERROR) + if (!LightMgr().InitiateAction(actor, action)) { - initiated = LightMgr().InitiateAction(actor, action); - - if (!initiated) - { - P6_LOG("Action is already in progress or active."); - } + P6_LOG("Action is already in progress or active."); } } diff --git a/examples/lock-app/infineon/psoc6/src/AppTask.cpp b/examples/lock-app/infineon/psoc6/src/AppTask.cpp index ad532c6707f72e..d9d46398ee8afa 100644 --- a/examples/lock-app/infineon/psoc6/src/AppTask.cpp +++ b/examples/lock-app/infineon/psoc6/src/AppTask.cpp @@ -388,18 +388,18 @@ void AppTask::AppTaskMain(void * pvParameter) void AppTask::LockActionEventHandler(AppEvent * event) { - bool initiated = false; LockManager::Action_t action; int32_t actor; - CHIP_ERROR err = CHIP_NO_ERROR; - if (event->Type == AppEvent::kEventType_Lock) + switch (event->Type) { + case AppEvent::kEventType_Lock: { action = static_cast(event->LockEvent.Action); actor = event->LockEvent.Actor; + break; } - else if (event->Type == AppEvent::kEventType_Button) - { + + case AppEvent::kEventType_Button: { if (LockMgr().NextState() == true) { action = LockManager::LOCK_ACTION; @@ -408,21 +408,18 @@ void AppTask::LockActionEventHandler(AppEvent * event) { action = LockManager::UNLOCK_ACTION; } + actor = AppEvent::kEventType_Button; + break; } - else - { - err = APP_ERROR_UNHANDLED_EVENT; + + default: + return; } - if (err == CHIP_NO_ERROR) + if (!LockMgr().InitiateAction(actor, action)) { - initiated = LockMgr().InitiateAction(actor, action); - - if (!initiated) - { - P6_LOG("Action is already in progress or active."); - } + P6_LOG("Action is already in progress or active."); } }