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 if (backlight_config.raw == 1) // enabled but level = 0
65 backlight_config.level = 1;
66 eeconfig_update_backlight(backlight_config.raw);
67 dprintf("backlight toggle: %u\n", backlight_config.enable);
68 backlight_set(backlight_config.enable ? backlight_config.level : 0);
71 void backlight_step(void)
73 backlight_config.level++;
74 if(backlight_config.level > BACKLIGHT_LEVELS)
76 backlight_config.level = 0;
78 backlight_config.enable = !!backlight_config.level;
79 eeconfig_update_backlight(backlight_config.raw);
80 dprintf("backlight step: %u\n", backlight_config.level);
81 backlight_set(backlight_config.level);
84 void backlight_level(uint8_t level)
86 if (level > BACKLIGHT_LEVELS)
87 level = BACKLIGHT_LEVELS;
88 backlight_config.level = level;
89 backlight_config.enable = !!backlight_config.level;
90 eeconfig_update_backlight(backlight_config.raw);
91 backlight_set(backlight_config.level);
94 uint8_t get_backlight_level(void)
96 return backlight_config.level;