sdm660-common: Support button backlight
Change-Id: Id13a42976df428c95c19eae49e1c114f057510bb
This commit is contained in:
parent
98a59e0d2c
commit
93f0b0ba58
3 changed files with 36 additions and 0 deletions
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
|
@ -29,6 +30,8 @@ namespace {
|
|||
#define LEDS "/sys/class/leds/"
|
||||
#define LCD_LED LEDS "lcd-backlight/"
|
||||
#define WHITE LEDS "white/"
|
||||
#define BUTTON LEDS "button-backlight/"
|
||||
#define BUTTON1 LEDS "button-backlight1/"
|
||||
#define BRIGHTNESS "brightness"
|
||||
#define MAX_BRIGHTNESS "max_brightness"
|
||||
#define BLINK "blink"
|
||||
|
@ -127,6 +130,24 @@ Light::Light() {
|
|||
max_led_brightness_ = kDefaultMaxLedBrightness;
|
||||
LOG(ERROR) << "Failed to read max LED brightness, fallback to " << kDefaultMaxLedBrightness;
|
||||
}
|
||||
|
||||
if (!access(BUTTON BRIGHTNESS, W_OK)) {
|
||||
lights_.emplace(std::make_pair(Type::BUTTONS,
|
||||
[this](auto&&... args) { setLightButtons(args...); }));
|
||||
buttons_.emplace_back(BUTTON BRIGHTNESS);
|
||||
|
||||
if (!access(BUTTON1 BRIGHTNESS, W_OK)) {
|
||||
buttons_.emplace_back(BUTTON1 BRIGHTNESS);
|
||||
}
|
||||
|
||||
if (ReadFileToString(BUTTON MAX_BRIGHTNESS, &buf)) {
|
||||
max_button_brightness_ = std::stoi(buf);
|
||||
} else {
|
||||
max_button_brightness_ = kDefaultMaxLedBrightness;
|
||||
LOG(ERROR) << "Failed to read max button brightness, fallback to "
|
||||
<< kDefaultMaxLedBrightness;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Return<Status> Light::setLight(Type type, const LightState& state) {
|
||||
|
@ -156,6 +177,13 @@ void Light::setLightBacklight(Type /*type*/, const LightState& state) {
|
|||
WriteToFile(LCD_LED BRIGHTNESS, brightness);
|
||||
}
|
||||
|
||||
void Light::setLightButtons(Type /*type*/, const LightState& state) {
|
||||
uint32_t brightness = RgbaToBrightness(state.color, max_button_brightness_);
|
||||
for (auto&& button : buttons_) {
|
||||
WriteToFile(button, brightness);
|
||||
}
|
||||
}
|
||||
|
||||
void Light::setLightNotification(Type type, const LightState& state) {
|
||||
bool found = false;
|
||||
for (auto&& [cur_type, cur_state] : notif_states_) {
|
||||
|
|
|
@ -41,9 +41,11 @@ class Light : public ILight {
|
|||
|
||||
private:
|
||||
void setLightBacklight(Type type, const LightState& state);
|
||||
void setLightButtons(Type type, const LightState& state);
|
||||
void setLightNotification(Type type, const LightState& state);
|
||||
void applyNotificationState(const LightState& state);
|
||||
|
||||
uint32_t max_button_brightness_;
|
||||
uint32_t max_led_brightness_;
|
||||
uint32_t max_screen_brightness_;
|
||||
|
||||
|
@ -57,6 +59,8 @@ class Light : public ILight {
|
|||
{Type::NOTIFICATIONS, {}},
|
||||
{Type::BATTERY, {}},
|
||||
}};
|
||||
|
||||
std::vector<std::string> buttons_;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
|
|
@ -16,6 +16,10 @@ on boot
|
|||
chmod 660 /sys/class/leds/white/pause_lo
|
||||
chmod 660 /sys/class/leds/white/ramp_step_ms
|
||||
chmod 660 /sys/class/leds/white/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
|
||||
|
||||
chown system system /sys/class/leds/lcd-backlight/max_brightness
|
||||
|
||||
|
|
Loading…
Reference in a new issue