forked from Rhoban/Metabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttons.h
59 lines (47 loc) · 1.19 KB
/
buttons.h
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
#ifndef _BUTTONS_H
#define _BUTTONS_H
#include "Arduino.h"
// Buttons
#define BTN_JLX A4
#define BTN_JLY A5
#define BTN_JRX A2
#define BTN_JRY A3
#define BTN_UP 5
#define BTN_LEFT 6
#define BTN_DOWN 7
#define BTN_RIGHT 8
#define BTN_R1 9
#define BTN_R2 11
#define BTN_R3 12
#define BTN_R4 10
#define BTN_LZ1 15
#define BTN_LZ2 16
#define BTN_RZ1 13
#define BTN_RZ2 14
#define BTN_START 4
#define BTN_SELECT 3
unsigned char allButtons[] = {
BTN_JLX, BTN_JLY, BTN_JRX, BTN_JRY,
BTN_UP, BTN_LEFT, BTN_DOWN, BTN_RIGHT,
BTN_R1, BTN_R2, BTN_R3, BTN_R4,
BTN_LZ1, BTN_LZ2, BTN_RZ1, BTN_RZ2,
BTN_START, BTN_SELECT
};
#define NB_BUTTONS (sizeof(allButtons))
// State of the buttons
struct state {
int joypad_left_x, joypad_left_y;
int joypad_right_x, joypad_right_y;
bool up, left, down, right;
bool r1, r2, r3, r4;
bool lz1, lz2, rz1, rz2;
bool start, select;
};
extern struct state last_btns;
void initButtons();
struct state readButtons();
float normalize(int pad);
#define ON_CHANGE(value) if (btns.value != last_btns.value)
#define ON_PRESS(value) ON_CHANGE(value) if (btns.value)
#define ON_RELEASE(value) ON_CHANGE(value) if (!btns.value)
#endif