libwebsockets
Lightweight C library for HTML5 websockets
lws-button.h
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 
30 typedef uint16_t lws_button_idx_t;
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 {
41  LWSBTNRGMFLAG_CLASSIFY_DOUBLECLICK = (1 << 0)
42 };
43 
44 typedef struct lws_button_regime {
45  uint16_t ms_min_down;
46  uint16_t ms_min_down_longpress;
47  uint16_t ms_up_settle;
48  uint16_t ms_doubleclick_grace;
49  uint16_t ms_repeat_down;
50  uint8_t flags;
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 {
65  _lws_plat_gpio_t gpio;
66  const char *smd_interaction_name;
70 
71 typedef struct lws_button_controller {
72  const char *smd_bc_name;
73  const lws_gpio_ops_t *gpio_ops;
74  const lws_button_map_t *button_map;
75  lws_button_idx_t active_state_bitmap;
76  uint8_t count_buttons;
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 
104 LWS_VISIBLE LWS_EXTERN void
105 lws_button_controller_destroy(struct lws_button_state *bcs);
106 
107 
108 LWS_VISIBLE LWS_EXTERN lws_button_idx_t
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 
115 LWS_VISIBLE LWS_EXTERN void
116 lws_button_enable(struct lws_button_state *bcs,
117  lws_button_idx_t _reset, lws_button_idx_t _set);
118 
119 #endif
120 
Definition: lws-button.h:71
Definition: lws-button.h:64
const lws_button_regime_t * regime
Definition: lws-button.h:67
Definition: lws-button.h:44
uint8_t flags
Definition: lws-button.h:50
Definition: lws-gpio.h:52