Skip to content

Commit b3cbeb9

Browse files
billwatersiiirestyled-commits
authored andcommitted
reworking example code to avoid compiler warning (#23297)
* reworking example code to avoid compiler warning * Restyled by clang-format Co-authored-by: Restyled.io <[email protected]>
1 parent 886d2da commit b3cbeb9

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

examples/lighting-app/infineon/psoc6/src/AppTask.cpp

+13-16
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,18 @@ void AppTask::AppTaskMain(void * pvParameter)
305305

306306
void AppTask::LightActionEventHandler(AppEvent * event)
307307
{
308-
bool initiated = false;
309308
LightingManager::Action_t action;
310-
int32_t actor = 0;
311-
CHIP_ERROR err = CHIP_NO_ERROR;
309+
int32_t actor;
312310

313-
if (event->Type == AppEvent::kEventType_Light)
311+
switch (event->Type)
314312
{
313+
case AppEvent::kEventType_Light: {
315314
action = static_cast<LightingManager::Action_t>(event->LightEvent.Action);
316315
actor = event->LightEvent.Actor;
316+
break;
317317
}
318-
else if (event->Type == AppEvent::kEventType_Button)
319-
{
318+
319+
case AppEvent::kEventType_Button: {
320320
if (LightMgr().IsLightOn())
321321
{
322322
action = LightingManager::OFF_ACTION;
@@ -325,21 +325,18 @@ void AppTask::LightActionEventHandler(AppEvent * event)
325325
{
326326
action = LightingManager::ON_ACTION;
327327
}
328+
328329
actor = AppEvent::kEventType_Button;
330+
break;
329331
}
330-
else
331-
{
332-
err = APP_ERROR_UNHANDLED_EVENT;
332+
333+
default:
334+
return;
333335
}
334336

335-
if (err == CHIP_NO_ERROR)
337+
if (!LightMgr().InitiateAction(actor, action))
336338
{
337-
initiated = LightMgr().InitiateAction(actor, action);
338-
339-
if (!initiated)
340-
{
341-
P6_LOG("Action is already in progress or active.");
342-
}
339+
P6_LOG("Action is already in progress or active.");
343340
}
344341
}
345342

examples/lock-app/infineon/psoc6/src/AppTask.cpp

+12-15
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,18 @@ void AppTask::AppTaskMain(void * pvParameter)
388388

389389
void AppTask::LockActionEventHandler(AppEvent * event)
390390
{
391-
bool initiated = false;
392391
LockManager::Action_t action;
393392
int32_t actor;
394-
CHIP_ERROR err = CHIP_NO_ERROR;
395393

396-
if (event->Type == AppEvent::kEventType_Lock)
394+
switch (event->Type)
397395
{
396+
case AppEvent::kEventType_Lock: {
398397
action = static_cast<LockManager::Action_t>(event->LockEvent.Action);
399398
actor = event->LockEvent.Actor;
399+
break;
400400
}
401-
else if (event->Type == AppEvent::kEventType_Button)
402-
{
401+
402+
case AppEvent::kEventType_Button: {
403403
if (LockMgr().NextState() == true)
404404
{
405405
action = LockManager::LOCK_ACTION;
@@ -408,21 +408,18 @@ void AppTask::LockActionEventHandler(AppEvent * event)
408408
{
409409
action = LockManager::UNLOCK_ACTION;
410410
}
411+
411412
actor = AppEvent::kEventType_Button;
413+
break;
412414
}
413-
else
414-
{
415-
err = APP_ERROR_UNHANDLED_EVENT;
415+
416+
default:
417+
return;
416418
}
417419

418-
if (err == CHIP_NO_ERROR)
420+
if (!LockMgr().InitiateAction(actor, action))
419421
{
420-
initiated = LockMgr().InitiateAction(actor, action);
421-
422-
if (!initiated)
423-
{
424-
P6_LOG("Action is already in progress or active.");
425-
}
422+
P6_LOG("Action is already in progress or active.");
426423
}
427424
}
428425

0 commit comments

Comments
 (0)