A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 109 lines 3.2 kB view raw
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 "config.h" 25#include "backlight-target.h" 26#include "system.h" 27#include "backlight.h" 28#include "backlight-sw-fading.h" 29 30#ifndef BRIGHTNESS_STEP 31#define BRIGHTNESS_STEP 1 32#endif 33 34/* To adapt a target do: 35 * - make sure backlight_hw_on doesn't set the brightness to something other than 36 * the previous value (lowest brightness in most cases) 37 * add proper #defines for software fading 38 */ 39 40/* can be MIN_BRIGHTNESS_SETTING-1 */ 41static int current_brightness = DEFAULT_BRIGHTNESS_SETTING; 42 43void _backlight_fade_update_state(int brightness) 44{ 45 current_brightness = brightness; 46} 47 48/* returns true if fade is finished */ 49static bool _backlight_fade_up(void) 50{ 51 if (LIKELY(current_brightness < backlight_brightness)) 52 { 53#if BRIGHTNESS_STEP == 1 54 backlight_hw_brightness(++current_brightness); 55#else 56 current_brightness += BRIGHTNESS_STEP; 57 if (current_brightness > MAX_BRIGHTNESS_SETTING) 58 current_brightness = MAX_BRIGHTNESS_SETTING; 59 backlight_hw_brightness(current_brightness); 60#endif 61 } 62 return(current_brightness >= backlight_brightness); 63} 64 65/* returns true if fade is finished */ 66static bool _backlight_fade_down(void) 67{ 68 if (LIKELY(current_brightness > MIN_BRIGHTNESS_SETTING)) 69 { 70#if BRIGHTNESS_STEP == 1 71 backlight_hw_brightness(--current_brightness); 72#else 73 current_brightness -= BRIGHTNESS_STEP; 74 if (current_brightness < MIN_BRIGHTNESS_SETTING) 75 current_brightness = MIN_BRIGHTNESS_SETTING; 76 backlight_hw_brightness(current_brightness); 77#endif 78 return false; 79 } 80 else 81 { 82 /* decrement once more, since backlight is off */ 83#if BRIGHTNESS_STEP == 1 84 current_brightness--; 85#else 86 current_brightness=MIN_BRIGHTNESS_SETTING -1; 87#endif 88 backlight_hw_off(); 89 return true; 90 } 91} 92 93bool _backlight_fade_step(int direction) 94{ 95 bool done; 96 switch(direction) 97 { 98 case FADING_UP: 99 done = _backlight_fade_up(); 100 break; 101 case FADING_DOWN: 102 done = _backlight_fade_down(); 103 break; 104 default: 105 done = true; 106 break; 107 } 108 return(done); 109}