-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NXP] App button manager rework (#35859)
* [nxp][examples][common] Rework button manager Create an abstraction over SDK buttons. If an app needs a custom behavior for a specific button: - it can implement the Button interface, similar to the ButtonDefault implementation - it can implement a ButtonWithTimer derived class, to also have access to timer behavior, such as scheduling a delay for a specific action (e.g. factory reset after 6s) The ButtonManager is responsible with registering Button instances. The button callback is common across all buttons because it delegates the proper action handling to the button itself through the provided Button::Handle* API. The ButtonRegistration header provides an API that can be used by other components (e.g. AppTask) to initialize the ButtonManager and register buttons. A default implementation is provided. Some button examples are implemented: - ButtonApp - ButtonBle - ButtonDefault Check the corresponding header for a description of actions. Signed-off-by: marius-alex-tache <[email protected]> * [nxp][examples][common] Update register buttons API usage Update AppEvent structure for some apps to take into account a way to pass extra args to App event processing. Signed-off-by: marius-alex-tache <[email protected]> * [nxp][examples][mcxw71_k32w1] Rework button manager Update build system files for all impacted applications. Signed-off-by: marius-alex-tache <[email protected]> * [nxp][examples][rw61x] Update empty button registration path Signed-off-by: marius-alex-tache <[email protected]> * [nxp][examples][common] Add double click button action for ButtonBle Double clicking the ButtonBle will trigger a toggle of SIT mode request through the DSLS mechanism. Signed-off-by: marius-alex-tache <[email protected]> * Restyled by gn * Restyled by prettier-markdown --------- Signed-off-by: marius-alex-tache <[email protected]> Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
1 parent
d404400
commit 57fb2e1
Showing
33 changed files
with
837 additions
and
508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ typedef void (*EventHandler)(const AppEvent &); | |
struct AppEvent | ||
{ | ||
EventHandler Handler; | ||
void * extra; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ typedef void (*EventHandler)(const AppEvent &); | |
struct AppEvent | ||
{ | ||
EventHandler Handler; | ||
void * extra; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,5 @@ struct AppEvent | |
}; | ||
|
||
EventHandler Handler; | ||
void * extra; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
examples/platform/nxp/common/matter_button/include/Button.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "fsl_component_button.h" | ||
|
||
#include <lib/core/CHIPError.h> | ||
|
||
namespace chip::NXP::App { | ||
|
||
/** | ||
* @brief This class is an abstraction over an SDK button. | ||
* | ||
*/ | ||
class Button | ||
{ | ||
public: | ||
using Callback = button_status_t (*)(void * handle, button_callback_message_t * message, void * param); | ||
|
||
virtual ~Button() = default; | ||
|
||
virtual CHIP_ERROR Init() = 0; | ||
virtual void HandleShortPress() = 0; | ||
virtual void HandleLongPress() = 0; | ||
virtual void HandleDoubleClick() = 0; | ||
|
||
/** | ||
* @brief This is an SDK handle for a button. | ||
* | ||
* It should be set in the Init method, based on a newly defined | ||
* handle or an already defined handle owned by the SDK. | ||
*/ | ||
button_handle_t handle = nullptr; | ||
}; | ||
|
||
} // namespace chip::NXP::App |
44 changes: 44 additions & 0 deletions
44
examples/platform/nxp/common/matter_button/include/ButtonApp.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Button.h" | ||
|
||
namespace chip::NXP::App { | ||
/** | ||
* @brief This class implements a custom app button behavior. | ||
* | ||
* | Action | Effect | | ||
* | ------------ | --------------------------------- | | ||
* | Short press | Switch a cluster attribute state | | ||
* | Long press | Schedule a soft reset taking into | | ||
* | | account Matter shutdown mechanism | | ||
* | Double click | Do nothing | | ||
* | ||
*/ | ||
class ButtonApp : public Button | ||
{ | ||
public: | ||
virtual CHIP_ERROR Init() override; | ||
virtual void HandleShortPress() override; | ||
virtual void HandleLongPress() override; | ||
virtual void HandleDoubleClick() override; | ||
}; | ||
|
||
} // namespace chip::NXP::App |
48 changes: 48 additions & 0 deletions
48
examples/platform/nxp/common/matter_button/include/ButtonBle.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ButtonWithTimer.h" | ||
|
||
namespace chip::NXP::App { | ||
|
||
/** | ||
* @brief This class implements a customized default button behavior. | ||
* | ||
* | Action | Effect | | ||
* | ------------ | -------------------------------------------------- | | ||
* | Short press | If a factory reset is scheduled, cancel it. | | ||
* | | Else if the device is commissioned and a factory | | ||
* | | reset is not scheduled, switch to ICD active mode. | | ||
* | | Otherwise, switch commissioning state. | | ||
* | Long press | Schedule a factory reset | | ||
* | Double click | Toggle SIT mode request through DSLS mechanism | | ||
* | ||
*/ | ||
class ButtonBle : public ButtonWithTimer | ||
{ | ||
public: | ||
virtual CHIP_ERROR Init() override; | ||
virtual void HandleShortPress() override; | ||
virtual void HandleLongPress() override; | ||
virtual void HandleDoubleClick() override; | ||
virtual void HandleTimerExpire() override; | ||
}; | ||
|
||
} // namespace chip::NXP::App |
Oops, something went wrong.