-
Notifications
You must be signed in to change notification settings - Fork 1
/
io.c
69 lines (58 loc) · 1.55 KB
/
io.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "io.h"
void io_update(game_state_t *state)
{
state->p1_right_debounce_timer += state->delta;
state->p1_left_debounce_timer += state->delta;
state->p1_right_down = !RPI_GetGpioValue(PLAYER_1_RIGHT);
state->p1_left_down = !RPI_GetGpioValue(PLAYER_1_LEFT);
state->p1_right_released |= !state->p1_right_down;
state->p1_left_released |= !state->p1_left_down;
if (state->p1_right_down
&& state->p1_right_debounce_timer > BUTTON_DEBOUNCE) {
state->p1_right_debounce_timer = 0;
state->p1_right_held = 1;
if (state->p1_right_released) {
state->p1_right_released = 0;
state->p1_right_clicked = 1;
}
}
if (state->p1_left_down
&& state->p1_left_debounce_timer > BUTTON_DEBOUNCE) {
state->p1_left_debounce_timer = 0;
state->p1_left_held = 1;
state->p1_left_clicked = 1;
if (state->p1_left_released) {
state->p1_left_released = 0;
state->p1_left_clicked = 1;
}
}
}
void io_reset(game_state_t *state)
{
state->p1_right_debounce_timer = 0;
state->p1_left_debounce_timer = 0;
state->p1_right_clicked = 0;
state->p1_left_clicked = 0;
state->p1_left_held = 0;
state->p1_right_held = 0;
state->p1_right_released = 0;
state->p1_left_released = 0;
}
void io_handle_click_right(game_state_t *state)
{
state->p1_right_clicked = 0;
}
void io_handle_click_left(game_state_t *state)
{
state->p1_left_clicked = 0;
}
void io_handle_hold_right(game_state_t *state)
{
state->p1_right_debounce_timer = 0;
state->p1_right_held = 0;
}
void io_handle_hold_left(game_state_t *state)
{
state->p1_left_debounce_timer = 0;
state->p1_left_held = 0;
}