diff options
Diffstat (limited to 'firmware/backlight-sw-fading.c')
-rw-r--r-- | firmware/backlight-sw-fading.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/firmware/backlight-sw-fading.c b/firmware/backlight-sw-fading.c new file mode 100644 index 0000000000..d7987567ce --- /dev/null +++ b/firmware/backlight-sw-fading.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 by Thomas Martitz | ||
11 | * Copyright (C) 2008 by Martin Ritter | ||
12 | * | ||
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. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | |||
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" | ||
29 | |||
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 | * - #define USE_BACKLIGHT_SW_FADING in config-<target>.h | ||
34 | */ | ||
35 | |||
36 | /* can be MIN_BRIGHTNESS_SETTING-1 */ | ||
37 | static int current_brightness = DEFAULT_BRIGHTNESS_SETTING; | ||
38 | |||
39 | void _backlight_fade_update_state(int brightness) | ||
40 | { | ||
41 | current_brightness = brightness; | ||
42 | } | ||
43 | |||
44 | /* returns true if fade is finished */ | ||
45 | static bool _backlight_fade_up(void) | ||
46 | { | ||
47 | if (LIKELY(current_brightness < backlight_brightness)) | ||
48 | { | ||
49 | _backlight_set_brightness(++current_brightness); | ||
50 | } | ||
51 | return(current_brightness >= backlight_brightness); | ||
52 | } | ||
53 | |||
54 | /* returns true if fade is finished */ | ||
55 | static bool _backlight_fade_down(void) | ||
56 | { | ||
57 | if (LIKELY(current_brightness > MIN_BRIGHTNESS_SETTING)) | ||
58 | { | ||
59 | _backlight_set_brightness(--current_brightness); | ||
60 | return false; | ||
61 | } | ||
62 | else | ||
63 | { | ||
64 | /* decrement once more, since backlight is off */ | ||
65 | current_brightness--; | ||
66 | _backlight_off(); | ||
67 | return true; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | bool _backlight_fade_step(int direction) | ||
72 | { | ||
73 | bool done; | ||
74 | switch(direction) | ||
75 | { | ||
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; | ||
85 | } | ||
86 | return(done); | ||
87 | } | ||