mirror of
https://github.com/yawut/SDL.git
synced 2026-08-20 07:44:03 -05:00
wiiu/joystick: Updates for the new joystick interfaces
This commit is contained in:
@@ -67,6 +67,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
|
||||
#ifdef SDL_JOYSTICK_HAIKU
|
||||
&SDL_HAIKU_JoystickDriver,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_WIIU
|
||||
&SDL_WIIU_JoystickDriver,
|
||||
#endif
|
||||
#ifdef SDL_JOYSTICK_USBHID /* !!! FIXME: "USBHID" is a generic name, and doubly-confusing with HIDAPI next to it. This is the *BSD interface, rename this. */
|
||||
&SDL_BSD_JoystickDriver,
|
||||
#endif
|
||||
|
||||
@@ -151,6 +151,7 @@ extern SDL_JoystickDriver SDL_HIDAPI_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_IOS_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
|
||||
extern SDL_JoystickDriver SDL_WIIU_JoystickDriver;
|
||||
|
||||
#endif /* SDL_sysjoystick_h_ */
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 2018 Roberto Van Eeden <r.r.qwertyuiop.r.r@gmail.com>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <vpad/input.h>
|
||||
#include <coreinit/debug.h>
|
||||
|
||||
#include "SDL_joystick.h"
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "../SDL_joystick_c.h"
|
||||
#include "../../events/SDL_touch_c.h"
|
||||
@@ -35,7 +36,8 @@
|
||||
|
||||
#define JOYSTICK_COUNT 1
|
||||
|
||||
static VPADButtons vpad_button_map[] = {
|
||||
static VPADButtons vpad_button_map[] =
|
||||
{
|
||||
VPAD_BUTTON_A, VPAD_BUTTON_B, VPAD_BUTTON_X, VPAD_BUTTON_Y,
|
||||
VPAD_BUTTON_STICK_L, VPAD_BUTTON_STICK_R,
|
||||
VPAD_BUTTON_L, VPAD_BUTTON_R,
|
||||
@@ -47,40 +49,53 @@ static VPADButtons vpad_button_map[] = {
|
||||
};
|
||||
|
||||
/* Function to scan the system for joysticks.
|
||||
* It should return the number of available joysticks,
|
||||
* or -1 on an unrecoverable fatal error.
|
||||
* Joystick 0 should be the system default joystick.
|
||||
* This function should return 0, or -1 on an unrecoverable error.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickInit(void)
|
||||
static int WIIU_JoystickInit(void)
|
||||
{
|
||||
return JOYSTICK_COUNT;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_NumJoysticks(void)
|
||||
/* Function to return the number of joystick devices plugged in right now */
|
||||
static int WIIU_JoystickGetCount(void)
|
||||
{
|
||||
return JOYSTICK_COUNT;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_JoystickDetect(void)
|
||||
/* Function to cause any queued joystick insertions to be processed */
|
||||
static void WIIU_JoystickDetect(void)
|
||||
{
|
||||
}
|
||||
|
||||
/* Function to get the device-dependent name of a joystick */
|
||||
const char *
|
||||
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
|
||||
static const char *WIIU_JoystickGetDeviceName(int device_index)
|
||||
{
|
||||
// Gamepad
|
||||
if (device_index == 0) {
|
||||
/* Gamepad */
|
||||
if (device_index == 0)
|
||||
return "WiiU Gamepad";
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
/* Function to perform the mapping from device index to the instance id for this index */
|
||||
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
|
||||
/* Function to get the player index of a joystick */
|
||||
static int WIIU_JoystickGetDevicePlayerIndex(int device_index)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Function to return the stable GUID for a plugged in device */
|
||||
static SDL_JoystickGUID WIIU_JoystickGetDeviceGUID(int device_index)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = WIIU_JoystickGetDeviceName(device_index);
|
||||
SDL_zero(guid);
|
||||
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
|
||||
return guid;
|
||||
}
|
||||
|
||||
/* Function to get the current instance id of the joystick located at device_index */
|
||||
static SDL_JoystickID WIIU_JoystickGetDeviceInstanceID(int device_index)
|
||||
{
|
||||
return device_index;
|
||||
}
|
||||
@@ -90,10 +105,9 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
|
||||
This should fill the nbuttons and naxes fields of the joystick structure.
|
||||
It returns 0, or -1 if there is an error.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
static int WIIU_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
{
|
||||
// Gamepad
|
||||
/* Gamepad */
|
||||
if (device_index == 0) {
|
||||
SDL_AddTouch(0, "WiiU Gamepad Touchscreen");
|
||||
joystick->nbuttons = sizeof(vpad_button_map) / sizeof(VPADButtons);
|
||||
@@ -106,14 +120,11 @@ SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Function to determine if this joystick is attached to the system right now */
|
||||
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
|
||||
/* Rumble functionality */
|
||||
static int WIIU_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
|
||||
{
|
||||
// Gamepad
|
||||
if (joystick->instance_id == 0) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
return SDL_FALSE;
|
||||
/* TODO */
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
/* Function to update the state of a joystick - called as a device poll.
|
||||
@@ -121,12 +132,12 @@ SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
|
||||
* but instead should call SDL_PrivateJoystick*() to deliver events
|
||||
* and update joystick device state.
|
||||
*/
|
||||
void
|
||||
SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
|
||||
static void WIIU_JoystickUpdate(SDL_Joystick *joystick)
|
||||
{
|
||||
// Gamepad
|
||||
if (joystick->instance_id == 0)
|
||||
{
|
||||
/* Gamepad */
|
||||
if (joystick->instance_id == 0) {
|
||||
int16_t x1, y1, x2, y2;
|
||||
|
||||
static uint16_t last_touch_x = 0;
|
||||
static uint16_t last_touch_y = 0;
|
||||
static uint16_t last_touched = 0;
|
||||
@@ -143,35 +154,35 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
|
||||
if (error != VPAD_READ_SUCCESS)
|
||||
return;
|
||||
|
||||
// touchscreen
|
||||
/* touchscreen */
|
||||
VPADGetTPCalibratedPoint(VPAD_CHAN_0, &tpdata, &vpad.tpNormal);
|
||||
if (tpdata.touched) {
|
||||
// Send an initial touch
|
||||
/* Send an initial touch */
|
||||
SDL_SendTouch(0, 0, SDL_TRUE,
|
||||
(float) tpdata.x / 1280.0f,
|
||||
(float) tpdata.y / 720.0f, 1);
|
||||
|
||||
// Always send the motion
|
||||
/* Always send the motion */
|
||||
SDL_SendTouchMotion(0, 0,
|
||||
(float) tpdata.x / 1280.0f,
|
||||
(float) tpdata.y / 720.0f, 1);
|
||||
|
||||
// Update old values
|
||||
/* Update old values */
|
||||
last_touch_x = tpdata.x;
|
||||
last_touch_y = tpdata.y;
|
||||
last_touched = 1;
|
||||
} else if (last_touched) {
|
||||
// Finger released from screen
|
||||
/* Finger released from screen */
|
||||
SDL_SendTouch(0, 0, SDL_FALSE,
|
||||
(float) last_touch_x / 1280.0f,
|
||||
(float) last_touch_y / 720.0f, 1);
|
||||
}
|
||||
|
||||
// axys
|
||||
int16_t x1 = (int16_t) ((vpad.leftStick.x) * 0x7ff0);
|
||||
int16_t y1 = (int16_t) -((vpad.leftStick.y) * 0x7ff0);
|
||||
int16_t x2 = (int16_t) ((vpad.rightStick.x) * 0x7ff0);
|
||||
int16_t y2 = (int16_t) -((vpad.rightStick.y) * 0x7ff0);
|
||||
/* axys */
|
||||
x1 = (int16_t) ((vpad.leftStick.x) * 0x7ff0);
|
||||
y1 = (int16_t) -((vpad.leftStick.y) * 0x7ff0);
|
||||
x2 = (int16_t) ((vpad.rightStick.x) * 0x7ff0);
|
||||
y2 = (int16_t) -((vpad.rightStick.y) * 0x7ff0);
|
||||
|
||||
if(x1 != x1_old) {
|
||||
SDL_PrivateJoystickAxis(joystick, 0, x1);
|
||||
@@ -190,7 +201,7 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
|
||||
y2_old = y2;
|
||||
}
|
||||
|
||||
// buttons
|
||||
/* buttons */
|
||||
for(int i = 0; i < joystick->nbuttons; i++)
|
||||
if (vpad.trigger & vpad_button_map[i])
|
||||
SDL_PrivateJoystickButton(joystick, (Uint8)i, SDL_PRESSED);
|
||||
@@ -201,35 +212,29 @@ SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
|
||||
}
|
||||
|
||||
/* Function to close a joystick after use */
|
||||
void
|
||||
SDL_SYS_JoystickClose(SDL_Joystick *joystick)
|
||||
static void WIIU_JoystickClose(SDL_Joystick *joystick)
|
||||
{
|
||||
}
|
||||
|
||||
/* Function to perform any system-specific joystick related cleanup */
|
||||
void
|
||||
SDL_SYS_JoystickQuit(void)
|
||||
static void WIIU_JoystickQuit(void)
|
||||
{
|
||||
}
|
||||
|
||||
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)
|
||||
SDL_JoystickDriver SDL_WIIU_JoystickDriver =
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = SDL_SYS_JoystickNameForDeviceIndex(device_index);
|
||||
SDL_zero(guid);
|
||||
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
|
||||
return guid;
|
||||
}
|
||||
|
||||
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = joystick->name;
|
||||
SDL_zero(guid);
|
||||
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
|
||||
return guid;
|
||||
}
|
||||
WIIU_JoystickInit,
|
||||
WIIU_JoystickGetCount,
|
||||
WIIU_JoystickDetect,
|
||||
WIIU_JoystickGetDeviceName,
|
||||
WIIU_JoystickGetDevicePlayerIndex,
|
||||
WIIU_JoystickGetDeviceGUID,
|
||||
WIIU_JoystickGetDeviceInstanceID,
|
||||
WIIU_JoystickOpen,
|
||||
WIIU_JoystickRumble,
|
||||
WIIU_JoystickUpdate,
|
||||
WIIU_JoystickClose,
|
||||
WIIU_JoystickQuit,
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user