sdm660: light: Support Red LED in Lights hal

* keep it for custom kernels

Change-Id: I30d8dcd41be3522b94bd7510c1f9be7569451d04
This commit is contained in:
Max Weffers 2020-04-15 10:08:29 +02:00 committed by OdSazib
parent 3109aa6db9
commit 53c8ca3cdb
No known key found for this signature in database
GPG key ID: CB336514F9F5CF69
3 changed files with 39 additions and 2 deletions

View file

@ -30,6 +30,7 @@ namespace {
#define LEDS "/sys/class/leds/"
#define LCD_LED LEDS "lcd-backlight/"
#define WHITE LEDS "white/"
#define RED LEDS "red/"
#define BUTTON LEDS "button-backlight/"
#define BUTTON1 LEDS "button-backlight1/"
#define BRIGHTNESS "brightness"
@ -128,7 +129,14 @@ Light::Light() {
max_led_brightness_ = std::stoi(buf);
} else {
max_led_brightness_ = kDefaultMaxLedBrightness;
LOG(ERROR) << "Failed to read max LED brightness, fallback to " << kDefaultMaxLedBrightness;
LOG(ERROR) << "Failed to read max white LED brightness, fallback to " << kDefaultMaxLedBrightness;
}
if (ReadFileToString(RED MAX_BRIGHTNESS, &buf)) {
max_red_led_brightness_= std::stoi(buf);
} else {
max_red_led_brightness_ = kDefaultMaxLedBrightness;
LOG(ERROR) << "Failed to read max red LED brightness, fallback to " << kDefaultMaxLedBrightness;
}
if (!access(BUTTON BRIGHTNESS, W_OK)) {
@ -202,9 +210,11 @@ void Light::setLightNotification(Type type, const LightState& state) {
void Light::applyNotificationState(const LightState& state) {
uint32_t white_brightness = RgbaToBrightness(state.color, max_led_brightness_);
uint32_t red_brightness = RgbaToBrightness(state.color, max_red_led_brightness_);
// Turn off the leds (initially)
WriteToFile(WHITE BLINK, 0);
WriteToFile(RED BLINK, 0);
if (state.flashMode == Flash::TIMED && state.flashOnMs > 0 && state.flashOffMs > 0) {
/*
@ -229,8 +239,17 @@ void Light::applyNotificationState(const LightState& state) {
WriteToFile(WHITE PAUSE_HI, static_cast<uint32_t>(pause_hi));
WriteToFile(WHITE RAMP_STEP_MS, static_cast<uint32_t>(step_duration));
WriteToFile(WHITE BLINK, 1);
// Red
WriteToFile(RED START_IDX, 0);
WriteToFile(RED DUTY_PCTS, GetScaledDutyPcts(red_brightness));
WriteToFile(RED PAUSE_LO, static_cast<uint32_t>(state.flashOffMs));
WriteToFile(RED PAUSE_HI, static_cast<uint32_t>(pause_hi));
WriteToFile(RED RAMP_STEP_MS, static_cast<uint32_t>(step_duration));
WriteToFile(RED BLINK, 1);
} else {
WriteToFile(WHITE BRIGHTNESS, white_brightness);
WriteToFile(RED BRIGHTNESS, red_brightness);
}
}

View file

@ -47,6 +47,7 @@ class Light : public ILight {
uint32_t max_button_brightness_;
uint32_t max_led_brightness_;
uint32_t max_red_led_brightness_;
uint32_t max_screen_brightness_;
std::unordered_map<Type, std::function<void(Type type, const LightState&)>> lights_{

View file

@ -17,6 +17,23 @@ on boot
chmod 660 /sys/class/leds/white/ramp_step_ms
chmod 660 /sys/class/leds/white/start_idx
chown system system /sys/class/leds/red/blink
chown system system /sys/class/leds/red/brightness
chown system system /sys/class/leds/red/duty_pcts
chown system system /sys/class/leds/red/max_brightness
chown system system /sys/class/leds/red/pause_hi
chown system system /sys/class/leds/red/pause_lo
chown system system /sys/class/leds/red/ramp_step_ms
chown system system /sys/class/leds/red/start_idx
chmod 660 /sys/class/leds/red/blink
chmod 660 /sys/class/leds/red/brightness
chmod 660 /sys/class/leds/red/duty_pcts
chmod 660 /sys/class/leds/red/pause_hi
chmod 660 /sys/class/leds/red/pause_lo
chmod 660 /sys/class/leds/red/ramp_step_ms
chmod 660 /sys/class/leds/red/start_idx
chown system system /sys/class/leds/button-backlight/max_brightness
chown system system /sys/class/leds/button-backlight1/brightness
chown system system /sys/class/leds/button-backlight1/max_brightness