This commit is contained in:
Samuel P 2018-08-04 15:30:22 +00:00 committed by GitHub
commit 8225e16c1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 180 additions and 0 deletions

View File

@ -48,6 +48,8 @@ extern "C" {
#include "switch/services/time.h" #include "switch/services/time.h"
#include "switch/services/usb.h" #include "switch/services/usb.h"
#include "switch/services/hid.h" #include "switch/services/hid.h"
#include "switch/services/hid_sys.h"
#include "switch/services/hid_dbg.h"
#include "switch/services/irs.h" #include "switch/services/irs.h"
#include "switch/services/pl.h" #include "switch/services/pl.h"
#include "switch/services/vi.h" #include "switch/services/vi.h"

View File

@ -0,0 +1,17 @@
/**
* @file hid.h
* @brief Human input device (hid:dbg) service IPC wrapper.
* @author p-sam
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
#define HID_DBG_DHB_MAX_TRIES 100
#define HID_DBG_DHB_RC (0x16eca)
Result hidDbgInitialize(void);
void hidDbgExit(void);
/// Enables the default behavior of the HOME button (going back to the main menu) if it was disabled
Result hidDbgDeactivateHomeButton();

View File

@ -0,0 +1,14 @@
/**
* @file hid.h
* @brief Human input device (hid:sys) service IPC wrapper.
* @author p-sam
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
Result hidSysInitialize(void);
void hidSysExit(void);
/// Disables the default behavior of the HOME button (going back to the main menu) if it was enabled
Result hidSysActivateHomeButton();

View File

@ -0,0 +1,77 @@
#include "types.h"
#include "arm/atomics.h"
#include "kernel/ipc.h"
#include "services/sm.h"
#include "services/hid_dbg.h"
static Service g_hidDbgSrv;
static u64 g_refCnt;
Result hidDbgInitialize(void)
{
atomicIncrement64(&g_refCnt);
if (serviceIsActive(&g_hidDbgSrv))
return 0;
return smGetService(&g_hidDbgSrv, "hid:dbg");
}
void hidDbgExit(void)
{
if (atomicDecrement64(&g_refCnt) == 0)
{
serviceClose(&g_hidDbgSrv);
}
}
Result _hidDbgDeactivateHomeButton() {
Result rc;
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
} *raw;
raw = ipcPrepareHeader(&c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 110;
rc = serviceIpcDispatch(&g_hidDbgSrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
ipcParse(&r);
struct {
u64 magic;
u64 result;
} *resp = r.Raw;
rc = resp->result;
}
return rc;
}
Result hidDbgDeactivateHomeButton() {
int i = HID_DBG_DHB_MAX_TRIES;
Result rc;
do {
i--;
rc = _hidDbgDeactivateHomeButton();
} while(rc == 0 && i > 0);
if(rc == 0) {
return HID_DBG_DHB_RC;
} else if(rc == HID_DBG_DHB_RC) {
return 0;
}
return rc;
}

View File

@ -0,0 +1,70 @@
#include "types.h"
#include "arm/atomics.h"
#include "kernel/ipc.h"
#include "services/sm.h"
#include "services/applet.h"
#include "services/hid_sys.h"
static Service g_hidSysSrv;
static u64 g_refCnt;
Result hidSysInitialize(void)
{
atomicIncrement64(&g_refCnt);
if (serviceIsActive(&g_hidSysSrv))
return 0;
return smGetService(&g_hidSysSrv, "hid:sys");
}
void hidSysExit(void)
{
if (atomicDecrement64(&g_refCnt) == 0)
{
serviceClose(&g_hidSysSrv);
}
}
Result hidSysActivateHomeButton() {
Result rc;
u64 AppletResourceUserId;
rc = appletGetAppletResourceUserId(&AppletResourceUserId);
if (R_FAILED(rc)) {
AppletResourceUserId = 0;
}
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
u64 AppletResourceUserId;
} *raw;
ipcSendPid(&c);
raw = ipcPrepareHeader(&c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 111;
raw->AppletResourceUserId = AppletResourceUserId;
rc = serviceIpcDispatch(&g_hidSysSrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
ipcParse(&r);
struct {
u64 magic;
u64 result;
} *resp = r.Raw;
rc = resp->result;
}
return rc;
}