-
Notifications
You must be signed in to change notification settings - Fork 75
/
joystick.h
69 lines (53 loc) · 2.03 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
/*
(C) Copyright 2007,2008, Stephen M. Cameron.
This file is part of Space Nerds In Space.
wordwarvi 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 2 of the License, or
(at your option) any later version.
Space Nerds In Space 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 Space Nerds In Space; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __JOYSTICK_H__
#define __JOYSTICK_H__
#include <stdio.h>
#ifdef __WIN32__
#include <gdk/gdktypes.h>
#endif
#define MAX_JOYSTICK_BUTTONS 40
#define MAX_JOYSTICK_AXES 40
/* joystick axes limits */
#define JOYSTICK_AXIS_MIN -32767
#define JOYSTICK_AXIS_MAX 32767
#define JS_EVENT_BUTTON 0x01 /* button pressed/released */
#define JS_EVENT_AXIS 0x02 /* joystick moved */
#define JS_EVENT_INIT 0x80 /* initial state of device */
struct js_event {
unsigned int time; /* event timestamp in milliseconds */
short value; /* value */
unsigned char type; /* event type */
unsigned char number; /* axis/button number */
};
struct js_state {
int button[MAX_JOYSTICK_BUTTONS];
int axis[MAX_JOYSTICK_AXES];
};
struct joystick_descriptor {
char *name;
int file_descriptor;
};
int discover_joysticks(struct joystick_descriptor **joystick, int *njoysticks);
#ifdef __WIN32__
extern int open_joystick(char *joystick_device, GdkWindow *window);
#else
extern int open_joystick(char *joystick_device, void *window);
#endif
extern int read_joystick_event(int fd, struct js_event *jse);
extern void close_joystick(int fd);
extern int get_joystick_state(int fd, struct js_state *state);
#endif