apple_pad_interface - use void *

This commit is contained in:
twinaphex 2014-09-28 15:06:28 +02:00
parent 747badfa6c
commit afd090edd9
5 changed files with 52 additions and 36 deletions

View File

@ -48,17 +48,15 @@ struct apple_pad_connection;
struct apple_pad_interface
{
void* (*connect)(struct apple_pad_connection* connection, uint32_t slot);
void* (*connect)(void *data, uint32_t slot);
void (*disconnect)(void* device);
void (*packet_handler)(void* device, uint8_t *packet, uint16_t size);
void (*set_rumble)(void* device, enum retro_rumble_effect effect,
uint16_t strength);
};
// Joypad data
int32_t apple_joypad_connect(const char* name,
struct apple_pad_connection* connection);
/* Joypad data */
int32_t apple_joypad_connect(const char* name, void *data);
int32_t apple_joypad_connect_gcapi(void);
@ -72,7 +70,7 @@ bool apple_joypad_has_interface(uint32_t slot);
/* This is implemented in the platform-specific
* portions of the input code */
void apple_joypad_send_hid_control(struct apple_pad_connection* connection,
void apple_joypad_send_hid_control(void *connect_data,
uint8_t* data, size_t size);
/* Input data for the main thread and the game thread */

View File

@ -54,11 +54,11 @@ static int32_t find_empty_slot(void)
return -1;
}
int32_t apple_joypad_connect(const char* name,
struct apple_pad_connection* connection)
int32_t apple_joypad_connect(const char* name, void *data)
{
int32_t slot;
slot = find_empty_slot();
struct apple_pad_connection* connection =
(struct apple_pad_connection*)data;
int32_t slot = find_empty_slot();
if (slot >= 0 && slot < MAX_PLAYERS)
{

View File

@ -51,11 +51,12 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device)
apple_pad_send_control(device->connection, report_buffer, sizeof(report_buffer));
}
static void* hidpad_ps3_connect(struct apple_pad_connection* connection, uint32_t slot)
static void* hidpad_ps3_connect(void *data, uint32_t slot)
{
struct apple_pad_connection* connection = (struct apple_pad_connection*)data;
struct hidpad_ps3_data* device = (struct hidpad_ps3_data*)calloc(1, sizeof(struct hidpad_ps3_data));
if (!device)
if (!device || !connection)
return NULL;
device->connection = connection;

View File

@ -20,11 +20,14 @@
#include "../boolean.h"
#include "wiimote.h"
static void* hidpad_wii_connect(struct apple_pad_connection* connection, uint32_t slot)
static void* hidpad_wii_connect(void *data, uint32_t slot)
{
struct wiimote_t* device = (struct wiimote_t*)calloc(1, sizeof(struct wiimote_t));
struct apple_pad_connection *connection =
(struct apple_pad_connection*)data;
struct wiimote_t *device = (struct wiimote_t*)
calloc(1, sizeof(struct wiimote_t));
if (!device)
if (!device || !connection)
return NULL;
device->connection = connection;
@ -37,15 +40,19 @@ static void* hidpad_wii_connect(struct apple_pad_connection* connection, uint32_
return device;
}
static void hidpad_wii_disconnect(struct wiimote_t* device)
static void hidpad_wii_disconnect(void *data)
{
struct wiimote_t* device = (struct wiimote_t*)data;
if (device)
free(device);
}
static int16_t hidpad_wii_get_axis(struct wiimote_t* device, unsigned axis)
static int16_t hidpad_wii_get_axis(void *data, unsigned axis)
{
if (device->exp.type == EXP_CLASSIC)
struct wiimote_t* device = (struct wiimote_t*)data;
if (device && device->exp.type == EXP_CLASSIC)
{
switch (axis)
{
@ -57,20 +64,22 @@ static int16_t hidpad_wii_get_axis(struct wiimote_t* device, unsigned axis)
return device->exp.cc.classic.rjs.x.value * 0x7FFF;
case 3:
return device->exp.cc.classic.rjs.y.value * 0x7FFF;
default:
return 0;
}
}
return 0;
}
static void hidpad_wii_packet_handler(struct wiimote_t* device,
static void hidpad_wii_packet_handler(void *data,
uint8_t *packet, uint16_t size)
{
int i;
struct wiimote_t* device = (struct wiimote_t*)data;
byte* msg = packet + 2;
if (!device)
return;
switch (packet[1])
{
case WM_RPT_BTN:
@ -93,13 +102,19 @@ static void hidpad_wii_packet_handler(struct wiimote_t* device,
g_current_input_data.pad_buttons[device->unid] = device->btns |
(device->exp.cc.classic.btns << 16);
for (i = 0; i < 4; i++)
g_current_input_data.pad_axis[device->unid][i] = hidpad_wii_get_axis(device, i);
g_current_input_data.pad_axis[device->unid][i] =
hidpad_wii_get_axis(device, i);
}
static void hidpad_wii_set_rumble(struct wiimote_t* device, enum retro_rumble_effect effect, uint16_t strength)
static void hidpad_wii_set_rumble(void *data,
enum retro_rumble_effect effect, uint16_t strength)
{
// TODO
/* TODO */
(void)data;
(void)effect;
(void)strength;
}
struct apple_pad_interface apple_pad_wii =

View File

@ -27,11 +27,15 @@ struct apple_pad_connection
static IOHIDManagerRef g_hid_manager;
static void apple_pad_send_control(struct apple_pad_connection* connection,
uint8_t* data, size_t size)
static void apple_pad_send_control(void *connect_data,
uint8_t* data, size_t size)
{
IOHIDDeviceSetReport(connection->device_handle,
kIOHIDReportTypeOutput, 0x01, data + 1, size - 1);
struct apple_pad_connection* connection =
(struct apple_pad_connection*)connect_data;
if (connection)
IOHIDDeviceSetReport(connection->device_handle,
kIOHIDReportTypeOutput, 0x01, data + 1, size - 1);
}
/* NOTE: I pieced this together through trial and error,
@ -40,18 +44,16 @@ static void apple_pad_send_control(struct apple_pad_connection* connection,
static void hid_device_input_callback(void* context, IOReturn result,
void* sender, IOHIDValueRef value)
{
IOHIDElementRef element;
uint32_t type, page, use;
struct apple_pad_connection* connection = (struct apple_pad_connection*)
context;
element = IOHIDValueGetElement(value);
type = IOHIDElementGetType(element);
page = IOHIDElementGetUsagePage(element);
use = IOHIDElementGetUsage(element);
IOHIDElementRef element = IOHIDValueGetElement(value);
uint32_t type = IOHIDElementGetType(element);
uint32_t page = IOHIDElementGetUsagePage(element);
uint32_t use = IOHIDElementGetUsage(element);
/* Joystick handler.
* TODO: Can GamePad work the same? */
if ((type == kIOHIDElementTypeInput_Button)
&& page == kHIDPage_Button)
{
@ -124,7 +126,7 @@ static void hid_device_report(void* context, IOReturn result, void *sender,
static void hid_manager_device_attached(void* context, IOReturn result,
void* sender, IOHIDDeviceRef device)
{
char device_name[1024];
char device_name[PATH_MAX];
CFStringRef device_name_ref;
struct apple_pad_connection* connection = (struct apple_pad_connection*)
calloc(1, sizeof(*connection));