add fan service (#376)

This commit is contained in:
HookedBehemoth 2020-02-28 19:23:10 +01:00 committed by GitHub
parent abc3522724
commit 7e07d1edf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 0 deletions

View File

@ -64,6 +64,7 @@ extern "C" {
#include "switch/services/bpc.h" #include "switch/services/bpc.h"
#include "switch/services/pcv.h" #include "switch/services/pcv.h"
#include "switch/services/clkrst.h" #include "switch/services/clkrst.h"
#include "switch/services/fan.h"
#include "switch/services/psm.h" #include "switch/services/psm.h"
#include "switch/services/spsm.h" #include "switch/services/spsm.h"
//#include "switch/services/bsd.h" Use <sys/socket.h> instead //#include "switch/services/bsd.h" Use <sys/socket.h> instead

View File

@ -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);

39
nx/source/services/fan.c Normal file
View File

@ -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);
}