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

106 lines
2.1 KiB
C
Raw Normal View History

#include "layers.h"
// 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[][DRIVER_LED_TOTAL][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 < DRIVER_LED_TOTAL; 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 );
}
}
}
void rgb_matrix_indicators_user(void) {
if (keyboard_config.disable_layer_led) {
return;
}
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;
}
}
uint32_t set_layer_colors(uint32_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;
};