From 7cebc6e5383c0a1ba6db84b1008ce48f88f356e6 Mon Sep 17 00:00:00 2001 From: Demon000 Date: Wed, 20 Nov 2019 13:24:58 +0100 Subject: [PATCH] davinci: fod: Calculate dim amount based on real brightness Change-Id: I72b7dd1fca426cc442f9a6fa382f413bbaadfc76 --- fod/FingerprintInscreen.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/fod/FingerprintInscreen.cpp b/fod/FingerprintInscreen.cpp index 1f6c666..93f2049 100644 --- a/fod/FingerprintInscreen.cpp +++ b/fod/FingerprintInscreen.cpp @@ -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 +static T get(const std::string& path, const T& def) { + std::ifstream file(path); + T result; + file >> result; + return file.fail() ? def : result; +} + template static void set(const std::string& path, const T& value) { std::ofstream file(path); @@ -119,14 +129,17 @@ Return FingerprintInscreen::setLongPressEnabled(bool) { } Return 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; }