version 2.8
ginput_toggle.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.org/license.html
6  */
7 
8 /**
9  * @file src/ginput/ginput_toggle.h
10  *
11  * @defgroup Toggle Toggle
12  * @ingroup GINPUT
13  *
14  * @brief Sub-Module to handle physical controls that provide provide a digital value (on/off, pressed/released, 1/0, ...).
15  *
16  * @details GINPUT allows it to interface toggle buttons easily to your
17  * application.
18  *
19  * @pre GFX_USE_GINPUT must be set to TRUE in your gfxconf.h
20  * @pre GINPUT_NEED_TOGGLE must be set to TRUE in your gfxconf.h
21  *
22  * @{
23  */
24 
25 #ifndef _GINPUT_TOGGLE_H
26 #define _GINPUT_TOGGLE_H
27 
28 #if GINPUT_NEED_TOGGLE || defined(__DOXYGEN__)
29 
30 /*===========================================================================*/
31 /* Low Level Driver details and error checks. */
32 /*===========================================================================*/
33 
34 // Get the hardware definitions - Number of instances etc.
35 #include "ginput_lld_toggle_config.h"
36 
37 #ifndef GINPUT_TOGGLE_POLL_PERIOD
38  #define GINPUT_TOGGLE_POLL_PERIOD 200
39 #endif
40 
41 /*===========================================================================*/
42 /* Type definitions */
43 /*===========================================================================*/
44 
45 // Event types for various ginput sources
46 #define GEVENT_TOGGLE (GEVENT_GINPUT_FIRST+3)
47 
48 typedef struct GEventToggle_t {
49  GEventType type; // The type of this event (GEVENT_TOGGLE)
50  uint16_t instance; // The toggle instance
51  bool_t on; // True if the toggle/button is on
52  } GEventToggle;
53 
54 // Toggle Listen Flags - passed to geventAddSourceToListener()
55 #define GLISTEN_TOGGLE_ON 0x0001 // Return an event when the toggle turns on
56 #define GLISTEN_TOGGLE_OFF 0x0002 // Return an event when the toggle turns off
57 
58 /*===========================================================================*/
59 /* External declarations. */
60 /*===========================================================================*/
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66  /**
67  * @brief Create a toggle input instance
68  *
69  * @param[in] instance The ID of the toggle input instance (from 0 to 9999)
70  *
71  * @return The source handle of the created instance
72  */
73  GSourceHandle ginputGetToggle(uint16_t instance);
74 
75  /**
76  * @brief Can be used to invert the sense of a toggle
77  *
78  * @param[in] instance The ID of the toggle input instance
79  * @param[in] invert If TRUE, will be inverted
80  */
81  void ginputInvertToggle(uint16_t instance, bool_t invert);
82 
83  /**
84  * @brief Get the current toggle status
85  *
86  * @param[in] instance The ID of the toggle input instance
87  * @param[in] ptoggle The toggle event struct
88  *
89  * @return Returns FALSE on an error (eg invalid instance)
90  */
91  bool_t ginputGetToggleStatus(uint16_t instance, GEventToggle *ptoggle);
92 
93 #ifdef __cplusplus
94 }
95 #endif
96 
97 #endif /* GINPUT_NEED_TOGGLE */
98 
99 #endif /* _GINPUT_TOGGLE_H */
100 /** @} */
101 
void ginputInvertToggle(uint16_t instance, bool_t invert)
Can be used to invert the sense of a toggle.
GSourceHandle ginputGetToggle(uint16_t instance)
Create a toggle input instance.
Definition: ginput_toggle.c:95
bool_t ginputGetToggleStatus(uint16_t instance, GEventToggle *ptoggle)
Get the current toggle status.