µGFX  2.9
version 2.9
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.io/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 GFXON in your gfxconf.h
20  * @pre GINPUT_NEED_TOGGLE must be set to GFXON 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  gU16 instance; // The toggle instance
51  gBool 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 /**
63  * @brief Create a toggle input instance
64  *
65  * @param[in] instance The ID of the toggle input instance (from 0 to 9999)
66  *
67  * @return The source handle of the created instance
68  */
69 GSourceHandle ginputGetToggle(gU16 instance);
70 
71 /**
72  * @brief Can be used to invert the sense of a toggle
73  *
74  * @param[in] instance The ID of the toggle input instance
75  * @param[in] invert If gTrue, will be inverted
76  */
77 void ginputInvertToggle(gU16 instance, gBool invert);
78 
79 /**
80  * @brief Get the current toggle status
81  *
82  * @param[in] instance The ID of the toggle input instance
83  * @param[in] ptoggle The toggle event struct
84  *
85  * @return Returns gFalse on an error (eg invalid instance)
86  */
87 gBool ginputGetToggleStatus(gU16 instance, GEventToggle *ptoggle);
88 
89 #endif /* GINPUT_NEED_TOGGLE */
90 
91 #endif /* _GINPUT_TOGGLE_H */
92 /** @} */
93 
void ginputInvertToggle(gU16 instance, gBool invert)
Can be used to invert the sense of a toggle.
gBool ginputGetToggleStatus(gU16 instance, GEventToggle *ptoggle)
Get the current toggle status.
GSourceHandle ginputGetToggle(gU16 instance)
Create a toggle input instance.
Definition: ginput_toggle.c:95