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
|
||||
|
||||
// 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.
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user