aboutsummaryrefslogtreecommitdiff
path: root/docs/custom_quantum_functions.md
diff options
context:
space:
mode:
authorYan-Fa Li <yanfali@gmail.com>2019-11-22 12:55:45 -0800
committerGitHub <noreply@github.com>2019-11-22 12:55:45 -0800
commite62ab7e259d4f33c639a9433264c1cbfb6381cb5 (patch)
tree0506398d1b45c55c3eeafd30c92b459d8920c6b5 /docs/custom_quantum_functions.md
parent0270d4d5a17690ddf85676a1d4721d06fc690739 (diff)
downloadqmk_firmware-e62ab7e259d4f33c639a9433264c1cbfb6381cb5.tar.gz
qmk_firmware-e62ab7e259d4f33c639a9433264c1cbfb6381cb5.zip
Allow overriding of all functions in wonderland.c (#7198)
* f * Allow overriding of all functions in wonderland.c - needed for custom LED functions in keymap.c * Example of layer indication via LEDs optimize * Use newer led_update_kb and led_update_user hooks - these allow overriding without use of __attribute((weak))__ * Update led documentation a bit - clarify some of the wording around how to use led_update_user * Update led_update_user example * Update audio example to be complete * trailing spaces smh * spaces * spaces * smh * Less code is good * Update docs/custom_quantum_functions.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update docs/custom_quantum_functions.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update docs/custom_quantum_functions.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update docs/custom_quantum_functions.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update docs/custom_quantum_functions.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update docs/custom_quantum_functions.md Co-Authored-By: fauxpark <fauxpark@gmail.com>
Diffstat (limited to 'docs/custom_quantum_functions.md')
-rw-r--r--docs/custom_quantum_functions.md66
1 files changed, 32 insertions, 34 deletions
diff --git a/docs/custom_quantum_functions.md b/docs/custom_quantum_functions.md
index 2d505b075..3879e43bc 100644
--- a/docs/custom_quantum_functions.md
+++ b/docs/custom_quantum_functions.md
@@ -114,7 +114,15 @@ Two more deprecated functions exist that provide the LED state as a `uint8_t`:
114 114
115This function will be called when the state of one of those 5 LEDs changes. It receives the LED state as a struct parameter. 115This function will be called when the state of one of those 5 LEDs changes. It receives the LED state as a struct parameter.
116 116
117You must return either `true` or `false` from this function, depending on whether you want to override the keyboard-level implementation. 117By convention, return `true` from `led_update_user()` to get the `led_update_kb()` hook to run its code, and
118return `false` when you would prefer not to run the code in `led_update_kb()`.
119
120Some examples include:
121
122 - overriding the LEDs to use them for something else like layer indication
123 - return `false` because you do not want the `_kb()` function to run, as it would override your layer behavior.
124 - play a sound when an LED turns on or off.
125 - return `true` because you want the `_kb` function to run, and this is in addition to the default LED behavior.
118 126
119?> Because the `led_set_*` functions return `void` instead of `bool`, they do not allow for overriding the keyboard LED control, and thus it's recommended to use `led_update_*` instead. 127?> Because the `led_set_*` functions return `void` instead of `bool`, they do not allow for overriding the keyboard LED control, and thus it's recommended to use `led_update_*` instead.
120 128
@@ -122,7 +130,8 @@ You must return either `true` or `false` from this function, depending on whethe
122 130
123```c 131```c
124bool led_update_kb(led_t led_state) { 132bool led_update_kb(led_t led_state) {
125 if(led_update_user(led_state)) { 133 bool res = led_update_user(led_state);
134 if(res) {
126 if (led_state.num_lock) { 135 if (led_state.num_lock) {
127 writePinLow(B0); 136 writePinLow(B0);
128 } else { 137 } else {
@@ -148,40 +157,29 @@ bool led_update_kb(led_t led_state) {
148 } else { 157 } else {
149 writePinHigh(B4); 158 writePinHigh(B4);
150 } 159 }
151 return true;
152 } 160 }
161 return res;
153} 162}
154``` 163```
155 164
156### Example `led_update_user()` Implementation 165### Example `led_update_user()` Implementation
157 166
167This incomplete example would play a sound if Caps Lock is turned on or off. It returns `true`, because you also want the LEDs to maintain their state.
168
158```c 169```c
170#ifdef AUDIO_ENABLE
171 float caps_on[][2] = SONG(CAPS_LOCK_ON_SOUND);
172 float caps_off[][2] = SONG(CAPS_LOCK_OFF_SOUND);
173#endif
174
159bool led_update_user(led_t led_state) { 175bool led_update_user(led_t led_state) {
160 if (led_state.num_lock) { 176 #ifdef AUDIO_ENABLE
161 writePinLow(B0); 177 static uint8_t caps_state = 0;
162 } else { 178 if (caps_state != led_state.caps_lock) {
163 writePinHigh(B0); 179 led_state.caps_lock ? PLAY_SONG(caps_on) : PLAY_SONG(caps_off);
164 } 180 caps_state = led_state.caps_lock;
165 if (led_state.caps_lock) {
166 writePinLow(B1);
167 } else {
168 writePinHigh(B1);
169 }
170 if (led_state.scroll_lock) {
171 writePinLow(B2);
172 } else {
173 writePinHigh(B2);
174 }
175 if (led_state.compose) {
176 writePinLow(B3);
177 } else {
178 writePinHigh(B3);
179 }
180 if (led_state.kana) {
181 writePinLow(B4);
182 } else {
183 writePinHigh(B4);
184 } 181 }
182 #endif
185 return true; 183 return true;
186} 184}
187``` 185```
@@ -411,7 +409,7 @@ void keyboard_post_init_user(void) {
411 // Set default layer, if enabled 409 // Set default layer, if enabled
412 if (user_config.rgb_layer_change) { 410 if (user_config.rgb_layer_change) {
413 rgblight_enable_noeeprom(); 411 rgblight_enable_noeeprom();
414 rgblight_sethsv_noeeprom_cyan(); 412 rgblight_sethsv_noeeprom_cyan();
415 rgblight_mode_noeeprom(1); 413 rgblight_mode_noeeprom(1);
416 } 414 }
417} 415}
@@ -459,18 +457,18 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
459 } 457 }
460 return true; // Let QMK send the enter press/release events 458 return true; // Let QMK send the enter press/release events
461 case RGB_LYR: // This allows me to use underglow as layer indication, or as normal 459 case RGB_LYR: // This allows me to use underglow as layer indication, or as normal
462 if (record->event.pressed) { 460 if (record->event.pressed) {
463 user_config.rgb_layer_change ^= 1; // Toggles the status 461 user_config.rgb_layer_change ^= 1; // Toggles the status
464 eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM 462 eeconfig_update_user(user_config.raw); // Writes the new status to EEPROM
465 if (user_config.rgb_layer_change) { // if layer state indication is enabled, 463 if (user_config.rgb_layer_change) { // if layer state indication is enabled,
466 layer_state_set(layer_state); // then immediately update the layer color 464 layer_state_set(layer_state); // then immediately update the layer color
467 } 465 }
468 } 466 }
469 return false; break; 467 return false; break;
470 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // For any of the RGB codes (see quantum_keycodes.h, L400 for reference) 468 case RGB_MODE_FORWARD ... RGB_MODE_GRADIENT: // For any of the RGB codes (see quantum_keycodes.h, L400 for reference)
471 if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled 469 if (record->event.pressed) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
472 if (user_config.rgb_layer_change) { // only if this is enabled 470 if (user_config.rgb_layer_change) { // only if this is enabled
473 user_config.rgb_layer_change = false; // disable it, and 471 user_config.rgb_layer_change = false; // disable it, and
474 eeconfig_update_user(user_config.raw); // write the setings to EEPROM 472 eeconfig_update_user(user_config.raw); // write the setings to EEPROM
475 } 473 }
476 } 474 }
@@ -483,7 +481,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
483And lastly, you want to add the `eeconfig_init_user` function, so that when the EEPROM is reset, you can specify default values, and even custom actions. To force an EEPROM reset, use the `EEP_RST` keycode or [Bootmagic](feature_bootmagic.md) functionallity. For example, if you want to set rgb layer indication by default, and save the default valued. 481And lastly, you want to add the `eeconfig_init_user` function, so that when the EEPROM is reset, you can specify default values, and even custom actions. To force an EEPROM reset, use the `EEP_RST` keycode or [Bootmagic](feature_bootmagic.md) functionallity. For example, if you want to set rgb layer indication by default, and save the default valued.
484 482
485```c 483```c
486void eeconfig_init_user(void) { // EEPROM is getting reset! 484void eeconfig_init_user(void) { // EEPROM is getting reset!
487 user_config.raw = 0; 485 user_config.raw = 0;
488 user_config.rgb_layer_change = true; // We want this enabled by default 486 user_config.rgb_layer_change = true; // We want this enabled by default
489 eeconfig_update_user(user_config.raw); // Write default value to EEPROM now 487 eeconfig_update_user(user_config.raw); // Write default value to EEPROM now
@@ -508,7 +506,7 @@ The `val` is the value of the data that you want to write to EEPROM. And the `e
508 506
509By default, the tapping term is defined globally, and is not configurable by key. For most users, this is perfectly fine. But in come cases, dual function keys would be greatly improved by different timeouts than `LT` keys, or because some keys may be easier to hold than others. Instead of using custom key codes for each, this allows for per key configurable `TAPPING_TERM`. 507By default, the tapping term is defined globally, and is not configurable by key. For most users, this is perfectly fine. But in come cases, dual function keys would be greatly improved by different timeouts than `LT` keys, or because some keys may be easier to hold than others. Instead of using custom key codes for each, this allows for per key configurable `TAPPING_TERM`.
510 508
511To enable this functionality, you need to add `#define TAPPING_TERM_PER_KEY` to your `config.h`, first. 509To enable this functionality, you need to add `#define TAPPING_TERM_PER_KEY` to your `config.h`, first.
512 510
513 511
514## Example `get_tapping_term` Implementation 512## Example `get_tapping_term` Implementation