davinci: light: Detect maximum brightness dynamically
Change-Id: I9385be40a8598e1142bb3844446b6bbeb5aab008
This commit is contained in:
parent
b7413b8791
commit
4979e2c172
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user