From 5ea10f19932bb4ac922605e6275c2f5368b9ed6e Mon Sep 17 00:00:00 2001 From: csaba215 Date: Fri, 11 Dec 2020 14:04:13 +0100 Subject: [PATCH] FP3: import LED patch for light HAL * Correctly declare all colors as supported * Support LED breathing Change-Id: I07e7dbc7bbc785f8b85c708e1d882242cf7abe54 --- light/Light.cpp | 84 +++++++++++++------ .../lineage/res/res/values/config.xml | 2 +- 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/light/Light.cpp b/light/Light.cpp index 6ce8f4c9..fc0dcf03 100644 --- a/light/Light.cpp +++ b/light/Light.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The LineageOS Project + * Copyright (C) 2017-2020 The LineageOS Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,11 @@ #include +#include +#include +#include +#include + #define LEDS "/sys/class/leds/" #define LCD_LED LEDS "lcd-backlight/" @@ -34,17 +39,62 @@ #define DELAY_OFF "delay_off" #define DELAY_ON "delay_on" + +static void set_breath(int redBrightness,int greenBrightness, int blueBrightness) { + int red = open(RED_LED BREATH,O_WRONLY); + int green = open(GREEN_LED BREATH,O_WRONLY); + int blue = open(BLUE_LED BREATH,O_WRONLY); + + if(red == -1) { + ALOGE("failed to open " RED_LED BREATH); + } + + if(green == -1) { + ALOGE("failed to open " GREEN_LED BREATH); + } + + if(blue == -1) { + ALOGE("failed to open " BLUE_LED BREATH); + } + + int re,ge,be; + if (redBrightness > 0) + re = write(red,"1",1); + else + re = write(red,"0",1); + + if (greenBrightness > 0) + ge = write(green,"1",1); + else + ge = write(green,"0",1); + + if (blueBrightness > 0) + be = write(blue,"1",1); + else + be = write(blue,"0",1); + + if(re != 1) + ALOGE("failed to write to " RED_LED BREATH " errorcode: %i",re); + if(ge != 1) + ALOGE("failed to write to " GREEN_LED BREATH " errorcode: %i",ge); + if(be != 1) + ALOGE("failed to write to " BLUE_LED BREATH " errorcode: %i",be); + close(red); + close(green); + close(blue); +} + /* * Write value to path and close file. */ static void set(std::string path, std::string value) { std::ofstream file(path); - + if (!file.is_open()) { ALOGE("failed to write %s to %s", value.c_str(), path.c_str()); return; } - + file << value; } @@ -59,7 +109,7 @@ static void handleBacklight(const LightState& state) { static void handleNotification(const LightState& state) { uint32_t redBrightness, greenBrightness, blueBrightness, brightness; - + /* * Extract brightness from AARRGGBB. */ @@ -79,27 +129,11 @@ static void handleNotification(const LightState& state) { } /* Disable blinking. */ - set(RED_LED BREATH, 0); - set(GREEN_LED BREATH, 0); - set(BLUE_LED BREATH, 0); + set_breath(0,0,0); if (state.flashMode == Flash::TIMED) { - /* Set LED */ - // set(RED_LED DELAY_OFF, state.flashOffMs); - // set(RED_LED DELAY_ON, state.flashOnMs); - // set(GREEN_LED DELAY_OFF, state.flashOffMs); - // set(GREEN_LED DELAY_ON, state.flashOnMs); - set(BLUE_LED DELAY_OFF, state.flashOffMs); - set(BLUE_LED DELAY_ON, state.flashOnMs); - - - // /* Enable blinking. */ - // if (redBrightness > 0) - // set(RED_LED BREATH, 1); - // if (greenBrightness > 0) - // set(GREEN_LED BREATH, 1); - if (blueBrightness > 0) - set(BLUE_LED BREATH, 1); + /* Enable blinking. */ + set_breath(redBrightness, greenBrightness, blueBrightness); } else { set(RED_LED BRIGHTNESS, redBrightness); set(GREEN_LED BRIGHTNESS, greenBrightness); @@ -128,7 +162,7 @@ namespace implementation { Return Light::setLight(Type type, const LightState& state) { LightStateHandler handler = nullptr; bool handled = false; - + /* Lock global mutex until light state is updated. */ std::lock_guard lock(globalLock); @@ -168,7 +202,7 @@ Return Light::getSupportedTypes(getSupportedTypes_cb _hidl_cb) { for (const LightBackend& backend : backends) { types.push_back(backend.type); } - + _hidl_cb(types); return Void(); diff --git a/overlay-lineage/lineage-sdk/lineage/res/res/values/config.xml b/overlay-lineage/lineage-sdk/lineage/res/res/values/config.xml index 560c54c6..ab135781 100644 --- a/overlay-lineage/lineage-sdk/lineage/res/res/values/config.xml +++ b/overlay-lineage/lineage-sdk/lineage/res/res/values/config.xml @@ -32,5 +32,5 @@ For example, a device support pulsating, RGB notification and battery LEDs would set this config to 11. --> - 84 + 235 -- GitLab