summaryrefslogtreecommitdiff
path: root/light/Light.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'light/Light.cpp')
-rw-r--r--light/Light.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/light/Light.cpp b/light/Light.cpp
index 0286b6a..1702603 100644
--- a/light/Light.cpp
+++ b/light/Light.cpp
@@ -24,6 +24,7 @@
#include <android-base/file.h>
#include <android-base/logging.h>
+#include <unistd.h>
namespace {
@@ -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;
@@ -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) {
@@ -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_) {