File: jsw.h

package info (click to toggle)
yiff 2.06-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,464 kB
  • ctags: 3,028
  • sloc: ansic: 47,463; makefile: 218; sh: 77
file content (156 lines) | stat: -rw-r--r-- 2,726 bytes parent folder | download | duplicates (3)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
                        Joystick Wrapper

	Any program wanting to use the Linux Joystick Wrapper
	functions (as specified in this file) needs to #include
	this file and link to the library libjsw.

	An example program called jswtest should acompany
	the program package that this header file came in.

        For contact information, see:

        http://fox.mit.edu/xsw/contacts.htm

 */

#ifndef JSW_H
#define JSW_H

#include <time.h>
#include <sys/types.h>


/*
 *	OS Specific Definations:
 */
#ifdef __linux__
# include <linux/joystick.h>
# define JSDefaultDevice		"/dev/js0"
# define JSDefaultCaliberation		".joystick"
#endif

/* Assume defaults for device and caliberation file. */
#ifndef JSDefaultDevice
# define JSDefaultDevice		"/dev/js0"
#endif

#ifndef JSDefaultCaliberation
# define JSDefaultCaliberation		".joystick"
#endif



/*
 *	Default stick bounds (in raw units):
 */
#ifndef JSDefaultMin
# define JSDefaultMin		0
#endif

#ifndef JSDefaultMax
# define JSDefaultMax		1000
#endif

#ifndef JSDefaultCenter
# define JSDefaultCenter	500
#endif

#ifndef JSDefaultNullZone
# define JSDefaultNullZone	100
#endif



/*
 *	Error codes:
 */
#define JSSuccess	0
#define JSError		1
#define JSBadValue	2
#define JSNoAccess	3
#define JSNoBuffers	4


/*
 *	Event codes:
 */
#define JSNoEvent	0
#define JSGotEvent	1

/*
 *	Button state codes:
 */
#define JSButtonStateOff	0
#define JSButtonStateOn		1


/*
 *	Joystick data structures:
 */

/* Axis structure. */
typedef struct {

	/* All units in raw units. */
	int cur;		/* Current position. */
	int min, cen, max;	/* Bounds. */
	int nz;			/* Null zone, in raw units from cen. */

	char flip;		/* Flip values? */

	char is_hat;		/* Treat this axis as a hat? */

} js_axis_struct;

/* Button structure. */
typedef struct {

	unsigned char state;	/* One of JSButtonState*. */

} js_button_struct;

/* Joystick caliberation and current data structure. */
typedef struct {

	/* Public, read only. */
	char *name;

	js_axis_struct **axis;
	int total_axises;

	js_button_struct **button;
	int total_buttons;

	char *device_name;
	char *caliberation_file;

	time_t time;

	/* Private, do not access. */
	int fd;

} js_data_struct;


/* Private functions. */
#ifdef __linux__
extern int JSLoadCaliberationLinux(js_data_struct *jsd);
#endif

/* Public functions. */
extern int JSIsAxisAllocated(js_data_struct *jsd, int n);
extern int JSIsButtonAllocated(js_data_struct *jsd, int n);

extern double JSGetAxisCoeff(js_data_struct *jsd, int n);
extern double JSGetAxisCoeffNZ(js_data_struct *jsd, int n);

extern int JSInit(
	js_data_struct *jsd,
	int argc, char *argv[]
);
extern int JSUpdate(js_data_struct *jsd);
extern void JSClose(js_data_struct *jsd);


#endif	/* JSW_H */