Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Infineon] PSoC6 Lock app not responding to button press after Factor… #24603

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
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