Fix svn:keywords property in as3525 target tree
[kugel-rb.git] / firmware / backlight-sw-fading.c
blobb9c9587cf45fe6bff179883b905261b107af3d0f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Thomas Martitz
11 * Copyright (C) 2008 by Martin Ritter
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
23 #include <stdbool.h>
24 #include "backlight-target.h"
25 #include "config.h"
26 #include "system.h"
27 #include "backlight.h"
28 #include "backlight-sw-fading.h"
30 /* To adapt a target do:
31 * - make sure _backlight_on doesn't set the brightness to something other than
32 * the previous value (lowest brightness in most cases)
33 * add proper #defines for software fading
36 /* can be MIN_BRIGHTNESS_SETTING-1 */
37 static int current_brightness = DEFAULT_BRIGHTNESS_SETTING;
39 void _backlight_fade_update_state(int brightness)
41 current_brightness = brightness;
44 /* returns true if fade is finished */
45 static bool _backlight_fade_up(void)
47 if (LIKELY(current_brightness < backlight_brightness))
49 _backlight_set_brightness(++current_brightness);
51 return(current_brightness >= backlight_brightness);
54 /* returns true if fade is finished */
55 static bool _backlight_fade_down(void)
57 if (LIKELY(current_brightness > MIN_BRIGHTNESS_SETTING))
59 _backlight_set_brightness(--current_brightness);
60 return false;
62 else
64 /* decrement once more, since backlight is off */
65 current_brightness--;
66 _backlight_off();
67 return true;
71 bool _backlight_fade_step(int direction)
73 bool done;
74 switch(direction)
76 case FADING_UP:
77 done = _backlight_fade_up();
78 break;
79 case FADING_DOWN:
80 done = _backlight_fade_down();
81 break;
82 default:
83 done = true;
84 break;
86 return(done);