diff --git a/nx/include/switch.h b/nx/include/switch.h index b51d25d5..69bcc034 100644 --- a/nx/include/switch.h +++ b/nx/include/switch.h @@ -64,6 +64,7 @@ extern "C" { #include "switch/services/bpc.h" #include "switch/services/pcv.h" #include "switch/services/clkrst.h" +#include "switch/services/fan.h" #include "switch/services/psm.h" #include "switch/services/spsm.h" //#include "switch/services/bsd.h" Use instead diff --git a/nx/include/switch/services/fan.h b/nx/include/switch/services/fan.h new file mode 100644 index 00000000..bb119b91 --- /dev/null +++ b/nx/include/switch/services/fan.h @@ -0,0 +1,11 @@ +#pragma once +#include "../types.h" +#include "../sf/service.h" + +Result fanInitialize(void); +void fanExit(void); +Service* fanGetServiceSession(void); +Service* fanGetServiceSession_Controller(void); + +Result fanSetRotationSpeedLevel(float level); +Result fanGetRotationSpeedLevel(float *level); \ No newline at end of file diff --git a/nx/source/services/fan.c b/nx/source/services/fan.c new file mode 100644 index 00000000..399feb3e --- /dev/null +++ b/nx/source/services/fan.c @@ -0,0 +1,46 @@ +#define NX_SERVICE_ASSUME_NON_DOMAIN +#include "service_guard.h" +#include "services/fan.h" + +static Service g_fanSrv; +static Service g_fanCtl; + +static Result _fanOpenController(void); + +NX_GENERATE_SERVICE_GUARD(fan); + +Result _fanInitialize(void) { + Result rc = smGetService(&g_fanSrv, "fan"); + + if (R_SUCCEEDED(rc)) rc = _fanOpenController(); + + return rc; +} + +void _fanCleanup(void) { + serviceClose(&g_fanSrv); +} + +Result _fanOpenController(void) { + u32 in = 0x3d000001; + return serviceDispatchIn(&g_fanSrv, 0, in, + .out_num_objects = 1, + .out_objects = &g_fanCtl + ); +} + +Service* fanGetServiceSession(void) { + return &g_fanSrv; +} + +Service* fanGetServiceSession_Controller(void) { + return &g_fanCtl; +} + +Result fanSetRotationSpeedLevel(float level) { + return serviceDispatchOut(&g_fanCtl, 0, level); +} + +Result fanGetRotationSpeedLevel(float *level) { + return serviceDispatchOut(&g_fanCtl, 2, *level); +}