From 1e3145f81d2da1f70a6c4a67dacfeaa9ec30b43b Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sat, 14 Nov 2020 19:32:43 -0500 Subject: [PATCH] hid: Struct adjustments. --- nx/include/switch/services/hid.h | 34 ++++++++++++++++---------------- nx/source/services/hid.c | 30 ++++++++++++++-------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index 4c2720aa..0cc62433 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -542,7 +542,7 @@ typedef struct HidKeyboard { // End HidKeyboard -// Begin HidController +// Begin HidNpad /// HidControllerMAC typedef struct HidControllerMAC { @@ -568,7 +568,7 @@ typedef struct HidNpadStateHeader { /// Info struct extracted from HidNpadStateHeader. /// Color fields are zero when not set. This can happen even when the *Set fields are set to true. -typedef struct HidControllerColors +typedef struct HidNpadControllerColor { bool singleSet; ///< Set to true when the below fields are valid. u32 singleColorBody; ///< RGBA Single Body Color @@ -579,7 +579,7 @@ typedef struct HidControllerColors u32 leftColorButtons; ///< RGBA Left Buttons Color u32 rightColorBody; ///< RGBA Right Body Color u32 rightColorButtons; ///< RGBA Right Buttons Color -} HidControllerColors; +} HidNpadControllerColor; /// HidControllerLayoutHeader typedef struct HidControllerLayoutHeader { @@ -615,27 +615,27 @@ typedef struct HidControllerLayout { HidControllerInputEntry entries[17]; } HidControllerLayout; -/// HidControllerSixAxisHeader -typedef struct HidControllerSixAxisHeader { +/// HidNpadSixAxisSensorHeader +typedef struct HidNpadSixAxisSensorHeader { u64 timestamp; u64 numEntries; u64 latestEntry; u64 maxEntryIndex; -} HidControllerSixAxisHeader; +} HidNpadSixAxisSensorHeader; -/// HidControllerSixAxisEntry -typedef struct HidControllerSixAxisEntry { +/// HidNpadSixAxisSensorState +typedef struct HidNpadSixAxisSensorState { u64 timestamp; u64 unk_1; u64 timestamp_2; SixAxisSensorValues values; u64 unk_3; -} HidControllerSixAxisEntry; +} HidNpadSixAxisSensorState; /// HidControllerSixAxisLayout typedef struct HidControllerSixAxisLayout { - HidControllerSixAxisHeader header; - HidControllerSixAxisEntry entries[17]; + HidNpadSixAxisSensorHeader header; + HidNpadSixAxisSensorState entries[17]; } HidControllerSixAxisLayout; /// Controller flags. @@ -677,16 +677,16 @@ typedef struct { u32 batteryCharge; ///< Battery charge, always 0-4. } HidPowerInfo; -/// HidController -typedef struct HidController { +/// HidNpad +typedef struct HidNpad { HidNpadStateHeader header; HidControllerLayout layouts[7]; HidControllerSixAxisLayout sixaxis[6]; HidControllerMisc misc; u8 unk_2[0xDF8]; -} HidController; +} HidNpad; -// End HidController +// End HidNpad /// HidConsoleSixAxisSensor typedef struct { @@ -710,7 +710,7 @@ typedef struct HidSharedMemory { u8 capture_button[0x200]; u8 input_detector[0x800]; u8 unique_pad[0x4000]; ///< [1.0.0-4.1.0] UniquePad - HidController controllers[10]; + HidNpad npad[10]; u8 gesture[0x800]; HidConsoleSixAxisSensor console_six_axis_sensor; ///< [5.0.0+] ConsoleSixAxisSensor u8 unk_x3C220[0x3DE0]; @@ -791,7 +791,7 @@ HidControllerLayoutType hidGetControllerLayout(HidControllerID id); /// Gets a bitmask of \ref HidNpadStyleTag for the specified controller. u32 hidGetNpadStyleSet(u32 id); -void hidGetControllerColors(HidControllerID id, HidControllerColors *colors); +void hidGetControllerColors(HidControllerID id, HidNpadControllerColor *colors); bool hidIsControllerConnected(HidControllerID id); /// Gets the \ref HidDeviceTypeBits for the specified controller. diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index ba451f1c..d364faa6 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -238,8 +238,8 @@ void hidScanInput(void) { } for (int i = 0; i < 10; i++) { - HidControllerLayout *currentLayout = &sharedMem->controllers[i].layouts[g_controllerLayout[i]]; - memcpy(&g_controllerHeaders[i], &sharedMem->controllers[i].header, sizeof(HidNpadStateHeader)); + HidControllerLayout *currentLayout = &sharedMem->npad[i].layouts[g_controllerLayout[i]]; + memcpy(&g_controllerHeaders[i], &sharedMem->npad[i].header, sizeof(HidNpadStateHeader)); u64 latestControllerEntry = currentLayout->header.latest_entry; HidControllerInputEntry *newInputEntry = ¤tLayout->entries[latestControllerEntry]; if ((s64)(newInputEntry->timestamp - g_controllerTimestamps[i]) >= 0) { @@ -252,30 +252,30 @@ void hidScanInput(void) { g_controllerDown[i] = (~g_controllerOld[i]) & g_controllerHeld[i]; g_controllerUp[i] = g_controllerOld[i] & (~g_controllerHeld[i]); - memcpy(&g_controllerMisc[i], &sharedMem->controllers[i].misc, sizeof(HidControllerMisc)); + memcpy(&g_controllerMisc[i], &sharedMem->npad[i].misc, sizeof(HidControllerMisc)); if (g_sixaxisEnabled[i]) { u32 style_set = g_controllerHeaders[i].style_set; HidControllerSixAxisLayout *sixaxis = NULL; if (style_set & HidNpadStyleTag_NpadFullKey) { - sixaxis = &sharedMem->controllers[i].sixaxis[0]; + sixaxis = &sharedMem->npad[i].sixaxis[0]; } else if (style_set & HidNpadStyleTag_NpadHandheld) { - sixaxis = &sharedMem->controllers[i].sixaxis[1]; + sixaxis = &sharedMem->npad[i].sixaxis[1]; } else if (style_set & HidNpadStyleTag_NpadJoyDual) { if (style_set & HidNpadStyleTag_NpadJoyLeft) { - sixaxis = &sharedMem->controllers[i].sixaxis[2]; + sixaxis = &sharedMem->npad[i].sixaxis[2]; } else { - sixaxis = &sharedMem->controllers[i].sixaxis[3]; + sixaxis = &sharedMem->npad[i].sixaxis[3]; } } else if (style_set & HidNpadStyleTag_NpadJoyLeft) { - sixaxis = &sharedMem->controllers[i].sixaxis[4]; + sixaxis = &sharedMem->npad[i].sixaxis[4]; } else if (style_set & HidNpadStyleTag_NpadJoyRight) { - sixaxis = &sharedMem->controllers[i].sixaxis[5]; + sixaxis = &sharedMem->npad[i].sixaxis[5]; } if (sixaxis) { memcpy(&g_sixaxisLayouts[i], sixaxis, sizeof(*sixaxis)); @@ -297,12 +297,12 @@ static Result _hidVerifyNpadIdType(u32 id) { return 0; } -static HidController *_hidNpadSharedmemGetInternalState(u32 id) { +static HidNpad *_hidNpadSharedmemGetInternalState(u32 id) { if (id >= 0x8) id = id==0x10 ? 0x9 : 0x8; HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr(); if (sharedmem == NULL) return NULL; - return &sharedmem->controllers[id]; + return &sharedmem->npad[id]; } u32 hidGetNpadStyleSet(u32 id) { @@ -310,7 +310,7 @@ u32 hidGetNpadStyleSet(u32 id) { u32 tmp=0; if (R_SUCCEEDED(rc)) { - HidController *npad = _hidNpadSharedmemGetInternalState(id); + HidNpad *npad = _hidNpadSharedmemGetInternalState(id); if (npad == NULL) rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized); else @@ -321,7 +321,7 @@ u32 hidGetNpadStyleSet(u32 id) { return tmp; } -void hidGetControllerColors(HidControllerID id, HidControllerColors *colors) { +void hidGetControllerColors(HidControllerID id, HidNpadControllerColor *colors) { if (id==CONTROLLER_P1_AUTO) { hidGetControllerColors(g_controllerP1AutoID, colors); return; @@ -331,7 +331,7 @@ void hidGetControllerColors(HidControllerID id, HidControllerColors *colors) { HidNpadStateHeader *hdr = &g_controllerHeaders[id]; - memset(colors, 0, sizeof(HidControllerColors)); + memset(colors, 0, sizeof(HidNpadControllerColor)); rwlockReadLock(&g_hidLock); @@ -421,7 +421,7 @@ static Result _hidGetNpadStates(u32 id, u32 layout, HidNpadStateEntry *states, s Result rc = _hidVerifyNpadIdType(id); if (R_FAILED(rc)) return rc; - HidController *npad = _hidNpadSharedmemGetInternalState(id); + HidNpad *npad = _hidNpadSharedmemGetInternalState(id); if (npad == NULL) return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);