libpynq
(release 5EID0-2023 version 0.3.0 of 2024-04-25 09:42 )
|
Go to the documentation of this file.
34 #define LOG_DOMAIN "buttons"
36 static bool buttons_initialized =
false;
37 static bool switches_initialized =
false;
40 if (buttons_initialized ==
true) {
41 pynq_error(
"buttons_destroy: buttons already initialized\n");
47 buttons_initialized =
true;
51 if (buttons_initialized ==
false) {
52 pynq_error(
"buttons_destroy: buttons weren't initialized\n");
54 buttons_initialized =
false;
58 if (switches_initialized ==
true) {
59 pynq_error(
"switches_destroy: switches already initialized\n");
63 switches_initialized =
true;
67 if (switches_initialized ==
false) {
68 pynq_error(
"switches_destroy: switches weren't initialized\n");
70 switches_initialized =
false;
74 if (buttons_initialized ==
false) {
75 pynq_error(
"get_button_state: buttons weren't initialized\n");
78 pynq_error(
"get_button_state: invalid button=%d, must be 0..%d-1\n",
86 if (buttons_initialized ==
false) {
87 pynq_error(
"wait_until_button_state: buttons weren't initialized\n");
90 pynq_error(
"get_button_state: invalid button=%d, must be 0..%d-1\n", button,
95 pynq_error(
"get_button_state: button %d has not been set as input\n",
98 struct timeval call, close;
100 gettimeofday(&call, NULL);
101 const unsigned int check =
105 gettimeofday(&close, NULL);
106 dTime = (close.tv_sec - call.tv_sec) * 1000.0;
107 dTime += (close.tv_usec - call.tv_usec) / 1000.0;
112 if (buttons_initialized ==
false) {
113 pynq_error(
"sleep_msec_button: buttons weren't initialized\n");
116 pynq_error(
"sleep_msec_button_pushed: invalid button=%d, must be 0..%d-1\n",
122 "sleep_msec_button_pushed: button %d has not been set as input\n",
126 struct timeval call, close;
129 gettimeofday(&call, NULL);
135 (void)gettimeofday(&close, NULL);
136 dTime = (close.tv_sec - call.tv_sec) * 1000.0;
137 dTime += (close.tv_usec - call.tv_usec) / 1000.0;
138 }
while (dTime < ms);
143 if (buttons_initialized ==
false) {
144 pynq_error(
"sleep_msec_buttons_pushed: buttons weren't initialized\n");
146 if (button_states == NULL) {
147 pynq_error(
"sleep_msec_buttons_pushed: button_states is NULL\n");
149 struct timeval call, close;
153 (void)gettimeofday(&call, NULL);
162 (void)gettimeofday(&close, NULL);
163 dTime = (close.tv_sec - call.tv_sec) * 1000.0;
164 dTime += (close.tv_usec - call.tv_usec) / 1000.0;
165 }
while (dTime < ms);
180 if (buttons_initialized ==
false) {
181 pynq_error(
"wait_until_any_button_pushed: buttons weren't initialized\n");
186 "wait_until_any_button_pushed: button %d has not been set as input\n",
201 if (buttons_initialized ==
false) {
202 pynq_error(
"wait_until_any_button_released: buttons weren't initialized\n");
206 pynq_error(
"wait_until_any_button_released: button %d has not been set "
220 if (switches_initialized ==
false) {
221 pynq_error(
"get_switch_state: switches weren't initialized\n");
224 pynq_error(
"get_switch_state: invalid switch_num=%d, must be 0..%i-1\n",
gpio_level_t gpio_get_level(const io_t pin)
Return the level of the IO pin.
void gpio_set_direction(const io_t pin, const gpio_direction_t direction)
Set the IO pin as in input or output.
@ IO_BTN0
Button input pins.
gpio_direction_t gpio_get_direction(const io_t pin)
Returns the direction the set pin is initialized in.
@ IO_SW0
Switch input pins.