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 backlight_set(backlight_config.enable ? backlight_config.level : 0);
34 void backlight_increase(void)
36 if(backlight_config.level < BACKLIGHT_LEVELS)
38 backlight_config.level++;
39 backlight_config.enable = 1;
40 eeconfig_write_backlight(backlight_config.raw);
42 dprintf("backlight increase: %u\n", backlight_config.level);
43 backlight_set(backlight_config.level);
46 void backlight_decrease(void)
48 if(backlight_config.level > 0)
50 backlight_config.level--;
51 backlight_config.enable = !!backlight_config.level;
52 eeconfig_write_backlight(backlight_config.raw);
54 dprintf("backlight decrease: %u\n", backlight_config.level);
55 backlight_set(backlight_config.level);
58 void backlight_toggle(void)
60 backlight_config.enable ^= 1;
61 eeconfig_write_backlight(backlight_config.raw);
62 dprintf("backlight toggle: %u\n", backlight_config.enable);
63 backlight_set(backlight_config.enable ? backlight_config.level : 0);
66 void backlight_step(void)
68 backlight_config.level++;
69 if(backlight_config.level > BACKLIGHT_LEVELS)
71 backlight_config.level = 0;
73 backlight_config.enable = !!backlight_config.level;
74 eeconfig_write_backlight(backlight_config.raw);
75 dprintf("backlight step: %u\n", backlight_config.level);
76 backlight_set(backlight_config.level);
79 void backlight_level(uint8_t level)
81 backlight_config.level ^= level;
82 backlight_config.enable = !!backlight_config.level;
83 eeconfig_write_backlight(backlight_config.raw);
84 backlight_set(backlight_config.level);