QMK/keyboards/betalupi_ergodox/keymaps/default/layers/layers.c

141 lines
2.8 KiB
C

#include "extra_mappings.h"
#define LAYER_INCLUDE_FILE "definitions/layers.inc"
/*
Setup
*/
// Generate layer ids
#define BETA_LAYER_KEYS
#define BETA_LAYER(name) LAYER_##name,
enum layer_indices {
#include LAYER_INCLUDE_FILE
X_LAYER_MAX
};
#undef BETA_LAYER
#undef BETA_LAYER_KEYS
// Generate RGBMatrix ids
// We don't use the same id for layers and layer colors
// to save memory. Not every layer has colors!
#define BETA_LAYER_LEDS
#define BETA_LAYER(name) LAYER_##name##_LEDS,
enum led_indices {
#include LAYER_INCLUDE_FILE
X_LAYER_LEDS_MAX
};
#undef BETA_LAYER
#undef BETA_LAYER_LEDS
/*
Load layers
*/
// Create keymap array
#define BETA_LAYER_KEYS
#define BETA_LAYER(name) [LAYER_##name] = BETA_LAYER_CONTEXT_DATA,
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
#include LAYER_INCLUDE_FILE
};
#undef BETA_LAYER
#undef BETA_LAYER_KEYS
// Create led map array
#define BETA_LAYER_LEDS
#define BETA_LAYER(name) [LAYER_##name##_LEDS] = BETA_LAYER_CONTEXT_DATA,
const uint8_t PROGMEM ledmaps[][RGB_MATRIX_LED_COUNT][3] = {
#include LAYER_INCLUDE_FILE
};
#undef BETA_LAYER
#undef BETA_LAYER_LEDS
// Create os layout array
#define BETA_LAYER_LAYOUTS
#define BETA_LAYER(name) [LAYER_##name] = BETA_LAYER_CONTEXT_DATA,
uint8_t layer_layouts[] = {
#include LAYER_INCLUDE_FILE
};
#undef BETA_LAYER
#undef BETA_LAYER_LAYOUTS
void set_layer_color(int layer) {
for (int i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
HSV hsv = {
.h = pgm_read_byte(&ledmaps[layer][i][0]),
.s = pgm_read_byte(&ledmaps[layer][i][1]),
.v = pgm_read_byte(&ledmaps[layer][i][2]),
};
if (!hsv.h && !hsv.s && !hsv.v) {
rgb_matrix_set_color( i, 0, 0, 0 );
} else {
RGB rgb = hsv_to_rgb( hsv );
float f = (float)rgb_matrix_config.hsv.v / UINT8_MAX;
rgb_matrix_set_color( i, f * rgb.r, f * rgb.g, f * rgb.b );
}
}
}
bool rgb_matrix_indicators_user(void) {
if (keyboard_config.disable_layer_led) {
return true;
}
switch (biton32(layer_state)) {
// Load layer RGBMatrix colors
#define BETA_LAYER_LEDS
#define BETA_LAYER(name)\
case LAYER_##name:\
set_layer_color(LAYER_##name##_LEDS);\
break;
#include LAYER_INCLUDE_FILE
#undef BETA_LAYER
#undef BETA_LAYER_LEDS
default:
if (rgb_matrix_get_flags() == LED_FLAG_NONE) {
rgb_matrix_set_color_all(0, 0, 0);
}
break;
}
return true;
}
layer_state_t layer_state_set_user(layer_state_t state) {
uint8_t layer = biton32(state);
ergodox_board_led_off();
ergodox_right_led_1_off();
ergodox_right_led_2_off();
ergodox_right_led_3_off();
switch (layer) {
// Load indicator LED cases
#define BETA_LAYER_INDICATORS
#define BETA_LAYER(name) LAYER_##name
#include LAYER_INCLUDE_FILE
#undef BETA_LAYER
#undef BETA_LAYER_INDICATORS
default:
break;
}
return state;
};