libwebsockets
Lightweight C library for HTML5 websockets
lws-button.h
Go to the documentation of this file.
1 /*
2  * Generic button ops
3  *
4  * Copyright (C) 2019 - 2020 Andy Green <andy@warmcat.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  *
24  * Leverages the lws generic gpio pieces to bind gpio buttons to smd events
25  */
26 
27 #if !defined(__LWS_BUTTON_H__)
28 #define __LWS_BUTTON_H__
29 
31 
32 /* actual minimum may be 1 x RTOS tick depending on platform */
33 #define LWS_BUTTON_MON_TIMER_MS 5
34 
35 typedef void (*lws_button_cb_t)(void *opaque, lws_button_idx_t idx, int state);
36 
37 /* These are specified in ms but the granularity is LWS_BUTTON_MON_TIMER_MS,
38  * which may have been rounded up to an RTOS tick depending on platform */
39 
40 enum {
42 };
43 
44 typedef struct lws_button_regime {
58 
59 /*
60  * This is the const part of the button controller, describing the static
61  * bindings to gpio, and lws_smd event name information
62  */
63 
64 typedef struct lws_button_map {
66  const char *smd_interaction_name;
70 
71 typedef struct lws_button_controller {
72  const char *smd_bc_name;
78 
79 struct lws_button_state; /* opaque */
80 
91 LWS_VISIBLE LWS_EXTERN struct lws_button_state *
92 lws_button_controller_create(struct lws_context *ctx,
93  const lws_button_controller_t *controller);
94 
105 lws_button_controller_destroy(struct lws_button_state *bcs);
106 
107 
109 lws_button_get_bit(struct lws_button_state *bcs, const char *name);
110 
111 /*
112  * lws_button_enable() - enable and disable buttons
113  */
114 
116 lws_button_enable(struct lws_button_state *bcs,
117  lws_button_idx_t _reset, lws_button_idx_t _set);
118 
119 #endif
120 
unsigned short uint16_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
@ LWSBTNRGMFLAG_CLASSIFY_DOUBLECLICK
Definition: lws-button.h:41
uint16_t lws_button_idx_t
Definition: lws-button.h:30
const lws_button_map_t * button_map
Definition: lws-button.h:74
LWS_VISIBLE LWS_EXTERN lws_button_idx_t lws_button_get_bit(struct lws_button_state *bcs, const char *name)
_lws_plat_gpio_t gpio
Definition: lws-button.h:65
uint16_t ms_min_down_longpress
Definition: lws-button.h:46
uint16_t ms_min_down
Definition: lws-button.h:45
const char * smd_interaction_name
Definition: lws-button.h:66
LWS_VISIBLE LWS_EXTERN struct lws_button_state * lws_button_controller_create(struct lws_context *ctx, const lws_button_controller_t *controller)
const lws_gpio_ops_t * gpio_ops
Definition: lws-button.h:73
uint16_t ms_doubleclick_grace
Definition: lws-button.h:48
struct lws_button_controller lws_button_controller_t
const lws_button_regime_t * regime
Definition: lws-button.h:67
void(* lws_button_cb_t)(void *opaque, lws_button_idx_t idx, int state)
Definition: lws-button.h:35
uint16_t ms_repeat_down
Definition: lws-button.h:49
lws_button_idx_t active_state_bitmap
Definition: lws-button.h:75
struct lws_button_regime lws_button_regime_t
LWS_VISIBLE LWS_EXTERN void lws_button_controller_destroy(struct lws_button_state *bcs)
struct lws_button_map lws_button_map_t
const char * smd_bc_name
Definition: lws-button.h:72
LWS_VISIBLE LWS_EXTERN void lws_button_enable(struct lws_button_state *bcs, lws_button_idx_t _reset, lws_button_idx_t _set)
uint16_t ms_up_settle
Definition: lws-button.h:47
int _lws_plat_gpio_t
Definition: lws-gpio.h:31