2 Copyright 2013 Mathias Andersson <wraul@dbox.se>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "backlight.h"
22 backlight_config_t backlight_config;
24 /** \brief Backlight initialization
28 void backlight_init(void)
31 if (!eeconfig_is_enabled()) {
34 backlight_config.raw = eeconfig_read_backlight();
35 if (backlight_config.level > BACKLIGHT_LEVELS) {
36 backlight_config.level = BACKLIGHT_LEVELS;
38 backlight_set(backlight_config.enable ? backlight_config.level : 0);
41 /** \brief Backlight increase
45 void backlight_increase(void)
47 if(backlight_config.level < BACKLIGHT_LEVELS)
49 backlight_config.level++;
51 backlight_config.enable = 1;
52 eeconfig_update_backlight(backlight_config.raw);
53 dprintf("backlight increase: %u\n", backlight_config.level);
54 backlight_set(backlight_config.level);
57 /** \brief Backlight decrease
61 void backlight_decrease(void)
63 if(backlight_config.level > 0)
65 backlight_config.level--;
66 backlight_config.enable = !!backlight_config.level;
67 eeconfig_update_backlight(backlight_config.raw);
69 dprintf("backlight decrease: %u\n", backlight_config.level);
70 backlight_set(backlight_config.level);
73 /** \brief Backlight toggle
77 void backlight_toggle(void)
79 backlight_config.enable ^= 1;
80 if (backlight_config.raw == 1) // enabled but level = 0
81 backlight_config.level = 1;
82 eeconfig_update_backlight(backlight_config.raw);
83 dprintf("backlight toggle: %u\n", backlight_config.enable);
84 backlight_set(backlight_config.enable ? backlight_config.level : 0);
87 /** \brief Backlight step through levels
91 void backlight_step(void)
93 backlight_config.level++;
94 if(backlight_config.level > BACKLIGHT_LEVELS)
96 backlight_config.level = 0;
98 backlight_config.enable = !!backlight_config.level;
99 eeconfig_update_backlight(backlight_config.raw);
100 dprintf("backlight step: %u\n", backlight_config.level);
101 backlight_set(backlight_config.level);
104 /** \brief Backlight set level
108 void backlight_level(uint8_t level)
110 if (level > BACKLIGHT_LEVELS)
111 level = BACKLIGHT_LEVELS;
112 backlight_config.level = level;
113 backlight_config.enable = !!backlight_config.level;
114 eeconfig_update_backlight(backlight_config.raw);
115 backlight_set(backlight_config.level);
118 /** \brief Get backlight level
122 uint8_t get_backlight_level(void)
124 return backlight_config.level;