From e1fe99f72f46136f82cbd56ffee2ae8fc180e59b Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Tue, 23 Jun 2020 01:55:38 +0200 Subject: [PATCH] sm8250-common: lights: Nuke RGB support --- lights/Light.cpp | 86 ------------------- lights/Light.h | 2 - ...hardware.light@2.0-service.oneplus_kona.rc | 8 -- 3 files changed, 96 deletions(-) diff --git a/lights/Light.cpp b/lights/Light.cpp index d914e55..2288cfd 100644 --- a/lights/Light.cpp +++ b/lights/Light.cpp @@ -56,10 +56,7 @@ static int rgbToBrightness(const LightState& state) { } Light::Light() { - mLights.emplace(Type::ATTENTION, std::bind(&Light::handleRgb, this, std::placeholders::_1, 0)); mLights.emplace(Type::BACKLIGHT, std::bind(&Light::handleBacklight, this, std::placeholders::_1)); - mLights.emplace(Type::BATTERY, std::bind(&Light::handleRgb, this, std::placeholders::_1, 2)); - mLights.emplace(Type::NOTIFICATIONS, std::bind(&Light::handleRgb, this, std::placeholders::_1, 1)); } void Light::handleBacklight(const LightState& state) { @@ -74,89 +71,6 @@ void Light::handleBacklight(const LightState& state) { set("/sys/class/backlight/panel0-backlight/brightness", brightness); } -void Light::handleRgb(const LightState& state, size_t index) { - mLightStates.at(index) = state; - - LightState stateToUse = mLightStates.front(); - for (const auto& lightState : mLightStates) { - if (lightState.color & 0xffffff) { - stateToUse = lightState; - break; - } - } - - std::map colorValues; - colorValues["red"] = (stateToUse.color >> 16) & 0xff; - // lower green and blue brightness to adjust for the (lower) brightness of red - colorValues["green"] = ((stateToUse.color >> 8) & 0xff) / 2; - colorValues["blue"] = (stateToUse.color & 0xff) / 2; - - int onMs = stateToUse.flashMode == Flash::TIMED ? stateToUse.flashOnMs : 0; - int offMs = stateToUse.flashMode == Flash::TIMED ? stateToUse.flashOffMs : 0; - - // LUT has 63 entries, we could theoretically use them as 3 (colors) * 21 (steps). - // However, the last LUT entries don't seem to behave correctly for unknown - // reasons, so we use 17 steps for a total of 51 LUT entries only. - static constexpr int kRampSteps = 16; - static constexpr int kRampMaxStepDurationMs = 15; - - auto makeLedPath = [](const std::string& led, const std::string& op) -> std::string { - return "/sys/class/leds/" + led + "/" + op; - }; - auto getScaledDutyPercent = [](int brightness) -> std::string { - std::string output; - for (int i = 0; i <= kRampSteps; i++) { - if (i != 0) { - output += ","; - } - output += std::to_string(i * 512 * brightness / (255 * kRampSteps)); - } - return output; - }; - - // Disable all blinking before starting - for (const auto& entry : colorValues) { - set(makeLedPath(entry.first, "blink"), 0); - } - - if (onMs > 0 && offMs > 0) { - int pauseLo, pauseHi, stepDuration, index = 0; - if (kRampMaxStepDurationMs * kRampSteps > onMs) { - stepDuration = onMs / kRampSteps; - pauseHi = 0; - pauseLo = offMs; - } else { - stepDuration = kRampMaxStepDurationMs; - pauseHi = onMs - kRampSteps * stepDuration; - pauseLo = offMs - kRampSteps * stepDuration; - } - - for (const auto& entry : colorValues) { - set(makeLedPath(entry.first, "lut_flags"), 95); - set(makeLedPath(entry.first, "start_idx"), index); - set(makeLedPath(entry.first, "duty_pcts"), getScaledDutyPercent(entry.second)); - set(makeLedPath(entry.first, "pause_lo"), pauseLo); - set(makeLedPath(entry.first, "pause_hi"), pauseHi); - set(makeLedPath(entry.first, "ramp_step_ms"), stepDuration); - index += kRampSteps + 1; - } - - // Start blinking - for (const auto& entry : colorValues) { - set(makeLedPath(entry.first, "blink"), entry.second); - } - } else { - for (const auto& entry : colorValues) { - set(makeLedPath(entry.first, "brightness"), entry.second); - } - } - - LOG(DEBUG) << base::StringPrintf( - "handleRgb: mode=%d, color=%08X, onMs=%d, offMs=%d", - static_cast::type>(stateToUse.flashMode), stateToUse.color, - onMs, offMs); -} - Return Light::setLight(Type type, const LightState& state) { auto it = mLights.find(type); diff --git a/lights/Light.h b/lights/Light.h index 27a701a..6ea3495 100644 --- a/lights/Light.h +++ b/lights/Light.h @@ -46,10 +46,8 @@ class Light : public ILight { private: void handleBacklight(const LightState& state); void handleRgb(const LightState& state, size_t index); - std::mutex mLock; std::unordered_map> mLights; - std::array mLightStates; }; } // namespace implementation diff --git a/lights/android.hardware.light@2.0-service.oneplus_kona.rc b/lights/android.hardware.light@2.0-service.oneplus_kona.rc index ba2c7af..b54ca95 100644 --- a/lights/android.hardware.light@2.0-service.oneplus_kona.rc +++ b/lights/android.hardware.light@2.0-service.oneplus_kona.rc @@ -1,11 +1,3 @@ -on boot - chown system system /sys/class/leds/red/start_idx - chown system system /sys/class/leds/green/start_idx - chown system system /sys/class/leds/blue/start_idx - chown system system /sys/class/leds/red/lut_flags - chown system system /sys/class/leds/green/lut_flags - chown system system /sys/class/leds/blue/lut_flags - service vendor.light-hal-2-0 /vendor/bin/hw/android.hardware.light@2.0-service interface android.hardware.light@2.0::ILight default class hal