The above code is similar to that used in previous examples. The one point to note is that you need to declare a variable to keep track of what layer is currently the active layer. We'll see why shortly.
Towards the bottom of your `keymap.c`, include the following code:
```
//Update active_layer
uint32_t layer_state_set_user(uint32_t state) {
switch (biton32(state)) {
case 1:
active_layer = 1;
break;
case 2:
active_layer = 2;
break;
case 3:
active_layer = 3;
break;
default:
active_layer = 0;
break;
}
return state;
}
```c
//Determine the current tap dance state
int cur_dance (qk_tap_dance_state_t *state) {
if (state->count == 1) {
if (!state->pressed) {return SINGLE_TAP;}
else return SINGLE_HOLD;
} else if (state->count == 2) {return DOUBLE_TAP;}
The is where the real logic of our tap dance key gets worked out. Since `layer_state_set_user()` is called on any layer switch, we use it to update `active_layer`. Our example is assuming that your `keymap.c` includes 4 layers, so adjust the switch statement here to fit your actual number of layers.
The above code is similar to that used in previous examples. The one point to note is that we need to be able to check which layers are active at any time so we can toggle them if needed. To do this we use the `layer_state_is( layer )` function which returns `true` if the given `layer` is active.
The use of `cur_dance()` and `ql_tap_state` mirrors the above examples.