davinci: light: Detect maximum brightness dynamically

Change-Id: I9385be40a8598e1142bb3844446b6bbeb5aab008
This commit is contained in:
vasishath 2018-06-06 08:57:37 -04:00 committed by Arian
parent b7413b8791
commit 4979e2c172
No known key found for this signature in database
GPG Key ID: 48029380598CE3B9

View File

@ -27,9 +27,7 @@
#define BREATH "breath" #define BREATH "breath"
#define BRIGHTNESS "brightness" #define BRIGHTNESS "brightness"
#define MAX_BRIGHTNESS "max_brightness"
#define MAX_LED_BRIGHTNESS 255
#define MAX_LCD_BRIGHTNESS 4095
namespace { namespace {
/* /*
@ -50,6 +48,22 @@ static void set(std::string path, int value) {
set(path, std::to_string(value)); set(path, std::to_string(value));
} }
/*
* Read max brightness from path and close file.
*/
static int getMaxBrightness(std::string path) {
std::ifstream file(path);
int value;
if (!file.is_open()) {
ALOGW("failed to read from %s", path.c_str());
return 0;
}
file >> value;
return value;
}
static uint32_t getBrightness(const LightState& state) { static uint32_t getBrightness(const LightState& state) {
uint32_t alpha, red, green, blue; uint32_t alpha, red, green, blue;
@ -84,12 +98,12 @@ static inline uint32_t getScaledBrightness(const LightState& state, uint32_t max
} }
static void handleBacklight(const LightState& state) { static void handleBacklight(const LightState& state) {
uint32_t brightness = getScaledBrightness(state, MAX_LCD_BRIGHTNESS); uint32_t brightness = getScaledBrightness(state, getMaxBrightness(PANEL_LED MAX_BRIGHTNESS));
set(PANEL_LED BRIGHTNESS, brightness); set(PANEL_LED BRIGHTNESS, brightness);
} }
static void handleNotification(const LightState& state) { static void handleNotification(const LightState& state) {
uint32_t notificationBrightness = getScaledBrightness(state, MAX_LED_BRIGHTNESS); uint32_t notificationBrightness = getScaledBrightness(state, getMaxBrightness(NOTIFICATION_LED MAX_BRIGHTNESS));
/* Disable breathing or blinking */ /* Disable breathing or blinking */
set(NOTIFICATION_LED BREATH, 0); set(NOTIFICATION_LED BREATH, 0);