From d3838b8e088b5e8f1878a1a744aa3ec0dc109f88 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sun, 22 Nov 2020 21:16:10 -0500 Subject: [PATCH] hid: Gesture support. Updated HidNpadSystemProperties. --- nx/include/switch/services/hid.h | 56 ++++++++++++++++++++++++++++++-- nx/source/services/hid.c | 21 ++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index 023a03d9..0d39492a 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -797,8 +797,8 @@ typedef struct { u64 bit6 : 1; ///< Unused u64 bit7 : 1; ///< Unused u64 bit8 : 1; ///< Unused - u64 is_unsuported_button_pressed_on_npad_system : 1; ///< IsUnsuportedButtonPressedOnNpadSystem - u64 is_unsuported_button_pressed_on_npad_system_ext : 1; ///< IsUnsuportedButtonPressedOnNpadSystemExt + u64 is_unsupported_button_pressed_on_npad_system : 1; ///< IsUnsupportedButtonPressedOnNpadSystem + u64 is_unsupported_button_pressed_on_npad_system_ext : 1; ///< IsUnsupportedButtonPressedOnNpadSystemExt u64 is_abxy_button_oriented : 1; ///< IsAbxyButtonOriented u64 is_sl_sr_button_oriented : 1; ///< IsSlSrButtonOriented @@ -878,6 +878,53 @@ typedef struct HidNpad { // End HidNpad +// Begin HidGesture + +/// HidGesturePoint +typedef struct HidGesturePoint { + u32 x; ///< X + u32 y; ///< Y +} HidGesturePoint; + +/// HidGestureState +typedef struct HidGestureState { + u64 sampling_number; ///< SamplingNumber + u64 context_number; ///< ContextNumber + u32 type; ///< \ref HidGestureType + u32 direction; ///< \ref HidGestureDirection + u32 x; ///< X + u32 y; ///< Y + s32 delta_x; ///< DeltaX + s32 delta_y; ///< DeltaY + float velocity_x; ///< VelocityX + float velocity_y; ///< VelocityY + u32 attributes; ///< Bitfield of \ref HidGestureAttribute. + u32 scale; ///< Scale + u32 rotation_angle; ///< RotationAngle + s32 point_count; ///< Number of entries in the points array. + HidGesturePoint points[4]; ///< Array of \ref HidGesturePoint with the above count. +} HidGestureState; + +/// HidGestureDummyStateAtomicStorage +typedef struct HidGestureDummyStateAtomicStorage { + u64 sampling_number; ///< SamplingNumber + HidGestureState state; +} HidGestureDummyStateAtomicStorage; + +/// HidGestureLifo +typedef struct HidGestureLifo { + HidCommonLifoHeader header; + HidGestureDummyStateAtomicStorage storage[17]; +} HidGestureLifo; + +/// HidGestureSharedMemoryFormat +typedef struct HidGestureSharedMemoryFormat { + HidGestureLifo lifo; + u8 pad[0xF8]; +} HidGestureSharedMemoryFormat; + +// End HidGesture + /// HidConsoleSixAxisSensor typedef struct { u64 sampling_number; ///< SamplingNumber @@ -901,7 +948,7 @@ typedef struct HidSharedMemory { u8 input_detector[0x800]; u8 unique_pad[0x4000]; ///< [1.0.0-4.1.0] UniquePad HidNpad npad[10]; - u8 gesture[0x800]; + HidGestureSharedMemoryFormat gesture; HidConsoleSixAxisSensor console_six_axis_sensor; ///< [5.0.0+] ConsoleSixAxisSensor u8 unk_x3C220[0x3DE0]; } HidSharedMemory; @@ -1053,6 +1100,9 @@ size_t hidGetNpadStatesSystem(HidNpadIdType id, HidNpadSystemState *states, size size_t hidGetSixAxisSensorStates(HidSixAxisSensorHandle handle, HidSixAxisSensorState *states, size_t count); +void hidInitializeGesture(void); +size_t hidGetGestureStates(HidGestureState *states, size_t count); + bool hidIsControllerConnected(HidControllerID id); u64 hidKeysHeld(HidControllerID id); diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index adfa120f..07247e4f 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -44,6 +44,7 @@ static Result _hidActivateTouchScreen(void); static Result _hidActivateMouse(void); static Result _hidActivateKeyboard(void); static Result _hidActivateNpad(void); +static Result _hidActivateGesture(void); static Result _hidSetDualModeAll(void); @@ -700,6 +701,20 @@ size_t hidGetSixAxisSensorStates(HidSixAxisSensorHandle handle, HidSixAxisSensor return total; } +void hidInitializeGesture(void) { + Result rc = _hidActivateGesture(); + if (R_FAILED(rc)) diagAbortWithResult(rc); +} + +size_t hidGetGestureStates(HidGestureState *states, size_t count) { + HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr(); + if (sharedmem == NULL) + diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); + + size_t total = _hidGetStates(&sharedmem->gesture.lifo.header, sharedmem->gesture.lifo.storage, 17, offsetof(HidGestureDummyStateAtomicStorage,state), offsetof(HidGestureState,sampling_number), states, sizeof(HidGestureState), count); + return total; +} + bool hidIsControllerConnected(HidControllerID id) { if (id==CONTROLLER_P1_AUTO) return hidIsControllerConnected(g_controllerP1AutoID); @@ -1121,6 +1136,12 @@ Result hidSetSupportedNpadStyleSet(u32 style_set) { return _hidCmdInU32AruidNoOut(style_set, 100); } +static Result _hidActivateGesture(void) { + u32 val=1; + + return _hidCmdInU32AruidNoOut(val, 91); // ActivateNpadWithRevision +} + Result hidGetSupportedNpadStyleSet(u32 *style_set) { u32 tmp=0; Result rc = _hidCmdOutU32(&tmp, 101);