Add hidTouchCount, hidTouchRead, KEY_TOUCH. Header tweaks.

This commit is contained in:
shinyquagsire23 2017-11-22 17:09:10 -07:00
parent aa458e59f9
commit 63f91dd215
2 changed files with 51 additions and 12 deletions

View File

@ -1,7 +1,7 @@
#include <assert.h>
#include <switch/types.h>
// Begin enums
// Begin enums and output structs
typedef enum
{
@ -259,6 +259,9 @@ typedef enum
KEY_SL = BIT(24), ///< SL
KEY_SR = BIT(25), ///< SR
// Pseudo-key for at least one finger on the touch screen
KEY_TOUCH = BIT(26),
// Buttons by orientation (for single Joy-Con), also works with Joy-Con pairs, Pro Controller
KEY_JOYCON_RIGHT = BIT(0),
KEY_JOYCON_DOWN = BIT(1),
@ -292,17 +295,26 @@ typedef enum
CONTROLLER_UNKNOWN = 9,
} HIDControllerID;
// End enums
typedef struct touchPosition
{
u32 px;
u32 py;
u32 dx;
u32 dy;
u32 angle;
} touchPosition;
// End enums and output structs
// Begin HIDTouchScreen
typedef struct HIDTouchScreenHeader
{
u64 timestamp;
u64 timestampTicks;
u64 numEntries;
u64 latestEntry;
u64 maxEntryIndex;
u64 timestamp_2;
u64 timestamp;
} HIDTouchScreenHeader;
static_assert(sizeof(HIDTouchScreenHeader) == 0x28, "HID touch screen header structure has incorrect size");
@ -316,13 +328,14 @@ static_assert(sizeof(HIDTouchScreenEntryHeader) == 0x10, "HID touch screen entry
typedef struct HIDTouchScreenEntryTouch
{
u64 timestamp;
u64 unk_1;
u32 padding;
u32 touchIndex;
u32 x;
u32 y;
u32 diameterX;
u32 diameterY;
u32 angle;
u32 unk_2;
u32 padding_2;
} HIDTouchScreenEntryTouch;
static_assert(sizeof(HIDTouchScreenEntryTouch) == 0x28, "HID touch screen touch structure has incorrect size");
@ -330,14 +343,15 @@ typedef struct HIDTouchScreenEntry
{
HIDTouchScreenEntryHeader header;
HIDTouchScreenEntryTouch touches[16];
u64 unk;
} HIDTouchScreenEntry;
static_assert(sizeof(HIDTouchScreenEntry) == 0x290, "HID touch screen entry structure has incorrect size");
static_assert(sizeof(HIDTouchScreenEntry) == 0x298, "HID touch screen entry structure has incorrect size");
typedef struct HIDTouchScreen
{
HIDTouchScreenHeader header;
HIDTouchScreenEntry entries[17];
u8 padding[0x448];
u8 padding[0x3c0];
} HIDTouchScreen;
static_assert(sizeof(HIDTouchScreen) == 0x3000, "HID touch screen structure has incorrect size");
@ -347,7 +361,7 @@ static_assert(sizeof(HIDTouchScreen) == 0x3000, "HID touch screen structure has
typedef struct HIDMouseHeader
{
u64 timestamp;
u64 timestampTicks;
u64 numEntries;
u64 latestEntry;
u64 maxEntryIndex;
@ -382,7 +396,7 @@ static_assert(sizeof(HIDMouse) == 0x400, "HID mouse structure has incorrect size
typedef struct HIDKeyboardHeader
{
u64 timestamp;
u64 timestampTicks;
u64 numEntries;
u64 latestEntry;
u64 maxEntryIndex;
@ -436,7 +450,7 @@ static_assert(sizeof(HIDControllerHeader) == 0x28, "HID controller header struct
typedef struct HIDControllerLayoutHeader
{
u64 timestamp;
u64 timestampTicks;
u64 numEntries;
u64 latestEntry;
u64 maxEntryIndex;
@ -522,3 +536,6 @@ bool hidKeyboardModifierUp(HIDKeyboardModifier modifier);
bool hidKeyboardHeld(HIDKeyboardScancode key);
bool hidKeyboardDown(HIDKeyboardScancode key);
bool hidKeyboardUp(HIDKeyboardScancode key);
u32 hidTouchCount(void);
void hidTouchRead(touchPosition *pos, u32 point_id);

View File

@ -137,6 +137,9 @@ void hidScanInput(void) {
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;
}
u64 latestMouseEntry = sharedMem->mouse.header.latestEntry;
@ -176,7 +179,7 @@ void hidScanInput(void) {
memcpy(&g_controllerEntries[i], newInputEntry, sizeof(HIDControllerInputEntry));
g_controllerTimestamps[i] = newInputEntry->timestamp;
g_controllerHeld[i] = g_controllerEntries[i].buttons;
g_controllerHeld[i] |= g_controllerEntries[i].buttons;
}
g_controllerDown[i] = (~g_controllerOld[i]) & g_controllerHeld[i];
@ -238,6 +241,25 @@ bool hidKeyboardUp(HIDKeyboardScancode key) {
return g_keyboardUp[key / 32] & (1 << (key % 32));
}
u32 hidTouchCount(void) {
return g_touchEntry.header.numTouches;
}
void hidTouchRead(touchPosition *pos, u32 point_id) {
if (pos) {
if (point_id >= g_touchEntry.header.numTouches) {
memset(pos, 0, sizeof(touchPosition));
return;
}
pos->px = g_touchEntry.touches[point_id].x;
pos->py = g_touchEntry.touches[point_id].y;
pos->dx = g_touchEntry.touches[point_id].diameterX;
pos->dy = g_touchEntry.touches[point_id].diameterY;
pos->angle = g_touchEntry.touches[point_id].angle;
}
}
static Result _hidCreateAppletResource(Handle sessionhandle, Handle* handle_out, u64 AppletResourceUserId) {
IpcCommand c;
ipcInitialize(&c);