Skip to content

Commit

Permalink
Add app_stop event.
Browse files Browse the repository at this point in the history
  • Loading branch information
jadhavrohit924 committed Jan 7, 2025
1 parent 62ff25f commit 22f1381
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
14 changes: 13 additions & 1 deletion examples/all-clusters-app/esp32/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,20 @@ CHIP_ERROR AppTask::StartAppTask()
return (xReturned == pdPASS) ? CHIP_NO_ERROR : APP_ERROR_CREATE_TASK_FAILED;
}

void AppTask::DeleteAppTask()
void AppTask::StopAppTask()
{
AppEvent event;
event.mType = AppEvent::kEventType_App_Stop;
event.mHandler = StopEventHandler;
sAppTask.PostEvent(&event);
}

void AppTask::StopEventHandler(AppEvent * aEvent)
{
if (aEvent->mType != AppEvent::kEventType_App_Stop)
{
return;
}
vTaskDelete(sAppTaskHandle);
vQueueDelete(sAppEventQueue);
}
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/esp32/main/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct AppEvent
kEventType_Timer,
kEventType_Light,
kEventType_Install,
kEventType_App_Stop,
};

uint16_t mType;
Expand Down
3 changes: 2 additions & 1 deletion examples/all-clusters-app/esp32/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AppTask
{
public:
CHIP_ERROR StartAppTask();
void DeleteAppTask();
void StopAppTask();
static void AppTaskMain(void * pvParameter);
void PostEvent(const AppEvent * event);
void ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction);
Expand All @@ -48,6 +48,7 @@ class AppTask

static void FunctionTimerEventHandler(AppEvent * aEvent);
static void TimerEventHandler(TimerHandle_t xTimer);
static void StopEventHandler(AppEvent * aEvent);

void DispatchEvent(AppEvent * event);

Expand Down
11 changes: 5 additions & 6 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,16 @@ void emberAfLaundryDryerControlsClusterInitCallback(EndpointId endpoint)
LaundryDryerControlsServer::SetDefaultDelegate(endpoint, &LaundryDryerControlDelegate::getLaundryDryerControlDelegate());
}

/** A sequence of API calls to shutdown matter server from the example.
usage: xTimerStart(xTimerCreate("Timer", 100, pdFALSE, nullptr, Shutdown), 0);
*/
static void Shutdown(TimerHandle_t xTimer)
{
DeviceLayer::StackLock lock;
ESP_LOGE(TAG, "Shutdown called");
Esp32AppServer::Shutdown();

ESP_LOGE(TAG, "Esp32AppServer Shutdown");
GetAppTask().DeleteAppTask();
Esp32AppServer::Shutdown();
GetAppTask().StopAppTask();

ESP_LOGE(TAG, "DeleteAppTask");
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
if (DeviceLayer::Internal::ESP32Utils::DeInitWiFiStack() != CHIP_NO_ERROR)
{
Expand All @@ -164,7 +164,6 @@ static void Shutdown(TimerHandle_t xTimer)
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI

ESP_LOGE(TAG, "nvs_flash_deinit");
esp_err_t err = nvs_flash_deinit();
if (err != ESP_OK)
{
Expand Down

0 comments on commit 22f1381

Please sign in to comment.