diff --git a/examples/lock-app/infineon/psoc6/include/AppTask.h b/examples/lock-app/infineon/psoc6/include/AppTask.h index f83ba6c1e42730..8d6ca18b1f8e8a 100644 --- a/examples/lock-app/infineon/psoc6/include/AppTask.h +++ b/examples/lock-app/infineon/psoc6/include/AppTask.h @@ -52,11 +52,12 @@ class AppTask void ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction); void UpdateClusterState(void); void InitOTARequestor(); + void lockMgr_Init(); private: friend AppTask & GetAppTask(void); - CHIP_ERROR Init(); + void Init(); static void ActionInitiated(LockManager::Action_t aAction, int32_t aActor); static void ActionCompleted(LockManager::Action_t aAction); diff --git a/examples/lock-app/infineon/psoc6/src/AppTask.cpp b/examples/lock-app/infineon/psoc6/src/AppTask.cpp index 39e04aa48303d6..71567f3486aa22 100644 --- a/examples/lock-app/infineon/psoc6/src/AppTask.cpp +++ b/examples/lock-app/infineon/psoc6/src/AppTask.cpp @@ -162,6 +162,8 @@ static void InitServer(intptr_t context) #if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR GetAppTask().InitOTARequestor(); #endif + + GetAppTask().lockMgr_Init(); } CHIP_ERROR AppTask::StartAppTask() @@ -178,55 +180,15 @@ CHIP_ERROR AppTask::StartAppTask() return (sAppTaskHandle == nullptr) ? APP_ERROR_CREATE_TASK_FAILED : CHIP_NO_ERROR; } -CHIP_ERROR AppTask::Init() +void AppTask::lockMgr_Init() { CHIP_ERROR err = CHIP_NO_ERROR; -#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR - int rc = boot_set_confirmed(); - if (rc != 0) - { - P6_LOG("boot_set_confirmed failed"); - appError(CHIP_ERROR_WELL_UNINITIALIZED); - } -#endif - // Register the callback to init the MDNS server when connectivity is available - PlatformMgr().AddEventHandler( - [](const ChipDeviceEvent * event, intptr_t arg) { - // Restart the server whenever an ip address is renewed - if (event->Type == DeviceEventType::kInternetConnectivityChange) - { - if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established || - event->InternetConnectivityChange.IPv6 == kConnectivity_Established) - { - chip::app::DnssdServer::Instance().StartServer(); - } - } - }, - 0); - chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast(nullptr)); - - // Initialise WSTK buttons PB0 and PB1 (including debounce). - ButtonHandler::Init(); - - // Create FreeRTOS sw timer for Function Selection. - sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel - 1, // == default timer period (mS) - false, // no timer reload (==one-shot) - (void *) this, // init timer id = app task obj context - TimerEventHandler // timer callback handler - ); - if (sFunctionTimer == NULL) - { - P6_LOG("funct timer create failed"); - appError(APP_ERROR_CREATE_TIMER_FAILED); - } NetWorkCommissioningInstInit(); P6_LOG("Current Software Version: %d", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION); // Initial lock state chip::app::DataModel::Nullable state; chip::EndpointId endpointId{ 1 }; - chip::DeviceLayer::PlatformMgr().LockChipStack(); chip::app::Clusters::DoorLock::Attributes::LockState::Get(endpointId, state); uint8_t numberOfCredentialsPerUser = 0; @@ -278,9 +240,6 @@ CHIP_ERROR AppTask::Init() numberOfHolidaySchedules = 10; } - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - // err = LockMgr().Init(state, maxCredentialsPerUser, numberOfSupportedUsers); err = LockMgr().Init(state, ParamBuilder() .SetNumberOfUsers(numberOfUsers) @@ -294,11 +253,29 @@ CHIP_ERROR AppTask::Init() P6_LOG("LockMgr().Init() failed"); appError(err); } + + // Initialise WSTK buttons PB0 and PB1 (including debounce). + ButtonHandler::Init(); + + // Create FreeRTOS sw timer for Function Selection. + sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel + 1, // == default timer period (mS) + false, // no timer reload (==one-shot) + (void *) this, // init timer id = app task obj context + TimerEventHandler // timer callback handler + ); + if (sFunctionTimer == NULL) + { + P6_LOG("funct timer create failed"); + appError(APP_ERROR_CREATE_TIMER_FAILED); + } + LockMgr().SetCallbacks(ActionInitiated, ActionCompleted); // Initialize LEDs sStatusLED.Init(SYSTEM_STATE_LED); sLockLED.Init(LOCK_STATE_LED); + if (state.Value() == DlLockState::kUnlocked) { sLockLED.Set(false); @@ -312,21 +289,41 @@ CHIP_ERROR AppTask::Init() // Print setup info PrintOnboardingCodes(chip::RendezvousInformationFlag(chip::RendezvousInformationFlag::kBLE)); +} - return err; +void AppTask::Init() +{ +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + int rc = boot_set_confirmed(); + if (rc != 0) + { + P6_LOG("boot_set_confirmed failed"); + appError(CHIP_ERROR_WELL_UNINITIALIZED); + } +#endif + // Register the callback to init the MDNS server when connectivity is available + PlatformMgr().AddEventHandler( + [](const ChipDeviceEvent * event, intptr_t arg) { + // Restart the server whenever an ip address is renewed + if (event->Type == DeviceEventType::kInternetConnectivityChange) + { + if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established || + event->InternetConnectivityChange.IPv6 == kConnectivity_Established) + { + chip::app::DnssdServer::Instance().StartServer(); + } + } + }, + 0); + + chip::DeviceLayer::PlatformMgr().ScheduleWork(InitServer, reinterpret_cast(nullptr)); } void AppTask::AppTaskMain(void * pvParameter) { AppEvent event; - CHIP_ERROR err = sAppTask.Init(); - if (err != CHIP_NO_ERROR) - { - P6_LOG("AppTask.Init() failed"); - appError(err); - } - + sAppTask.Init(); P6_LOG("App Task started"); // Users and credentials should be checked once from flash on boot diff --git a/examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp b/examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp index 84aaac16ae3d41..551b97d39414fd 100644 --- a/examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp +++ b/examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp @@ -99,11 +99,7 @@ void ButtonHandler::TimerCallback(TimerHandle_t xTimer) timerId = (uint32_t) pvTimerGetTimerID(xTimer); if (timerId) { - buttonevent = cyhal_gpio_read(APP_FUNCTION_BUTTON); - if (buttonevent) - { - GetAppTask().ButtonEventHandler(timerId, APP_BUTTON_PRESSED); - } + GetAppTask().ButtonEventHandler(timerId, APP_BUTTON_PRESSED); } else {