Skip to content

Commit

Permalink
breeze: lights: Detect maximum brightness dynamically
Browse files Browse the repository at this point in the history
Change-Id: I9385be40a8598e1142bb3844446b6bbeb5aab008
Signed-off-by: SamarV-121 <samarvispute121@pm.me>
Signed-off-by: Sarthak Roy <sarthakroy2002@gmail.com>
Signed-off-by: SakthivelNadar <s2234nadar@gmail.com>
  • Loading branch information
vasishath authored and Hadenix committed Oct 20, 2023
1 parent 2ade9c5 commit 07002c9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions light/Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#define TRIGGER "trigger"

#define MAX_LED_BRIGHTNESS 13
#define MAX_LCD_BRIGHTNESS 2047

#define MAX_BRIGHTNESS "max_brightness"

namespace {
/*
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 07002c9

Please sign in to comment.