fan: expose fanOpenController

This commit is contained in:
HookedBehemoth 2020-02-28 18:49:48 +01:00
parent 11c55b3189
commit 48eb64a53e
2 changed files with 16 additions and 25 deletions

View File

@ -8,6 +8,10 @@
#include "../types.h" #include "../types.h"
#include "../sf/service.h" #include "../sf/service.h"
typedef struct {
Service s;
} FanController;
/// Initialize fan. /// Initialize fan.
Result fanInitialize(void); Result fanInitialize(void);
@ -17,9 +21,9 @@ void fanExit(void);
/// Gets the Service object for the actual fan service session. /// Gets the Service object for the actual fan service session.
Service* fanGetServiceSession(void); Service* fanGetServiceSession(void);
/// Gets the Service object for the actual fan controller service session. /// Opens IController session.
Service* fanGetServiceSession_Controller(void); Result fanOpenController(FanController *out, u32 device_code);
/// @warning Disabling your fan can damage your system. /// @warning Disabling your fan can damage your system.
Result fanSetRotationSpeedLevel(float level); Result fanSetRotationSpeedLevel(FanController *controller, float level);
Result fanGetRotationSpeedLevel(float *level); Result fanGetRotationSpeedLevel(FanController *controller, float *level);

View File

@ -4,30 +4,21 @@
#include "runtime/hosversion.h" #include "runtime/hosversion.h"
static Service g_fanSrv; static Service g_fanSrv;
static Service g_fanCtl;
static Result _fanOpenController(void);
NX_GENERATE_SERVICE_GUARD(fan); NX_GENERATE_SERVICE_GUARD(fan);
Result _fanInitialize(void) { Result _fanInitialize(void) {
Result rc = smGetService(&g_fanSrv, "fan"); return smGetService(&g_fanSrv, "fan");
if (R_SUCCEEDED(rc)) rc = _fanOpenController();
return rc;
} }
void _fanCleanup(void) { void _fanCleanup(void) {
serviceClose(&g_fanCtl);
serviceClose(&g_fanSrv); serviceClose(&g_fanSrv);
} }
Result _fanOpenController(void) { Result fanOpenController(FanController *out, u32 device_code) {
u32 in = hosversionBefore(7,0,0) ? 1 : 0x3d000001; return serviceDispatchIn(&g_fanSrv, 0, device_code,
return serviceDispatchIn(&g_fanSrv, 0, in,
.out_num_objects = 1, .out_num_objects = 1,
.out_objects = &g_fanCtl .out_objects = &out->s,
); );
} }
@ -35,14 +26,10 @@ Service* fanGetServiceSession(void) {
return &g_fanSrv; return &g_fanSrv;
} }
Service* fanGetServiceSession_Controller(void) { Result fanSetRotationSpeedLevel(FanController *controller, float level) {
return &g_fanCtl; return serviceDispatchIn(&controller->s, 0, level);
} }
Result fanSetRotationSpeedLevel(float level) { Result fanGetRotationSpeedLevel(FanController *controller, float *level) {
return serviceDispatchIn(&g_fanCtl, 0, level); return serviceDispatchOut(&controller->s, 2, *level);
}
Result fanGetRotationSpeedLevel(float *level) {
return serviceDispatchOut(&g_fanCtl, 2, *level);
} }