mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-29 22:25:05 +00:00
(input/connect) Cleanups
This commit is contained in:
parent
33509d8600
commit
6433cdf2e7
@ -47,11 +47,11 @@ static void hidpad_ps3_send_control(struct hidpad_ps3_data* device)
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
|
||||
report_buffer[11] = 1 << ((device->slot % 4) + 1);
|
||||
report_buffer[4] = device->motors[1] >> 8;
|
||||
report_buffer[6] = device->motors[0] >> 8;
|
||||
|
||||
|
||||
device->send_control(device->connection, report_buffer, sizeof(report_buffer));
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ static void* hidpad_ps3_init(void *data, uint32_t slot, send_control_t ptr)
|
||||
#endif
|
||||
struct pad_connection* connection = (struct pad_connection*)data;
|
||||
struct hidpad_ps3_data* device = (struct hidpad_ps3_data*)
|
||||
calloc(1, sizeof(struct hidpad_ps3_data));
|
||||
calloc(1, sizeof(struct hidpad_ps3_data));
|
||||
|
||||
if (!device)
|
||||
return NULL;
|
||||
@ -77,7 +77,7 @@ static void* hidpad_ps3_init(void *data, uint32_t slot, send_control_t ptr)
|
||||
device->connection = connection;
|
||||
device->slot = slot;
|
||||
device->send_control = ptr;
|
||||
|
||||
|
||||
#ifdef IOS
|
||||
device->send_control(device->connection, magic_data, 6);
|
||||
#endif
|
||||
@ -91,7 +91,7 @@ static void* hidpad_ps3_init(void *data, uint32_t slot, send_control_t ptr)
|
||||
static void hidpad_ps3_deinit(void *data)
|
||||
{
|
||||
struct hidpad_ps3_data *device = (struct hidpad_ps3_data*)data;
|
||||
|
||||
|
||||
if (device)
|
||||
free(device);
|
||||
}
|
||||
@ -142,10 +142,10 @@ static void hidpad_ps3_packet_handler(void *data, uint8_t *packet, uint16_t size
|
||||
16 //< PS Button
|
||||
};
|
||||
struct hidpad_ps3_data *device = (struct hidpad_ps3_data*)data;
|
||||
|
||||
|
||||
if (!device)
|
||||
return;
|
||||
|
||||
|
||||
if (!device->have_led)
|
||||
{
|
||||
hidpad_ps3_send_control(device);
|
||||
@ -157,15 +157,15 @@ static void hidpad_ps3_packet_handler(void *data, uint8_t *packet, uint16_t size
|
||||
device->buttons = 0;
|
||||
|
||||
pressed_keys = device->data[3] | (device->data[4] << 8) |
|
||||
((device->data[5] & 1) << 16);
|
||||
((device->data[5] & 1) << 16);
|
||||
|
||||
for (i = 0; i < 17; i ++)
|
||||
device->buttons |= (pressed_keys & (1 << i)) ?
|
||||
(1 << button_mapping[i]) : 0;
|
||||
(1 << button_mapping[i]) : 0;
|
||||
}
|
||||
|
||||
static void hidpad_ps3_set_rumble(void *data,
|
||||
enum retro_rumble_effect effect, uint16_t strength)
|
||||
enum retro_rumble_effect effect, uint16_t strength)
|
||||
{
|
||||
struct hidpad_ps3_data *device = (struct hidpad_ps3_data*)data;
|
||||
unsigned idx = (effect == RETRO_RUMBLE_STRONG) ? 0 : 1;
|
||||
|
@ -23,54 +23,54 @@
|
||||
|
||||
enum connect_ps4_dpad_states
|
||||
{
|
||||
DPAD_UP = 0x0,
|
||||
DPAD_UP_RIGHT = 0x1,
|
||||
DPAD_RIGHT = 0x2,
|
||||
DPAD_RIGHT_DOWN = 0x3,
|
||||
DPAD_DOWN = 0x4,
|
||||
DPAD_DOWN_LEFT = 0x5,
|
||||
DPAD_LEFT = 0x6,
|
||||
DPAD_LEFT_UP = 0x7,
|
||||
DPAD_OFF = 0x8,
|
||||
DPAD_UP = 0x0,
|
||||
DPAD_UP_RIGHT = 0x1,
|
||||
DPAD_RIGHT = 0x2,
|
||||
DPAD_RIGHT_DOWN = 0x3,
|
||||
DPAD_DOWN = 0x4,
|
||||
DPAD_DOWN_LEFT = 0x5,
|
||||
DPAD_LEFT = 0x6,
|
||||
DPAD_LEFT_UP = 0x7,
|
||||
DPAD_OFF = 0x8,
|
||||
};
|
||||
|
||||
struct ps4buttons
|
||||
{
|
||||
uint8_t dpad : 4;
|
||||
uint8_t square : 1;
|
||||
uint8_t cross : 1;
|
||||
uint8_t circle : 1;
|
||||
uint8_t triangle : 1;
|
||||
|
||||
uint8_t l1 : 1;
|
||||
uint8_t r1 : 1;
|
||||
uint8_t l2 : 1;
|
||||
uint8_t r2 : 1;
|
||||
uint8_t share : 1;
|
||||
uint8_t options : 1;
|
||||
uint8_t l3 : 1;
|
||||
uint8_t r3 : 1;
|
||||
|
||||
uint8_t ps : 1;
|
||||
uint8_t touchpad : 1;
|
||||
uint8_t reportcounter : 6;
|
||||
uint8_t dpad : 4;
|
||||
uint8_t square : 1;
|
||||
uint8_t cross : 1;
|
||||
uint8_t circle : 1;
|
||||
uint8_t triangle : 1;
|
||||
|
||||
uint8_t l1 : 1;
|
||||
uint8_t r1 : 1;
|
||||
uint8_t l2 : 1;
|
||||
uint8_t r2 : 1;
|
||||
uint8_t share : 1;
|
||||
uint8_t options : 1;
|
||||
uint8_t l3 : 1;
|
||||
uint8_t r3 : 1;
|
||||
|
||||
uint8_t ps : 1;
|
||||
uint8_t touchpad : 1;
|
||||
uint8_t reportcounter : 6;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct ps4
|
||||
{
|
||||
uint8_t hatvalue[4];
|
||||
struct ps4buttons btn;
|
||||
uint8_t trigger[2];
|
||||
uint8_t hatvalue[4];
|
||||
struct ps4buttons btn;
|
||||
uint8_t trigger[2];
|
||||
};
|
||||
|
||||
struct hidpad_ps4_data
|
||||
{
|
||||
struct pad_connection* connection;
|
||||
send_control_t send_control;
|
||||
struct ps4 data;
|
||||
uint32_t slot;
|
||||
bool have_led;
|
||||
uint16_t motors[2];
|
||||
struct pad_connection* connection;
|
||||
send_control_t send_control;
|
||||
struct ps4 data;
|
||||
uint32_t slot;
|
||||
bool have_led;
|
||||
uint16_t motors[2];
|
||||
};
|
||||
|
||||
static void hidpad_ps4_send_control(struct hidpad_ps4_data* device)
|
||||
@ -79,14 +79,14 @@ static void hidpad_ps4_send_control(struct hidpad_ps4_data* device)
|
||||
static uint8_t report_buffer[79] = {
|
||||
0x52, 0x11, 0xB0, 0x00, 0x0F
|
||||
};
|
||||
|
||||
|
||||
#if 0
|
||||
uint8_t rgb[4][3] = { { 0xFF, 0, 0 }, { 0, 0xFF, 0 }, { 0, 0, 0xFF }, { 0xFF, 0xFF, 0xFF } };
|
||||
report_buffer[ 9] = rgb[(device->slot % 4)][0];
|
||||
report_buffer[10] = rgb[(device->slot % 4)][1];
|
||||
report_buffer[11] = rgb[(device->slot % 4)][2];
|
||||
#endif
|
||||
|
||||
|
||||
device->send_control(device->connection, report_buffer, sizeof(report_buffer));
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr)
|
||||
uint8_t magic_data[0x25];
|
||||
struct pad_connection* connection = (struct pad_connection*)data;
|
||||
struct hidpad_ps4_data* device = (struct hidpad_ps4_data*)
|
||||
calloc(1, sizeof(struct hidpad_ps4_data));
|
||||
calloc(1, sizeof(struct hidpad_ps4_data));
|
||||
|
||||
if (!device)
|
||||
return NULL;
|
||||
@ -109,7 +109,7 @@ static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr)
|
||||
device->connection = connection;
|
||||
device->slot = slot;
|
||||
device->send_control = ptr;
|
||||
|
||||
|
||||
#if 0
|
||||
/* TODO - unsure of this */
|
||||
/* This is needed to get full input packet over bluetooth. */
|
||||
@ -118,7 +118,7 @@ static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr)
|
||||
|
||||
/* Without this, the digital buttons won't be reported. */
|
||||
hidpad_ps4_send_control(device);
|
||||
|
||||
|
||||
(void)magic_data;
|
||||
|
||||
return device;
|
||||
@ -127,26 +127,26 @@ static void* hidpad_ps4_init(void *data, uint32_t slot, send_control_t ptr)
|
||||
static void hidpad_ps4_deinit(void *data)
|
||||
{
|
||||
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
|
||||
|
||||
|
||||
if (device)
|
||||
free(device);
|
||||
}
|
||||
|
||||
static bool hidpad_ps4_check_dpad(struct ps4 *rpt, unsigned id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_JOYPAD_UP:
|
||||
return (rpt->btn.dpad == DPAD_LEFT_UP) || (rpt->btn.dpad == DPAD_UP) || (rpt->btn.dpad == DPAD_UP_RIGHT);
|
||||
case RETRO_DEVICE_ID_JOYPAD_RIGHT:
|
||||
return (rpt->btn.dpad == DPAD_UP_RIGHT) || (rpt->btn.dpad == DPAD_RIGHT) || (rpt->btn.dpad == DPAD_RIGHT_DOWN);
|
||||
case RETRO_DEVICE_ID_JOYPAD_DOWN:
|
||||
return (rpt->btn.dpad == DPAD_RIGHT_DOWN) || (rpt->btn.dpad == DPAD_DOWN) || (rpt->btn.dpad == DPAD_DOWN_LEFT);
|
||||
case RETRO_DEVICE_ID_JOYPAD_LEFT:
|
||||
return (rpt->btn.dpad == DPAD_DOWN_LEFT) || (rpt->btn.dpad == DPAD_LEFT) || (rpt->btn.dpad == DPAD_LEFT_UP);
|
||||
}
|
||||
|
||||
return false;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_JOYPAD_UP:
|
||||
return (rpt->btn.dpad == DPAD_LEFT_UP) || (rpt->btn.dpad == DPAD_UP) || (rpt->btn.dpad == DPAD_UP_RIGHT);
|
||||
case RETRO_DEVICE_ID_JOYPAD_RIGHT:
|
||||
return (rpt->btn.dpad == DPAD_UP_RIGHT) || (rpt->btn.dpad == DPAD_RIGHT) || (rpt->btn.dpad == DPAD_RIGHT_DOWN);
|
||||
case RETRO_DEVICE_ID_JOYPAD_DOWN:
|
||||
return (rpt->btn.dpad == DPAD_RIGHT_DOWN) || (rpt->btn.dpad == DPAD_DOWN) || (rpt->btn.dpad == DPAD_DOWN_LEFT);
|
||||
case RETRO_DEVICE_ID_JOYPAD_LEFT:
|
||||
return (rpt->btn.dpad == DPAD_DOWN_LEFT) || (rpt->btn.dpad == DPAD_LEFT) || (rpt->btn.dpad == DPAD_LEFT_UP);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint64_t hidpad_ps4_get_buttons(void *data)
|
||||
@ -154,38 +154,29 @@ static uint64_t hidpad_ps4_get_buttons(void *data)
|
||||
uint64_t buttonstate = 0;
|
||||
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
|
||||
struct ps4 *rpt = device ? (struct ps4*)&device->data : NULL;
|
||||
|
||||
|
||||
if (!device || !rpt)
|
||||
return 0;
|
||||
|
||||
//RARCH_LOG("Left stick X: %d\n", rpt_ptr[0]);
|
||||
//RARCH_LOG("Left stick Y: %d\n", rpt_ptr[1]);
|
||||
//RARCH_LOG("Right stick X: %d\n", rpt_ptr[2]);
|
||||
//RARCH_LOG("Right stick Y: %d\n", rpt_ptr[3]);
|
||||
//RARCH_LOG("Digital buttons: %d\n", rpt_ptr[4]);
|
||||
//RARCH_LOG("Start/share: %d\n", rpt_ptr[5]);
|
||||
//RARCH_LOG("Test: %d\n", rpt_ptr[6] & 0x01);
|
||||
//RARCH_LOG("L2 button: %d\n", rpt_ptr[7]);
|
||||
//RARCH_LOG("R2 button: %d\n", rpt_ptr[8]);
|
||||
buttonstate |= (rpt->btn.r3 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R3) : 0);
|
||||
buttonstate |= (rpt->btn.l3 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L3) : 0);
|
||||
buttonstate |= (rpt->btn.options ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0);
|
||||
buttonstate |= (rpt->btn.share ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0);
|
||||
buttonstate |= (rpt->btn.r2 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R2) : 0);
|
||||
buttonstate |= (rpt->btn.l2 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L2) : 0);
|
||||
buttonstate |= (rpt->btn.r1 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0);
|
||||
buttonstate |= (rpt->btn.l1 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0);
|
||||
|
||||
buttonstate |= (rpt->btn.triangle ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0);
|
||||
buttonstate |= (rpt->btn.circle ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0);
|
||||
buttonstate |= (rpt->btn.cross ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0);
|
||||
buttonstate |= (rpt->btn.square ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0);
|
||||
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_LEFT)) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0);
|
||||
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_DOWN)) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0);
|
||||
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_RIGHT)) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0);
|
||||
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_UP)) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0);
|
||||
buttonstate |= (rpt->btn.ps ? (1ULL << RARCH_MENU_TOGGLE) : 0);
|
||||
|
||||
|
||||
buttonstate |= (rpt->btn.r3 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R3) : 0);
|
||||
buttonstate |= (rpt->btn.l3 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L3) : 0);
|
||||
buttonstate |= (rpt->btn.options ? (1ULL << RETRO_DEVICE_ID_JOYPAD_START) : 0);
|
||||
buttonstate |= (rpt->btn.share ? (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT) : 0);
|
||||
buttonstate |= (rpt->btn.r2 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R2) : 0);
|
||||
buttonstate |= (rpt->btn.l2 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L2) : 0);
|
||||
buttonstate |= (rpt->btn.r1 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_R) : 0);
|
||||
buttonstate |= (rpt->btn.l1 ? (1ULL << RETRO_DEVICE_ID_JOYPAD_L) : 0);
|
||||
|
||||
buttonstate |= (rpt->btn.triangle ? (1ULL << RETRO_DEVICE_ID_JOYPAD_X) : 0);
|
||||
buttonstate |= (rpt->btn.circle ? (1ULL << RETRO_DEVICE_ID_JOYPAD_A) : 0);
|
||||
buttonstate |= (rpt->btn.cross ? (1ULL << RETRO_DEVICE_ID_JOYPAD_B) : 0);
|
||||
buttonstate |= (rpt->btn.square ? (1ULL << RETRO_DEVICE_ID_JOYPAD_Y) : 0);
|
||||
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_LEFT)) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0);
|
||||
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_DOWN)) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0);
|
||||
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_RIGHT)) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0);
|
||||
buttonstate |= ((hidpad_ps4_check_dpad(rpt, RETRO_DEVICE_ID_JOYPAD_UP)) ? (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0);
|
||||
buttonstate |= (rpt->btn.ps ? (1ULL << RARCH_MENU_TOGGLE) : 0);
|
||||
|
||||
return buttonstate;
|
||||
}
|
||||
|
||||
@ -193,7 +184,7 @@ static int16_t hidpad_ps4_get_axis(void *data, unsigned axis)
|
||||
{
|
||||
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
|
||||
struct ps4 *rpt = device ? (struct ps4*)&device->data : NULL;
|
||||
|
||||
|
||||
if (device && (axis < 4))
|
||||
{
|
||||
int val = rpt ? rpt->hatvalue[axis] : 0;
|
||||
@ -207,10 +198,10 @@ static int16_t hidpad_ps4_get_axis(void *data, unsigned axis)
|
||||
static void hidpad_ps4_packet_handler(void *data, uint8_t *packet, uint16_t size)
|
||||
{
|
||||
struct hidpad_ps4_data *device = (struct hidpad_ps4_data*)data;
|
||||
|
||||
|
||||
if (!device)
|
||||
return;
|
||||
|
||||
|
||||
#if 0
|
||||
if (!device->have_led)
|
||||
{
|
||||
@ -219,11 +210,11 @@ static void hidpad_ps4_packet_handler(void *data, uint8_t *packet, uint16_t size
|
||||
}
|
||||
#endif
|
||||
|
||||
memcpy(&device->data, &packet[2], sizeof(struct ps4));
|
||||
memcpy(&device->data, &packet[2], sizeof(struct ps4));
|
||||
}
|
||||
|
||||
static void hidpad_ps4_set_rumble(void *data,
|
||||
enum retro_rumble_effect effect, uint16_t strength)
|
||||
enum retro_rumble_effect effect, uint16_t strength)
|
||||
{
|
||||
/* TODO */
|
||||
#if 0
|
||||
|
@ -169,35 +169,33 @@ typedef struct wiimote_t
|
||||
#define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
|
||||
#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
|
||||
|
||||
#ifndef NO_BAKED_IN_WIIMOTE
|
||||
/*
|
||||
* Send a packet to the wiimote.
|
||||
*
|
||||
* This function should replace any write()s directly to the wiimote device.
|
||||
*/
|
||||
|
||||
static int wiimote_send(struct wiimote_t* wm,
|
||||
uint8_t report_type, uint8_t* msg, int len)
|
||||
{
|
||||
int x = 2;
|
||||
uint8_t buf[32];
|
||||
|
||||
(void)x;
|
||||
|
||||
buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
|
||||
buf[1] = report_type;
|
||||
|
||||
memcpy(buf+2, msg, len);
|
||||
|
||||
int x = 2;
|
||||
uint8_t buf[32];
|
||||
|
||||
(void)x;
|
||||
|
||||
buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
|
||||
buf[1] = report_type;
|
||||
|
||||
memcpy(buf+2, msg, len);
|
||||
|
||||
#ifdef WIIMOTE_DBG
|
||||
printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
|
||||
for (; x < len+2; ++x)
|
||||
printf("%.2x ", buf[x]);
|
||||
printf("\n");
|
||||
printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
|
||||
for (; x < len+2; ++x)
|
||||
printf("%.2x ", buf[x]);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
wm->send_control(wm->connection, buf, len + 2);
|
||||
return 1;
|
||||
|
||||
wm->send_control(wm->connection, buf, len + 2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -273,9 +271,9 @@ static void wiimote_pressed_buttons(struct wiimote_t* wm, uint8_t* msg)
|
||||
static int classic_ctrl_handshake(struct wiimote_t* wm,
|
||||
struct classic_ctrl_t* cc, uint8_t* data, unsigned short len)
|
||||
{
|
||||
memset(cc, 0, sizeof(*cc));
|
||||
wm->exp.type = EXP_CLASSIC;
|
||||
return 1;
|
||||
memset(cc, 0, sizeof(*cc));
|
||||
wm->exp.type = EXP_CLASSIC;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static float normalize_and_interpolate(float min, float max, float t)
|
||||
@ -287,38 +285,38 @@ static float normalize_and_interpolate(float min, float max, float t)
|
||||
|
||||
static void process_axis(struct axis_t* axis, uint8_t raw)
|
||||
{
|
||||
if (!axis->has_center)
|
||||
{
|
||||
axis->has_center = true;
|
||||
axis->min = raw - 2;
|
||||
axis->center = raw;
|
||||
axis->max = raw + 2;
|
||||
}
|
||||
|
||||
if (raw < axis->min)
|
||||
axis->min = raw;
|
||||
if (raw > axis->max)
|
||||
axis->max = raw;
|
||||
axis->raw_value = raw;
|
||||
|
||||
if (raw < axis->center)
|
||||
axis->value = -normalize_and_interpolate(
|
||||
axis->center, axis->min, raw);
|
||||
else if (raw > axis->center)
|
||||
axis->value = normalize_and_interpolate(
|
||||
axis->center, axis->max, raw);
|
||||
else
|
||||
axis->value = 0;
|
||||
if (!axis->has_center)
|
||||
{
|
||||
axis->has_center = true;
|
||||
axis->min = raw - 2;
|
||||
axis->center = raw;
|
||||
axis->max = raw + 2;
|
||||
}
|
||||
|
||||
if (raw < axis->min)
|
||||
axis->min = raw;
|
||||
if (raw > axis->max)
|
||||
axis->max = raw;
|
||||
axis->raw_value = raw;
|
||||
|
||||
if (raw < axis->center)
|
||||
axis->value = -normalize_and_interpolate(
|
||||
axis->center, axis->min, raw);
|
||||
else if (raw > axis->center)
|
||||
axis->value = normalize_and_interpolate(
|
||||
axis->center, axis->max, raw);
|
||||
else
|
||||
axis->value = 0;
|
||||
}
|
||||
|
||||
static void classic_ctrl_event(struct classic_ctrl_t* cc, uint8_t* msg)
|
||||
{
|
||||
cc->btns = ~BIG_ENDIAN_SHORT(*(short*)(msg + 4)) & CLASSIC_CTRL_BUTTON_ALL;
|
||||
process_axis(&cc->ljs.x, (msg[0] & 0x3F));
|
||||
process_axis(&cc->ljs.y, (msg[1] & 0x3F));
|
||||
process_axis(&cc->rjs.x, ((msg[0] & 0xC0) >> 3) |
|
||||
((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7));
|
||||
process_axis(&cc->rjs.y, (msg[2] & 0x1F));
|
||||
cc->btns = ~BIG_ENDIAN_SHORT(*(short*)(msg + 4)) & CLASSIC_CTRL_BUTTON_ALL;
|
||||
process_axis(&cc->ljs.x, (msg[0] & 0x3F));
|
||||
process_axis(&cc->ljs.y, (msg[1] & 0x3F));
|
||||
process_axis(&cc->rjs.x, ((msg[0] & 0xC0) >> 3) |
|
||||
((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7));
|
||||
process_axis(&cc->rjs.y, (msg[2] & 0x1F));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -341,37 +339,37 @@ static void wiimote_handle_expansion(struct wiimote_t* wm, uint8_t* msg)
|
||||
* Write data to the wiimote.
|
||||
*/
|
||||
static int wiimote_write_data(struct wiimote_t* wm,
|
||||
unsigned int addr, uint8_t* data, uint8_t len)
|
||||
unsigned int addr, uint8_t* data, uint8_t len)
|
||||
{
|
||||
int i = 0;
|
||||
uint8_t buf[21] = {0}; /* the payload is always 23 */
|
||||
|
||||
(void)i;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
if (!data || !len)
|
||||
return 0;
|
||||
|
||||
int i = 0;
|
||||
uint8_t buf[21] = {0}; /* the payload is always 23 */
|
||||
|
||||
(void)i;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
if (!data || !len)
|
||||
return 0;
|
||||
|
||||
#ifdef WIIMOTE_DBG
|
||||
printf("Writing %i bytes to memory location 0x%x...\n", len, addr);
|
||||
printf("Write data is: ");
|
||||
for (; i < len; ++i)
|
||||
printf("%x ", data[i]);
|
||||
printf("\n");
|
||||
printf("Writing %i bytes to memory location 0x%x...\n", len, addr);
|
||||
printf("Write data is: ");
|
||||
for (; i < len; ++i)
|
||||
printf("%x ", data[i]);
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
/* the offset is in big endian */
|
||||
*(int*)(buf) = BIG_ENDIAN_LONG(addr);
|
||||
|
||||
/* length */
|
||||
*(uint8_t*)(buf + 4) = len;
|
||||
|
||||
/* data */
|
||||
memcpy(buf + 5, data, len);
|
||||
|
||||
wiimote_send(wm, WM_CMD_WRITE_DATA, buf, 21);
|
||||
return 1;
|
||||
|
||||
/* the offset is in big endian */
|
||||
*(int*)(buf) = BIG_ENDIAN_LONG(addr);
|
||||
|
||||
/* length */
|
||||
*(uint8_t*)(buf + 4) = len;
|
||||
|
||||
/* data */
|
||||
memcpy(buf + 5, data, len);
|
||||
|
||||
wiimote_send(wm, WM_CMD_WRITE_DATA, buf, 21);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -386,27 +384,27 @@ static int wiimote_write_data(struct wiimote_t* wm,
|
||||
*/
|
||||
|
||||
static int wiimote_read_data(struct wiimote_t* wm, unsigned int addr,
|
||||
unsigned short len)
|
||||
unsigned short len)
|
||||
{
|
||||
uint8_t buf[6];
|
||||
|
||||
/* No puden ser mas de 16 lo leido o vendra en trozos! */
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm) || !len)
|
||||
return 0;
|
||||
|
||||
/* the offset is in big endian */
|
||||
*(int*)(buf) = BIG_ENDIAN_LONG(addr);
|
||||
|
||||
/* the length is in big endian */
|
||||
*(short*)(buf + 4) = BIG_ENDIAN_SHORT(len);
|
||||
|
||||
uint8_t buf[6];
|
||||
|
||||
/* No puden ser mas de 16 lo leido o vendra en trozos! */
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm) || !len)
|
||||
return 0;
|
||||
|
||||
/* the offset is in big endian */
|
||||
*(int*)(buf) = BIG_ENDIAN_LONG(addr);
|
||||
|
||||
/* the length is in big endian */
|
||||
*(short*)(buf + 4) = BIG_ENDIAN_SHORT(len);
|
||||
|
||||
#ifdef WIIMOTE_DBG
|
||||
printf("Request read at address: 0x%x length: %i", addr, len);
|
||||
printf("Request read at address: 0x%x length: %i", addr, len);
|
||||
#endif
|
||||
wiimote_send(wm, WM_CMD_READ_DATA, buf, 6);
|
||||
|
||||
return 1;
|
||||
wiimote_send(wm, WM_CMD_READ_DATA, buf, 6);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -606,11 +604,6 @@ static int wiimote_handshake(struct wiimote_t* wm, uint8_t event, uint8_t* data
|
||||
} while(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
static void* hidpad_wii_init(void *data, uint32_t slot,
|
||||
send_control_t ptr)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user