Added HID event code, based on the GSP event code. Added event id check in gspWaitForEvent().
This commit is contained in:
parent
2a1c7c8ea9
commit
9425edc406
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
//See also: http://3dbrew.org/wiki/HID_Services http://3dbrew.org/wiki/HID_Shared_Memory
|
||||
|
||||
#define HID_SHAREDMEM_DEFAULT (0x10000000)
|
||||
|
||||
typedef enum
|
||||
@ -39,6 +41,17 @@ typedef struct
|
||||
s16 dx, dy;
|
||||
} circlePosition;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
HIDEVENT_PAD0 = 0, //"Event signaled by HID-module, when the sharedmem+0(PAD/circle-pad)/+0xA8(touch-screen) region was updated."
|
||||
HIDEVENT_PAD1, //"Event signaled by HID-module, when the sharedmem+0(PAD/circle-pad)/+0xA8(touch-screen) region was updated."
|
||||
HIDEVENT_Accel, //"Event signaled by HID-module, when the sharedmem accelerometer state was updated."
|
||||
HIDEVENT_Gyro, //"Event signaled by HID-module, when the sharedmem gyroscope state was updated."
|
||||
HIDEVENT_DebugPad, //"Event signaled by HID-module, when the sharedmem DebugPad state was updated."
|
||||
|
||||
HIDEVENT_MAX, // used to know how many events there are
|
||||
} HID_Event;
|
||||
|
||||
extern Handle hidMemHandle;
|
||||
extern vu32* hidSharedMem;
|
||||
|
||||
@ -52,6 +65,8 @@ u32 hidKeysUp();
|
||||
void hidTouchRead(touchPosition* pos);
|
||||
void hidCircleRead(circlePosition* pos);
|
||||
|
||||
void hidWaitForEvent(HID_Event id, bool nextEvent);
|
||||
|
||||
// libnds compatibility defines
|
||||
#define scanKeys hidScanInput
|
||||
#define keysHeld hidKeysHeld
|
||||
@ -60,7 +75,7 @@ void hidCircleRead(circlePosition* pos);
|
||||
#define touchRead hidTouchRead
|
||||
#define circleRead hidCircleRead
|
||||
|
||||
Result HIDUSER_GetSharedMem(Handle* outMemHandle);
|
||||
Result HIDUSER_GetHandles(Handle* outMemHandle, Handle *eventpad0, Handle *eventpad1, Handle *eventaccel, Handle *eventgyro, Handle *eventdebugpad);
|
||||
Result HIDUSER_EnableAccelerometer();
|
||||
Result HIDUSER_DisableAccelerometer();
|
||||
Result HIDUSER_EnableGyroscope();
|
||||
|
@ -68,6 +68,8 @@ void gspExitEventHandler()
|
||||
|
||||
void gspWaitForEvent(GSP_Event id, bool nextEvent)
|
||||
{
|
||||
if(id>=GSPEVENT_MAX)return;
|
||||
|
||||
if (nextEvent)
|
||||
svcClearEvent(gspEvents[id]);
|
||||
svcWaitSynchronization(gspEvents[id], U64_MAX);
|
||||
|
@ -8,6 +8,8 @@
|
||||
Handle hidHandle;
|
||||
Handle hidMemHandle;
|
||||
|
||||
Handle hidEvents[5];
|
||||
|
||||
vu32* hidSharedMem;
|
||||
|
||||
static u32 kOld, kHeld, kDown, kUp;
|
||||
@ -24,7 +26,7 @@ Result hidInit(u32* sharedMem)
|
||||
if((ret=srvGetServiceHandle(&hidHandle, "hid:USER")))return ret;
|
||||
|
||||
// Get sharedmem handle.
|
||||
if((ret=HIDUSER_GetSharedMem(&hidMemHandle))) goto cleanup1;
|
||||
if((ret=HIDUSER_GetHandles(&hidMemHandle, &hidEvents[HIDEVENT_PAD0], &hidEvents[HIDEVENT_PAD1], &hidEvents[HIDEVENT_Accel], &hidEvents[HIDEVENT_Gyro], &hidEvents[HIDEVENT_DebugPad]))) goto cleanup1;
|
||||
|
||||
// Map HID shared memory at addr "sharedMem".
|
||||
hidSharedMem=sharedMem;
|
||||
@ -49,6 +51,17 @@ void hidExit()
|
||||
svcCloseHandle(hidHandle);
|
||||
}
|
||||
|
||||
void hidWaitForEvent(HID_Event id, bool nextEvent)
|
||||
{
|
||||
if(id>=HIDEVENT_MAX)return;
|
||||
|
||||
if (nextEvent)
|
||||
svcClearEvent(hidEvents[id]);
|
||||
svcWaitSynchronization(hidEvents[id], U64_MAX);
|
||||
if (!nextEvent)
|
||||
svcClearEvent(hidEvents[id]);
|
||||
}
|
||||
|
||||
void hidScanInput()
|
||||
{
|
||||
kOld = kHeld;
|
||||
@ -93,7 +106,7 @@ void hidCircleRead(circlePosition* pos)
|
||||
if (pos) *pos = cPos;
|
||||
}
|
||||
|
||||
Result HIDUSER_GetSharedMem(Handle* outMemHandle)
|
||||
Result HIDUSER_GetHandles(Handle* outMemHandle, Handle *eventpad0, Handle *eventpad1, Handle *eventaccel, Handle *eventgyro, Handle *eventdebugpad)
|
||||
{
|
||||
u32* cmdbuf=getThreadCommandBuffer();
|
||||
cmdbuf[0]=0xa0000; //request header code
|
||||
@ -103,6 +116,12 @@ Result HIDUSER_GetSharedMem(Handle* outMemHandle)
|
||||
|
||||
if(outMemHandle)*outMemHandle=cmdbuf[3];
|
||||
|
||||
if(eventpad0)*eventpad0=cmdbuf[4];
|
||||
if(eventpad1)*eventpad1=cmdbuf[5];
|
||||
if(eventaccel)*eventaccel=cmdbuf[6];
|
||||
if(eventgyro)*eventgyro=cmdbuf[7];
|
||||
if(eventdebugpad)*eventdebugpad=cmdbuf[8];
|
||||
|
||||
return cmdbuf[1];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user