mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
hid: Struct adjustments.
This commit is contained in:
parent
54a296bc69
commit
1e3145f81d
@ -542,7 +542,7 @@ typedef struct HidKeyboard {
|
|||||||
|
|
||||||
// End HidKeyboard
|
// End HidKeyboard
|
||||||
|
|
||||||
// Begin HidController
|
// Begin HidNpad
|
||||||
|
|
||||||
/// HidControllerMAC
|
/// HidControllerMAC
|
||||||
typedef struct HidControllerMAC {
|
typedef struct HidControllerMAC {
|
||||||
@ -568,7 +568,7 @@ typedef struct HidNpadStateHeader {
|
|||||||
|
|
||||||
/// Info struct extracted from 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.
|
/// 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.
|
bool singleSet; ///< Set to true when the below fields are valid.
|
||||||
u32 singleColorBody; ///< RGBA Single Body Color
|
u32 singleColorBody; ///< RGBA Single Body Color
|
||||||
@ -579,7 +579,7 @@ typedef struct HidControllerColors
|
|||||||
u32 leftColorButtons; ///< RGBA Left Buttons Color
|
u32 leftColorButtons; ///< RGBA Left Buttons Color
|
||||||
u32 rightColorBody; ///< RGBA Right Body Color
|
u32 rightColorBody; ///< RGBA Right Body Color
|
||||||
u32 rightColorButtons; ///< RGBA Right Buttons Color
|
u32 rightColorButtons; ///< RGBA Right Buttons Color
|
||||||
} HidControllerColors;
|
} HidNpadControllerColor;
|
||||||
|
|
||||||
/// HidControllerLayoutHeader
|
/// HidControllerLayoutHeader
|
||||||
typedef struct HidControllerLayoutHeader {
|
typedef struct HidControllerLayoutHeader {
|
||||||
@ -615,27 +615,27 @@ typedef struct HidControllerLayout {
|
|||||||
HidControllerInputEntry entries[17];
|
HidControllerInputEntry entries[17];
|
||||||
} HidControllerLayout;
|
} HidControllerLayout;
|
||||||
|
|
||||||
/// HidControllerSixAxisHeader
|
/// HidNpadSixAxisSensorHeader
|
||||||
typedef struct HidControllerSixAxisHeader {
|
typedef struct HidNpadSixAxisSensorHeader {
|
||||||
u64 timestamp;
|
u64 timestamp;
|
||||||
u64 numEntries;
|
u64 numEntries;
|
||||||
u64 latestEntry;
|
u64 latestEntry;
|
||||||
u64 maxEntryIndex;
|
u64 maxEntryIndex;
|
||||||
} HidControllerSixAxisHeader;
|
} HidNpadSixAxisSensorHeader;
|
||||||
|
|
||||||
/// HidControllerSixAxisEntry
|
/// HidNpadSixAxisSensorState
|
||||||
typedef struct HidControllerSixAxisEntry {
|
typedef struct HidNpadSixAxisSensorState {
|
||||||
u64 timestamp;
|
u64 timestamp;
|
||||||
u64 unk_1;
|
u64 unk_1;
|
||||||
u64 timestamp_2;
|
u64 timestamp_2;
|
||||||
SixAxisSensorValues values;
|
SixAxisSensorValues values;
|
||||||
u64 unk_3;
|
u64 unk_3;
|
||||||
} HidControllerSixAxisEntry;
|
} HidNpadSixAxisSensorState;
|
||||||
|
|
||||||
/// HidControllerSixAxisLayout
|
/// HidControllerSixAxisLayout
|
||||||
typedef struct HidControllerSixAxisLayout {
|
typedef struct HidControllerSixAxisLayout {
|
||||||
HidControllerSixAxisHeader header;
|
HidNpadSixAxisSensorHeader header;
|
||||||
HidControllerSixAxisEntry entries[17];
|
HidNpadSixAxisSensorState entries[17];
|
||||||
} HidControllerSixAxisLayout;
|
} HidControllerSixAxisLayout;
|
||||||
|
|
||||||
/// Controller flags.
|
/// Controller flags.
|
||||||
@ -677,16 +677,16 @@ typedef struct {
|
|||||||
u32 batteryCharge; ///< Battery charge, always 0-4.
|
u32 batteryCharge; ///< Battery charge, always 0-4.
|
||||||
} HidPowerInfo;
|
} HidPowerInfo;
|
||||||
|
|
||||||
/// HidController
|
/// HidNpad
|
||||||
typedef struct HidController {
|
typedef struct HidNpad {
|
||||||
HidNpadStateHeader header;
|
HidNpadStateHeader header;
|
||||||
HidControllerLayout layouts[7];
|
HidControllerLayout layouts[7];
|
||||||
HidControllerSixAxisLayout sixaxis[6];
|
HidControllerSixAxisLayout sixaxis[6];
|
||||||
HidControllerMisc misc;
|
HidControllerMisc misc;
|
||||||
u8 unk_2[0xDF8];
|
u8 unk_2[0xDF8];
|
||||||
} HidController;
|
} HidNpad;
|
||||||
|
|
||||||
// End HidController
|
// End HidNpad
|
||||||
|
|
||||||
/// HidConsoleSixAxisSensor
|
/// HidConsoleSixAxisSensor
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -710,7 +710,7 @@ typedef struct HidSharedMemory {
|
|||||||
u8 capture_button[0x200];
|
u8 capture_button[0x200];
|
||||||
u8 input_detector[0x800];
|
u8 input_detector[0x800];
|
||||||
u8 unique_pad[0x4000]; ///< [1.0.0-4.1.0] UniquePad
|
u8 unique_pad[0x4000]; ///< [1.0.0-4.1.0] UniquePad
|
||||||
HidController controllers[10];
|
HidNpad npad[10];
|
||||||
u8 gesture[0x800];
|
u8 gesture[0x800];
|
||||||
HidConsoleSixAxisSensor console_six_axis_sensor; ///< [5.0.0+] ConsoleSixAxisSensor
|
HidConsoleSixAxisSensor console_six_axis_sensor; ///< [5.0.0+] ConsoleSixAxisSensor
|
||||||
u8 unk_x3C220[0x3DE0];
|
u8 unk_x3C220[0x3DE0];
|
||||||
@ -791,7 +791,7 @@ HidControllerLayoutType hidGetControllerLayout(HidControllerID id);
|
|||||||
/// Gets a bitmask of \ref HidNpadStyleTag for the specified controller.
|
/// Gets a bitmask of \ref HidNpadStyleTag for the specified controller.
|
||||||
u32 hidGetNpadStyleSet(u32 id);
|
u32 hidGetNpadStyleSet(u32 id);
|
||||||
|
|
||||||
void hidGetControllerColors(HidControllerID id, HidControllerColors *colors);
|
void hidGetControllerColors(HidControllerID id, HidNpadControllerColor *colors);
|
||||||
bool hidIsControllerConnected(HidControllerID id);
|
bool hidIsControllerConnected(HidControllerID id);
|
||||||
|
|
||||||
/// Gets the \ref HidDeviceTypeBits for the specified controller.
|
/// Gets the \ref HidDeviceTypeBits for the specified controller.
|
||||||
|
@ -238,8 +238,8 @@ void hidScanInput(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
HidControllerLayout *currentLayout = &sharedMem->controllers[i].layouts[g_controllerLayout[i]];
|
HidControllerLayout *currentLayout = &sharedMem->npad[i].layouts[g_controllerLayout[i]];
|
||||||
memcpy(&g_controllerHeaders[i], &sharedMem->controllers[i].header, sizeof(HidNpadStateHeader));
|
memcpy(&g_controllerHeaders[i], &sharedMem->npad[i].header, sizeof(HidNpadStateHeader));
|
||||||
u64 latestControllerEntry = currentLayout->header.latest_entry;
|
u64 latestControllerEntry = currentLayout->header.latest_entry;
|
||||||
HidControllerInputEntry *newInputEntry = ¤tLayout->entries[latestControllerEntry];
|
HidControllerInputEntry *newInputEntry = ¤tLayout->entries[latestControllerEntry];
|
||||||
if ((s64)(newInputEntry->timestamp - g_controllerTimestamps[i]) >= 0) {
|
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_controllerDown[i] = (~g_controllerOld[i]) & g_controllerHeld[i];
|
||||||
g_controllerUp[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]) {
|
if (g_sixaxisEnabled[i]) {
|
||||||
u32 style_set = g_controllerHeaders[i].style_set;
|
u32 style_set = g_controllerHeaders[i].style_set;
|
||||||
HidControllerSixAxisLayout *sixaxis = NULL;
|
HidControllerSixAxisLayout *sixaxis = NULL;
|
||||||
if (style_set & HidNpadStyleTag_NpadFullKey) {
|
if (style_set & HidNpadStyleTag_NpadFullKey) {
|
||||||
sixaxis = &sharedMem->controllers[i].sixaxis[0];
|
sixaxis = &sharedMem->npad[i].sixaxis[0];
|
||||||
}
|
}
|
||||||
else if (style_set & HidNpadStyleTag_NpadHandheld) {
|
else if (style_set & HidNpadStyleTag_NpadHandheld) {
|
||||||
sixaxis = &sharedMem->controllers[i].sixaxis[1];
|
sixaxis = &sharedMem->npad[i].sixaxis[1];
|
||||||
}
|
}
|
||||||
else if (style_set & HidNpadStyleTag_NpadJoyDual) {
|
else if (style_set & HidNpadStyleTag_NpadJoyDual) {
|
||||||
if (style_set & HidNpadStyleTag_NpadJoyLeft) {
|
if (style_set & HidNpadStyleTag_NpadJoyLeft) {
|
||||||
sixaxis = &sharedMem->controllers[i].sixaxis[2];
|
sixaxis = &sharedMem->npad[i].sixaxis[2];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sixaxis = &sharedMem->controllers[i].sixaxis[3];
|
sixaxis = &sharedMem->npad[i].sixaxis[3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (style_set & HidNpadStyleTag_NpadJoyLeft) {
|
else if (style_set & HidNpadStyleTag_NpadJoyLeft) {
|
||||||
sixaxis = &sharedMem->controllers[i].sixaxis[4];
|
sixaxis = &sharedMem->npad[i].sixaxis[4];
|
||||||
}
|
}
|
||||||
else if (style_set & HidNpadStyleTag_NpadJoyRight) {
|
else if (style_set & HidNpadStyleTag_NpadJoyRight) {
|
||||||
sixaxis = &sharedMem->controllers[i].sixaxis[5];
|
sixaxis = &sharedMem->npad[i].sixaxis[5];
|
||||||
}
|
}
|
||||||
if (sixaxis) {
|
if (sixaxis) {
|
||||||
memcpy(&g_sixaxisLayouts[i], sixaxis, sizeof(*sixaxis));
|
memcpy(&g_sixaxisLayouts[i], sixaxis, sizeof(*sixaxis));
|
||||||
@ -297,12 +297,12 @@ static Result _hidVerifyNpadIdType(u32 id) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HidController *_hidNpadSharedmemGetInternalState(u32 id) {
|
static HidNpad *_hidNpadSharedmemGetInternalState(u32 id) {
|
||||||
if (id >= 0x8) id = id==0x10 ? 0x9 : 0x8;
|
if (id >= 0x8) id = id==0x10 ? 0x9 : 0x8;
|
||||||
|
|
||||||
HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr();
|
HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr();
|
||||||
if (sharedmem == NULL) return NULL;
|
if (sharedmem == NULL) return NULL;
|
||||||
return &sharedmem->controllers[id];
|
return &sharedmem->npad[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 hidGetNpadStyleSet(u32 id) {
|
u32 hidGetNpadStyleSet(u32 id) {
|
||||||
@ -310,7 +310,7 @@ u32 hidGetNpadStyleSet(u32 id) {
|
|||||||
u32 tmp=0;
|
u32 tmp=0;
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
HidController *npad = _hidNpadSharedmemGetInternalState(id);
|
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
|
||||||
if (npad == NULL)
|
if (npad == NULL)
|
||||||
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
rc = MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||||
else
|
else
|
||||||
@ -321,7 +321,7 @@ u32 hidGetNpadStyleSet(u32 id) {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidGetControllerColors(HidControllerID id, HidControllerColors *colors) {
|
void hidGetControllerColors(HidControllerID id, HidNpadControllerColor *colors) {
|
||||||
if (id==CONTROLLER_P1_AUTO) {
|
if (id==CONTROLLER_P1_AUTO) {
|
||||||
hidGetControllerColors(g_controllerP1AutoID, colors);
|
hidGetControllerColors(g_controllerP1AutoID, colors);
|
||||||
return;
|
return;
|
||||||
@ -331,7 +331,7 @@ void hidGetControllerColors(HidControllerID id, HidControllerColors *colors) {
|
|||||||
|
|
||||||
HidNpadStateHeader *hdr = &g_controllerHeaders[id];
|
HidNpadStateHeader *hdr = &g_controllerHeaders[id];
|
||||||
|
|
||||||
memset(colors, 0, sizeof(HidControllerColors));
|
memset(colors, 0, sizeof(HidNpadControllerColor));
|
||||||
|
|
||||||
rwlockReadLock(&g_hidLock);
|
rwlockReadLock(&g_hidLock);
|
||||||
|
|
||||||
@ -421,7 +421,7 @@ static Result _hidGetNpadStates(u32 id, u32 layout, HidNpadStateEntry *states, s
|
|||||||
Result rc = _hidVerifyNpadIdType(id);
|
Result rc = _hidVerifyNpadIdType(id);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
HidController *npad = _hidNpadSharedmemGetInternalState(id);
|
HidNpad *npad = _hidNpadSharedmemGetInternalState(id);
|
||||||
if (npad == NULL)
|
if (npad == NULL)
|
||||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user