diff --git a/light/Light.cpp b/light/Light.cpp index 00bb9c4..88ec9dc 100644 --- a/light/Light.cpp +++ b/light/Light.cpp @@ -32,7 +32,8 @@ #define TRIGGER "trigger" #define MAX_LED_BRIGHTNESS 13 -#define MAX_LCD_BRIGHTNESS 2047 + +#define MAX_BRIGHTNESS "max_brightness" namespace { /* @@ -53,6 +54,22 @@ static void set(std::string path, int 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) { uint32_t alpha, red, green, blue; @@ -87,7 +104,7 @@ static inline uint32_t getScaledBrightness(const LightState& state, uint32_t max } static void handleBacklight(const LightState& state) { - uint32_t brightness = getScaledBrightness(state, MAX_LCD_BRIGHTNESS); + uint32_t brightness = getScaledBrightness(state, getMaxBrightness(LCD_LED MAX_BRIGHTNESS)); set(LCD_LED BRIGHTNESS, brightness); }