2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-07-27 13:48:33 -04:00
|
|
|
|
2021-09-30 16:11:47 -04:00
|
|
|
#include <cmath>
|
2018-07-27 13:48:33 -04:00
|
|
|
#include <memory>
|
|
|
|
|
2018-07-27 14:01:17 -04:00
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "core/hle/ipc_helpers.h"
|
2018-07-27 13:48:33 -04:00
|
|
|
#include "core/hle/service/lbl/lbl.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
#include "core/hle/service/sm/sm.h"
|
|
|
|
|
|
|
|
namespace Service::LBL {
|
|
|
|
|
|
|
|
class LBL final : public ServiceFramework<LBL> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit LBL(Core::System& system_) : ServiceFramework{system_, "lbl"} {
|
2018-07-27 13:48:33 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-10-21 16:15:29 -04:00
|
|
|
{0, nullptr, "SaveCurrentSetting"},
|
|
|
|
{1, nullptr, "LoadCurrentSetting"},
|
2021-01-20 08:46:03 -05:00
|
|
|
{2, &LBL::SetCurrentBrightnessSetting, "SetCurrentBrightnessSetting"},
|
|
|
|
{3, &LBL::GetCurrentBrightnessSetting, "GetCurrentBrightnessSetting"},
|
2018-10-21 16:15:29 -04:00
|
|
|
{4, nullptr, "ApplyCurrentBrightnessSettingToBacklight"},
|
|
|
|
{5, nullptr, "GetBrightnessSettingAppliedToBacklight"},
|
2021-01-20 08:46:03 -05:00
|
|
|
{6, &LBL::SwitchBacklightOn, "SwitchBacklightOn"},
|
|
|
|
{7, &LBL::SwitchBacklightOff, "SwitchBacklightOff"},
|
|
|
|
{8, &LBL::GetBacklightSwitchStatus, "GetBacklightSwitchStatus"},
|
|
|
|
{9, &LBL::EnableDimming, "EnableDimming"},
|
|
|
|
{10, &LBL::DisableDimming, "DisableDimming"},
|
|
|
|
{11, &LBL::IsDimmingEnabled, "IsDimmingEnabled"},
|
|
|
|
{12, &LBL::EnableAutoBrightnessControl, "EnableAutoBrightnessControl"},
|
|
|
|
{13, &LBL::DisableAutoBrightnessControl, "DisableAutoBrightnessControl"},
|
|
|
|
{14, &LBL::IsAutoBrightnessControlEnabled, "IsAutoBrightnessControlEnabled"},
|
|
|
|
{15, &LBL::SetAmbientLightSensorValue, "SetAmbientLightSensorValue"},
|
|
|
|
{16, &LBL::GetAmbientLightSensorValue, "GetAmbientLightSensorValue"},
|
|
|
|
{17, &LBL::SetBrightnessReflectionDelayLevel, "SetBrightnessReflectionDelayLevel"},
|
|
|
|
{18, &LBL::GetBrightnessReflectionDelayLevel, "GetBrightnessReflectionDelayLevel"},
|
|
|
|
{19, &LBL::SetCurrentBrightnessMapping, "SetCurrentBrightnessMapping"},
|
|
|
|
{20, &LBL::GetCurrentBrightnessMapping, "GetCurrentBrightnessMapping"},
|
|
|
|
{21, &LBL::SetCurrentAmbientLightSensorMapping, "SetCurrentAmbientLightSensorMapping"},
|
|
|
|
{22, &LBL::GetCurrentAmbientLightSensorMapping, "GetCurrentAmbientLightSensorMapping"},
|
|
|
|
{23, &LBL::IsAmbientLightSensorAvailable, "IsAmbientLightSensorAvailable"},
|
|
|
|
{24, &LBL::SetCurrentBrightnessSettingForVrMode, "SetCurrentBrightnessSettingForVrMode"},
|
|
|
|
{25, &LBL::GetCurrentBrightnessSettingForVrMode, "GetCurrentBrightnessSettingForVrMode"},
|
2018-07-27 14:01:17 -04:00
|
|
|
{26, &LBL::EnableVrMode, "EnableVrMode"},
|
|
|
|
{27, &LBL::DisableVrMode, "DisableVrMode"},
|
2018-10-21 16:15:29 -04:00
|
|
|
{28, &LBL::IsVrModeEnabled, "IsVrModeEnabled"},
|
2020-06-27 06:43:33 -04:00
|
|
|
{29, nullptr, "IsAutoBrightnessControlSupported"},
|
2018-07-27 13:48:33 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-07-27 14:01:17 -04:00
|
|
|
|
|
|
|
private:
|
2021-01-20 08:46:03 -05:00
|
|
|
enum class BacklightSwitchStatus : u32 {
|
|
|
|
Off = 0,
|
|
|
|
On = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetCurrentBrightnessSetting(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
auto brightness = rp.Pop<float>();
|
|
|
|
|
|
|
|
if (!std::isfinite(brightness)) {
|
|
|
|
LOG_ERROR(Service_LBL, "Brightness is infinite!");
|
|
|
|
brightness = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_LBL, "called brightness={}", brightness);
|
|
|
|
|
|
|
|
current_brightness = brightness;
|
|
|
|
update_instantly = true;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetCurrentBrightnessSetting(Kernel::HLERequestContext& ctx) {
|
|
|
|
auto brightness = current_brightness;
|
|
|
|
if (!std::isfinite(brightness)) {
|
|
|
|
LOG_ERROR(Service_LBL, "Brightness is infinite!");
|
|
|
|
brightness = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_LBL, "called brightness={}", brightness);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
rb.Push(brightness);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchBacklightOn(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto fade_time = rp.Pop<u64_le>();
|
|
|
|
LOG_WARNING(Service_LBL, "(STUBBED) called, fade_time={}", fade_time);
|
|
|
|
|
|
|
|
backlight_enabled = true;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchBacklightOff(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto fade_time = rp.Pop<u64_le>();
|
|
|
|
LOG_WARNING(Service_LBL, "(STUBBED) called, fade_time={}", fade_time);
|
|
|
|
|
|
|
|
backlight_enabled = false;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetBacklightSwitchStatus(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
rb.PushEnum<BacklightSwitchStatus>(backlight_enabled ? BacklightSwitchStatus::On
|
|
|
|
: BacklightSwitchStatus::Off);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableDimming(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
dimming = true;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisableDimming(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
dimming = false;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void IsDimmingEnabled(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
rb.Push(dimming);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EnableAutoBrightnessControl(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
auto_brightness = true;
|
|
|
|
update_instantly = true;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisableAutoBrightnessControl(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
auto_brightness = false;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void IsAutoBrightnessControlEnabled(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
rb.Push(auto_brightness);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAmbientLightSensorValue(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto light_value = rp.Pop<float>();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_LBL, "called light_value={}", light_value);
|
|
|
|
|
|
|
|
ambient_light_value = light_value;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetAmbientLightSensorValue(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
rb.Push(ambient_light_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetBrightnessReflectionDelayLevel(Kernel::HLERequestContext& ctx) {
|
|
|
|
// This is Intentional, this function does absolutely nothing
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetBrightnessReflectionDelayLevel(Kernel::HLERequestContext& ctx) {
|
|
|
|
// This is intentional, the function is hard coded to return 0.0f on hardware
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
rb.Push(0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCurrentBrightnessMapping(Kernel::HLERequestContext& ctx) {
|
|
|
|
// This is Intentional, this function does absolutely nothing
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetCurrentBrightnessMapping(Kernel::HLERequestContext& ctx) {
|
|
|
|
// This is Intentional, this function does absolutely nothing
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
// This function is suppose to return something but it seems like it doesn't
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCurrentAmbientLightSensorMapping(Kernel::HLERequestContext& ctx) {
|
|
|
|
// This is Intentional, this function does absolutely nothing
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetCurrentAmbientLightSensorMapping(Kernel::HLERequestContext& ctx) {
|
|
|
|
// This is Intentional, this function does absolutely nothing
|
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
// This function is suppose to return something but it seems like it doesn't
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsAmbientLightSensorAvailable(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_WARNING(Service_LBL, "(STUBBED) called");
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
// TODO(ogniK): Only return true if there's no device error
|
|
|
|
rb.Push(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCurrentBrightnessSettingForVrMode(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
auto brightness = rp.Pop<float>();
|
|
|
|
|
|
|
|
if (!std::isfinite(brightness)) {
|
|
|
|
LOG_ERROR(Service_LBL, "Brightness is infinite!");
|
|
|
|
brightness = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_LBL, "called brightness={}", brightness);
|
|
|
|
|
|
|
|
current_vr_brightness = brightness;
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetCurrentBrightnessSettingForVrMode(Kernel::HLERequestContext& ctx) {
|
|
|
|
auto brightness = current_vr_brightness;
|
|
|
|
if (!std::isfinite(brightness)) {
|
|
|
|
LOG_ERROR(Service_LBL, "Brightness is infinite!");
|
|
|
|
brightness = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_LBL, "called brightness={}", brightness);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-01-20 08:46:03 -05:00
|
|
|
rb.Push(brightness);
|
|
|
|
}
|
|
|
|
|
2018-07-27 14:01:17 -04:00
|
|
|
void EnableVrMode(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
2018-07-27 14:01:17 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-07-27 14:01:17 -04:00
|
|
|
|
|
|
|
vr_mode_enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisableVrMode(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
2018-07-27 14:01:17 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-07-27 14:01:17 -04:00
|
|
|
|
|
|
|
vr_mode_enabled = false;
|
|
|
|
}
|
|
|
|
|
2018-10-21 16:15:29 -04:00
|
|
|
void IsVrModeEnabled(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_LBL, "called");
|
|
|
|
|
2018-07-27 14:01:17 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2018-07-27 14:01:17 -04:00
|
|
|
rb.Push(vr_mode_enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool vr_mode_enabled = false;
|
2021-01-20 08:46:03 -05:00
|
|
|
float current_brightness = 1.0f;
|
|
|
|
float ambient_light_value = 0.0f;
|
|
|
|
float current_vr_brightness = 1.0f;
|
|
|
|
bool dimming = true;
|
|
|
|
bool backlight_enabled = true;
|
|
|
|
bool update_instantly = false;
|
|
|
|
bool auto_brightness = false; // TODO(ogniK): Move to system settings
|
2018-07-27 13:48:33 -04:00
|
|
|
};
|
|
|
|
|
2020-11-26 15:19:08 -05:00
|
|
|
void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
|
|
|
|
std::make_shared<LBL>(system)->InstallAsService(sm);
|
2018-07-27 13:48:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::LBL
|