aboutsummaryrefslogtreecommitdiff
path: root/docs/ref_functions.md
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2018-10-18 21:34:40 -0700
committerJack Humbert <jack.humb@gmail.com>2018-10-19 00:34:40 -0400
commit7e1b57add42dcc3330d9d99e28c9b7f96eb2eee8 (patch)
tree2bc1b19e3f7345b4bd50c6b8461f987a822f344b /docs/ref_functions.md
parentf4094930a393ec3dc597e06e95cd3365e3f8cb97 (diff)
downloadqmk_firmware-7e1b57add42dcc3330d9d99e28c9b7f96eb2eee8.tar.gz
qmk_firmware-7e1b57add42dcc3330d9d99e28c9b7f96eb2eee8.zip
Some cleanup of the Useful Functions docs (#4064)
* Add examples for tri layers * Clean up and spelling fixes
Diffstat (limited to 'docs/ref_functions.md')
-rw-r--r--docs/ref_functions.md78
1 files changed, 64 insertions, 14 deletions
diff --git a/docs/ref_functions.md b/docs/ref_functions.md
index 7d0cda322..9b5be7a88 100644
--- a/docs/ref_functions.md
+++ b/docs/ref_functions.md
@@ -1,28 +1,79 @@
1# List of Useful Core Functions To Make Your Keyboard Better 1# List of Useful Core Functions To Make Your Keyboard Better
2 2
3There are a lot of hidden functions in QMK that are incredible useful, or may add a bit of functionality that you've been wanting. Functions that are specific to certain features are not included here, as those will be on their respective feature page. 3There are a lot of hidden functions in QMK that are incredible useful, or may add a bit of functionality that you've been wanting. Functions that are specific to certain features are not included here, as those will be on their respective feature page.
4 4
5## (OLKB) Tri Layers 5## (OLKB) Tri Layers
6 6
7There are actually separate functions that you can use there, depending on what you're after. 7There are actually separate functions that you can use there, depending on what you're after.
8 8
9The first is the `update_tri_layer(x, y, z)` function. This function check to see if layers `x` and `y` are both on. If they are both on, then it runs on layer `z`. Otherwise, if both `x` and `y` are not both on (either only one is, or neither is), then it runs off layer `z`. 9### `update_tri_layer(x, y, z)`
10 10
11This function is useful if you want to create specific keys that have this functionality, but other layer keycodes won't do this. 11The first is the `update_tri_layer(x, y, z)` function. This function check to see if layers `x` and `y` are both on. If they are both on, then it runs on layer `z`. Otherwise, if both `x` and `y` are not both on (either only one is, or neither is), then it runs off layer `z`.
12 12
13The other function is `update_tri_layer_state(state, x, y, z)`. This function is meant to be called from they [`layer_state_set_*` functions](custom_quantum_functions.md#layer-change-code). This means that any time that you use a keycode to change the layer, this will be checked. So you could use `LT(layer, kc)` to change the layer and it will trigger the same layer check. 13This function is useful if you want to create specific keys that have this functionality, but other layer keycodes won't do this.
14 14
15The caveat to this method is that you cannot access the `z` layer without having `x` and `y` layers on, since if you try to activate just layer `z`, it will run this code and turn off layer `z` before you could use it. 15#### Example
16
17```c
18bool process_record_user(uint16_t keycode, keyrecord_t *record) {
19 switch (keycode) {
20 case LOWER:
21 if (record->event.pressed) {
22 layer_on(_LOWER);
23 update_tri_layer(_LOWER, _RAISE, _ADJUST);
24 } else {
25 layer_off(_LOWER);
26 update_tri_layer(_LOWER, _RAISE, _ADJUST);
27 }
28 return false;
29 break;
30 case RAISE:
31 if (record->event.pressed) {
32 layer_on(_RAISE);
33 update_tri_layer(_LOWER, _RAISE, _ADJUST);
34 } else {
35 layer_off(_RAISE);
36 update_tri_layer(_LOWER, _RAISE, _ADJUST);
37 }
38 return false;
39 break;
40 }
41 return true;
42}
43```
44
45### `update_tri_layer_state(state, x, y, z)`
46The other function is `update_tri_layer_state(state, x, y, z)`. This function is meant to be called from they [`layer_state_set_*` functions](custom_quantum_functions.md#layer-change-code). This means that any time that you use a keycode to change the layer, this will be checked. So you could use `LT(layer, kc)` to change the layer and it will trigger the same layer check.
47
48The caveat to this method is that you cannot access the `z` layer without having `x` and `y` layers on, since if you try to activate just layer `z`, it will run this code and turn off layer `z` before you could use it.
49
50#### Example
51
52```c
53uint32_t layer_state_set_user(uint32_t state) {
54 return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
55}
56```
57
58Alternatively, you don't have to immediately "return" the value. This is useful if you want to add multiple tri layers, or if you want to add additional effects.
59
60```c
61uint32_t layer_state_set_user(uint32_t state) {
62 state = update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
63 state = update_tri_layer_state(state, _RAISE, _SYMB, _SPECIAL);
64 return state;
65}
66```
16 67
17## Setting the Persistent Default Layer 68## Setting the Persistent Default Layer
18 69
19Do you want to set the default layer, so that it's retained even after you unplug the board? If so, this is the function for you. 70Do you want to set the default layer, so that it's retained even after you unplug the board? If so, this is the function for you.
20 71
21To use this, you would use `set_single_persistent_default_layer(layer)`. If you have a name defined for your layer, you can use that instead (such as _QWERTY, _DVORAK or _COLEMAK). 72To use this, you would use `set_single_persistent_default_layer(layer)`. If you have a name defined for your layer, you can use that instead (such as _QWERTY, _DVORAK or _COLEMAK).
22 73
23This will set the default layer, update the persistent settings, and play a tune if you have [Audio](feature_audio.md) enabled on your board, and the default layer sounds set. 74This will set the default layer, update the persistent settings, and play a tune if you have [Audio](feature_audio.md) enabled on your board, and the default layer sounds set.
24 75
25To configure the default layer sounds, you would want to define this in your `config.h` file, like this: 76To configure the default layer sounds, you would want to define this in your `config.h` file, like this:
26 77
27```c 78```c
28#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \ 79#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
@@ -36,13 +87,12 @@ To configure the default layer sounds, you would want to define this in your `co
36 87
37## Reseting the keyboard 88## Reseting the keyboard
38 89
39There is the `RESET` quantum keycode that you can use. But if you want to reset the board as part of a macro, rather than hitting a key separately, you can do that. 90There is the `RESET` quantum keycode that you can use. But if you want to reset the board as part of a macro, rather than hitting a key separately, you can do that.
40 91
41And to do so, add `reset_keyboard()` to your function or macro, and this will reset to bootloader. 92And to do so, add `reset_keyboard()` to your function or macro, and this will reset to bootloader.
42 93
43## Wiping the EEPROM (Persistent Storage) 94## Wiping the EEPROM (Persistent Storage)
44 95
45If you're having issues with Audio, RGB Underglow, backlighting or keys acting weird, then you can reset the EEPROM (persistent setting storage). Bootmagic is one way to do this, but if that isn't enabled, then you can use a custom macro to do so. 96If you're having issues with Audio, RGB Underglow, backlighting or keys acting weird, then you can reset the EEPROM (persistent setting storage). Bootmagic is one way to do this, but if that isn't enabled, then you can use a custom macro to do so.
46
47To wipe the EEPROM, run `eeconfig_init()` from your function or macro to reset most of the settings to default.
48 97
98To wipe the EEPROM, run `eeconfig_init()` from your function or macro to reset most of the settings to default.