mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
hid: Updated structs.
This commit is contained in:
parent
967a5054a3
commit
902af6cce0
@ -451,19 +451,13 @@ typedef struct SixAxisSensorValues {
|
||||
|
||||
// End enums and output structs
|
||||
|
||||
/// HidCommonStateHeader
|
||||
typedef struct HidCommonStateHeader {
|
||||
u64 timestamp_ticks;
|
||||
u64 total_entries;
|
||||
u64 latest_entry;
|
||||
u64 max_entry;
|
||||
} HidCommonStateHeader;
|
||||
|
||||
/// HidCommonStateEntry
|
||||
typedef struct HidCommonStateEntry {
|
||||
u64 timestamp;
|
||||
u8 state[];
|
||||
} HidCommonStateEntry;
|
||||
/// HidCommonLifoHeader
|
||||
typedef struct HidCommonLifoHeader {
|
||||
u64 sampling_number;
|
||||
u64 buffer_count;
|
||||
u64 tail;
|
||||
u64 count;
|
||||
} HidCommonLifoHeader;
|
||||
|
||||
// Begin HidTouchScreen
|
||||
|
||||
@ -482,7 +476,7 @@ typedef struct HidTouchState {
|
||||
|
||||
/// HidTouchScreenState
|
||||
typedef struct HidTouchScreenState {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
s32 count;
|
||||
u32 reserved;
|
||||
HidTouchState touches[16];
|
||||
@ -490,24 +484,29 @@ typedef struct HidTouchScreenState {
|
||||
|
||||
/// HidTouchScreenStateAtomicStorage
|
||||
typedef struct HidTouchScreenStateAtomicStorage {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
HidTouchScreenState state;
|
||||
} HidTouchScreenStateAtomicStorage;
|
||||
|
||||
/// HidTouchScreenLifo
|
||||
typedef struct HidTouchScreenLifo {
|
||||
HidCommonStateHeader header;
|
||||
HidTouchScreenStateAtomicStorage entries[17];
|
||||
u8 padding[0x3c8];
|
||||
HidCommonLifoHeader header;
|
||||
HidTouchScreenStateAtomicStorage storage[17];
|
||||
} HidTouchScreenLifo;
|
||||
|
||||
/// HidTouchScreenSharedMemoryFormat
|
||||
typedef struct HidTouchScreenSharedMemoryFormat {
|
||||
HidTouchScreenLifo lifo;
|
||||
u8 padding[0x3c8];
|
||||
} HidTouchScreenSharedMemoryFormat;
|
||||
|
||||
// End HidTouchScreen
|
||||
|
||||
// Begin HidMouse
|
||||
|
||||
/// HidMouseState
|
||||
typedef struct HidMouseState {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
MousePosition position;
|
||||
u32 buttons;
|
||||
u32 attributes;
|
||||
@ -515,49 +514,58 @@ typedef struct HidMouseState {
|
||||
|
||||
/// HidMouseStateAtomicStorage
|
||||
typedef struct HidMouseStateAtomicStorage {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
HidMouseState state;
|
||||
} HidMouseStateAtomicStorage;
|
||||
|
||||
/// HidMouseLifo
|
||||
typedef struct HidMouseLifo {
|
||||
HidCommonStateHeader header;
|
||||
HidMouseStateAtomicStorage entries[17];
|
||||
u8 padding[0xB0];
|
||||
HidCommonLifoHeader header;
|
||||
HidMouseStateAtomicStorage storage[17];
|
||||
} HidMouseLifo;
|
||||
|
||||
/// HidMouseSharedMemoryFormat
|
||||
typedef struct HidMouseSharedMemoryFormat {
|
||||
HidMouseLifo lifo;
|
||||
u8 padding[0xB0];
|
||||
} HidMouseSharedMemoryFormat;
|
||||
|
||||
// End HidMouse
|
||||
|
||||
// Begin HidKeyboard
|
||||
|
||||
/// HidKeyboardState
|
||||
typedef struct HidKeyboardState {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
u64 modifier;
|
||||
u32 keys[8];
|
||||
} HidKeyboardState;
|
||||
|
||||
/// HidKeyboardStateAtomicStorage
|
||||
typedef struct HidKeyboardStateAtomicStorage {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
HidKeyboardState state;
|
||||
} HidKeyboardStateAtomicStorage;
|
||||
|
||||
/// HidKeyboardLifo
|
||||
typedef struct HidKeyboardLifo {
|
||||
HidCommonStateHeader header;
|
||||
HidKeyboardStateAtomicStorage entries[17];
|
||||
u8 padding[0x28];
|
||||
HidCommonLifoHeader header;
|
||||
HidKeyboardStateAtomicStorage storage[17];
|
||||
} HidKeyboardLifo;
|
||||
|
||||
/// HidKeyboardSharedMemoryFormat
|
||||
typedef struct HidKeyboardSharedMemoryFormat {
|
||||
HidKeyboardLifo lifo;
|
||||
u8 padding[0x28];
|
||||
} HidKeyboardSharedMemoryFormat;
|
||||
|
||||
// End HidKeyboard
|
||||
|
||||
// Begin HidNpad
|
||||
|
||||
/// Npad colors.
|
||||
/// Color fields are zero when not set.
|
||||
typedef struct HidNpadControllerColor
|
||||
{
|
||||
typedef struct HidNpadControllerColor {
|
||||
u32 color_body; ///< RGBA Body Color
|
||||
u32 color_buttons; ///< RGBA Buttons Color
|
||||
} HidNpadControllerColor;
|
||||
@ -573,110 +581,117 @@ typedef struct HidNpadStateHeader {
|
||||
HidNpadControllerColor right_colors;
|
||||
} HidNpadStateHeader;
|
||||
|
||||
/// HidNpadStateEntry
|
||||
typedef struct HidNpadStateEntry {
|
||||
u64 timestamp;
|
||||
/// HidNpadCommonState
|
||||
typedef struct HidNpadCommonState {
|
||||
u64 sampling_number;
|
||||
u64 buttons;
|
||||
JoystickPosition joysticks[JOYSTICK_NUM_STICKS];
|
||||
u32 connectionState;
|
||||
u32 pad;
|
||||
} HidNpadStateEntry;
|
||||
u32 attributes;
|
||||
u32 reserved;
|
||||
} HidNpadCommonState;
|
||||
|
||||
typedef HidNpadStateEntry HidNpadFullKeyState;
|
||||
typedef HidNpadStateEntry HidNpadHandheldState;
|
||||
typedef HidNpadStateEntry HidNpadJoyDualState;
|
||||
typedef HidNpadStateEntry HidNpadJoyLeftState;
|
||||
typedef HidNpadStateEntry HidNpadJoyRightState;
|
||||
typedef HidNpadCommonState HidNpadFullKeyState;
|
||||
typedef HidNpadCommonState HidNpadHandheldState;
|
||||
typedef HidNpadCommonState HidNpadJoyDualState;
|
||||
typedef HidNpadCommonState HidNpadJoyLeftState;
|
||||
typedef HidNpadCommonState HidNpadJoyRightState;
|
||||
|
||||
/// HidNpadGcState
|
||||
typedef struct HidNpadGcState {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
u64 buttons;
|
||||
JoystickPosition joysticks[JOYSTICK_NUM_STICKS];
|
||||
u32 connectionState;
|
||||
u32 attributes;
|
||||
u32 l_trigger; ///< L analog trigger. Valid range: 0x0-0x7FFF.
|
||||
u32 r_trigger; ///< R analog trigger. Valid range: 0x0-0x7FFF.
|
||||
u32 pad;
|
||||
} HidNpadGcState;
|
||||
|
||||
typedef HidNpadStateEntry HidNpadPalmaState;
|
||||
typedef HidNpadCommonState HidNpadPalmaState;
|
||||
|
||||
/// HidNpadLarkState
|
||||
typedef struct HidNpadLarkState {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
u64 buttons;
|
||||
JoystickPosition joysticks[JOYSTICK_NUM_STICKS]; ///< Joysticks state are always zero.
|
||||
u32 connectionState;
|
||||
u32 unk;
|
||||
u32 attributes;
|
||||
u32 lark_type_l_and_main; ///< LarkTypeLAndMain
|
||||
} HidNpadLarkState;
|
||||
|
||||
/// HidNpadHandheldLarkState
|
||||
typedef struct HidNpadHandheldLarkState {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
u64 buttons;
|
||||
JoystickPosition joysticks[JOYSTICK_NUM_STICKS];
|
||||
u32 connectionState;
|
||||
u32 unk0;
|
||||
u32 unk1;
|
||||
u32 attributes;
|
||||
u32 lark_type_l_and_main; ///< LarkTypeLAndMain
|
||||
u32 lark_type_r; ///< LarkTypeR
|
||||
u32 pad;
|
||||
} HidNpadHandheldLarkState;
|
||||
|
||||
/// HidNpadLuciaState
|
||||
typedef struct HidNpadLuciaState {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
u64 buttons;
|
||||
JoystickPosition joysticks[JOYSTICK_NUM_STICKS]; ///< Joysticks state are always zero.
|
||||
u32 connectionState;
|
||||
u32 unk;
|
||||
u32 attributes;
|
||||
u32 lucia_type; ///< LuciaType
|
||||
} HidNpadLuciaState;
|
||||
|
||||
typedef HidNpadStateEntry HidNpadSystemExtState;
|
||||
typedef HidNpadStateEntry HidNpadSystemState; ///< Joysticks state are always zero. Only the following button bits are available: KEY_A, KEY_B, KEY_X, KEY_Y, KEY_DLEFT, KEY_DUP, KEY_DRIGHT, KEY_DDOWN, KEY_L, KEY_R.
|
||||
typedef HidNpadCommonState HidNpadSystemExtState;
|
||||
typedef HidNpadCommonState HidNpadSystemState; ///< Joysticks state are always zero. Only the following button bits are available: KEY_A, KEY_B, KEY_X, KEY_Y, KEY_DLEFT, KEY_DUP, KEY_DRIGHT, KEY_DDOWN, KEY_L, KEY_R.
|
||||
|
||||
/// HidControllerInputEntry
|
||||
typedef struct HidControllerInputEntry {
|
||||
u64 timestamp;
|
||||
HidNpadStateEntry state;
|
||||
} HidControllerInputEntry;
|
||||
/// HidNpadCommonStateAtomicStorage
|
||||
typedef struct HidNpadCommonStateAtomicStorage {
|
||||
u64 sampling_number;
|
||||
HidNpadCommonState state;
|
||||
} HidNpadCommonStateAtomicStorage;
|
||||
|
||||
/// HidControllerLayout
|
||||
typedef struct HidControllerLayout {
|
||||
HidCommonStateHeader header;
|
||||
HidControllerInputEntry entries[17];
|
||||
} HidControllerLayout;
|
||||
/// HidNpadCommonLifo
|
||||
typedef struct HidNpadCommonLifo {
|
||||
HidCommonLifoHeader header;
|
||||
HidNpadCommonStateAtomicStorage storage[17];
|
||||
} HidNpadCommonLifo;
|
||||
|
||||
/// HidNpadGcTriggerState
|
||||
typedef struct HidNpadGcTriggerState {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
u32 l_trigger;
|
||||
u32 r_trigger;
|
||||
} HidNpadGcTriggerState;
|
||||
|
||||
/// HidNpadGcTriggerStateEntry
|
||||
typedef struct HidNpadGcTriggerStateEntry {
|
||||
u64 timestamp;
|
||||
/// HidNpadGcTriggerStateAtomicStorage
|
||||
typedef struct HidNpadGcTriggerStateAtomicStorage {
|
||||
u64 sampling_number;
|
||||
HidNpadGcTriggerState state;
|
||||
} HidNpadGcTriggerStateEntry;
|
||||
} HidNpadGcTriggerStateAtomicStorage;
|
||||
|
||||
/// HidNpadGcTriggerLifo
|
||||
typedef struct HidNpadGcTriggerLifo {
|
||||
HidCommonLifoHeader header;
|
||||
HidNpadGcTriggerStateAtomicStorage storage[17];
|
||||
} HidNpadGcTriggerLifo;
|
||||
|
||||
/// HidSixAxisSensorState
|
||||
typedef struct HidSixAxisSensorState {
|
||||
u64 unk_1;
|
||||
u64 timestamp;
|
||||
u64 delta_time;
|
||||
u64 sampling_number;
|
||||
SixAxisSensorValues values;
|
||||
u64 unk_3;
|
||||
u32 attributes;
|
||||
u32 reserved;
|
||||
} HidSixAxisSensorState;
|
||||
|
||||
/// HidNpadSixAxisSensorState
|
||||
typedef struct HidNpadSixAxisSensorState {
|
||||
u64 timestamp;
|
||||
/// HidSixAxisSensorStateAtomicStorage
|
||||
typedef struct HidSixAxisSensorStateAtomicStorage {
|
||||
u64 sampling_number;
|
||||
HidSixAxisSensorState state;
|
||||
} HidNpadSixAxisSensorState;
|
||||
} HidSixAxisSensorStateAtomicStorage;
|
||||
|
||||
/// HidControllerSixAxisLayout
|
||||
typedef struct HidControllerSixAxisLayout {
|
||||
HidCommonStateHeader header;
|
||||
HidNpadSixAxisSensorState entries[17];
|
||||
} HidControllerSixAxisLayout;
|
||||
/// HidNpadSixAxisSensorLifo
|
||||
typedef struct HidNpadSixAxisSensorLifo {
|
||||
HidCommonLifoHeader header;
|
||||
HidSixAxisSensorStateAtomicStorage storage[17];
|
||||
} HidNpadSixAxisSensorLifo;
|
||||
|
||||
/// NpadSystemProperties
|
||||
typedef struct {
|
||||
@ -712,28 +727,28 @@ typedef struct {
|
||||
/// HidNfcXcdDeviceHandleState
|
||||
typedef struct HidNfcXcdDeviceHandleState {
|
||||
u64 handle;
|
||||
u8 flag0;
|
||||
u8 flag1;
|
||||
u8 pad[6];
|
||||
u64 timestamp;
|
||||
u8 is_available;
|
||||
u8 is_activated;
|
||||
u8 reserved[6];
|
||||
u64 sampling_number;
|
||||
} HidNfcXcdDeviceHandleState;
|
||||
|
||||
/// HidNfcXcdDeviceHandleStateEntry
|
||||
typedef struct HidNfcXcdDeviceHandleStateEntry {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
HidNfcXcdDeviceHandleState state;
|
||||
} HidNfcXcdDeviceHandleStateEntry;
|
||||
|
||||
/// HidNpad
|
||||
typedef struct HidNpad {
|
||||
HidNpadStateHeader header;
|
||||
HidControllerLayout layouts[7];
|
||||
HidControllerSixAxisLayout sixaxis[6];
|
||||
u32 deviceType;
|
||||
u32 pad;
|
||||
HidNpadCommonLifo layouts[7];
|
||||
HidNpadSixAxisSensorLifo sixaxis[6];
|
||||
u32 device_type;
|
||||
u32 reserved;
|
||||
HidNpadSystemProperties system_properties;
|
||||
HidNpadSystemButtonProperties system_button_properties;
|
||||
u32 batteryCharge[3];
|
||||
u32 battery_level[3];
|
||||
union {
|
||||
struct { // [1.0.0-3.0.2]
|
||||
u8 nfc_xcd_device_handle_header[0x20];
|
||||
@ -749,19 +764,19 @@ typedef struct HidNpad {
|
||||
};
|
||||
u8 mutex[0x8];
|
||||
u8 unk_x4210[0x18];
|
||||
HidCommonStateHeader npad_gc_trigger_header;
|
||||
HidNpadGcTriggerStateEntry npad_gc_trigger_state[17];
|
||||
u32 unk_x43E0;
|
||||
u32 unk_x43E4;
|
||||
u32 unk_x43E8;
|
||||
u8 unk_x43EC[0xC14];
|
||||
HidNpadGcTriggerLifo gc_trigger_lifo;
|
||||
u32 lark_type_l_and_main; ///< LarkTypeLAndMain
|
||||
u32 lark_type_r; ///< LarkTypeR
|
||||
u32 lucia_type; ///< LuciaType
|
||||
u32 unk_x43EC;
|
||||
u8 unk_x43F0[0xC10];
|
||||
} HidNpad;
|
||||
|
||||
// End HidNpad
|
||||
|
||||
/// HidConsoleSixAxisSensor
|
||||
typedef struct {
|
||||
u64 timestamp; ///< Timestamp in samples
|
||||
u64 sampling_number; ///< Timestamp in samples
|
||||
u8 is_at_rest; ///< IsSevenSixAxisSensorAtRest
|
||||
u8 pad[0x3];
|
||||
float verticalization_error; ///< VerticalizationError
|
||||
@ -772,9 +787,9 @@ typedef struct {
|
||||
/// HidSharedMemory
|
||||
typedef struct HidSharedMemory {
|
||||
u8 debug_pad[0x400];
|
||||
HidTouchScreenLifo touchscreen;
|
||||
HidMouseLifo mouse;
|
||||
HidKeyboardLifo keyboard;
|
||||
HidTouchScreenSharedMemoryFormat touchscreen;
|
||||
HidMouseSharedMemoryFormat mouse;
|
||||
HidKeyboardSharedMemoryFormat keyboard;
|
||||
u8 digitizer[0x1000]; ///< [10.0.0+] Digitizer [1.0.0-9.2.0] BasicXpad
|
||||
u8 home_button[0x200];
|
||||
u8 sleep_button[0x200];
|
||||
@ -790,7 +805,7 @@ typedef struct HidSharedMemory {
|
||||
/// HidSevenSixAxisSensorState
|
||||
typedef struct {
|
||||
u64 timestamp0;
|
||||
u64 timestamp1;
|
||||
u64 sampling_number;
|
||||
|
||||
u64 unk_x10;
|
||||
float unk_x18[10];
|
||||
@ -798,15 +813,15 @@ typedef struct {
|
||||
|
||||
/// HidSevenSixAxisSensorStateEntry
|
||||
typedef struct {
|
||||
u64 timestamp;
|
||||
u64 sampling_number;
|
||||
u64 unused;
|
||||
HidSevenSixAxisSensorState state;
|
||||
} HidSevenSixAxisSensorStateEntry;
|
||||
|
||||
/// HidSevenSixAxisSensorStates
|
||||
typedef struct {
|
||||
HidCommonStateHeader header;
|
||||
HidSevenSixAxisSensorStateEntry entries[0x21];
|
||||
HidCommonLifoHeader header;
|
||||
HidSevenSixAxisSensorStateEntry storage[0x21];
|
||||
} HidSevenSixAxisSensorStates;
|
||||
|
||||
/// HidSixAxisSensorHandle
|
||||
|
@ -28,7 +28,7 @@ static RwLock g_hidLock;
|
||||
static HidTouchScreenState g_touchScreenState;
|
||||
static HidMouseState g_mouseState;
|
||||
static HidKeyboardState g_keyboardState;
|
||||
static HidNpadStateEntry g_controllerEntries[10];
|
||||
static HidNpadCommonState g_controllerEntries[10];
|
||||
|
||||
static u64 g_mouseOld, g_mouseHeld, g_mouseDown, g_mouseUp;
|
||||
static u64 g_keyboardModOld, g_keyboardModHeld, g_keyboardModDown, g_keyboardModUp;
|
||||
@ -258,7 +258,7 @@ void hidScanInput(void) {
|
||||
}
|
||||
|
||||
g_controllerP1AutoID = CONTROLLER_HANDHELD;
|
||||
if (g_controllerEntries[CONTROLLER_PLAYER_1].connectionState & CONTROLLER_STATE_CONNECTED)
|
||||
if (g_controllerEntries[CONTROLLER_PLAYER_1].attributes & CONTROLLER_STATE_CONNECTED)
|
||||
g_controllerP1AutoID = CONTROLLER_PLAYER_1;
|
||||
|
||||
rwlockWriteUnlock(&g_hidLock);
|
||||
@ -326,7 +326,7 @@ Result hidGetNpadControllerColorSplit(HidNpadIdType id, HidNpadControllerColor *
|
||||
}
|
||||
|
||||
u32 hidGetNpadDeviceType(HidNpadIdType id) {
|
||||
return atomic_load_explicit(&_hidGetNpadInternalState(id)->deviceType, memory_order_acquire);
|
||||
return atomic_load_explicit(&_hidGetNpadInternalState(id)->device_type, memory_order_acquire);
|
||||
}
|
||||
|
||||
void hidGetNpadSystemProperties(HidNpadIdType id, HidNpadSystemProperties *out) {
|
||||
@ -338,7 +338,7 @@ void hidGetNpadSystemButtonProperties(HidNpadIdType id, HidNpadSystemButtonPrope
|
||||
}
|
||||
|
||||
static void _hidGetNpadPowerInfo(HidNpad *npad, HidPowerInfo *info, u32 powerInfo, u32 i) {
|
||||
info->batteryCharge = atomic_load_explicit(&npad->batteryCharge[i], memory_order_acquire);
|
||||
info->batteryCharge = atomic_load_explicit(&npad->battery_level[i], memory_order_acquire);
|
||||
if (info->batteryCharge > 4) info->batteryCharge = 4; // sdknso would Abort when this occurs.
|
||||
|
||||
info->isCharging = (powerInfo & BIT(i)) != 0;
|
||||
@ -372,29 +372,29 @@ u8 hidGetAppletFooterUiTypes(HidNpadIdType id) {
|
||||
return atomic_load_explicit(&_hidGetNpadInternalState(id)->applet_footer_ui_type, memory_order_acquire);
|
||||
}
|
||||
|
||||
static size_t _hidGetStates(HidCommonStateHeader *header, void* in_states, size_t max_states, size_t state_offset, size_t sampling_number_offset, void* states, size_t entrysize, size_t count) {
|
||||
s32 total_entries = (s32)atomic_load_explicit(&header->max_entry, memory_order_acquire);
|
||||
static size_t _hidGetStates(HidCommonLifoHeader *header, void* in_states, size_t max_states, size_t state_offset, size_t sampling_number_offset, void* states, size_t entrysize, size_t count) {
|
||||
s32 total_entries = (s32)atomic_load_explicit(&header->count, memory_order_acquire);
|
||||
if (total_entries < 0) total_entries = 0;
|
||||
if (total_entries > count) total_entries = count;
|
||||
s32 latest_entry = (s32)atomic_load_explicit(&header->latest_entry, memory_order_acquire);
|
||||
s32 tail = (s32)atomic_load_explicit(&header->tail, memory_order_acquire);
|
||||
|
||||
for (s32 i=0; i<total_entries; i++) {
|
||||
s32 entrypos = (((latest_entry + (max_states+1)) - total_entries) + i) % max_states;
|
||||
HidCommonStateEntry *state_entry = (HidCommonStateEntry*)((uintptr_t)in_states + entrypos*(state_offset+entrysize));
|
||||
s32 entrypos = (((tail + (max_states+1)) - total_entries) + i) % max_states;
|
||||
void* state_entry = (void*)((uintptr_t)in_states + entrypos*(state_offset+entrysize));
|
||||
void* out_state = (void*)((uintptr_t)states + (total_entries-i-1)*entrysize);
|
||||
void* out_state_prev = (void*)((uintptr_t)states + (total_entries-i)*entrysize);
|
||||
|
||||
u64 timestamp0=0, timestamp1=0;
|
||||
u64 sampling_number0=0, sampling_number1=0;
|
||||
|
||||
timestamp0 = atomic_load_explicit(&state_entry->timestamp, memory_order_acquire);
|
||||
sampling_number0 = atomic_load_explicit((u64*)state_entry, memory_order_acquire);
|
||||
memcpy(out_state, (void*)((uintptr_t)state_entry + state_offset), entrysize);
|
||||
timestamp1 = atomic_load_explicit(&state_entry->timestamp, memory_order_acquire);
|
||||
sampling_number1 = atomic_load_explicit((u64*)state_entry, memory_order_acquire);
|
||||
|
||||
if (timestamp0 != timestamp1 || (i>0 && *((u64*)((uintptr_t)out_state+sampling_number_offset)) - *((u64*)((uintptr_t)out_state_prev+sampling_number_offset)) != 1)) {
|
||||
s32 tmpcount = (s32)atomic_load_explicit(&header->max_entry, memory_order_acquire);
|
||||
if (sampling_number0 != sampling_number1 || (i>0 && *((u64*)((uintptr_t)out_state+sampling_number_offset)) - *((u64*)((uintptr_t)out_state_prev+sampling_number_offset)) != 1)) {
|
||||
s32 tmpcount = (s32)atomic_load_explicit(&header->count, memory_order_acquire);
|
||||
tmpcount = total_entries < tmpcount ? tmpcount : total_entries;
|
||||
total_entries = tmpcount < count ? tmpcount : count;
|
||||
latest_entry = (s32)atomic_load_explicit(&header->latest_entry, memory_order_acquire);
|
||||
tail = (s32)atomic_load_explicit(&header->tail, memory_order_acquire);
|
||||
|
||||
i=-1;
|
||||
}
|
||||
@ -413,7 +413,7 @@ size_t hidGetTouchScreenStates(HidTouchScreenState *states, size_t count) {
|
||||
if (sharedmem == NULL)
|
||||
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized));
|
||||
|
||||
size_t total = _hidGetStates(&sharedmem->touchscreen.header, sharedmem->touchscreen.entries, 17, offsetof(HidTouchScreenStateAtomicStorage,state), offsetof(HidTouchScreenState,timestamp), states, sizeof(HidTouchScreenState), count);
|
||||
size_t total = _hidGetStates(&sharedmem->touchscreen.lifo.header, sharedmem->touchscreen.lifo.storage, 17, offsetof(HidTouchScreenStateAtomicStorage,state), offsetof(HidTouchScreenState,sampling_number), states, sizeof(HidTouchScreenState), count);
|
||||
size_t max_touches = sizeof(states[0].touches)/sizeof(states[0].touches[0]);
|
||||
for (size_t i=0; i<total; i++) {
|
||||
if (states[i].count > max_touches) states[i].count = max_touches;
|
||||
@ -431,7 +431,7 @@ size_t hidGetMouseStates(HidMouseState *states, size_t count) {
|
||||
if (sharedmem == NULL)
|
||||
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized));
|
||||
|
||||
size_t total = _hidGetStates(&sharedmem->mouse.header, sharedmem->mouse.entries, 17, offsetof(HidMouseStateAtomicStorage,state), offsetof(HidMouseState,timestamp), states, sizeof(HidMouseState), count);
|
||||
size_t total = _hidGetStates(&sharedmem->mouse.lifo.header, sharedmem->mouse.lifo.storage, 17, offsetof(HidMouseStateAtomicStorage,state), offsetof(HidMouseState,sampling_number), states, sizeof(HidMouseState), count);
|
||||
return total;
|
||||
}
|
||||
|
||||
@ -445,7 +445,7 @@ size_t hidGetKeyboardStates(HidKeyboardState *states, size_t count) {
|
||||
if (sharedmem == NULL)
|
||||
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized));
|
||||
|
||||
size_t total = _hidGetStates(&sharedmem->keyboard.header, sharedmem->keyboard.entries, 17, offsetof(HidKeyboardStateAtomicStorage,state), offsetof(HidKeyboardState,timestamp), states, sizeof(HidKeyboardState), count);
|
||||
size_t total = _hidGetStates(&sharedmem->keyboard.lifo.header, sharedmem->keyboard.lifo.storage, 17, offsetof(HidKeyboardStateAtomicStorage,state), offsetof(HidKeyboardState,sampling_number), states, sizeof(HidKeyboardState), count);
|
||||
return total;
|
||||
}
|
||||
|
||||
@ -454,10 +454,10 @@ void hidInitializeNpad(void) {
|
||||
if (R_FAILED(rc)) diagAbortWithResult(rc);
|
||||
}
|
||||
|
||||
static size_t _hidGetNpadStates(HidNpad *npad, u32 layout, HidNpadStateEntry *states, size_t count) {
|
||||
HidControllerLayout *states_buf = &npad->layouts[layout];
|
||||
static size_t _hidGetNpadStates(HidNpad *npad, u32 layout, HidNpadCommonState *states, size_t count) {
|
||||
HidNpadCommonLifo *states_buf = &npad->layouts[layout];
|
||||
if (count > 17) count = 17;
|
||||
return _hidGetStates(&states_buf->header, states_buf->entries, 17, offsetof(HidControllerInputEntry,state), offsetof(HidNpadStateEntry,timestamp), states, sizeof(HidNpadStateEntry), count);
|
||||
return _hidGetStates(&states_buf->header, states_buf->storage, 17, offsetof(HidNpadCommonStateAtomicStorage,state), offsetof(HidNpadCommonState,sampling_number), states, sizeof(HidNpadCommonState), count);
|
||||
}
|
||||
|
||||
size_t hidGetNpadStatesFullKey(HidNpadIdType id, HidNpadFullKeyState *states, size_t count) {
|
||||
@ -506,25 +506,25 @@ size_t hidGetNpadStatesJoyRight(HidNpadIdType id, HidNpadJoyRightState *states,
|
||||
}
|
||||
|
||||
size_t hidGetNpadStatesGc(HidNpadIdType id, HidNpadGcState *states, size_t count) {
|
||||
HidNpadStateEntry tmp_entries[17];
|
||||
HidNpadCommonState tmp_entries[17];
|
||||
HidNpadGcTriggerState tmp_entries_trigger[17];
|
||||
|
||||
HidNpad *npad = _hidGetNpadInternalState(id);
|
||||
size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count);
|
||||
size_t total2 = _hidGetStates(&npad->npad_gc_trigger_header, npad->npad_gc_trigger_state, 17, offsetof(HidNpadGcTriggerStateEntry,state), offsetof(HidNpadGcTriggerState,timestamp), tmp_entries_trigger, sizeof(HidNpadGcTriggerState), total);
|
||||
size_t total2 = _hidGetStates(&npad->gc_trigger_lifo.header, npad->gc_trigger_lifo.storage, 17, offsetof(HidNpadGcTriggerStateAtomicStorage,state), offsetof(HidNpadGcTriggerState,sampling_number), tmp_entries_trigger, sizeof(HidNpadGcTriggerState), total);
|
||||
if (total2 < total) total = total2;
|
||||
|
||||
memset(states, 0, sizeof(HidNpadGcState) * total);
|
||||
|
||||
for (size_t i=0; i<total; i++) {
|
||||
states[i].timestamp = tmp_entries[i].timestamp;
|
||||
states[i].sampling_number = tmp_entries[i].sampling_number;
|
||||
|
||||
// sdknso would handle button-bitmasking with ControlPadRestriction here.
|
||||
|
||||
states[i].buttons = tmp_entries[i].buttons;
|
||||
|
||||
memcpy(states[i].joysticks, tmp_entries[i].joysticks, sizeof(tmp_entries[i].joysticks)); // sdknso uses index 0 for the src here.
|
||||
states[i].connectionState = tmp_entries[i].connectionState;
|
||||
states[i].attributes = tmp_entries[i].attributes;
|
||||
|
||||
states[i].l_trigger = tmp_entries_trigger[i].l_trigger;
|
||||
states[i].r_trigger = tmp_entries_trigger[i].r_trigger;
|
||||
@ -543,18 +543,18 @@ size_t hidGetNpadStatesPalma(HidNpadIdType id, HidNpadPalmaState *states, size_t
|
||||
}
|
||||
|
||||
size_t hidGetNpadStatesLark(HidNpadIdType id, HidNpadLarkState *states, size_t count) {
|
||||
HidNpadStateEntry tmp_entries[17];
|
||||
HidNpadCommonState tmp_entries[17];
|
||||
|
||||
HidNpad *npad = _hidGetNpadInternalState(id);
|
||||
size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count);
|
||||
|
||||
memset(states, 0, sizeof(HidNpadLarkState) * total);
|
||||
|
||||
u32 unk = atomic_load_explicit(&npad->unk_x43E0, memory_order_acquire);
|
||||
if (!(unk>=1 && unk<=4)) unk = 0;
|
||||
u32 lark_type_l_and_main = atomic_load_explicit(&npad->lark_type_l_and_main, memory_order_acquire);
|
||||
if (!(lark_type_l_and_main>=1 && lark_type_l_and_main<=4)) lark_type_l_and_main = 0;
|
||||
|
||||
for (size_t i=0; i<total; i++) {
|
||||
states[i].timestamp = tmp_entries[i].timestamp;
|
||||
states[i].sampling_number = tmp_entries[i].sampling_number;
|
||||
|
||||
// sdknso would handle button-bitmasking with ControlPadRestriction here.
|
||||
|
||||
@ -562,56 +562,56 @@ size_t hidGetNpadStatesLark(HidNpadIdType id, HidNpadLarkState *states, size_t c
|
||||
|
||||
// Leave joysticks state at zeros.
|
||||
|
||||
states[i].connectionState = tmp_entries[i].connectionState;
|
||||
states[i].unk = unk;
|
||||
states[i].attributes = tmp_entries[i].attributes;
|
||||
states[i].lark_type_l_and_main = lark_type_l_and_main;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
size_t hidGetNpadStatesHandheldLark(HidNpadIdType id, HidNpadHandheldLarkState *states, size_t count) {
|
||||
HidNpadStateEntry tmp_entries[17];
|
||||
HidNpadCommonState tmp_entries[17];
|
||||
|
||||
HidNpad *npad = _hidGetNpadInternalState(id);
|
||||
size_t total = _hidGetNpadStates(npad, 1, tmp_entries, count);
|
||||
|
||||
memset(states, 0, sizeof(HidNpadHandheldLarkState) * total);
|
||||
|
||||
u32 unk0 = atomic_load_explicit(&npad->unk_x43E0, memory_order_acquire);
|
||||
if (!(unk0>=1 && unk0<=4)) unk0 = 0;
|
||||
u32 lark_type_l_and_main = atomic_load_explicit(&npad->lark_type_l_and_main, memory_order_acquire);
|
||||
if (!(lark_type_l_and_main>=1 && lark_type_l_and_main<=4)) lark_type_l_and_main = 0;
|
||||
|
||||
u32 unk1 = atomic_load_explicit(&npad->unk_x43E4, memory_order_acquire);
|
||||
if (!(unk1>=1 && unk1<=4)) unk1 = 0;
|
||||
u32 lark_type_r = atomic_load_explicit(&npad->lark_type_r, memory_order_acquire);
|
||||
if (!(lark_type_r>=1 && lark_type_r<=4)) lark_type_r = 0;
|
||||
|
||||
for (size_t i=0; i<total; i++) {
|
||||
states[i].timestamp = tmp_entries[i].timestamp;
|
||||
states[i].sampling_number = tmp_entries[i].sampling_number;
|
||||
|
||||
// sdknso would handle button-bitmasking with ControlPadRestriction here.
|
||||
|
||||
states[i].buttons = tmp_entries[i].buttons;
|
||||
|
||||
memcpy(states[i].joysticks, tmp_entries[i].joysticks, sizeof(tmp_entries[i].joysticks)); // sdknso uses index 0 for the src here.
|
||||
states[i].connectionState = tmp_entries[i].connectionState;
|
||||
states[i].unk0 = unk0;
|
||||
states[i].unk1 = unk1;
|
||||
states[i].attributes = tmp_entries[i].attributes;
|
||||
states[i].lark_type_l_and_main = lark_type_l_and_main;
|
||||
states[i].lark_type_r = lark_type_r;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
size_t hidGetNpadStatesLucia(HidNpadIdType id, HidNpadLuciaState *states, size_t count) {
|
||||
HidNpadStateEntry tmp_entries[17];
|
||||
HidNpadCommonState tmp_entries[17];
|
||||
|
||||
HidNpad *npad = _hidGetNpadInternalState(id);
|
||||
size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count);
|
||||
|
||||
memset(states, 0, sizeof(HidNpadLuciaState) * total);
|
||||
|
||||
u32 unk = atomic_load_explicit(&npad->unk_x43E8, memory_order_acquire);
|
||||
if (!(unk>=1 && unk<=3)) unk = 0;
|
||||
u32 lucia_type = atomic_load_explicit(&npad->lucia_type, memory_order_acquire);
|
||||
if (!(lucia_type>=1 && lucia_type<=3)) lucia_type = 0;
|
||||
|
||||
for (size_t i=0; i<total; i++) {
|
||||
states[i].timestamp = tmp_entries[i].timestamp;
|
||||
states[i].sampling_number = tmp_entries[i].sampling_number;
|
||||
|
||||
// sdknso would handle button-bitmasking with ControlPadRestriction here.
|
||||
|
||||
@ -619,8 +619,8 @@ size_t hidGetNpadStatesLucia(HidNpadIdType id, HidNpadLuciaState *states, size_t
|
||||
|
||||
// Leave joysticks state at zeros.
|
||||
|
||||
states[i].connectionState = tmp_entries[i].connectionState;
|
||||
states[i].unk = unk;
|
||||
states[i].attributes = tmp_entries[i].attributes;
|
||||
states[i].lucia_type = lucia_type;
|
||||
}
|
||||
|
||||
return total;
|
||||
@ -696,7 +696,7 @@ size_t hidGetSixAxisSensorStates(HidSixAxisSensorHandle handle, HidSixAxisSensor
|
||||
}
|
||||
|
||||
HidNpad *npad = _hidGetNpadInternalState(handle.npad_id_type);
|
||||
size_t total = _hidGetStates(&npad->sixaxis[index].header, npad->sixaxis[index].entries, 17, offsetof(HidNpadSixAxisSensorState,state), offsetof(HidSixAxisSensorState,timestamp), states, sizeof(HidSixAxisSensorState), count);
|
||||
size_t total = _hidGetStates(&npad->sixaxis[index].header, npad->sixaxis[index].storage, 17, offsetof(HidSixAxisSensorStateAtomicStorage,state), offsetof(HidSixAxisSensorState,sampling_number), states, sizeof(HidSixAxisSensorState), count);
|
||||
return total;
|
||||
}
|
||||
|
||||
@ -706,7 +706,7 @@ bool hidIsControllerConnected(HidControllerID id) {
|
||||
if (id < 0 || id > 9) return 0;
|
||||
|
||||
rwlockReadLock(&g_hidLock);
|
||||
bool flag = (g_controllerEntries[id].connectionState & CONTROLLER_STATE_CONNECTED) != 0;
|
||||
bool flag = (g_controllerEntries[id].attributes & CONTROLLER_STATE_CONNECTED) != 0;
|
||||
rwlockReadUnlock(&g_hidLock);
|
||||
return flag;
|
||||
}
|
||||
@ -1602,7 +1602,7 @@ Result hidGetSevenSixAxisSensorStates(HidSevenSixAxisSensorState *states, size_t
|
||||
|
||||
HidSevenSixAxisSensorStates *states_buf = (HidSevenSixAxisSensorStates*)g_sevenSixAxisSensorBuffer;
|
||||
|
||||
size_t total = _hidGetStates(&states_buf->header, states_buf->entries, 0x21, offsetof(HidSevenSixAxisSensorStateEntry,state), offsetof(HidSevenSixAxisSensorState,timestamp1), states, sizeof(HidSevenSixAxisSensorState), count);
|
||||
size_t total = _hidGetStates(&states_buf->header, states_buf->storage, 0x21, offsetof(HidSevenSixAxisSensorStateEntry,state), offsetof(HidSevenSixAxisSensorState,sampling_number), states, sizeof(HidSevenSixAxisSensorState), count);
|
||||
if (total_out) *total_out = total;
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user