sm6150-common: lights: Dynamically pick the left or white LED path

Change-Id: I1bc0514c29f9d63554240e1fb95e9aa9625bda6d
This commit is contained in:
Arian 2021-01-23 19:14:48 +01:00
parent 645f7d8c90
commit 4d4f9e343b
No known key found for this signature in database
GPG Key ID: 48029380598CE3B9
2 changed files with 21 additions and 8 deletions

View File

@ -22,18 +22,27 @@
#include <fstream>
#define NOTIFICATION_LED "/sys/class/leds/left/"
#define NOTIFICATION_LED_LEFT(x) "/sys/class/leds/left/" + x
#define NOTIFICATION_LED_WHITE(x) "/sys/class/leds/white/" + x
#define BREATH "breath"
#define BRIGHTNESS "brightness"
#define MAX_BRIGHTNESS "max_brightness"
namespace {
/*
* Get the full path to the led node.
*/
static std::string getLedPath(std::string path) {
std::ifstream left_path(NOTIFICATION_LED_LEFT(path));
return left_path.good() ? NOTIFICATION_LED_LEFT(path) : NOTIFICATION_LED_WHITE(path);
}
/*
* Write value to path and close file.
*/
static void set(std::string path, std::string value) {
std::ofstream file(path);
std::ofstream file(getLedPath(path));
if (!file.is_open()) {
ALOGW("failed to write %s to %s", value.c_str(), path.c_str());
@ -51,7 +60,7 @@ static void set(std::string path, int value) {
* Read max brightness from path and close file.
*/
static int getMaxBrightness(std::string path) {
std::ifstream file(path);
std::ifstream file(getLedPath(path));
int value;
if (!file.is_open()) {
@ -97,11 +106,11 @@ static inline uint32_t getScaledBrightness(const LightState& state, uint32_t max
}
static void handleNotification(const LightState& state) {
uint32_t notificationBrightness = getScaledBrightness(state, getMaxBrightness(NOTIFICATION_LED MAX_BRIGHTNESS));
uint32_t notificationBrightness = getScaledBrightness(state, getMaxBrightness(MAX_BRIGHTNESS));
/* Disable breathing or blinking */
set(NOTIFICATION_LED BREATH, 0);
set(NOTIFICATION_LED BRIGHTNESS, 0);
set(BREATH, 0);
set(BRIGHTNESS, 0);
if (!notificationBrightness) {
return;
@ -111,11 +120,11 @@ static void handleNotification(const LightState& state) {
case Flash::HARDWARE:
case Flash::TIMED:
/* Breathing */
set(NOTIFICATION_LED BREATH, 1);
set(BREATH, 1);
break;
case Flash::NONE:
default:
set(NOTIFICATION_LED BRIGHTNESS, notificationBrightness);
set(BRIGHTNESS, notificationBrightness);
}
}

View File

@ -3,11 +3,15 @@ on boot
chown system system /sys/class/leds/left/breath
chown system system /sys/class/leds/right/brightness
chown system system /sys/class/leds/right/breath
chown system system /sys/class/leds/white/brightness
chown system system /sys/class/leds/white/breath
chmod 0644 /sys/class/leds/left/brightness
chmod 0644 /sys/class/leds/left/breath
chmod 0644 /sys/class/leds/right/brightness
chmod 0644 /sys/class/leds/right/breath
chmod 0644 /sys/class/leds/white/brightness
chmod 0644 /sys/class/leds/white/breath
service vendor.light-hal-2-0 /vendor/bin/hw/android.hardware.light@2.0-service.xiaomi_sm6150
interface android.hardware.light@2.0::ILight default