diff --git a/nx/include/switch.h b/nx/include/switch.h index b51d25d5..eed43dc6 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -84,6 +84,7 @@ extern "C" { #include "switch/services/ns.h" #include "switch/services/ldr.h" #include "switch/services/ro.h" +#include "switch/services/tc.h" #include "switch/services/ts.h" #include "switch/services/pm.h" #include "switch/services/set.h" diff --git a/nx/include/switch/services/tc.h b/nx/include/switch/services/tc.h new file mode 100644 index 00000000..56be6c06 --- /dev/null +++ b/nx/include/switch/services/tc.h @@ -0,0 +1,26 @@ +/** + * @file tc.h + * @brief Temperature control (tc) service IPC wrapper. + * @author Behemoth + * @copyright libnx Authors + */ +#pragma once +#include "../types.h" +#include "../sf/service.h" + +/// Initialize tc. +Result tcInitialize(void); + +/// Exit tc. +void tcExit(void); + +/// Gets the Service for tc. +Service* tcGetServiceSession(void); + +Result tcEnableFanControl(void); +/// @warning Disabling your fan can damage your system. +Result tcDisableFanControl(void); +Result tcIsFanControlEnabled(bool *status); +/// Only available on [5.0.0+]. +Result tcGetSkinTemperatureMilliC(s32 *skinTemp); + diff --git a/nx/source/services/tc.c b/nx/source/services/tc.c new file mode 100644 index 00000000..dae85f88 --- /dev/null +++ b/nx/source/services/tc.c @@ -0,0 +1,47 @@ +#define NX_SERVICE_ASSUME_NON_DOMAIN +#include +#include "service_guard.h" +#include "runtime/hosversion.h" +#include "services/tc.h" + +static Service g_tcSrv; + +NX_GENERATE_SERVICE_GUARD(tc); + +Result _tcInitialize(void) { + return smGetService(&g_tcSrv, "tc"); +} + +void _tcCleanup(void) { + serviceClose(&g_tcSrv); +} + +Service* tcGetServiceSession(void) { + return &g_tcSrv; +} + +static Result _tcNoInNoOut(u32 cmd_id) { + return serviceDispatch(&g_tcSrv, cmd_id); +} + +Result tcEnableFanControl(void) { + return _tcNoInNoOut(6); +} + +Result tcDisableFanControl(void) { + return _tcNoInNoOut(7); +} + +Result tcIsFanControlEnabled(bool *status) { + u8 tmp=0; + Result rc = serviceDispatchOut(&g_tcSrv, 8, tmp); + if (R_SUCCEEDED(rc) && status) *status = tmp & 1; + return rc; +} + +Result tcGetSkinTemperatureMilliC(s32 *skinTemp) { + if (hosversionBefore(5,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&g_tcSrv, 9, *skinTemp); +}