diff --git a/nx/include/switch/services/fan.h b/nx/include/switch/services/fan.h index 97e9bc56..a9d9b27a 100644 --- a/nx/include/switch/services/fan.h +++ b/nx/include/switch/services/fan.h @@ -8,6 +8,10 @@ #include "../types.h" #include "../sf/service.h" +typedef struct { + Service s; +} FanController; + /// Initialize fan. Result fanInitialize(void); @@ -17,9 +21,9 @@ void fanExit(void); /// Gets the Service object for the actual fan service session. Service* fanGetServiceSession(void); -/// Gets the Service object for the actual fan controller service session. -Service* fanGetServiceSession_Controller(void); +/// Opens IController session. +Result fanOpenController(FanController *out, u32 device_code); /// @warning Disabling your fan can damage your system. -Result fanSetRotationSpeedLevel(float level); -Result fanGetRotationSpeedLevel(float *level); \ No newline at end of file +Result fanSetRotationSpeedLevel(FanController *controller, float level); +Result fanGetRotationSpeedLevel(FanController *controller, float *level); \ No newline at end of file diff --git a/nx/source/services/fan.c b/nx/source/services/fan.c index e6941fa9..e2c6b82c 100644 --- a/nx/source/services/fan.c +++ b/nx/source/services/fan.c @@ -4,30 +4,21 @@ #include "runtime/hosversion.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; + return smGetService(&g_fanSrv, "fan"); } void _fanCleanup(void) { - serviceClose(&g_fanCtl); serviceClose(&g_fanSrv); } -Result _fanOpenController(void) { - u32 in = hosversionBefore(7,0,0) ? 1 : 0x3d000001; - return serviceDispatchIn(&g_fanSrv, 0, in, +Result fanOpenController(FanController *out, u32 device_code) { + return serviceDispatchIn(&g_fanSrv, 0, device_code, .out_num_objects = 1, - .out_objects = &g_fanCtl + .out_objects = &out->s, ); } @@ -35,14 +26,10 @@ Service* fanGetServiceSession(void) { return &g_fanSrv; } -Service* fanGetServiceSession_Controller(void) { - return &g_fanCtl; +Result fanSetRotationSpeedLevel(FanController *controller, float level) { + return serviceDispatchIn(&controller->s, 0, level); } -Result fanSetRotationSpeedLevel(float level) { - return serviceDispatchIn(&g_fanCtl, 0, level); -} - -Result fanGetRotationSpeedLevel(float *level) { - return serviceDispatchOut(&g_fanCtl, 2, *level); +Result fanGetRotationSpeedLevel(FanController *controller, float *level) { + return serviceDispatchOut(&controller->s, 2, *level); }