Re: [PATCH] Add LED pattern trigger

From: Pavel Machek
Date: Mon Dec 30 2013 - 13:33:15 EST


Hi!

> The LED pattern trigger allows LEDs blink in user defined pattern.
>
> new file: Documentation/leds/ledtrig-pattern.txt
> modified: drivers/leds/trigger/Kconfig
> modified: drivers/leds/trigger/Makefile
> new file: drivers/leds/trigger/ledtrig-pattern.c
>
> Suggested-by: Pavel Machek <pavel@xxxxxx>
> Signed-off-by: Joe Xue <lgxue@xxxxxxxxxxx>

> + echo pattern > trigger
> + echo "# ## /"
> +
> + The behaviour is like below:
> +
> + on(125ms)off(125ms)on(250ms)off


> +static void pattern_timer_function(unsigned long data)
> +{
> + struct led_classdev *led_cdev = (struct led_classdev *) data;
> + struct pattern_trig_data *pattern_data = led_cdev->trigger_data;
> +
> + if (pattern_data->pattern[pattern_data->count] == '#') {
> + __led_set_brightness(led_cdev, pattern_data->brightness_on);
> + mod_timer(&pattern_data->timer,
> + jiffies + msecs_to_jiffies(pattern_data->delay_unit));
> + } else if (pattern_data->pattern[pattern_data->count] == ' ') {
> + __led_set_brightness(led_cdev, LED_OFF);
> + mod_timer(&pattern_data->timer,
> + jiffies + msecs_to_jiffies(pattern_data->delay_unit));
> + /* stop blinking */
> + } else if (pattern_data->pattern[pattern_data->count] == '/') {
> + return;
> + }

What about something like this?

Not shcheduling timer when nothing changed should save a bit of power/cpu...

if (pattern_data->pattern[pattern_data->count] == '/') {
return;
}

this = pattern_data->pattern[pattern_data->count]
if (this == '#')
new_brigtness = pattern_data->brightness_on;
if (this == ' ')
new_brigtness = LED_OFF;
repeat = 1;
while (pattern_data->pattern[pattern_data->count + repeat] == this)
repeat++;

mod_timer(&pattern_data->timer,
jiffies + msecs_to_jiffies(pattern_data->delay_unit * repeat));


Thanks,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/