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 void backlight_init(void)
27 if (!eeconfig_is_enabled()) {
30 backlight_config.raw = eeconfig_read_backlight();
31 if (backlight_config.level > BACKLIGHT_LEVELS) {
32 backlight_config.level = BACKLIGHT_LEVELS;
34 backlight_set(backlight_config.enable ? backlight_config.level : 0);
37 void backlight_increase(void)
39 if(backlight_config.level < BACKLIGHT_LEVELS)
41 backlight_config.level++;
43 backlight_config.enable = 1;
44 eeconfig_update_backlight(backlight_config.raw);
45 dprintf("backlight increase: %u\n", backlight_config.level);
46 backlight_set(backlight_config.level);
49 void backlight_decrease(void)
51 if(backlight_config.level > 0)
53 backlight_config.level--;
54 backlight_config.enable = !!backlight_config.level;
55 eeconfig_update_backlight(backlight_config.raw);
57 dprintf("backlight decrease: %u\n", backlight_config.level);
58 backlight_set(backlight_config.level);
61 void backlight_toggle(void)
63 backlight_config.enable ^= 1;
64 eeconfig_update_backlight(backlight_config.raw);
65 dprintf("backlight toggle: %u\n", backlight_config.enable);
66 backlight_set(backlight_config.enable ? backlight_config.level : 0);
69 void backlight_step(void)
71 backlight_config.level++;
72 if(backlight_config.level > BACKLIGHT_LEVELS)
74 backlight_config.level = 0;
76 backlight_config.enable = !!backlight_config.level;
77 eeconfig_update_backlight(backlight_config.raw);
78 dprintf("backlight step: %u\n", backlight_config.level);
79 backlight_set(backlight_config.level);
82 void backlight_level(uint8_t level)
84 backlight_config.level ^= level;
85 backlight_config.enable = !!backlight_config.level;
86 eeconfig_update_backlight(backlight_config.raw);
87 backlight_set(backlight_config.level);
90 uint8_t get_backlight_level(void)
92 return backlight_config.level;