From 12672713448bd8fb93381cd7fab2b82b4a4017d7 Mon Sep 17 00:00:00 2001 From: srningap <107042150+srningap@users.noreply.github.com> Date: Fri, 10 Feb 2023 19:00:43 +0530 Subject: [PATCH] [Silabs] [SiWx917] Added button support for Window app (#24945) * enabled button for window-app * cleaned up the code * Applied restyle --- .../silabs/SiWx917/include/WindowAppImpl.h | 44 ++----------------- .../silabs/SiWx917/src/WindowAppImpl.cpp | 15 ++++--- 2 files changed, 11 insertions(+), 48 deletions(-) mode change 100644 => 100755 examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp diff --git a/examples/window-app/silabs/SiWx917/include/WindowAppImpl.h b/examples/window-app/silabs/SiWx917/include/WindowAppImpl.h index a486de4f5dcb08..efaf194618b3a9 100644 --- a/examples/window-app/silabs/SiWx917/include/WindowAppImpl.h +++ b/examples/window-app/silabs/SiWx917/include/WindowAppImpl.h @@ -34,49 +34,12 @@ #include #endif -#define SL_SIMPLE_BUTTON_MODE_POLL 0U ///< BUTTON input capture using polling -#define SL_SIMPLE_BUTTON_MODE_POLL_AND_DEBOUNCE 1U ///< BUTTON input capture using polling and debouncing -#define SL_SIMPLE_BUTTON_MODE_INTERRUPT 2U ///< BUTTON input capture using interrupt +#define SIWx917_BTN0 0 +#define SIWx917_BTN1 1 -#define SL_SIMPLE_BUTTON_DISABLED 2U ///< BUTTON state is disabled #define SL_SIMPLE_BUTTON_PRESSED 1U ///< BUTTON state is pressed #define SL_SIMPLE_BUTTON_RELEASED 0U ///< BUTTON state is released -typedef uint8_t sl_button_mode_t; ///< BUTTON mode -typedef uint8_t sl_button_state_t; ///< BUTTON state -typedef struct sl_button sl_button_t; - -/// A BUTTON instance -typedef struct sl_button -{ - void * context; ///< The context for this BUTTON instance - void (*init)(const sl_button_t * handle); ///< Member function to initialize BUTTON instance - void (*poll)(const sl_button_t * handle); ///< Member function to poll BUTTON - void (*enable)(const sl_button_t * handle); ///< Member function to enable BUTTON - void (*disable)(const sl_button_t * handle); ///< Member function to disable BUTTON - sl_button_state_t (*get_state)(const sl_button_t * handle); ///< Member function to retrieve BUTTON state -} sl_button; - -const sl_button_t sl_button_btn0 = { - .context = NULL, - .init = NULL, - .poll = NULL, - .enable = NULL, - .disable = NULL, - .get_state = NULL, -}; -#define APP_FUNCTION_BUTTON &sl_button_btn0 - -const sl_button_t sl_button_btn1 = { - .context = NULL, - .init = NULL, - .poll = NULL, - .enable = NULL, - .disable = NULL, - .get_state = NULL, -}; -#define APP_LIGHT_SWITCH &sl_button_btn1 - class WindowAppImpl : public WindowApp { public: @@ -88,8 +51,7 @@ class WindowAppImpl : public WindowApp void Finish() override; void PostEvent(const WindowApp::Event & event) override; void PostAttributeChange(chip::EndpointId endpoint, chip::AttributeId attributeId) override; - friend void sl_button_on_change(const sl_button_t * handle); - void OnButtonChange(const sl_button_t * handle); + void OnButtonChange(uint8_t btn, uint8_t btnAction); protected: struct Timer : public WindowApp::Timer diff --git a/examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp b/examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp old mode 100644 new mode 100755 index a0582a4dd6e4f8..6f44407e18b8be --- a/examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp +++ b/examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp @@ -32,7 +32,7 @@ #include #endif // QR_CODE_ENABLED -extern "C" void sl_button_on_change(); +extern "C" void sl_button_on_change(uint8_t btn, uint8_t btnAction); #ifdef SL_WIFI #include "wfx_host_events.h" @@ -528,16 +528,17 @@ void WindowAppImpl::OnMainLoop() //------------------------------------------------------------------------------ WindowAppImpl::Button::Button(WindowApp::Button::Id id, const char * name) : WindowApp::Button(id, name) {} -void WindowAppImpl::OnButtonChange(const sl_button_t * handle) +void WindowAppImpl::OnButtonChange(uint8_t Btn, uint8_t btnAction) { - WindowApp::Button * btn = static_cast