Skip to content

Commit

Permalink
[Infineon] PSoC6 Lock app not responding to button press after Factor… (
Browse files Browse the repository at this point in the history
#24603)

* [Infineon] PSoC6 Lock app not responding to button press after Factory reset

* Update ButtonHandler.cpp

Map long press and short press of the USER_BTN2 to Factory reset

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Nov 20, 2023
1 parent 19a50a1 commit 1093652
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 58 deletions.
3 changes: 2 additions & 1 deletion examples/lock-app/infineon/psoc6/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
101 changes: 49 additions & 52 deletions examples/lock-app/infineon/psoc6/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<intptr_t>(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<chip::app::Clusters::DoorLock::DlLockState> state;
chip::EndpointId endpointId{ 1 };
chip::DeviceLayer::PlatformMgr().LockChipStack();
chip::app::Clusters::DoorLock::Attributes::LockState::Get(endpointId, state);

uint8_t numberOfCredentialsPerUser = 0;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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<intptr_t>(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
Expand Down
6 changes: 1 addition & 5 deletions examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 1093652

Please sign in to comment.