mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 20:42:44 +02:00
lbl: Updated for new-ipc and improved docs.
This commit is contained in:
parent
d25144afbd
commit
d3376aa816
@ -6,10 +6,15 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
#include "../services/sm.h"
|
#include "../sf/service.h"
|
||||||
|
|
||||||
|
/// Initialize lbl.
|
||||||
Result lblInitialize(void);
|
Result lblInitialize(void);
|
||||||
|
|
||||||
|
/// Exit lbl.
|
||||||
void lblExit(void);
|
void lblExit(void);
|
||||||
|
|
||||||
|
/// Gets the Service object for the actual lbl service session.
|
||||||
Service* lblGetServiceSession(void);
|
Service* lblGetServiceSession(void);
|
||||||
|
|
||||||
Result lblSwitchBacklightOn(u64 fade_time);
|
Result lblSwitchBacklightOn(u64 fade_time);
|
||||||
|
@ -1,179 +1,56 @@
|
|||||||
#include "types.h"
|
#define NX_SERVICE_ASSUME_NON_DOMAIN
|
||||||
#include "result.h"
|
#include "service_guard.h"
|
||||||
#include "arm/atomics.h"
|
|
||||||
#include "kernel/ipc.h"
|
|
||||||
#include "services/lbl.h"
|
#include "services/lbl.h"
|
||||||
#include "services/sm.h"
|
|
||||||
|
|
||||||
static Service g_lblSrv;
|
static Service g_lblSrv;
|
||||||
static u64 g_refCnt;
|
|
||||||
|
|
||||||
Result lblInitialize(void) {
|
NX_GENERATE_SERVICE_GUARD(lbl);
|
||||||
Result rc = 0;
|
|
||||||
|
|
||||||
atomicIncrement64(&g_refCnt);
|
Result _lblInitialize(void) {
|
||||||
|
return smGetService(&g_lblSrv, "lbl");
|
||||||
if (serviceIsActive(&g_lblSrv))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
rc = smGetService(&g_lblSrv, "lbl");
|
|
||||||
|
|
||||||
if (R_FAILED(rc)) lblExit();
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lblExit(void) {
|
void _lblCleanup(void) {
|
||||||
if (atomicDecrement64(&g_refCnt) == 0) {
|
|
||||||
serviceClose(&g_lblSrv);
|
serviceClose(&g_lblSrv);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Service* lblGetServiceSession(void) {
|
Service* lblGetServiceSession(void) {
|
||||||
return &g_lblSrv;
|
return &g_lblSrv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result _lblCmdNoIO(u64 cmd_id) {
|
static Result _lblCmdNoIO(u32 cmd_id) {
|
||||||
IpcCommand c;
|
return serviceDispatch(&g_lblSrv, cmd_id);
|
||||||
ipcInitialize(&c);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 cmd_id;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_lblSrv, &c, sizeof(*raw));
|
|
||||||
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = cmd_id;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_lblSrv);
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_lblSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Result _lblSwitchBacklight(u64 cmd_id, u64 fade_time) {
|
static Result _lblCmdInU64NoOut(u64 inval, u32 cmd_id) {
|
||||||
IpcCommand c;
|
return serviceDispatchIn(&g_lblSrv, cmd_id, inval);
|
||||||
ipcInitialize(&c);
|
}
|
||||||
|
|
||||||
struct {
|
static Result _lblCmdNoInOutU8(u8 *out, u32 cmd_id) {
|
||||||
u64 magic;
|
return serviceDispatchOut(&g_lblSrv, cmd_id, *out);
|
||||||
u64 cmd_id;
|
}
|
||||||
u64 fade_time;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_lblSrv, &c, sizeof(*raw));
|
|
||||||
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = cmd_id;
|
|
||||||
raw->fade_time = fade_time;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_lblSrv);
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_lblSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
static Result _lblCmdNoInOutBool(bool *out, u32 cmd_id) {
|
||||||
|
u8 tmpout=0;
|
||||||
|
Result rc = _lblCmdNoInOutU8(&tmpout, cmd_id);
|
||||||
|
if (R_SUCCEEDED(rc) && out) *out = tmpout!=0;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result lblSwitchBacklightOn(u64 fade_time) {
|
Result lblSwitchBacklightOn(u64 fade_time) {
|
||||||
return _lblSwitchBacklight(6, fade_time);
|
return _lblCmdInU64NoOut(fade_time, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result lblSwitchBacklightOff(u64 fade_time) {
|
Result lblSwitchBacklightOff(u64 fade_time) {
|
||||||
return _lblSwitchBacklight(7, fade_time);
|
return _lblCmdInU64NoOut(fade_time, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result lblSetCurrentBrightnessSetting(float brightness) {
|
Result lblSetCurrentBrightnessSetting(float brightness) {
|
||||||
IpcCommand c;
|
return serviceDispatchIn(&g_lblSrv, 2, brightness);
|
||||||
ipcInitialize(&c);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 cmd_id;
|
|
||||||
float value;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_lblSrv, &c, sizeof(*raw));
|
|
||||||
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = 2;
|
|
||||||
raw->value = brightness;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_lblSrv);
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_lblSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result lblGetCurrentBrightnessSetting(float *out_value) {
|
Result lblGetCurrentBrightnessSetting(float *out_value) {
|
||||||
IpcCommand c;
|
return serviceDispatchOut(&g_lblSrv, 3, *out_value);
|
||||||
ipcInitialize(&c);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 cmd_id;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_lblSrv, &c, sizeof(*raw));
|
|
||||||
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = 3;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_lblSrv);
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
float brightness;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_lblSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
if (R_SUCCEEDED(rc))
|
|
||||||
*out_value = resp->brightness;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result lblEnableAutoBrightnessControl(void) {
|
Result lblEnableAutoBrightnessControl(void) {
|
||||||
@ -185,36 +62,5 @@ Result lblDisableAutoBrightnessControl(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result lblIsAutoBrightnessControlEnabled(bool *out_value){
|
Result lblIsAutoBrightnessControlEnabled(bool *out_value){
|
||||||
IpcCommand c;
|
return _lblCmdNoInOutBool(out_value, 14);
|
||||||
ipcInitialize(&c);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 cmd_id;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_lblSrv, &c, sizeof(*raw));
|
|
||||||
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = 14;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_lblSrv);
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
u8 isEnabled;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_lblSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
if (R_SUCCEEDED(rc))
|
|
||||||
*out_value = resp->isEnabled != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user