Skip to content

Commit

Permalink
Control led brightness and color separately
Browse files Browse the repository at this point in the history
Now that the mce libhybris plugin supports controlling led brightness
separately from led color, make mce utilize it.

[mce] Control led brightness and color separately. Fixes JB#19788
  • Loading branch information
spiiroin committed Jun 3, 2014
1 parent 22b02a7 commit df16f7a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
13 changes: 13 additions & 0 deletions mce-hybris.c
Expand Up @@ -540,6 +540,19 @@ void mce_hybris_indicator_enable_breathing(bool enable)
if( real ) real(enable);
}

/** Set indicator led brightness
*
* @param level 1=minimum, 255=maximum
*
* @return true on success, or false on failure
*/
bool mce_hybris_indicator_set_brightness(int level)
{
static bool (*real)(int) = 0;
RESOLVE;
return !real ? false : real(level);
}

/* ------------------------------------------------------------------------- *
* proximity sensor
* ------------------------------------------------------------------------- */
Expand Down
1 change: 1 addition & 0 deletions mce-hybris.h
Expand Up @@ -57,6 +57,7 @@ bool mce_hybris_indicator_init(void);
void mce_hybris_indicator_quit(void);
bool mce_hybris_indicator_set_pattern(int r, int g, int b, int ms_on, int ms_off);
void mce_hybris_indicator_enable_breathing(bool enable);
bool mce_hybris_indicator_set_brightness(int level);

/* - - - - - - - - - - - - - - - - - - - *
* proximity sensor
Expand Down
26 changes: 3 additions & 23 deletions modules/led.c
Expand Up @@ -735,10 +735,9 @@ static void hybris_set_brightness(gint brightness)

mce_log(LL_DEBUG, "Brightness set to %d", active_brightness);

/* Since there is no separate brightness control when operating
* via libhybris, we need to reprogram the current pattern */
if( active_pattern )
hybris_program_led(active_pattern);
/* Scale from [1...100%] to [1...255] range */
brightness = mce_xlat_int(1,maximum_led_brightness, 1,255, brightness);
mce_hybris_indicator_set_brightness(brightness);
}
#endif /* ENABLE_HYBRIS */

Expand Down Expand Up @@ -1136,20 +1135,6 @@ static void mono_program_led(const pattern_struct *const pattern)
}

#ifdef ENABLE_HYBRIS
/** Scale RGB channel value according to the current brightness value
*
* @param value red, green or blue value in 0 to 255 range
*
* @return scaled rgb value
*/
static inline int hybris_tune_brightness(int value)
{
/* Note: active_brightness = 0 ... MAXIMUM_HYBRIS_LED_BRIGHTNESS */
int top = MAXIMUM_HYBRIS_LED_BRIGHTNESS;
int res = (value * active_brightness + top/2) / top;
return (res < 0) ? 0 : (res > 255) ? 255 : res;
}

/**
* Setup and activate a new libhybris-LED pattern
*
Expand All @@ -1161,11 +1146,6 @@ static void hybris_program_led(const pattern_struct *const pattern)
int g = (pattern->rgb_color >> 8) & 0xff;
int b = (pattern->rgb_color >> 0) & 0xff;

/* Do als based brightness scaling before use*/
r = hybris_tune_brightness(r);
g = hybris_tune_brightness(g);
b = hybris_tune_brightness(b);

mce_hybris_indicator_set_pattern(r, g, b,
pattern->on_period,
pattern->off_period);
Expand Down

0 comments on commit df16f7a

Please sign in to comment.