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

Commit 5ea10f19 authored by csaba215's avatar csaba215 Committed by Sooraj S
Browse files

FP3: import LED patch for light HAL

* Correctly declare all colors as supported
* Support LED breathing

Change-Id: I07e7dbc7bbc785f8b85c708e1d882242cf7abe54
parent b3c480de
Loading
Loading
Loading
Loading
+59 −25
Original line number Original line Diff line number Diff line
/*
/*
 * Copyright (C) 2017 The LineageOS Project
 * Copyright (C) 2017-2020 The LineageOS Project
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * you may not use this file except in compliance with the License.
@@ -22,6 +22,11 @@


#include <fstream>
#include <fstream>


#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define LEDS            "/sys/class/leds/"
#define LEDS            "/sys/class/leds/"


#define LCD_LED         LEDS "lcd-backlight/"
#define LCD_LED         LEDS "lcd-backlight/"
@@ -34,6 +39,51 @@
#define DELAY_OFF       "delay_off"
#define DELAY_OFF       "delay_off"
#define DELAY_ON        "delay_on"
#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.
 * Write value to path and close file.
 */
 */
@@ -79,27 +129,11 @@ static void handleNotification(const LightState& state) {
    }
    }


    /* Disable blinking. */
    /* Disable blinking. */
    set(RED_LED BREATH, 0);
    set_breath(0,0,0);
    set(GREEN_LED BREATH, 0);
    set(BLUE_LED BREATH, 0);


    if (state.flashMode == Flash::TIMED) {
    if (state.flashMode == Flash::TIMED) {
        /* Set LED */
        /* Enable blinking. */
        // set(RED_LED DELAY_OFF, state.flashOffMs);
        set_breath(redBrightness, greenBrightness, blueBrightness);
        // 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);
    } else {
    } else {
        set(RED_LED BRIGHTNESS, redBrightness);
        set(RED_LED BRIGHTNESS, redBrightness);
        set(GREEN_LED BRIGHTNESS, greenBrightness);
        set(GREEN_LED BRIGHTNESS, greenBrightness);
+1 −1
Original line number Original line Diff line number Diff line
@@ -32,5 +32,5 @@


         For example, a device support pulsating, RGB notification and
         For example, a device support pulsating, RGB notification and
         battery LEDs would set this config to 11. -->
         battery LEDs would set this config to 11. -->
    <integer name="config_deviceLightCapabilities" translatable="false">84</integer>
    <integer name="config_deviceLightCapabilities" translatable="false">235</integer>
</resources>
</resources>