summaryrefslogtreecommitdiffstats
path: root/liblights
diff options
context:
space:
mode:
authorSimon Shields <simon@lineageos.org>2017-02-18 20:55:11 +1100
committerSimon Shields <simon@lineageos.org>2017-02-24 12:53:18 +0000
commit310d1999e5478a28b73eacbc5b4db62174431ee9 (patch)
treece7bbe8b5aabed0529b14388f43520e778429b17 /liblights
parent5eda55f20adda211d96359cace7a9a9d8bbfa8ea (diff)
downloadandroid_hardware_samsung-310d1999e5478a28b73eacbc5b4db62174431ee9.tar.gz
android_hardware_samsung-310d1999e5478a28b73eacbc5b4db62174431ee9.tar.bz2
android_hardware_samsung-310d1999e5478a28b73eacbc5b4db62174431ee9.zip
liblights: add support for adjusting notification LED brightness
The old exynos4x12 lights HAL had logic for scaling the brightness of lights according to the light's type and also scaling each R/G/B colour. Bring this logic across, and make the battery LED not eye-searing at night. Based on work by Daniel Hillenbrand. REGRESSION-66 Change-Id: Ia6108468f57c3b6c6a1a68da76a1c3362fd982a5
Diffstat (limited to 'liblights')
-rw-r--r--liblights/include/samsung_lights.h22
-rw-r--r--liblights/lights.c41
2 files changed, 59 insertions, 4 deletions
diff --git a/liblights/include/samsung_lights.h b/liblights/include/samsung_lights.h
index ab0630e..dc07b6f 100644
--- a/liblights/include/samsung_lights.h
+++ b/liblights/include/samsung_lights.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 The CyanogenMod Project
+ * Copyright (C) 2017 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.
@@ -29,4 +30,25 @@
#define BUTTON_BRIGHTNESS_NODE "/sys/class/sec/sec_touchkey/brightness"
#define LED_BLINK_NODE "/sys/class/sec/led/led_blink"
+/*
+ * Brightness adjustment factors
+ *
+ * If one of your device's LEDs is more powerful than the others, use these
+ * values to equalise them. This value is in the range 0.0-1.0.
+ */
+#define LED_ADJUSTMENT_R 1.0
+#define LED_ADJUSTMENT_G 1.0
+#define LED_ADJUSTMENT_B 1.0
+
+/*
+ * Light brightness factors
+ *
+ * It might make sense for all colours to be scaled down (for example, if your
+ * LED is too bright). Use these values to adjust the brightness of each
+ * light. This value is within the range 0-255.
+ */
+#define LED_BRIGHTNESS_BATTERY 255
+#define LED_BRIGHTNESS_NOTIFICATION 255
+#define LED_BRIGHTNESS_ATTENTION 255
+
#endif // SAMSUNG_LIGHTS_H
diff --git a/liblights/lights.c b/liblights/lights.c
index 36a049b..f7d1d60 100644
--- a/liblights/lights.c
+++ b/liblights/lights.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013 The Android Open Source Project
* Copyright (C) 2015-2016 The CyanogenMod Project
+ * Copyright (C) 2017 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.
@@ -44,6 +45,12 @@ enum component_mask_t {
COMPONENT_LED = 0x4,
};
+enum light_t {
+ TYPE_BATTERY = 0,
+ TYPE_NOTIFICATION = 1,
+ TYPE_ATTENTION = 2,
+};
+
// Assume backlight is always supported
static int hw_components = COMPONENT_BACKLIGHT;
@@ -197,10 +204,20 @@ static int write_leds(const struct led_config *led)
return err;
}
+static int calibrate_color(int color, int brightness)
+{
+ int red = ((color >> 16) & 0xFF) * LED_ADJUSTMENT_R;
+ int green = ((color >> 8) & 0xFF) * LED_ADJUSTMENT_G;
+ int blue = (color & 0xFF) * LED_ADJUSTMENT_B;
+
+ return (((red * brightness) / 255) << 16) + (((green * brightness) / 255) << 8) + ((blue * brightness) / 255);
+}
+
static int set_light_leds(struct light_state_t const *state, int type)
{
struct led_config *led;
int err = 0;
+ int adjusted_brightness;
ALOGV("%s: type=%d, color=0x%010x, fM=%d, fOnMS=%d, fOffMs=%d.", __func__,
type, state->color,state->flashMode, state->flashOnMS, state->flashOffMS);
@@ -230,7 +247,23 @@ static int set_light_leds(struct light_state_t const *state, int type)
return -EINVAL;
}
- led->color = state->color & COLOR_MASK;
+ switch (type) {
+ case TYPE_BATTERY:
+ adjusted_brightness = LED_BRIGHTNESS_BATTERY;
+ break;
+ case TYPE_NOTIFICATION:
+ adjusted_brightness = LED_BRIGHTNESS_NOTIFICATION;
+ break;
+ case TYPE_ATTENTION:
+ adjusted_brightness = LED_BRIGHTNESS_ATTENTION;
+ break;
+ default:
+ adjusted_brightness = 255;
+ }
+
+
+
+ led->color = calibrate_color(state->color & COLOR_MASK, adjusted_brightness);
if (led->color > 0) {
/* This LED is lit. */
@@ -266,13 +299,13 @@ switched:
static int set_light_leds_battery(struct light_device_t *dev __unused,
struct light_state_t const *state)
{
- return set_light_leds(state, 0);
+ return set_light_leds(state, TYPE_BATTERY);
}
static int set_light_leds_notifications(struct light_device_t *dev __unused,
struct light_state_t const *state)
{
- return set_light_leds(state, 1);
+ return set_light_leds(state, TYPE_NOTIFICATION);
}
static int set_light_leds_attention(struct light_device_t *dev __unused,
@@ -298,7 +331,7 @@ static int set_light_leds_attention(struct light_device_t *dev __unused,
break;
}
- return set_light_leds(&fixed, 2);
+ return set_light_leds(&fixed, TYPE_ATTENTION);
}
static int open_lights(const struct hw_module_t *module, char const *name,