2 FILE: joystick_driver.h
5 DATE: Tue Jun 4 14:57:25 PDT 1996
9 Copyright 1999, Be Incorporated. All Rights Reserved.
10 This file may be used under the terms of the Be Sample Code License.
13 #ifndef _JOYSTICK_DRIVER_H
14 #define _JOYSTICK_DRIVER_H
18 #include <SupportDefs.h>
22 typedef struct _joystick
{
30 /* maximum number of axes on one controller (pads count as 2 axes each) */
32 /* maximum number of hats on one controller -- PADS SHOULD BE RETURNED AS AXES! */
34 /* maximum number of buttons on one controller */
35 #define MAX_BUTTONS 32
36 /* maximum number of controllers on one port */
39 typedef struct _extended_joystick
{
40 bigtime_t timestamp
; /* system_time when it was read */
41 uint32 buttons
; /* lsb to msb, 1 == on */
42 int16 axes
[MAX_AXES
]; /* -32768 to 32767, X, Y, Z, U, V, W */
43 uint8 hats
[MAX_HATS
]; /* 0 through 8 (1 == N, 3 == E, 5 == S, 7 == W) */
44 } _PACKED extended_joystick
;
47 // This is a helper structure to manage variably sized data. It is here to
48 // make storing and accessing the flat data in the "data" member easier. When
49 // transferring data via read/write/ioctl only the flat data in "data" is ever
50 // transmitted, not the whole structure.
51 typedef struct _variable_joystick
{
53 status_t
initialize(uint32 axisCount
, uint32 hatCount
, uint32 buttonCount
)
55 axis_count
= axisCount
;
57 button_blocks
= (buttonCount
+ 31) / 32;
59 data_size
= sizeof(bigtime_t
) // timestamp
60 + button_blocks
* sizeof(uint32
) // bitmaps
61 + axis_count
* sizeof(int16
) // axis values
62 + hat_count
* sizeof(uint8
); // hat values
64 data
= (uint8
*)malloc(data_size
);
68 // fill in the convenience pointers
69 timestamp
= (bigtime_t
*)data
;
70 buttons
= (uint32
*)×tamp
[1];
71 axes
= (int16
*)&buttons
[button_blocks
];
72 hats
= (uint8
*)&axes
[axis_count
];
76 status_t
initialize_to_extended_joystick()
78 return initialize(MAX_AXES
, MAX_HATS
, MAX_BUTTONS
);
85 // count of 32 bit button bitmap blocks == (button_count + 31) / 32
87 // These pointers all point into the data section and are here for
88 // convenience. They need to be set up manually by the one who creates this
89 // structure or by using the initialize() method.
90 bigtime_t
* timestamp
;
95 // The data is always structured in the following way (see extended_joystick
96 // for data interpretation):
97 // bigtime_t timestamp;
98 // uint32 button_bitmap_blocks[button_blocks];
99 // int16 axes[axis_count];
100 // uint8 hats[hat_count];
106 #define MAX_CONFIG_SIZE 100
108 enum { /* flags for joystick module info */
109 js_flag_force_feedback
= 0x1,
110 js_flag_force_feedback_directional
= 0x2,
111 js_flag_variable_size_reads
= 0x4
114 typedef struct _joystick_module_info
{
115 char module_name
[64];
116 char device_name
[64];
124 char device_config
[MAX_CONFIG_SIZE
]; /* device specific */
125 } joystick_module_info
;
127 /* Note that joystick_module is something used by the game port driver */
128 /* to talk to digital joysticks; if you're writing a sound card driver */
129 /* and want to add support for a /dev/joystick device, use the generic_gameport */
132 typedef struct _joystick_module
{
134 /** "configure" might change the "info" if it auto-detects a device */
135 int (*configure
)(int port
, joystick_module_info
* info
, size_t size
, void ** out_cookie
);
136 /** "read" actual data from device into "data" */
137 int (*read
)(void * cookie
, int port
, extended_joystick
* data
, size_t size
);
138 /** "crumble" the cookie (deallocate) when done */
139 int (*crumble
)(void * cookie
, int port
);
140 /** "force" tells the joystick to exert force on the same axes as input for the specified duration */
141 int (*force
)(void * cookie
, int port
, bigtime_t duration
, extended_joystick
* force
, size_t size
);
145 /** Doing force feedback means writing an extended_joystick to the device with force values.
146 The "timestamp" should be the duration of the feedback. Successive writes will be queued
147 by the device module. */
148 enum { /* Joystick driver ioctl() opcodes */
149 B_JOYSTICK_GET_SPEED_COMPENSATION
= B_JOYSTICK_DRIVER_BASE
,
150 /* arg -> ptr to int32 */
151 B_JOYSTICK_SET_SPEED_COMPENSATION
, /* arg -> ptr to int32 */
152 B_JOYSTICK_GET_MAX_LATENCY
, /* arg -> ptr to long long */
153 B_JOYSTICK_SET_MAX_LATENCY
, /* arg -> ptr to long long */
154 B_JOYSTICK_SET_DEVICE_MODULE
, /* arg -> ptr to joystick_module; also enters enhanced mode */
155 B_JOYSTICK_GET_DEVICE_MODULE
, /* arg -> ptr to joystick_module */
156 B_JOYSTICK_SET_RAW_MODE
/* arg -> ptr to bool (true or false) */
159 /* Speed compensation is not generally necessary, because the joystick */
160 /* driver is measuring using real time, not just # cycles. "0" means the */
161 /* default, center value. + typically returns higher values; - returns lower */
162 /* A typical range might be from -10 to +10, but it varies by driver */
164 /* Lower latency will make for more overhead in reading the joystick */
165 /* ideally, you set this value to just short of how long it takes you */
166 /* to calculate and render a frame. 30 fps -> latency 33000 */
169 typedef struct _generic_gameport_module
{
171 status_t (*create_device
)(int port
, void ** out_storage
);
172 status_t (*delete_device
)(void * storage
);
173 status_t (*open_hook
)(void * storage
, uint32 flags
, void ** out_cookie
);
174 status_t (*close_hook
)(void * cookie
);
175 status_t (*free_hook
)(void * cookie
);
176 status_t (*control_hook
)(void * cookie
, uint32 op
, void * data
, size_t len
);
177 status_t (*read_hook
)(void * cookie
, off_t pos
, void * data
, size_t * len
);
178 status_t (*write_hook
)(void * cookie
, off_t pos
, const void * data
, size_t * len
);
180 } generic_gameport_module
;