Steve Bavin | f684726 | 2008-11-26 08:26:13 +0000 | [diff] [blame] | 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> |
Steve Bavin | f684726 | 2008-11-26 08:26:13 +0000 | [diff] [blame] | 24 | #include "config.h" |
Szymon Dziok | c1d6ba1 | 2014-02-23 20:31:23 +0000 | [diff] [blame] | 25 | #include "backlight-target.h" |
Steve Bavin | f684726 | 2008-11-26 08:26:13 +0000 | [diff] [blame] | 26 | #include "system.h" |
| 27 | #include "backlight.h" |
Thomas Martitz | 81df953 | 2009-01-22 10:50:11 +0000 | [diff] [blame] | 28 | #include "backlight-sw-fading.h" |
Steve Bavin | f684726 | 2008-11-26 08:26:13 +0000 | [diff] [blame] | 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) |
Thomas Martitz | 12a0ed3 | 2009-01-26 23:21:49 +0000 | [diff] [blame] | 33 | * add proper #defines for software fading |
Steve Bavin | f684726 | 2008-11-26 08:26:13 +0000 | [diff] [blame] | 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 | { |
Steve Bavin | 4bde6da | 2008-11-26 11:08:27 +0000 | [diff] [blame] | 41 | current_brightness = brightness; |
Steve Bavin | f684726 | 2008-11-26 08:26:13 +0000 | [diff] [blame] | 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 | } |