mirror of
https://github.com/MaJerle/lwbtn.git
synced 2026-08-17 09:33:54 +08:00
fix: increase guards for optional functions
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
## Develop
|
||||
|
||||
- Guard all optional functions with the conditional compilation depending on the user configuration
|
||||
|
||||
## v1.3.1
|
||||
|
||||
- Fire the on-press/on-release events as soon as the transition happen. Do not wait next process cycle.
|
||||
|
||||
@@ -171,13 +171,18 @@ typedef struct lwbtn {
|
||||
#endif /* LWBTN_CFG_GET_STATE_MODE != LWBTN_GET_STATE_MODE_MANUAL || __DOXYGEN__ */
|
||||
} lwbtn_t;
|
||||
|
||||
/* Core functions */
|
||||
uint8_t lwbtn_init_ex(lwbtn_t* lwobj, lwbtn_btn_t* btns, uint16_t btns_cnt, lwbtn_get_state_fn get_state_fn,
|
||||
lwbtn_evt_fn evt_fn);
|
||||
uint8_t lwbtn_process_ex(lwbtn_t* lwobj, lwbtn_time_t mstime);
|
||||
uint8_t lwbtn_process_btn_ex(lwbtn_t* lwobj, lwbtn_btn_t* btn, lwbtn_time_t mstime);
|
||||
uint8_t lwbtn_set_btn_state(lwbtn_btn_t* btn, uint8_t state);
|
||||
uint8_t lwbtn_is_btn_active(const lwbtn_btn_t* btn);
|
||||
uint8_t lwbtn_reset(lwbtn_t* lwobj, lwbtn_btn_t* btn);
|
||||
uint8_t lwbtn_is_btn_active(const lwbtn_btn_t* btn);
|
||||
|
||||
/* State function */
|
||||
#if LWBTN_CFG_GET_STATE_MODE != LWBTN_GET_STATE_MODE_CALLBACK || __DOXYGEN__
|
||||
uint8_t lwbtn_set_btn_state(lwbtn_btn_t* btn, uint8_t state);
|
||||
#endif /* LWBTN_CFG_GET_STATE_MODE != LWBTN_GET_STATE_MODE_CALLBACK || __DOXYGEN__ */
|
||||
|
||||
/* Debounce configuration functions */
|
||||
lwbtn_time_t lwbtn_debounce_get_press_time(const lwbtn_btn_t* btn);
|
||||
@@ -239,6 +244,7 @@ uint8_t lwbtn_click_get_count(const lwbtn_btn_t* btn);
|
||||
*/
|
||||
#define lwbtn_process_btn(btn, mstime) lwbtn_process_btn_ex(NULL, (btn), (mstime))
|
||||
|
||||
/* Keep alive functions */
|
||||
#if LWBTN_CFG_USE_KEEPALIVE || __DOXYGEN__
|
||||
|
||||
lwbtn_time_t lwbtn_keepalive_get_period(const lwbtn_btn_t* btn);
|
||||
|
||||
@@ -408,25 +408,27 @@ lwbtn_process_btn_ex(lwbtn_t* lwobj, lwbtn_btn_t* btn, lwbtn_time_t mstime) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if LWBTN_CFG_GET_STATE_MODE != LWBTN_GET_STATE_MODE_CALLBACK || __DOXYGEN__
|
||||
|
||||
/**
|
||||
* \brief Set button state to either "active" or "inactive".
|
||||
*
|
||||
* \note Available only when \ref LWBTN_CFG_GET_STATE_MODE is NOT set to \ref LWBTN_GET_STATE_MODE_CALLBACK,
|
||||
* which implies that user can use callback or direct (dynamic configuration) state set
|
||||
*
|
||||
* \param[in] btn: Button instance
|
||||
* \param[in] state: New button state. `1` is for active (pressed), `0` is for inactive (released).
|
||||
* \return `1` on success, `0` otherwise
|
||||
*/
|
||||
uint8_t
|
||||
lwbtn_set_btn_state(lwbtn_btn_t* btn, uint8_t state) {
|
||||
#if LWBTN_CFG_GET_STATE_MODE != LWBTN_GET_STATE_MODE_CALLBACK
|
||||
btn->curr_state = state;
|
||||
btn->flags |= LWBTN_FLAG_MANUAL_STATE;
|
||||
return 1;
|
||||
#else /* LWBTN_CFG_GET_STATE_MODE != LWBTN_GET_STATE_MODE_CALLBACK */
|
||||
(void)btn;
|
||||
(void)state;
|
||||
return 0;
|
||||
#endif /* LWBTN_CFG_GET_STATE_MODE != LWBTN_GET_STATE_MODE_CALLBACK */
|
||||
}
|
||||
|
||||
#endif /* LWBTN_CFG_GET_STATE_MODE != LWBTN_GET_STATE_MODE_CALLBACK || __DOXYGEN__ */
|
||||
|
||||
/**
|
||||
* \brief Check if button is active.
|
||||
*
|
||||
@@ -543,7 +545,7 @@ lwbtn_debounce_set_release_time(lwbtn_btn_t* btn, lwbtn_time_t time) {
|
||||
|
||||
#endif /* LWBTN_CFG_TIME_DEBOUNCE_RELEASE_DYNAMIC || __DOXYGEN__ */
|
||||
|
||||
/* Click configuration functions */
|
||||
#if LWBTN_CFG_USE_CLICK || __DOXYGEN__
|
||||
|
||||
/**
|
||||
* \brief Get minimum pressed time for valid click event, for specific button
|
||||
@@ -681,8 +683,6 @@ lwbtn_click_set_max_consecutive(lwbtn_btn_t* btn, uint8_t max) {
|
||||
|
||||
#endif /* LWBTN_CFG_CLICK_MAX_CONSECUTIVE_DYNAMIC || __DOXYGEN__ */
|
||||
|
||||
#if LWBTN_CFG_USE_CLICK || __DOXYGEN__
|
||||
|
||||
/**
|
||||
* \brief Get number of consecutive click events on a button since the last events.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user