backlight.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. Copyright 2013 Mathias Andersson <wraul@dbox.se>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "backlight.h"
  15. #include "eeconfig.h"
  16. #include "debug.h"
  17. backlight_config_t backlight_config;
  18. void backlight_init(void)
  19. {
  20. /* check signature */
  21. if (!eeconfig_is_enabled()) {
  22. eeconfig_init();
  23. }
  24. backlight_config.raw = eeconfig_read_backlight();
  25. if (backlight_config.level > BACKLIGHT_LEVELS) {
  26. backlight_config.level = BACKLIGHT_LEVELS;
  27. }
  28. backlight_set(backlight_config.enable ? backlight_config.level : 0);
  29. }
  30. void backlight_increase(void)
  31. {
  32. if(backlight_config.level < BACKLIGHT_LEVELS)
  33. {
  34. backlight_config.level++;
  35. }
  36. backlight_config.enable = 1;
  37. eeconfig_update_backlight(backlight_config.raw);
  38. dprintf("backlight increase: %u\n", backlight_config.level);
  39. backlight_set(backlight_config.level);
  40. }
  41. void backlight_decrease(void)
  42. {
  43. if(backlight_config.level > 0)
  44. {
  45. backlight_config.level--;
  46. backlight_config.enable = !!backlight_config.level;
  47. eeconfig_update_backlight(backlight_config.raw);
  48. }
  49. dprintf("backlight decrease: %u\n", backlight_config.level);
  50. backlight_set(backlight_config.level);
  51. }
  52. void backlight_toggle(void)
  53. {
  54. backlight_config.enable ^= 1;
  55. eeconfig_update_backlight(backlight_config.raw);
  56. dprintf("backlight toggle: %u\n", backlight_config.enable);
  57. backlight_set(backlight_config.enable ? backlight_config.level : 0);
  58. }
  59. void backlight_step(void)
  60. {
  61. backlight_config.level++;
  62. if(backlight_config.level > BACKLIGHT_LEVELS)
  63. {
  64. backlight_config.level = 0;
  65. }
  66. backlight_config.enable = !!backlight_config.level;
  67. eeconfig_update_backlight(backlight_config.raw);
  68. dprintf("backlight step: %u\n", backlight_config.level);
  69. backlight_set(backlight_config.level);
  70. }
  71. void backlight_level(uint8_t level)
  72. {
  73. backlight_config.level ^= level;
  74. backlight_config.enable = !!backlight_config.level;
  75. eeconfig_update_backlight(backlight_config.raw);
  76. backlight_set(backlight_config.level);
  77. }
  78. uint8_t get_backlight_level(void)
  79. {
  80. return backlight_config.level;
  81. }