diff --git a/light/Android.bp b/light/Android.bp index 1ff5684..78ac65b 100644 --- a/light/Android.bp +++ b/light/Android.bp @@ -1,3 +1,4 @@ +// // Copyright (C) 2018 The LineageOS Project // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/light/Light.cpp b/light/Light.cpp index 2e229f4..b63d72e 100644 --- a/light/Light.cpp +++ b/light/Light.cpp @@ -24,34 +24,30 @@ #define LEDS "/sys/class/leds/" -#define BUTTON1_LED LEDS "button-backlight1/" -#define BUTTON_LED LEDS "button-backlight/" #define LCD_LED LEDS "lcd-backlight/" -#define WHITE_LED LEDS "white/" +#define WHITE_LED LEDS "red/" #define BLINK "blink" #define BRIGHTNESS "brightness" +#define MAX_BRIGHTNESS "max_brightness" #define DUTY_PCTS "duty_pcts" #define PAUSE_HI "pause_hi" #define PAUSE_LO "pause_lo" #define RAMP_STEP_MS "ramp_step_ms" #define START_IDX "start_idx" -#define MAX_LED_BRIGHTNESS 255 -#define MAX_LCD_BRIGHTNESS 4095 - /* * 8 duty percent steps. */ -#define RAMP_STEPS 8 +#define RAMP_STEPS 15 /* * Each step will stay on for 50ms by default. */ -#define RAMP_STEP_DURATION 50 +#define RAMP_STEP_DURATION 150 /* * Each value represents a duty percent (0 - 100) for the led pwm. */ -static int32_t BRIGHTNESS_RAMP[RAMP_STEPS] = {0, 12, 25, 37, 50, 72, 85, 100}; +static int32_t BRIGHTNESS_RAMP[RAMP_STEPS] = {0, 12, 25, 37, 50, 72, 85, 100, 85, 72, 50, 37, 25, 12, 0}; namespace { /* @@ -72,6 +68,25 @@ static void set(std::string path, int value) { set(path, std::to_string(value)); } +static int get(std::string path) { + std::ifstream file(path); + int value; + + if (!file.is_open()) { + ALOGW("failed to read from %s", path.c_str()); + return 0; + } + + file >> value; + return value; +} + +static int getMaxBrightness(std::string path) { + int value = get(path); + ALOGW("Got max brightness %d", value); + return value; +} + static uint32_t getBrightness(const LightState& state) { uint32_t alpha, red, green, blue; @@ -104,16 +119,10 @@ static inline uint32_t getScaledBrightness(const LightState& state, uint32_t max } static void handleBacklight(Type /* type */, const LightState& state) { - uint32_t brightness = getScaledBrightness(state, MAX_LCD_BRIGHTNESS); + uint32_t brightness = getScaledBrightness(state, getMaxBrightness(LCD_LED MAX_BRIGHTNESS)); set(LCD_LED BRIGHTNESS, brightness); } -static void handleButtons(Type /* type */, const LightState& state) { - uint32_t brightness = getScaledBrightness(state, MAX_LED_BRIGHTNESS); - set(BUTTON_LED BRIGHTNESS, brightness); - set(BUTTON1_LED BRIGHTNESS, brightness); -} - /* * Scale each value of the brightness ramp according to the * brightness of the color. @@ -130,7 +139,7 @@ static std::string getScaledRamp(uint32_t brightness) { } static void setNotification(const LightState& state) { - uint32_t whiteBrightness = getScaledBrightness(state, MAX_LED_BRIGHTNESS); + uint32_t whiteBrightness = getScaledBrightness(state, getMaxBrightness(WHITE_LED MAX_BRIGHTNESS)); /* Disable blinking */ set(WHITE_LED BLINK, 0); @@ -146,7 +155,7 @@ static void setNotification(const LightState& state) { int32_t pauseLo = state.flashOffMs; if (pauseHi < 0) { - stepDuration = state.flashOnMs / (RAMP_STEPS * 2); + //stepDuration = state.flashOnMs / (RAMP_STEPS * 2); pauseHi = 0; } @@ -179,33 +188,28 @@ static std::vector> notificationStates = { }; static void handleNotification(Type type, const LightState& state) { - bool handled = false; - - for (auto it : notificationStates) { + for(auto it : notificationStates) { if (it.first == type) { it.second = state; } - if (!handled && isLit(it.second)) { + if (isLit(it.second)) { setNotification(it.second); - handled = true; + return; } } - if (!handled) { - setNotification(offState); - } + setNotification(offState); } -static std::map> lights = { +static std::map> lights = { { Type::ATTENTION, handleNotification }, { Type::NOTIFICATIONS, handleNotification }, { Type::BATTERY, handleNotification }, { Type::BACKLIGHT, handleBacklight }, - { Type::BUTTONS, handleButtons }, }; -} // anonymous namespace +} // anonymous namespace namespace android { namespace hardware { diff --git a/light/Light.h b/light/Light.h index ab41348..26f6770 100644 --- a/light/Light.h +++ b/light/Light.h @@ -21,11 +21,12 @@ #include #include #include -#include #include +#include using ::android::hardware::Return; using ::android::hardware::Void; +using ::android::hardware::hidl_vec; using ::android::hardware::light::V2_0::ILight; using ::android::hardware::light::V2_0::Flash; using ::android::hardware::light::V2_0::LightState; diff --git a/light/android.hardware.light@2.0-service.xiaomi_sdm660.rc b/light/android.hardware.light@2.0-service.xiaomi_sdm660.rc index c471875..54123c3 100644 --- a/light/android.hardware.light@2.0-service.xiaomi_sdm660.rc +++ b/light/android.hardware.light@2.0-service.xiaomi_sdm660.rc @@ -1,23 +1,18 @@ on boot - # White light - chown system system /sys/class/leds/white/brightness + chown system system /sys/class/leds/red/brightness + chown system system /sys/class/leds/red/blink + chown system system /sys/class/leds/red/duty_pcts + chown system system /sys/class/leds/red/pause_hi + chown system system /sys/class/leds/red/pause_lo + chown system system /sys/class/leds/red/ramp_step_ms + chown system system /sys/class/leds/red/start_idx - chown system system /sys/class/leds/white/blink - chown system system /sys/class/leds/white/duty_pcts - chown system system /sys/class/leds/white/pause_hi - chown system system /sys/class/leds/white/pause_lo - chown system system /sys/class/leds/white/ramp_step_ms - chown system system /sys/class/leds/white/start_idx - - chmod 660 /sys/class/leds/white/blink - chmod 660 /sys/class/leds/white/duty_pcts - chmod 660 /sys/class/leds/white/pause_hi - chmod 660 /sys/class/leds/white/pause_lo - chmod 660 /sys/class/leds/white/ramp_step_ms - chmod 660 /sys/class/leds/white/start_idx - - # Button backlight - chown system system /sys/class/leds/button-backlight1/brightness + chmod 660 /sys/class/leds/red/blink + chmod 660 /sys/class/leds/red/duty_pcts + chmod 660 /sys/class/leds/red/pause_hi + chmod 660 /sys/class/leds/red/pause_lo + chmod 660 /sys/class/leds/red/ramp_step_ms + chmod 660 /sys/class/leds/red/start_idx service light-hal-2-0 /vendor/bin/hw/android.hardware.light@2.0-service.xiaomi_sdm660 class hal diff --git a/light/service.cpp b/light/service.cpp index f6fa4fb..27ba1a7 100644 --- a/light/service.cpp +++ b/light/service.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "android.hardware.light@2.0-service.xiaomi_msm8998" +#define LOG_TAG "android.hardware.light@2.0-service.xiaomi_sdm660" #include @@ -31,7 +31,7 @@ using android::sp; using android::status_t; int main() { - sp service = new Light(); + android::sp service = new Light(); configureRpcThreadpool(1, true);