aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Brait <andrebrait@gmail.com>2021-08-13 20:33:04 +0200
committerGitHub <noreply@github.com>2021-08-13 11:33:04 -0700
commit5711a3bac296fa7ed793b1c59da6d1bb898455cb (patch)
tree76eaab6518089e051ae5871511e999b54c5d7f48
parentfa1ec32e39a23380c887e3f75db8b4be6e71b798 (diff)
downloadqmk_firmware-5711a3bac296fa7ed793b1c59da6d1bb898455cb.tar.gz
qmk_firmware-5711a3bac296fa7ed793b1c59da6d1bb898455cb.zip
[Keymap] Improve andrebrait keymap (#13985)
-rw-r--r--keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c
index febca3b97..b80164043 100644
--- a/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c
+++ b/keyboards/gmmk/pro/ansi/keymaps/andrebrait/keymap.c
@@ -21,9 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef RGB_CONFIRMATION_BLINKING_TIME 21 #ifndef RGB_CONFIRMATION_BLINKING_TIME
22 #define RGB_CONFIRMATION_BLINKING_TIME 2000 // 2 seconds 22 #define RGB_CONFIRMATION_BLINKING_TIME 2000 // 2 seconds
23 #endif 23 #endif
24 #if RGB_CONFIRMATION_BLINKING_TIME > 0
25 #include <lib/lib8tion/lib8tion.h>
26 #endif // RGB_CONFIRMATION_BLINKING_TIME > 0
27#endif // RGB_MATRIX_ENABLE 24#endif // RGB_MATRIX_ENABLE
28 25
29// clang-format off 26// clang-format off
@@ -83,6 +80,10 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
83 80
84#ifdef RGB_MATRIX_ENABLE 81#ifdef RGB_MATRIX_ENABLE
85 82
83/* Renaming those to make the purpose on this keymap clearer */
84#define LED_FLAG_CAPS LED_FLAG_NONE
85#define LED_FLAG_EFFECTS LED_FLAG_INDICATOR
86
86static void set_rgb_caps_leds(void); 87static void set_rgb_caps_leds(void);
87 88
88#if RGB_CONFIRMATION_BLINKING_TIME > 0 89#if RGB_CONFIRMATION_BLINKING_TIME > 0
@@ -90,6 +91,13 @@ static uint16_t effect_started_time = 0;
90static uint8_t r_effect = 0x0, g_effect = 0x0, b_effect = 0x0; 91static uint8_t r_effect = 0x0, g_effect = 0x0, b_effect = 0x0;
91static void start_effects(void); 92static void start_effects(void);
92 93
94/* The higher this is, the slower the blinking will be */
95#ifndef TIME_SELECTED_BIT
96 #define TIME_SELECTED_BIT 8
97#endif
98#if TIME_SELECTED_BIT < 0 || TIME_SELECTED_BIT >= 16
99 #error "TIME_SELECTED_BIT must be a positive integer smaller than 16"
100#endif
93#define effect_red() r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0 101#define effect_red() r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0
94#define effect_green() r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0 102#define effect_green() r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0
95#endif // RGB_CONFIRMATION_BLINKING_TIME > 0 103#endif // RGB_CONFIRMATION_BLINKING_TIME > 0
@@ -98,10 +106,10 @@ bool led_update_user(led_t led_state) {
98 if (led_state.caps_lock) { 106 if (led_state.caps_lock) {
99 if (!rgb_matrix_is_enabled()) { 107 if (!rgb_matrix_is_enabled()) {
100 /* Turn ON the RGB Matrix for CAPS LOCK */ 108 /* Turn ON the RGB Matrix for CAPS LOCK */
101 rgb_matrix_set_flags(LED_FLAG_NONE); 109 rgb_matrix_set_flags(LED_FLAG_CAPS);
102 rgb_matrix_enable(); 110 rgb_matrix_enable();
103 } 111 }
104 } else if (rgb_matrix_get_flags() == LED_FLAG_NONE) { 112 } else if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
105 /* RGB Matrix was only ON because of CAPS LOCK. Turn it OFF. */ 113 /* RGB Matrix was only ON because of CAPS LOCK. Turn it OFF. */
106 rgb_matrix_set_flags(LED_FLAG_ALL); 114 rgb_matrix_set_flags(LED_FLAG_ALL);
107 rgb_matrix_disable(); 115 rgb_matrix_disable();
@@ -167,9 +175,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
167 if (rgb_matrix_is_enabled()) { 175 if (rgb_matrix_is_enabled()) {
168 switch (rgb_matrix_get_flags()) { 176 switch (rgb_matrix_get_flags()) {
169 #if RGB_CONFIRMATION_BLINKING_TIME > 0 177 #if RGB_CONFIRMATION_BLINKING_TIME > 0
170 case LED_FLAG_INDICATOR: 178 case LED_FLAG_EFFECTS:
171 #endif 179 #endif
172 case LED_FLAG_NONE: 180 case LED_FLAG_CAPS:
173 /* Turned ON because of EFFECTS or CAPS, is actually OFF */ 181 /* Turned ON because of EFFECTS or CAPS, is actually OFF */
174 /* Change to LED_FLAG_ALL to signal it's really ON */ 182 /* Change to LED_FLAG_ALL to signal it's really ON */
175 rgb_matrix_set_flags(LED_FLAG_ALL); 183 rgb_matrix_set_flags(LED_FLAG_ALL);
@@ -180,15 +188,15 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
180 /* Is actually ON */ 188 /* Is actually ON */
181 #if RGB_CONFIRMATION_BLINKING_TIME > 0 189 #if RGB_CONFIRMATION_BLINKING_TIME > 0
182 if (effect_started_time > 0) { 190 if (effect_started_time > 0) {
183 /* Change to LED_FLAG_INDICATOR to signal EFFECTS */ 191 /* Signal EFFECTS */
184 rgb_matrix_set_flags(LED_FLAG_INDICATOR); 192 rgb_matrix_set_flags(LED_FLAG_EFFECTS);
185 /* Will be re-enabled by the processing of the toggle */ 193 /* Will be re-enabled by the processing of the toggle */
186 rgb_matrix_disable_noeeprom(); 194 rgb_matrix_disable_noeeprom();
187 } else 195 } else
188 #endif 196 #endif
189 if (host_keyboard_led_state().caps_lock) { 197 if (host_keyboard_led_state().caps_lock) {
190 /* Change to LED_FLAG_NONE to signal CAPS */ 198 /* Signal CAPS */
191 rgb_matrix_set_flags(LED_FLAG_NONE); 199 rgb_matrix_set_flags(LED_FLAG_CAPS);
192 /* Will be re-enabled by the processing of the toggle */ 200 /* Will be re-enabled by the processing of the toggle */
193 rgb_matrix_disable_noeeprom(); 201 rgb_matrix_disable_noeeprom();
194 } 202 }
@@ -204,12 +212,11 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
204 212
205void rgb_matrix_indicators_user() { 213void rgb_matrix_indicators_user() {
206 #if RGB_CONFIRMATION_BLINKING_TIME > 0 214 #if RGB_CONFIRMATION_BLINKING_TIME > 0
207 if (effect_started_time != 0) { 215 if (effect_started_time > 0) {
208 /* Render blinking EFFECTS */ 216 /* Render blinking EFFECTS */
209 uint16_t deltaTime = sync_timer_elapsed(effect_started_time); 217 uint16_t deltaTime = sync_timer_elapsed(effect_started_time);
210 if (deltaTime <= RGB_CONFIRMATION_BLINKING_TIME) { 218 if (deltaTime <= RGB_CONFIRMATION_BLINKING_TIME) {
211 uint16_t time = scale16by8(deltaTime, UINT8_MAX / 2); 219 uint8_t led_state = ((~deltaTime) >> TIME_SELECTED_BIT) & 0x01;
212 uint8_t led_state = sin8(time) >> 7;
213 uint8_t val_r = led_state * r_effect; 220 uint8_t val_r = led_state * r_effect;
214 uint8_t val_g = led_state * g_effect; 221 uint8_t val_g = led_state * g_effect;
215 uint8_t val_b = led_state * b_effect; 222 uint8_t val_b = led_state * b_effect;
@@ -221,11 +228,11 @@ void rgb_matrix_indicators_user() {
221 } else { 228 } else {
222 /* EFFECTS duration is finished */ 229 /* EFFECTS duration is finished */
223 effect_started_time = 0; 230 effect_started_time = 0;
224 if (rgb_matrix_get_flags() == LED_FLAG_INDICATOR) { 231 if (rgb_matrix_get_flags() == LED_FLAG_EFFECTS) {
225 /* It was turned ON because of EFFECTS */ 232 /* It was turned ON because of EFFECTS */
226 if (host_keyboard_led_state().caps_lock) { 233 if (host_keyboard_led_state().caps_lock) {
227 /* CAPS is still ON. Demote to CAPS */ 234 /* CAPS is still ON. Demote to CAPS */
228 rgb_matrix_set_flags(LED_FLAG_NONE); 235 rgb_matrix_set_flags(LED_FLAG_CAPS);
229 } else { 236 } else {
230 /* There is nothing else keeping RGB enabled. Reset flags and turn if off. */ 237 /* There is nothing else keeping RGB enabled. Reset flags and turn if off. */
231 rgb_matrix_set_flags(LED_FLAG_ALL); 238 rgb_matrix_set_flags(LED_FLAG_ALL);
@@ -235,7 +242,7 @@ void rgb_matrix_indicators_user() {
235 } 242 }
236 } 243 }
237 #endif // RGB_CONFIRMATION_BLINKING_TIME > 0 244 #endif // RGB_CONFIRMATION_BLINKING_TIME > 0
238 if (rgb_matrix_get_flags() == LED_FLAG_NONE) { 245 if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
239 rgb_matrix_set_color_all(0x0, 0x0, 0x0); 246 rgb_matrix_set_color_all(0x0, 0x0, 0x0);
240 } 247 }
241 if (host_keyboard_led_state().caps_lock) { 248 if (host_keyboard_led_state().caps_lock) {
@@ -248,11 +255,11 @@ static void start_effects() {
248 effect_started_time = sync_timer_read(); 255 effect_started_time = sync_timer_read();
249 if (!rgb_matrix_is_enabled()) { 256 if (!rgb_matrix_is_enabled()) {
250 /* Turn it ON, signal the cause (EFFECTS) */ 257 /* Turn it ON, signal the cause (EFFECTS) */
251 rgb_matrix_set_flags(LED_FLAG_INDICATOR); 258 rgb_matrix_set_flags(LED_FLAG_EFFECTS);
252 rgb_matrix_enable_noeeprom(); 259 rgb_matrix_enable_noeeprom();
253 } else if (rgb_matrix_get_flags() == LED_FLAG_NONE) { 260 } else if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
254 /* It's already ON, promote the cause from CAPS to EFFECTS */ 261 /* It's already ON, promote the cause from CAPS to EFFECTS */
255 rgb_matrix_set_flags(LED_FLAG_INDICATOR); 262 rgb_matrix_set_flags(LED_FLAG_EFFECTS);
256 } 263 }
257} 264}
258#endif // RGB_CONFIRMATION_BLINKING_TIME > 0 265#endif // RGB_CONFIRMATION_BLINKING_TIME > 0