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
tirimbino
Simon Shields 8 years ago
parent 5eda55f20a
commit 310d1999e5
  1. 22
      liblights/include/samsung_lights.h
  2. 41
      liblights/lights.c

@ -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

@ -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,

Loading…
Cancel
Save