mirror of
https://github.com/Evolution-X-Devices/device_xiaomi_sm6150-common
synced 2026-01-27 16:26:02 +00:00
* Our maximum brightness is 500. * However, for safety related reason, I have capped this to 255. * 255 is more than sufficient, and I do not want to be responsible for LED damage. * Finding the default percentage took some trial and error, in this case, 59% correlated to 75. Co-authored-by: rahul <rahul@aospa.co> Change-Id: Ie20969362c531391e4c51b22365b74d62ccb8e5e Signed-off-by: John Galt <johngaltfirstrun@gmail.com> Signed-off-by: therealmharc <therealmharc@gmail.com>
82 lines
2.2 KiB
C++
82 lines
2.2 KiB
C++
/*
|
|
* Copyright (C) 2024 LibreMobileOS Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include "CameraProviderExtension.h"
|
|
|
|
#include <fstream>
|
|
|
|
#define TORCH_BRIGHTNESS "brightness"
|
|
#define TORCH_MAX_BRIGHTNESS "max_brightness"
|
|
#define TOGGLE_SWITCH "/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:switch_2/brightness"
|
|
|
|
static std::string kTorchLedPaths[] = {
|
|
"/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:torch_0",
|
|
"/sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm6150l@5:qcom,leds@d300/leds/led:torch_1",
|
|
};
|
|
|
|
/**
|
|
* Write value to path and close file.
|
|
*/
|
|
template <typename T>
|
|
static void set(const std::string& path, const T& value) {
|
|
std::ofstream file(path);
|
|
file << value;
|
|
}
|
|
|
|
/**
|
|
* Read value from the path and close file.
|
|
*/
|
|
template <typename T>
|
|
static T get(const std::string& path, const T& def) {
|
|
std::ifstream file(path);
|
|
T result;
|
|
|
|
file >> result;
|
|
return file.fail() ? def : result;
|
|
}
|
|
|
|
bool supportsTorchStrengthControlExt() {
|
|
return true;
|
|
}
|
|
|
|
bool supportsSetTorchModeExt() {
|
|
return false;
|
|
}
|
|
|
|
int32_t getTorchDefaultStrengthLevelExt() {
|
|
// Our default value is 75. This corresponds to 15%.
|
|
// As we have changed the maximum value, 59% now corresponds to 75.
|
|
return 59;
|
|
}
|
|
|
|
int32_t getTorchMaxStrengthLevelExt() {
|
|
// 255 out of 500 is a sane brightness.
|
|
// Let's cap it to 255 as max, we can go much higher, but I don't want to test this.
|
|
return 255;
|
|
}
|
|
|
|
int32_t getTorchStrengthLevelExt() {
|
|
// We write same value in the both LEDs,
|
|
// so get from one.
|
|
auto node = kTorchLedPaths[0] + "/" + TORCH_BRIGHTNESS;
|
|
return get(node, 0);
|
|
}
|
|
|
|
void setTorchStrengthLevelExt(int32_t torchStrength, bool enabled) {
|
|
set(TOGGLE_SWITCH, 0);
|
|
for (auto& path : kTorchLedPaths) {
|
|
auto node = path + "/" + TORCH_BRIGHTNESS;
|
|
set(node, torchStrength);
|
|
}
|
|
if (enabled)
|
|
set(TOGGLE_SWITCH, 255);
|
|
}
|
|
|
|
void setTorchModeExt(bool enabled) {
|
|
int32_t strength = getTorchDefaultStrengthLevelExt();
|
|
setTorchStrengthLevelExt(enabled ? strength : 0, enabled);
|
|
}
|