blob: 2aff2f9c2717ac40ad6d10a1bea72adfcc259301 [file] [log] [blame]
Steve Bavinf6847262008-11-26 08:26:13 +00001/***************************************************************************
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>
Steve Bavinf6847262008-11-26 08:26:13 +000024#include "config.h"
Szymon Dziokc1d6ba12014-02-23 20:31:23 +000025#include "backlight-target.h"
Steve Bavinf6847262008-11-26 08:26:13 +000026#include "system.h"
27#include "backlight.h"
Thomas Martitz81df9532009-01-22 10:50:11 +000028#include "backlight-sw-fading.h"
Steve Bavinf6847262008-11-26 08:26:13 +000029
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)
Thomas Martitz12a0ed32009-01-26 23:21:49 +000033 * add proper #defines for software fading
Steve Bavinf6847262008-11-26 08:26:13 +000034 */
35
36/* can be MIN_BRIGHTNESS_SETTING-1 */
37static int current_brightness = DEFAULT_BRIGHTNESS_SETTING;
38
39void _backlight_fade_update_state(int brightness)
40{
Steve Bavin4bde6da2008-11-26 11:08:27 +000041 current_brightness = brightness;
Steve Bavinf6847262008-11-26 08:26:13 +000042}
43
44/* returns true if fade is finished */
45static 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 */
55static 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
71bool _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}