Skip to content

Commit

Permalink
sdm660-common: Support button backlight
Browse files Browse the repository at this point in the history
Change-Id: Id13a42976df428c95c19eae49e1c114f057510bb
  • Loading branch information
moetayuko authored and mikeNG committed Apr 29, 2020
1 parent 54bb902 commit f417401
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions light/Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <android-base/file.h>
#include <android-base/logging.h>
#include <unistd.h>

namespace {

Expand All @@ -35,6 +36,8 @@ namespace {
#define LEDS(x) PPCAT(/sys/class/leds, x)
#define LCD_ATTR(x) STRINGIFY(PPCAT(LEDS(lcd-backlight), x))
#define WHITE_ATTR(x) STRINGIFY(PPCAT(LEDS(white), x))
#define BUTTON_ATTR(x) STRINGIFY(PPCAT(LEDS(button-backlight), x))
#define BUTTON1_ATTR(x) STRINGIFY(PPCAT(LEDS(button-backlight1), x))

using ::android::base::ReadFileToString;
using ::android::base::WriteStringToFile;
Expand Down Expand Up @@ -125,6 +128,24 @@ Light::Light() {
max_led_brightness_ = kDefaultMaxLedBrightness;
LOG(ERROR) << "Failed to read max LED brightness, fallback to " << kDefaultMaxLedBrightness;
}

if (!access(BUTTON_ATTR(brightness), W_OK)) {
lights_.emplace(std::make_pair(Type::BUTTONS,
[this](auto&&... args) { setLightButtons(args...); }));
buttons_.emplace_back(BUTTON_ATTR(brightness));

if (!access(BUTTON1_ATTR(brightness), W_OK)) {
buttons_.emplace_back(BUTTON1_ATTR(brightness));
}

if (ReadFileToString(BUTTON_ATTR(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) {
Expand Down Expand Up @@ -154,6 +175,13 @@ void Light::setLightBacklight(Type /*type*/, const LightState& state) {
WriteToFile(LCD_ATTR(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_) {
Expand Down
4 changes: 4 additions & 0 deletions light/Light.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand All @@ -57,6 +59,8 @@ class Light : public ILight {
{Type::NOTIFICATIONS, {}},
{Type::BATTERY, {}},
}};

std::vector<std::string> buttons_;
};

} // namespace implementation
Expand Down
4 changes: 4 additions & 0 deletions light/[email protected]_sdm660.rc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on boot
chown system system /sys/class/leds/white/ramp_step_ms
chown system system /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

start vendor.light-hal-2-0
Expand Down

0 comments on commit f417401

Please sign in to comment.