Skip to content

Commit

Permalink
[led] Add support for always breathing CSD LED pattern. Fixes JB#32696
Browse files Browse the repository at this point in the history
The CSD test has a led pattern that should utilize sw breathing regardless
of the state of breathing settings.

Make it similar exception as battery full pattern already is.
  • Loading branch information
spiiroin committed Oct 7, 2015
1 parent 0447a1a commit b8e8dc2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
3 changes: 3 additions & 0 deletions mce.h
Expand Up @@ -49,6 +49,9 @@
/** LED pattern used when the battery is full */
#define MCE_LED_PATTERN_BATTERY_FULL "PatternBatteryFull"

/** LED pattern used by CSD that should always use sw breathing */
#define MCE_LED_PATTERN_CSD_BREATHING "PatternCsdLedBlink"

/** LED pattern used when the battery is low */
#define MCE_LED_PATTERN_BATTERY_LOW "PatternBatteryLow"

Expand Down
47 changes: 41 additions & 6 deletions modules/led.c
Expand Up @@ -318,6 +318,7 @@ static void disable_led (void);
static pattern_struct *led_pattern_create (void);
static void led_pattern_delete (pattern_struct *self);
static void led_pattern_set_active (pattern_struct *self, gboolean active);
static bool led_pattern_should_breathe (const pattern_struct *self);
static bool led_pattern_can_breathe (const pattern_struct *self);
static gboolean led_pattern_timeout_cb (gpointer data);
static void lysti_program_led (const pattern_struct *const pattern);
Expand Down Expand Up @@ -1005,6 +1006,43 @@ static void led_pattern_set_active(pattern_struct *self, gboolean active)
return;
}

/** Check if a led pattern should always utilize sw breathing
*
* @param self led pattern object
*
* @return true if the pattern should always breathe, false otherwise
*/
static bool led_pattern_should_breathe(const pattern_struct *self)
{
static const char * const lut[] =
{
/* Battery full breathes by default. If user has tuned
* the pattern config to disable battery full blinking,
* the led_pattern_can_breathe() should catch it. */
MCE_LED_PATTERN_BATTERY_FULL,

/* The CSD test has a led pattern that should utilize
* breathing regardless of the breathing settings */
MCE_LED_PATTERN_CSD_BREATHING,
};

bool breathe = false;

if( !self || !self->name )
goto EXIT;

for( size_t i = 0; i < G_N_ELEMENTS(lut); ++i ) {
if( strcmp(self->name, lut[i]) )
continue;

breathe = true;
break;
}

EXIT:
return breathe;
}

/** Check if pattern is breathable
*
* @param self led pattern object
Expand Down Expand Up @@ -2832,12 +2870,9 @@ static void sw_breathing_rethink(void)
breathe = false;
}
else {
/* Battery full breathes by default. If user has tuned
* the pattern config to disable battery full blinking,
* the led_pattern_can_breathe() below should catch it. */
if( !strcmp(active_pattern->name,
MCE_LED_PATTERN_BATTERY_FULL) )
breathe = true;
/* Check for always breathing special cases */
if( !breathe )
breathe = led_pattern_should_breathe(active_pattern);

/* If pattern is configured not to breathe, we should
* not breathe even if it were allowed */
Expand Down

0 comments on commit b8e8dc2

Please sign in to comment.