davinci: fod: Calculate dim amount based on real brightness

Change-Id: I72b7dd1fca426cc442f9a6fa382f413bbaadfc76
This commit is contained in:
Demon000 2019-11-20 13:24:58 +01:00 committed by Arian
parent 22363a500d
commit 7cebc6e538
No known key found for this signature in database
GPG Key ID: 48029380598CE3B9

View File

@ -38,8 +38,18 @@
#define FOD_SENSOR_Y 1931
#define FOD_SENSOR_SIZE 190
#define BRIGHTNESS_PATH "/sys/class/backlight/panel0-backlight/brightness"
namespace {
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;
}
template <typename T>
static void set(const std::string& path, const T& value) {
std::ofstream file(path);
@ -119,14 +129,17 @@ Return<void> FingerprintInscreen::setLongPressEnabled(bool) {
}
Return<int32_t> FingerprintInscreen::getDimAmount(int32_t brightness) {
int realBrightness = get(BRIGHTNESS_PATH, 0);
float alpha;
if (brightness > 62) {
alpha = 1.0 - pow(brightness / 255.0 * 430.0 / 600.0, 0.45);
if (realBrightness > 500) {
alpha = 1.0 - pow(realBrightness / 2047.0 * 430.0 / 600.0, 0.455);
} else {
alpha = 1.0 - pow(brightness / 200.0, 0.45);
alpha = 1.0 - pow(realBrightness / 1680.0, 0.455);
}
(void) brightness;
return 255 * alpha;
}