From 7e07d1edf0a6601a0daa96f51c5ce346ebd30da2 Mon Sep 17 00:00:00 2001 From: HookedBehemoth Date: Fri, 28 Feb 2020 19:23:10 +0100 Subject: [PATCH] add fan service (#376) --- nx/include/switch.h | 1 + nx/include/switch/services/fan.h | 32 ++++++++++++++++++++++++++ nx/source/services/fan.c | 39 ++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 nx/include/switch/services/fan.h create mode 100644 nx/source/services/fan.c diff --git a/nx/include/switch.h b/nx/include/switch.h index eed43dc6..5b06c4fd 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..b77bf4b4 --- /dev/null +++ b/nx/include/switch/services/fan.h @@ -0,0 +1,32 @@ +/** + * @file fan.h + * @brief Fan service IPC wrapper. + * @author Behemoth + * @copyright libnx Authors + */ +#pragma once +#include "../types.h" +#include "../sf/service.h" + +typedef struct { + Service s; +} FanController; + +/// Initialize fan. +Result fanInitialize(void); + +/// Exit fan. +void fanExit(void); + +/// Gets the Service object for the actual fan service session. +Service* fanGetServiceSession(void); + +/// Opens IController session. +Result fanOpenController(FanController *out, u32 device_code); + +/// Close IController session. +void fanControllerClose(FanController *controller); + +/// @warning Disabling your fan can damage your system. +Result fanControllerSetRotationSpeedLevel(FanController *controller, float level); +Result fanControllerGetRotationSpeedLevel(FanController *controller, float *level); diff --git a/nx/source/services/fan.c b/nx/source/services/fan.c new file mode 100644 index 00000000..1a94d147 --- /dev/null +++ b/nx/source/services/fan.c @@ -0,0 +1,39 @@ +#define NX_SERVICE_ASSUME_NON_DOMAIN +#include "service_guard.h" +#include "services/fan.h" +#include "runtime/hosversion.h" + +static Service g_fanSrv; + +NX_GENERATE_SERVICE_GUARD(fan); + +Result _fanInitialize(void) { + return smGetService(&g_fanSrv, "fan"); +} + +void _fanCleanup(void) { + serviceClose(&g_fanSrv); +} + +Result fanOpenController(FanController *out, u32 device_code) { + return serviceDispatchIn(&g_fanSrv, 0, device_code, + .out_num_objects = 1, + .out_objects = &out->s, + ); +} + +Service* fanGetServiceSession(void) { + return &g_fanSrv; +} + +void fanControllerClose(FanController *controller) { + serviceClose(&controller->s); +} + +Result fanControllerSetRotationSpeedLevel(FanController *controller, float level) { + return serviceDispatchIn(&controller->s, 0, level); +} + +Result fanControllerGetRotationSpeedLevel(FanController *controller, float *level) { + return serviceDispatchOut(&controller->s, 2, *level); +}