forked from jberaud/joystick_remote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
joystick.h
78 lines (62 loc) · 1.85 KB
/
joystick.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
This file is part of joystick_remote.
joystick_remote is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or any later version.
joystick_remote is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with joystick_remote.
If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _JOYSTICK_H_
#define _JOYSTICK_H_
#define MAX_NAME_LEN 128
enum {
JOYSTICK_AXIS_ROLL,
JOYSTICK_AXIS_PITCH,
JOYSTICK_AXIS_THROTTLE,
JOYSTICK_AXIS_YAW,
JOYSTICK_NUM_AXIS
};
enum {
JOYSTICK_BUTTON_MODE1,
JOYSTICK_BUTTON_MODE2,
JOYSTICK_BUTTON_MODE3,
JOYSTICK_BUTTON_MODE4,
JOYSTICK_BUTTON_MODE5,
JOYSTICK_BUTTON_MODE6,
JOYSTICK_NUM_MODES
};
struct joystick_pwms {
uint16_t roll;
uint16_t pitch;
uint16_t throttle;
uint16_t yaw;
uint16_t mode;
};
struct joystick_axis {
uint8_t number;
/* 1 or -1 */
int8_t direction;
};
struct joystick {
char name[MAX_NAME_LEN];
int fd;
pthread_t thread;
pthread_mutex_t mutex;
struct joystick_pwms pwms;
/* buttons mapping */
uint8_t buttons[JOYSTICK_NUM_MODES];
/* axis mapping */
struct joystick_axis axes[JOYSTICK_NUM_AXIS];
/* modes pwm mapping */
uint16_t mode_pwms[JOYSTICK_NUM_MODES];
};
int joystick_start(char *path, struct joystick *joystick);
void joystick_get_pwms(struct joystick *joystick, uint16_t *pwms, uint8_t *len);
int joystick_set_type(struct joystick *joystick, char *type);
#endif // _JOYSTICK_H_