hid: Add hidJoystickRead

This commit is contained in:
shinyquagsire23 2018-01-19 20:43:59 -07:00
parent 8ae150d110
commit 7888f316c2
2 changed files with 36 additions and 4 deletions

View File

@ -275,6 +275,14 @@ typedef enum
KEY_RIGHT = KEY_DRIGHT | KEY_LSTICK_RIGHT | KEY_RSTICK_RIGHT, ///< D-Pad Right or Sticks Right KEY_RIGHT = KEY_DRIGHT | KEY_LSTICK_RIGHT | KEY_RSTICK_RIGHT, ///< D-Pad Right or Sticks Right
} HidControllerKeys; } HidControllerKeys;
typedef enum
{
JOYSTICK_LEFT = 0,
JOYSTICK_RIGHT = 1,
JOYSTICK_NUM_STICKS = 2,
} HidControllerJoystick;
typedef enum typedef enum
{ {
CONTROLLER_STATE_CONNECTED = BIT(0), CONTROLLER_STATE_CONNECTED = BIT(0),
@ -305,6 +313,15 @@ typedef struct touchPosition
u32 angle; u32 angle;
} touchPosition; } touchPosition;
typedef struct circlePosition
{
s32 dx;
s32 dy;
} circlePosition;
#define JOYSTICK_MAX (0x8000)
#define JOYSTICK_MIN (-0x8000)
// End enums and output structs // End enums and output structs
// Begin HidTouchScreen // Begin HidTouchScreen
@ -463,10 +480,7 @@ typedef struct HidControllerInputEntry
u64 timestamp; u64 timestamp;
u64 timestamp_2; u64 timestamp_2;
u64 buttons; u64 buttons;
u32 joystickLeftX; circlePosition joysticks[JOYSTICK_NUM_STICKS];
u32 joystickLeftY;
u32 joystickRightX;
u32 joystickRightY;
u64 connectionState; u64 connectionState;
} HidControllerInputEntry; } HidControllerInputEntry;
static_assert(sizeof(HidControllerInputEntry) == 0x30, "Hid controller input entry structure has incorrect size"); static_assert(sizeof(HidControllerInputEntry) == 0x30, "Hid controller input entry structure has incorrect size");
@ -540,3 +554,5 @@ bool hidKeyboardUp(HidKeyboardScancode key);
u32 hidTouchCount(void); u32 hidTouchCount(void);
void hidTouchRead(touchPosition *pos, u32 point_id); void hidTouchRead(touchPosition *pos, u32 point_id);
void hidJoystickRead(circlePosition *pos, HidControllerID id, HidControllerJoystick stick);

View File

@ -327,6 +327,22 @@ void hidTouchRead(touchPosition *pos, u32 point_id) {
} }
} }
void hidJoystickRead(circlePosition *pos, HidControllerID id, HidControllerJoystick stick) {
if (id == CONTROLLER_P1_AUTO) return hidJoystickRead(pos, g_controllerP1AutoID, stick);
if (pos) {
if (id < 0 || id > 9 || stick >= JOYSTICK_NUM_STICKS) {
memset(pos, 0, sizeof(touchPosition));
return;
}
rwlockReadLock(&g_hidLock);
pos->dx = g_controllerEntries[id].joysticks[stick].dx;
pos->dy = g_controllerEntries[id].joysticks[stick].dy;
rwlockReadUnlock(&g_hidLock);
}
}
static Result _hidCreateAppletResource(Service* srv, Service* srv_out, u64 AppletResourceUserId) { static Result _hidCreateAppletResource(Service* srv, Service* srv_out, u64 AppletResourceUserId) {
IpcCommand c; IpcCommand c;
ipcInitialize(&c); ipcInitialize(&c);