-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjoystick.h
More file actions
29 lines (24 loc) · 726 Bytes
/
joystick.h
File metadata and controls
29 lines (24 loc) · 726 Bytes
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
// joystick.h
#ifndef JOYSTICK_H
#define JOYSTICK_H
#include <stdint.h>
#include <linux/joystick.h>
// Joystick structure definition
typedef struct {
int js_fd;
int axis_count;
int button_count;
struct js_event event;
int16_t *axes;
int8_t *buttons;
char name[128];
} Joystick;
// Function declarations
int joystick_init(Joystick *js, const char *device_path);
void joystick_update(Joystick *js);
void joystick_close(Joystick *js);
// Utility functions
float joystick_get_axis_normalized(Joystick *js, int axis_index); // Returns -1.0 to 1.0
int joystick_get_button(Joystick *js, int button_index); // Returns 0 or 1
const char* joystick_get_name(Joystick *js);
#endif // JOYSTICK_H