diff options
author | Phillip Tennen <phillip.ennen@gmail.com> | 2018-11-14 16:45:46 +0100 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2018-11-14 07:45:46 -0800 |
commit | 0cda2f43e2c95fe5dd440e6391ae807f508b040b (patch) | |
tree | 05d9cd5db86789ca0f475f43db7b0fbcb6251f1d | |
parent | f7fcba329dbd659a4bb37acdf7e2dc24204a81c8 (diff) | |
download | qmk_firmware-0cda2f43e2c95fe5dd440e6391ae807f508b040b.tar.gz qmk_firmware-0cda2f43e2c95fe5dd440e6391ae807f508b040b.zip |
Backlight status functions (#4259)
* add functions to set specific backlight state
* add function to query backlight state
* update documentation with new backlight functions
* Update tmk_core/common/backlight.c
Co-Authored-By: codyd51 <phillip.ennen@gmail.com>
* Update tmk_core/common/backlight.h
Co-Authored-By: codyd51 <phillip.ennen@gmail.com>
* update docs for is_backlight_enabled() name change
-rw-r--r-- | docs/feature_backlight.md | 19 | ||||
-rw-r--r-- | tmk_core/common/backlight.c | 51 | ||||
-rw-r--r-- | tmk_core/common/backlight.h | 4 |
3 files changed, 60 insertions, 14 deletions
diff --git a/docs/feature_backlight.md b/docs/feature_backlight.md index 7bb7e03a8..f7a35406c 100644 --- a/docs/feature_backlight.md +++ b/docs/feature_backlight.md | |||
@@ -54,14 +54,17 @@ In this handler, the value of an incrementing counter is mapped onto a precomput | |||
54 | 54 | ||
55 | ## Backlight Functions | 55 | ## Backlight Functions |
56 | 56 | ||
57 | |Function |Description | | 57 | |Function |Description | |
58 | |----------|----------------------------------------------------------| | 58 | |----------|-----------------------------------------------------------| |
59 | |`backlight_toggle()` |Turn the backlight on or off | | 59 | |`backlight_toggle()` |Turn the backlight on or off | |
60 | |`backlight_step()` |Cycle through backlight levels | | 60 | |`backlight_enable()` |Turn the backlight on | |
61 | |`backlight_increase()` |Increase the backlight level | | 61 | |`backlight_disable()` |Turn the backlight off | |
62 | |`backlight_decrease()` |Decrease the backlight level | | 62 | |`backlight_step()` |Cycle through backlight levels | |
63 | |`backlight_level(x)` |Sets the backlight level to specified level | | 63 | |`backlight_increase()` |Increase the backlight level | |
64 | |`get_backlight_level()`|Return the current backlight level | | 64 | |`backlight_decrease()` |Decrease the backlight level | |
65 | |`backlight_level(x)` |Sets the backlight level to specified level | | ||
66 | |`get_backlight_level()` |Return the current backlight level | | ||
67 | |`is_backlight_enabled()`|Return whether the backlight is currently on | | ||
65 | 68 | ||
66 | ### Backlight Breathing Functions | 69 | ### Backlight Breathing Functions |
67 | 70 | ||
diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c index 3e29aacc4..8ddacd98b 100644 --- a/tmk_core/common/backlight.c +++ b/tmk_core/common/backlight.c | |||
@@ -76,12 +76,51 @@ void backlight_decrease(void) | |||
76 | */ | 76 | */ |
77 | void backlight_toggle(void) | 77 | void backlight_toggle(void) |
78 | { | 78 | { |
79 | backlight_config.enable ^= 1; | 79 | bool enabled = backlight_config.enable; |
80 | if (backlight_config.raw == 1) // enabled but level = 0 | 80 | dprintf("backlight toggle: %u\n", enabled); |
81 | backlight_config.level = 1; | 81 | if (enabled) |
82 | eeconfig_update_backlight(backlight_config.raw); | 82 | backlight_disable(); |
83 | dprintf("backlight toggle: %u\n", backlight_config.enable); | 83 | else |
84 | backlight_set(backlight_config.enable ? backlight_config.level : 0); | 84 | backlight_enable(); |
85 | } | ||
86 | |||
87 | /** \brief Enable backlight | ||
88 | * | ||
89 | * FIXME: needs doc | ||
90 | */ | ||
91 | void backlight_enable(void) | ||
92 | { | ||
93 | if (backlight_config.enable) return; // do nothing if backlight is already on | ||
94 | |||
95 | backlight_config.enable = true; | ||
96 | if (backlight_config.raw == 1) // enabled but level == 0 | ||
97 | backlight_config.level = 1; | ||
98 | eeconfig_update_backlight(backlight_config.raw); | ||
99 | dprintf("backlight enable\n"); | ||
100 | backlight_set(backlight_config.level); | ||
101 | } | ||
102 | |||
103 | /** /brief Disable backlight | ||
104 | * | ||
105 | * FIXME: needs doc | ||
106 | */ | ||
107 | void backlight_disable(void) | ||
108 | { | ||
109 | if (!backlight_config.enable) return; // do nothing if backlight is already off | ||
110 | |||
111 | backlight_config.enable = false; | ||
112 | eeconfig_update_backlight(backlight_config.raw); | ||
113 | dprintf("backlight disable\n"); | ||
114 | backlight_set(0); | ||
115 | } | ||
116 | |||
117 | /** /brief Get the backlight status | ||
118 | * | ||
119 | * FIXME: needs doc | ||
120 | */ | ||
121 | bool is_backlight_enabled(void) | ||
122 | { | ||
123 | return backlight_config.enable; | ||
85 | } | 124 | } |
86 | 125 | ||
87 | /** \brief Backlight step through levels | 126 | /** \brief Backlight step through levels |
diff --git a/tmk_core/common/backlight.h b/tmk_core/common/backlight.h index ef8ab9b2b..420c9d19e 100644 --- a/tmk_core/common/backlight.h +++ b/tmk_core/common/backlight.h | |||
@@ -32,7 +32,11 @@ void backlight_init(void); | |||
32 | void backlight_increase(void); | 32 | void backlight_increase(void); |
33 | void backlight_decrease(void); | 33 | void backlight_decrease(void); |
34 | void backlight_toggle(void); | 34 | void backlight_toggle(void); |
35 | void backlight_enable(void); | ||
36 | void backlight_disable(void); | ||
37 | bool is_backlight_enabled(void); | ||
35 | void backlight_step(void); | 38 | void backlight_step(void); |
36 | void backlight_set(uint8_t level); | 39 | void backlight_set(uint8_t level); |
37 | void backlight_level(uint8_t level); | 40 | void backlight_level(uint8_t level); |
38 | uint8_t get_backlight_level(void); | 41 | uint8_t get_backlight_level(void); |
42 | |||