hid: Added hidGetTouchScreenStates, which hidScanInput now uses.

Struct adjustments.
This commit is contained in:
yellows8 2020-11-19 12:55:31 -05:00 committed by fincs
parent 2c26092608
commit 1c82758c03
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
2 changed files with 60 additions and 58 deletions

View File

@ -467,47 +467,39 @@ typedef struct HidCommonStateEntry {
// Begin HidTouchScreen // Begin HidTouchScreen
/// HidTouchScreenHeader /// HidTouchState
typedef struct HidTouchScreenHeader { typedef struct HidTouchState {
u64 timestampTicks; u64 delta_time;
u64 numEntries; u32 attributes;
u64 latestEntry; u32 finger_id;
u64 maxEntryIndex;
u64 timestamp;
} HidTouchScreenHeader;
/// HidTouchScreenEntryHeader
typedef struct HidTouchScreenEntryHeader {
u64 timestamp;
u64 numTouches;
} HidTouchScreenEntryHeader;
/// HidTouchScreenEntryTouch
typedef struct HidTouchScreenEntryTouch {
u64 timestamp;
u32 padding;
u32 touchIndex;
u32 x; u32 x;
u32 y; u32 y;
u32 diameterX; u32 diameter_x;
u32 diameterY; u32 diameter_y;
u32 angle; u32 rotation_angle;
u32 padding_2; u32 reserved;
} HidTouchScreenEntryTouch; } HidTouchState;
/// HidTouchScreenEntry /// HidTouchScreenState
typedef struct HidTouchScreenEntry { typedef struct HidTouchScreenState {
HidTouchScreenEntryHeader header; u64 timestamp;
HidTouchScreenEntryTouch touches[16]; s32 count;
u64 unk; u32 reserved;
} HidTouchScreenEntry; HidTouchState touches[16];
} HidTouchScreenState;
/// HidTouchScreen /// HidTouchScreenStateAtomicStorage
typedef struct HidTouchScreen { typedef struct HidTouchScreenStateAtomicStorage {
HidTouchScreenHeader header; u64 timestamp;
HidTouchScreenEntry entries[17]; HidTouchScreenState state;
u8 padding[0x3c0]; } HidTouchScreenStateAtomicStorage;
} HidTouchScreen;
/// HidTouchScreenLifo
typedef struct HidTouchScreenLifo {
HidCommonStateHeader header;
HidTouchScreenStateAtomicStorage entries[17];
u8 padding[0x3c8];
} HidTouchScreenLifo;
// End HidTouchScreen // End HidTouchScreen
@ -769,7 +761,7 @@ typedef struct {
/// HidSharedMemory /// HidSharedMemory
typedef struct HidSharedMemory { typedef struct HidSharedMemory {
u8 debug_pad[0x400]; u8 debug_pad[0x400];
HidTouchScreen touchscreen; HidTouchScreenLifo touchscreen;
HidMouse mouse; HidMouse mouse;
HidKeyboard keyboard; HidKeyboard keyboard;
u8 digitizer[0x1000]; ///< [10.0.0+] Digitizer [1.0.0-9.2.0] BasicXpad u8 digitizer[0x1000]; ///< [10.0.0+] Digitizer [1.0.0-9.2.0] BasicXpad
@ -877,6 +869,8 @@ void* hidGetSharedmemAddr(void);
void hidScanInput(void); void hidScanInput(void);
size_t hidGetTouchScreenStates(HidTouchScreenState *states, size_t count);
/// Gets a bitfield of \ref HidNpadStyleTag for the specified controller. /// Gets a bitfield of \ref HidNpadStyleTag for the specified controller.
u32 hidGetNpadStyleSet(HidNpadIdType id); u32 hidGetNpadStyleSet(HidNpadIdType id);

View File

@ -16,7 +16,7 @@ static Service g_hidIAppletResource;
static Service g_hidIActiveVibrationDeviceList; static Service g_hidIActiveVibrationDeviceList;
static SharedMemory g_hidSharedmem; static SharedMemory g_hidSharedmem;
static HidTouchScreenEntry g_touchEntry; static HidTouchScreenState g_touchScreenState;
static HidMouseEntry *g_mouseEntry; static HidMouseEntry *g_mouseEntry;
static HidMouse g_mouse; static HidMouse g_mouse;
static HidKeyboardEntry g_keyboardEntry; static HidKeyboardEntry g_keyboardEntry;
@ -27,7 +27,7 @@ static u64 g_keyboardModOld, g_keyboardModHeld, g_keyboardModDown, g_keyboardMod
static u32 g_keyboardOld[8], g_keyboardHeld[8], g_keyboardDown[8], g_keyboardUp[8]; static u32 g_keyboardOld[8], g_keyboardHeld[8], g_keyboardDown[8], g_keyboardUp[8];
static u64 g_controllerOld[10], g_controllerHeld[10], g_controllerDown[10], g_controllerUp[10]; static u64 g_controllerOld[10], g_controllerHeld[10], g_controllerDown[10], g_controllerUp[10];
static u64 g_touchTimestamp, g_mouseTimestamp, g_keyboardTimestamp; static u64 g_mouseTimestamp, g_keyboardTimestamp;
static HidControllerID g_controllerP1AutoID; static HidControllerID g_controllerP1AutoID;
@ -119,7 +119,7 @@ void hidReset(void) {
rwlockWriteLock(&g_hidLock); rwlockWriteLock(&g_hidLock);
// Reset internal state // Reset internal state
memset(&g_touchEntry, 0, sizeof(HidTouchScreenEntry)); memset(&g_touchScreenState, 0, sizeof(HidTouchScreenState));
memset(&g_mouse, 0, sizeof(HidMouse)); memset(&g_mouse, 0, sizeof(HidMouse));
memset(&g_keyboardEntry, 0, sizeof(HidKeyboardEntry)); memset(&g_keyboardEntry, 0, sizeof(HidKeyboardEntry));
memset(g_controllerEntries, 0, sizeof(g_controllerEntries)); memset(g_controllerEntries, 0, sizeof(g_controllerEntries));
@ -132,7 +132,7 @@ void hidReset(void) {
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
g_controllerOld[i] = g_controllerHeld[i] = g_controllerDown[i] = g_controllerUp[i] = 0; g_controllerOld[i] = g_controllerHeld[i] = g_controllerDown[i] = g_controllerUp[i] = 0;
g_touchTimestamp = g_mouseTimestamp = g_keyboardTimestamp = 0; g_mouseTimestamp = g_keyboardTimestamp = 0;
g_controllerP1AutoID = CONTROLLER_HANDHELD; g_controllerP1AutoID = CONTROLLER_HANDHELD;
@ -161,18 +161,13 @@ void hidScanInput(void) {
g_keyboardModHeld = 0; g_keyboardModHeld = 0;
memset(g_keyboardHeld, 0, sizeof(g_keyboardHeld)); memset(g_keyboardHeld, 0, sizeof(g_keyboardHeld));
memset(g_controllerHeld, 0, sizeof(g_controllerHeld)); memset(g_controllerHeld, 0, sizeof(g_controllerHeld));
memset(&g_touchEntry, 0, sizeof(HidTouchScreenEntry)); memset(&g_touchScreenState, 0, sizeof(HidTouchScreenState));
memset(&g_mouse, 0, sizeof(HidMouse)); memset(&g_mouse, 0, sizeof(HidMouse));
memset(&g_keyboardEntry, 0, sizeof(HidKeyboardEntry)); memset(&g_keyboardEntry, 0, sizeof(HidKeyboardEntry));
memset(g_controllerEntries, 0, sizeof(g_controllerEntries)); memset(g_controllerEntries, 0, sizeof(g_controllerEntries));
u64 latestTouchEntry = sharedMem->touchscreen.header.latestEntry; if (hidGetTouchScreenStates(&g_touchScreenState, 1)) {
HidTouchScreenEntry *newTouchEntry = &sharedMem->touchscreen.entries[latestTouchEntry]; if (g_touchScreenState.count >= 1)
if ((s64)(newTouchEntry->header.timestamp - g_touchTimestamp) >= 0) {
memcpy(&g_touchEntry, newTouchEntry, sizeof(HidTouchScreenEntry));
g_touchTimestamp = newTouchEntry->header.timestamp;
if (hidTouchCount())
g_controllerHeld[CONTROLLER_HANDHELD] |= KEY_TOUCH; g_controllerHeld[CONTROLLER_HANDHELD] |= KEY_TOUCH;
} }
@ -418,6 +413,19 @@ static size_t _hidGetStates(HidCommonStateHeader *header, void* in_states, size_
return total_entries; return total_entries;
} }
size_t hidGetTouchScreenStates(HidTouchScreenState *states, size_t count) {
HidSharedMemory *sharedmem = (HidSharedMemory*)hidGetSharedmemAddr();
if (sharedmem == NULL)
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized));
size_t total = _hidGetStates(&sharedmem->touchscreen.header, sharedmem->touchscreen.entries, offsetof(HidTouchScreenState,timestamp), 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;
}
return total;
}
static size_t _hidGetNpadStates(HidNpad *npad, u32 layout, HidNpadStateEntry *states, size_t count) { static size_t _hidGetNpadStates(HidNpad *npad, u32 layout, HidNpadStateEntry *states, size_t count) {
HidControllerLayout *states_buf = &npad->layouts[layout]; HidControllerLayout *states_buf = &npad->layouts[layout];
if (count > 17) count = 17; if (count > 17) count = 17;
@ -821,22 +829,22 @@ bool hidKeyboardUp(HidKeyboardScancode key) {
} }
u32 hidTouchCount(void) { u32 hidTouchCount(void) {
return g_touchEntry.header.numTouches; return g_touchScreenState.count;
} }
void hidTouchRead(touchPosition *pos, u32 point_id) { void hidTouchRead(touchPosition *pos, u32 point_id) {
if (pos) { if (pos) {
if (point_id >= g_touchEntry.header.numTouches) { if (point_id >= g_touchScreenState.count) {
memset(pos, 0, sizeof(touchPosition)); memset(pos, 0, sizeof(touchPosition));
return; return;
} }
pos->id = g_touchEntry.touches[point_id].touchIndex; pos->id = g_touchScreenState.touches[point_id].finger_id;
pos->px = g_touchEntry.touches[point_id].x; pos->px = g_touchScreenState.touches[point_id].x;
pos->py = g_touchEntry.touches[point_id].y; pos->py = g_touchScreenState.touches[point_id].y;
pos->dx = g_touchEntry.touches[point_id].diameterX; pos->dx = g_touchScreenState.touches[point_id].diameter_x;
pos->dy = g_touchEntry.touches[point_id].diameterY; pos->dy = g_touchScreenState.touches[point_id].diameter_y;
pos->angle = g_touchEntry.touches[point_id].angle; pos->angle = g_touchScreenState.touches[point_id].rotation_angle;
} }
} }