Skip to content

Commit

Permalink
[Silabs] [SiWx917] Added button support for Window app (#24945)
Browse files Browse the repository at this point in the history
* enabled button for window-app

* cleaned up the code

* Applied restyle
  • Loading branch information
silabs-srishylam authored Feb 10, 2023
1 parent a5b80df commit 36735ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 48 deletions.
44 changes: 3 additions & 41 deletions examples/window-app/silabs/SiWx917/include/WindowAppImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,12 @@
#include <LcdPainter.h>
#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:
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <setup_payload/SetupPayload.h>
#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"
Expand Down Expand Up @@ -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<Button *>((handle == &sl_button_btn0) ? sInstance.mButtonUp : sInstance.mButtonDown);
WindowApp::Button * btn = static_cast<Button *>((Btn == SIWx917_BTN0) ? sInstance.mButtonUp : sInstance.mButtonDown);
btn->Press();
// since sl_button_on_change is being called only with button press, calling Release() without condition
btn->Release();
}

// Silabs button callback from button event ISR
void sl_button_on_change()
void sl_button_on_change(uint8_t btn, uint8_t btnAction)
{
const sl_button_t * handle = &sl_button_btn0;
WindowAppImpl * app = static_cast<WindowAppImpl *>(&WindowAppImpl::sInstance);
app->OnButtonChange(handle);
WindowAppImpl * app = static_cast<WindowAppImpl *>(&WindowAppImpl::sInstance);
app->OnButtonChange(btn, btnAction);
}

0 comments on commit 36735ed

Please sign in to comment.