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