Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13abfb0a authored by Bruno Martins's avatar Bruno Martins Committed by TARKZiM
Browse files

kitakami-common: light: Always apply RGB brightness scaling

 * Prior to this change, attention and battery lights weren't handled
   in the same way as notification lights. Apply RGB brightness scaling
   for all of those and avoid relying on the frameworks.

Change-Id: Ie4983c67e378382985217a47f3fc425045aa8e0f
parent 0a0fb780
Loading
Loading
Loading
Loading
+17 −34
Original line number Diff line number Diff line
@@ -155,35 +155,7 @@ void Light::setBatteryLight(const LightState& state) {

void Light::setNotificationLight(const LightState& state) {
    std::lock_guard<std::mutex> lock(mLock);

    uint32_t brightness, color, rgb[3];
    LightState localState = state;

    // If a brightness has been applied by the user
    brightness = (localState.color & 0xff000000) >> 24;
    if (brightness > 0 && brightness < 255) {
        // Retrieve each of the RGB colors
        color = localState.color & 0x00ffffff;
        rgb[0] = (color >> 16) & 0xff;
        rgb[1] = (color >> 8) & 0xff;
        rgb[2] = color & 0xff;

        // Apply the brightness level
        if (rgb[0] > 0) {
            rgb[0] = (rgb[0] * brightness) / 0xff;
        }
        if (rgb[1] > 0) {
            rgb[1] = (rgb[1] * brightness) / 0xff;
        }
        if (rgb[2] > 0) {
            rgb[2] = (rgb[2] * brightness) / 0xff;
        }

        // Update with the new color
        localState.color = (rgb[0] << 16) + (rgb[1] << 8) + rgb[2];
    }

    mNotificationState = localState;
    mNotificationState = state;
    setSpeakerBatteryLightLocked();
}

@@ -208,7 +180,22 @@ void Light::setSpeakerBatteryLightLocked() {
void Light::setSpeakerLightLocked(const LightState& state) {
    int red, green, blue, blink;
    int onMs, offMs, stepDuration, pauseHi;
    uint32_t colorRGB = state.color;
    uint32_t alpha;

    // Extract brightness from AARRGGBB
    alpha = (state.color >> 24) & 0xff;

    // Retrieve each of the RGB colors
    red = (state.color >> 16) & 0xff;
    green = (state.color >> 8) & 0xff;
    blue = state.color & 0xff;

    // Scale RGB colors if a brightness has been applied by the user
    if (alpha != 0xff) {
        red = (red * alpha) / 0xff;
        green = (green * alpha) / 0xff;
        blue = (blue * alpha) / 0xff;
    }

    switch (state.flashMode) {
        case Flash::TIMED:
@@ -221,10 +208,6 @@ void Light::setSpeakerLightLocked(const LightState& state) {
            offMs = 0;
            break;
    }

    red = (colorRGB >> 16) & 0xff;
    green = (colorRGB >> 8) & 0xff;
    blue = colorRGB & 0xff;
    blink = onMs > 0 && offMs > 0;

    // Disable all blinking to start