mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-03 18:12:14 +02:00
hid: Add hidJoystickRead
This commit is contained in:
parent
8ae150d110
commit
7888f316c2
@ -275,6 +275,14 @@ typedef enum
|
||||
KEY_RIGHT = KEY_DRIGHT | KEY_LSTICK_RIGHT | KEY_RSTICK_RIGHT, ///< D-Pad Right or Sticks Right
|
||||
} HidControllerKeys;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
JOYSTICK_LEFT = 0,
|
||||
JOYSTICK_RIGHT = 1,
|
||||
|
||||
JOYSTICK_NUM_STICKS = 2,
|
||||
} HidControllerJoystick;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CONTROLLER_STATE_CONNECTED = BIT(0),
|
||||
@ -305,6 +313,15 @@ typedef struct touchPosition
|
||||
u32 angle;
|
||||
} touchPosition;
|
||||
|
||||
typedef struct circlePosition
|
||||
{
|
||||
s32 dx;
|
||||
s32 dy;
|
||||
} circlePosition;
|
||||
|
||||
#define JOYSTICK_MAX (0x8000)
|
||||
#define JOYSTICK_MIN (-0x8000)
|
||||
|
||||
// End enums and output structs
|
||||
|
||||
// Begin HidTouchScreen
|
||||
@ -463,10 +480,7 @@ typedef struct HidControllerInputEntry
|
||||
u64 timestamp;
|
||||
u64 timestamp_2;
|
||||
u64 buttons;
|
||||
u32 joystickLeftX;
|
||||
u32 joystickLeftY;
|
||||
u32 joystickRightX;
|
||||
u32 joystickRightY;
|
||||
circlePosition joysticks[JOYSTICK_NUM_STICKS];
|
||||
u64 connectionState;
|
||||
} HidControllerInputEntry;
|
||||
static_assert(sizeof(HidControllerInputEntry) == 0x30, "Hid controller input entry structure has incorrect size");
|
||||
@ -540,3 +554,5 @@ bool hidKeyboardUp(HidKeyboardScancode key);
|
||||
|
||||
u32 hidTouchCount(void);
|
||||
void hidTouchRead(touchPosition *pos, u32 point_id);
|
||||
|
||||
void hidJoystickRead(circlePosition *pos, HidControllerID id, HidControllerJoystick stick);
|
||||
|
@ -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) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
|
Loading…
Reference in New Issue
Block a user