From 6a9d194fe3048aa83df93e3a79c8d451fa461c42 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 16 Oct 2018 22:45:44 -0400 Subject: [PATCH] Added hidGetControllerColors and HidControllerColors. Changed rightColorbuttons to rightColorButtons in HidControllerHeader. Updated CONTROLLER_P1_AUTO comment. --- nx/include/switch/services/hid.h | 20 ++++++++++++++++++-- nx/source/services/hid.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/nx/include/switch/services/hid.h b/nx/include/switch/services/hid.h index 1d74ce9d..4d487038 100644 --- a/nx/include/switch/services/hid.h +++ b/nx/include/switch/services/hid.h @@ -310,7 +310,7 @@ typedef enum CONTROLLER_PLAYER_8 = 7, CONTROLLER_HANDHELD = 8, CONTROLLER_UNKNOWN = 9, - CONTROLLER_P1_AUTO = 10, /// Not an actual HID-sysmodule ID. Only for hidKeys*()/hidJoystickRead(). Automatically uses CONTROLLER_PLAYER_1 when connected, otherwise uses CONTROLLER_HANDHELD. + CONTROLLER_P1_AUTO = 10, /// Not an actual HID-sysmodule ID. Only for hidKeys*()/hidJoystickRead()/hidSixAxisSensorValuesRead()/hidGetControllerType()/hidGetControllerColors(). Automatically uses CONTROLLER_PLAYER_1 when connected, otherwise uses CONTROLLER_HANDHELD. } HidControllerID; typedef struct touchPosition @@ -491,10 +491,25 @@ typedef struct HidControllerHeader u32 leftColorBody; u32 leftColorButtons; u32 rightColorBody; - u32 rightColorbuttons; + u32 rightColorButtons; } HidControllerHeader; static_assert(sizeof(HidControllerHeader) == 0x28, "Hid controller header structure has incorrect size"); +/// Info struct extracted from HidControllerHeader. +/// Color fields are zero when not set. This can happen even when the *Set fields are set to true. +typedef struct HidControllerColors +{ + bool singleSet; ///< Set to true when the below fields are valid. + u32 singleColorBody; ///< RGBA Single Body Color + u32 singleColorButtons; ///< RGBA Single Buttons Color + + bool splitSet; ///< Set to true when the below fields are valid. + u32 leftColorBody; ///< RGBA Left Body Color + u32 leftColorButtons; ///< RGBA Left Buttons Color + u32 rightColorBody; ///< RGBA Right Body Color + u32 rightColorButtons; ///< RGBA Right Buttons Color +} HidControllerColors; + typedef struct HidControllerLayoutHeader { u64 timestampTicks; @@ -607,6 +622,7 @@ void* hidGetSharedmemAddr(void); void hidSetControllerLayout(HidControllerID id, HidControllerLayoutType layoutType); HidControllerLayoutType hidGetControllerLayout(HidControllerID id); HidControllerType hidGetControllerType(HidControllerID id); +void hidGetControllerColors(HidControllerID id, HidControllerColors *colors); void hidScanInput(void); diff --git a/nx/source/services/hid.c b/nx/source/services/hid.c index 3afa7e05..13148a01 100644 --- a/nx/source/services/hid.c +++ b/nx/source/services/hid.c @@ -302,6 +302,38 @@ HidControllerType hidGetControllerType(HidControllerID id) { return tmp; } +void hidGetControllerColors(HidControllerID id, HidControllerColors *colors) { + if (id==CONTROLLER_P1_AUTO) { + hidGetControllerColors(g_controllerP1AutoID, colors); + return; + } + if (id < 0 || id > 9) return; + if (colors == NULL) return; + + HidControllerHeader *hdr = &g_controllerHeaders[id]; + + memset(colors, 0, sizeof(HidControllerColors)); + + rwlockReadLock(&g_hidLock); + + colors->singleSet = (hdr->singleColorsDescriptor & BIT(1)) == 0; + colors->splitSet = (hdr->splitColorsDescriptor & BIT(1)) == 0; + + if (colors->singleSet) { + colors->singleColorBody = hdr->singleColorBody; + colors->singleColorButtons = hdr->singleColorButtons; + } + + if (colors->splitSet) { + colors->leftColorBody = hdr->leftColorBody; + colors->leftColorButtons = hdr->leftColorButtons; + colors->rightColorBody = hdr->rightColorBody; + colors->rightColorButtons = hdr->rightColorButtons; + } + + rwlockReadUnlock(&g_hidLock); +} + u64 hidKeysHeld(HidControllerID id) { if (id==CONTROLLER_P1_AUTO) return hidKeysHeld(g_controllerP1AutoID); if (id < 0 || id > 9) return 0;