diff --git a/samples/matter/common/src/board_interface.cpp b/samples/matter/common/src/board_interface.cpp index 4622b3075fa1..dce4c94b1603 100644 --- a/samples/matter/common/src/board_interface.cpp +++ b/samples/matter/common/src/board_interface.cpp @@ -186,7 +186,7 @@ void BoardInterface::FunctionTimerEventHandler(const void *context) /* If we reached here, the button was held past kFactoryResetTriggerTimeout, initiate factory reset */ if (sInstance.mFunction == SystemEventType::SoftwareUpdate) { - LOG_INF("Factory Reset Triggered. Release button within %ums to cancel.", + LOG_INF("Factory reset has been triggered. Release button within %ums to cancel.", FactoryResetConsts::kFactoryResetTriggerTimeout); /* Start timer for kFactoryResetCancelWindowTimeout to allow user to cancel, if required. */ @@ -220,7 +220,7 @@ void BoardInterface::FunctionTimerEventHandler(const void *context) void BoardInterface::ButtonEventHandler(uint32_t buttonState, uint32_t hasChanged) { SystemEvent buttonEvent; - bool iSAppButtonEvent = false; + bool isAppButtonEvent = false; ButtonActions action; DeviceButtons source; @@ -249,24 +249,24 @@ void BoardInterface::ButtonEventHandler(uint32_t buttonState, uint32_t hasChange source = DeviceButtons::kAppButton; action = (APPLICATION_BUTTON_MASK & buttonState) ? ButtonActions::kButtonPressed : ButtonActions::kButtonReleased; - iSAppButtonEvent = true; + isAppButtonEvent = true; } if (USER_BUTTON_1_MASK & hasChanged) { source = DeviceButtons::kUserButton1; action = (USER_BUTTON_1_MASK & buttonState) ? ButtonActions::kButtonPressed : ButtonActions::kButtonReleased; - iSAppButtonEvent = true; + isAppButtonEvent = true; } if (USER_BUTTON_2_MASK & hasChanged) { source = DeviceButtons::kUserButton2; action = (USER_BUTTON_2_MASK & buttonState) ? ButtonActions::kButtonPressed : ButtonActions::kButtonReleased; - iSAppButtonEvent = true; + isAppButtonEvent = true; } #endif - if (iSAppButtonEvent && sInstance.mButtonCallback) { + if (isAppButtonEvent && sInstance.mButtonCallback) { sInstance.mButtonCallback(source, action); } } @@ -279,8 +279,9 @@ void BoardInterface::FunctionHandler(const void *context) SystemEvent event(context); - if (event.ButtonEvent.PinNo != FUNCTION_BUTTON) + if (event.ButtonEvent.PinNo != FUNCTION_BUTTON) { return; + } if (event.ButtonEvent.Action == static_cast(SystemEventType::ButtonPushed)) { if (!sInstance.mFunctionTimerActive && sInstance.mFunction == SystemEventType::None) { @@ -303,7 +304,7 @@ void BoardInterface::FunctionHandler(const void *context) sInstance.CancelTimer(); sInstance.UpdateStatusLED(); sInstance.mFunction = SystemEventType::None; - LOG_INF("Factory Reset has been Canceled"); + LOG_INF("Factory reset has been canceled"); } } } diff --git a/samples/matter/common/src/event_manager.cpp b/samples/matter/common/src/event_manager.cpp index 8b25c5e8893e..761b765c8239 100644 --- a/samples/matter/common/src/event_manager.cpp +++ b/samples/matter/common/src/event_manager.cpp @@ -19,12 +19,13 @@ constexpr size_t kEventQueueSize = 10; K_MSGQ_DEFINE(sEventQueue, sizeof(Event), kEventQueueSize, alignof(Event)); -void EventManager::PostEvent(Event &event) +CHIP_ERROR EventManager::PostEvent(Event &event) { /* Allocate context on the Heap */ void* context = chip::DeviceLayer::Malloc::Malloc(event.mContextSize); if(!context){ - LOG_INF("Failed to store context in Heap"); + LOG_ERR("Failed to store context in Heap"); + return CHIP_ERROR_NO_MEMORY; } memcpy(context, event.mContext, event.mContextSize); @@ -32,8 +33,11 @@ void EventManager::PostEvent(Event &event) event.mContext = context; if (k_msgq_put(&sEventQueue, &event, K_NO_WAIT) != 0) { - LOG_INF("Failed to post event to app task event queue"); + LOG_ERR("Failed to post event to app task event queue"); + return CHIP_ERROR_NO_MEMORY; } + + return CHIP_NO_ERROR; } void EventManager::DispatchEvent() diff --git a/samples/matter/common/src/event_manager.h b/samples/matter/common/src/event_manager.h index 0bdc22032f66..b4291db52f5b 100644 --- a/samples/matter/common/src/event_manager.h +++ b/samples/matter/common/src/event_manager.h @@ -10,6 +10,8 @@ #include #include +#include + enum class EventSource : uint8_t { Undefined, Application, System }; struct Event { @@ -41,7 +43,7 @@ class EventManager { public: /** - * @brief Dispatch en event from the event queue and call associated handler. + * @brief Dispatch an event from the event queue and call associated handler. * * This method should be run in the while loop within the application thread. * @@ -55,6 +57,8 @@ class EventManager { * It should be called from the Zephyr's thread. * * @param event event to be posted. + * @return CHIP_ERROR_NO_MEMORY if there is no memory to post new Event + * @return CHIP_NO_ERROR if the Event has been posted */ - static void PostEvent(Event &event); + static CHIP_ERROR PostEvent(Event &event); };