xref: /haiku/headers/private/device/joystick_driver.h (revision 4f2fd49bdc6078128b1391191e4edac647044c3d)
1 /* ++++++++++
2 	FILE:	joystick_driver.h
3 	REVS:	$Revision: 1.1 $
4 	NAME:	herold
5 	DATE:	Tue Jun  4 14:57:25 PDT 1996
6 +++++ */
7 
8 /*
9 	Copyright 1999, Be Incorporated.   All Rights Reserved.
10 	This file may be used under the terms of the Be Sample Code License.
11 */
12 
13 #ifndef _JOYSTICK_DRIVER_H
14 #define _JOYSTICK_DRIVER_H
15 
16 #include <SupportDefs.h>
17 #include <Drivers.h>
18 #include <module.h>
19 
20 typedef struct _joystick {
21 	bigtime_t	timestamp;
22 	uint32		horizontal;
23 	uint32		vertical;
24 	bool		button1;
25 	bool		button2;
26 } joystick;
27 
28 /* maximum number of axes on one controller (pads count as 2 axes each) */
29 #define MAX_AXES 12
30 /* maximum number of hats on one controller -- PADS SHOULD BE RETURNED AS AXES! */
31 #define MAX_HATS 8
32 /* maximum number of buttons on one controller */
33 #define MAX_BUTTONS 32
34 /* maximum number of controllers on one port */
35 #define MAX_STICKS 4
36 
37 typedef struct _extended_joystick {
38 	bigtime_t	timestamp;		/* system_time when it was read */
39 	uint32		buttons;		/* lsb to msb, 1 == on */
40 	int16		axes[MAX_AXES];	/* -32768 to 32767, X, Y, Z, U, V, W */
41 	uint8		hats[MAX_HATS];	/* 0 through 8 (1 == N, 3 == E, 5 == S, 7 == W) */
42 } extended_joystick;
43 
44 #define MAX_CONFIG_SIZE 100
45 
46 enum {	/* flags for joystick module info */
47 	js_flag_force_feedback = 0x1,
48 	js_flag_force_feedback_directional = 0x2
49 };
50 
51 typedef struct _joystick_module_info {
52 	char			module_name[64];
53 	char			device_name[64];
54 	int16			num_axes;
55 	int16			num_buttons;
56 	int16			num_hats;
57 	uint16			_reserved[7];
58 	uint32			flags;
59 	uint16			num_sticks;
60 	int16			config_size;
61 	char			device_config[MAX_CONFIG_SIZE];	/* device specific */
62 } joystick_module_info;
63 
64 /* Note that joystick_module is something used by the game port driver */
65 /* to talk to digital joysticks; if you're writing a sound card driver */
66 /* and want to add support for a /dev/joystick device, use the generic_gameport */
67 /* module. */
68 
69 typedef struct _joystick_module {
70 	module_info minfo;
71 	/** "configure" might change the "info" if it auto-detects a device */
72 	int (*configure)(int port, joystick_module_info * info, size_t size, void ** out_cookie);
73 	/** "read" actual data from device into "data" */
74 	int (*read)(void * cookie, int port, extended_joystick * data, size_t size);
75 	/** "crumble" the cookie (deallocate) when done */
76 	int (*crumble)(void * cookie, int port);
77 	/** "force" tells the joystick to exert force on the same axes as input for the specified duration */
78 	int (*force)(void * cookie, int port, bigtime_t duration, extended_joystick * force, size_t size);
79 	int _reserved_;
80 } joystick_module;
81 
82 /** Doing force feedback means writing an extended_joystick to the device with force values.
83     The "timestamp" should be the duration of the feedback. Successive writes will be queued
84     by the device module. */
85 enum { /* Joystick driver ioctl() opcodes */
86     B_JOYSTICK_GET_SPEED_COMPENSATION = B_JOYSTICK_DRIVER_BASE,
87                                             /* arg -> ptr to int32 */
88     B_JOYSTICK_SET_SPEED_COMPENSATION,      /* arg -> ptr to int32 */
89     B_JOYSTICK_GET_MAX_LATENCY,             /* arg -> ptr to long long */
90     B_JOYSTICK_SET_MAX_LATENCY,             /* arg -> ptr to long long */
91     B_JOYSTICK_SET_DEVICE_MODULE,			/* arg -> ptr to joystick_module; also enters enhanced mode */
92     B_JOYSTICK_GET_DEVICE_MODULE,           /* arg -> ptr to joystick_module */
93 	B_JOYSTICK_SET_RAW_MODE					/* arg -> ptr to bool (true or false) */
94 };
95 
96 /* Speed compensation is not generally necessary, because the joystick */
97 /* driver is measuring using real time, not just # cycles. "0" means the */
98 /* default, center value. + typically returns higher values; - returns lower */
99 /* A typical range might be from -10 to +10, but it varies by driver */
100 
101 /* Lower latency will make for more overhead in reading the joystick */
102 /* ideally, you set this value to just short of how long it takes you */
103 /* to calculate and render a frame. 30 fps -> latency 33000 */
104 
105 
106 typedef struct _generic_gameport_module {
107 	module_info minfo;
108 	status_t (*create_device)(int port, void ** out_storage);
109 	status_t (*delete_device)(void * storage);
110 	status_t (*open_hook)(void * storage, uint32 flags, void ** out_cookie);
111 	status_t (*close_hook)(void * cookie);
112 	status_t (*free_hook)(void * cookie);
113 	status_t (*control_hook)(void * cookie, uint32 op, void * data, size_t len);
114 	status_t (*read_hook)(void * cookie, off_t pos, void * data, size_t * len);
115 	status_t (*write_hook)(void * cookie, off_t pos, const void * data, size_t * len);
116 	int	_reserved_;
117 } generic_gameport_module;
118 
119 
120 #endif
121