#ifndef _JOYSTICK_DRIVER_H
#define _JOYSTICK_DRIVER_H
#include <stdlib.h>
#include <SupportDefs.h>
#include <Drivers.h>
#include <module.h>
typedef struct _joystick {
bigtime_t timestamp;
uint32 horizontal;
uint32 vertical;
bool button1;
bool button2;
} joystick;
#define MAX_AXES 12
#define MAX_HATS 8
#define MAX_BUTTONS 32
#define MAX_STICKS 4
typedef struct _extended_joystick {
bigtime_t timestamp;
uint32 buttons;
int16 axes[MAX_AXES];
uint8 hats[MAX_HATS];
} _PACKED extended_joystick;
typedef struct _variable_joystick {
#ifdef __cplusplus
status_t initialize(uint32 axisCount, uint32 hatCount, uint32 buttonCount)
{
axis_count = axisCount;
hat_count = hatCount;
button_blocks = (buttonCount + 31) / 32;
data_size = sizeof(bigtime_t)
+ button_blocks * sizeof(uint32)
+ axis_count * sizeof(int16)
+ hat_count * sizeof(uint8);
data = (uint8 *)malloc(data_size);
if (data == NULL)
return B_NO_MEMORY;
timestamp = (bigtime_t *)data;
buttons = (uint32 *)×tamp[1];
axes = (int16 *)&buttons[button_blocks];
hats = (uint8 *)&axes[axis_count];
return B_OK;
}
status_t initialize_to_extended_joystick()
{
return initialize(MAX_AXES, MAX_HATS, MAX_BUTTONS);
}
#endif
uint32 axis_count;
uint32 hat_count;
uint32 button_blocks;
bigtime_t * timestamp;
uint32 * buttons;
int16 * axes;
uint8 * hats;
size_t data_size;
uint8 * data;
} variable_joystick;
#define MAX_CONFIG_SIZE 100
enum {
js_flag_force_feedback = 0x1,
js_flag_force_feedback_directional = 0x2,
js_flag_variable_size_reads = 0x4
};
typedef struct _joystick_module_info {
char module_name[64];
char device_name[64];
int16 num_axes;
int16 num_buttons;
int16 num_hats;
uint16 _reserved[7];
uint32 flags;
uint16 num_sticks;
int16 config_size;
char device_config[MAX_CONFIG_SIZE];
} joystick_module_info;
typedef struct _joystick_module {
module_info minfo;
int (*configure)(int port, joystick_module_info * info, size_t size, void ** out_cookie);
int (*read)(void * cookie, int port, extended_joystick * data, size_t size);
int (*crumble)(void * cookie, int port);
int (*force)(void * cookie, int port, bigtime_t duration, extended_joystick * force, size_t size);
int _reserved_;
} joystick_module;
enum {
B_JOYSTICK_GET_SPEED_COMPENSATION = B_JOYSTICK_DRIVER_BASE,
B_JOYSTICK_SET_SPEED_COMPENSATION,
B_JOYSTICK_GET_MAX_LATENCY,
B_JOYSTICK_SET_MAX_LATENCY,
B_JOYSTICK_SET_DEVICE_MODULE,
B_JOYSTICK_GET_DEVICE_MODULE,
B_JOYSTICK_SET_RAW_MODE
};
typedef struct _generic_gameport_module {
module_info minfo;
status_t (*create_device)(int port, void ** out_storage);
status_t (*delete_device)(void * storage);
status_t (*open_hook)(void * storage, uint32 flags, void ** out_cookie);
status_t (*close_hook)(void * cookie);
status_t (*free_hook)(void * cookie);
status_t (*control_hook)(void * cookie, uint32 op, void * data, size_t len);
status_t (*read_hook)(void * cookie, off_t pos, void * data, size_t * len);
status_t (*write_hook)(void * cookie, off_t pos, const void * data, size_t * len);
int _reserved_;
} generic_gameport_module;
#endif