You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

backlight.c 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. Copyright 2013 Mathias Andersson <[email protected]>
  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 "breathing_led.h"
  16. #include "eeconfig.h"
  17. #include "debug.h"
  18. backlight_config_t backlight_config;
  19. void backlight_init(void)
  20. {
  21. /* check signature */
  22. if (!eeconfig_is_enabled()) {
  23. eeconfig_init();
  24. }
  25. backlight_config.raw = eeconfig_read_backlight();
  26. backlight_set(backlight_config.enable ? backlight_config.level : 0);
  27. }
  28. void backlight_increase(void)
  29. {
  30. #if defined(BACKLIGHT_CUSTOM) || defined(BREATHING_LED_ENABLE)
  31. if (backlight_config.enable) {
  32. if (backlight_config.level < BACKLIGHT_LEVELS) {
  33. backlight_config.level++;
  34. eeconfig_write_backlight(backlight_config.raw);
  35. }
  36. dprintf("backlight custom increase: %u\n", backlight_config.level);
  37. backlight_set(backlight_config.level);
  38. }
  39. #ifdef BREATHING_LED_ENABLE
  40. breathing_led_increase();
  41. #endif
  42. #else
  43. if(backlight_config.level < BACKLIGHT_LEVELS)
  44. {
  45. backlight_config.level++;
  46. backlight_config.enable = 1;
  47. eeconfig_write_backlight(backlight_config.raw);
  48. }
  49. dprintf("backlight increase: %u\n", backlight_config.level);
  50. backlight_set(backlight_config.level);
  51. #endif
  52. }
  53. void backlight_decrease(void)
  54. {
  55. #if defined(BACKLIGHT_CUSTOM) || defined(BREATHING_LED_ENABLE)
  56. if (backlight_config.enable) {
  57. if(backlight_config.level > 1)
  58. {
  59. backlight_config.level--;
  60. eeconfig_write_backlight(backlight_config.raw);
  61. }
  62. dprintf("backlight custom decrease: %u\n", backlight_config.level);
  63. backlight_set(backlight_config.level);
  64. }
  65. #ifdef BREATHING_LED_ENABLE
  66. breathing_led_decrease();
  67. #endif
  68. #else
  69. if(backlight_config.level > 0)
  70. {
  71. backlight_config.level--;
  72. backlight_config.enable = !!backlight_config.level;
  73. eeconfig_write_backlight(backlight_config.raw);
  74. }
  75. dprintf("backlight decrease: %u\n", backlight_config.level);
  76. backlight_set(backlight_config.level);
  77. #endif
  78. }
  79. void backlight_toggle(void)
  80. {
  81. #ifdef BREATHING_LED_ENABLE
  82. if (breathing_led_is_enabled()) {
  83. breathing_led_disable();
  84. backlight_disable();
  85. return;
  86. }
  87. #endif
  88. backlight_config.enable ^= 1;
  89. if (backlight_config.enable) {
  90. #if defined(BACKLIGHT_CUSTOM) || defined(BREATHING_LED_ENABLE)
  91. backlight_enable();
  92. #endif
  93. if (backlight_config.level == 0) {
  94. backlight_config.level = 1;
  95. }
  96. }
  97. else {
  98. #ifndef BREATHING_LED_ENABLE
  99. #ifdef BACKLIGHT_CUSTOM
  100. backlight_disable();
  101. #endif
  102. #endif
  103. }
  104. eeconfig_write_backlight(backlight_config.raw);
  105. dprintf("backlight toggle: %u\n", backlight_config.enable);
  106. backlight_set(backlight_config.enable ? backlight_config.level : 0);
  107. #ifdef BREATHING_LED_ENABLE
  108. if (!backlight_config.enable) {
  109. breathing_led_enable();
  110. }
  111. #endif
  112. }
  113. void backlight_step(void)
  114. {
  115. backlight_config.level++;
  116. if(backlight_config.level > BACKLIGHT_LEVELS)
  117. {
  118. backlight_config.level = 0;
  119. }
  120. backlight_config.enable = !!backlight_config.level;
  121. eeconfig_write_backlight(backlight_config.raw);
  122. dprintf("backlight step: %u\n", backlight_config.level);
  123. backlight_set(backlight_config.level);
  124. }