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

141 lines
2.8 KiB
C
Raw Permalink Normal View History

2022-07-21 21:20:16 -07:00
#include "extra_mappings.h"
2024-08-23 09:43:24 -07:00
#define LAYER_INCLUDE_FILE "definitions/include.c"
2022-12-27 13:22:07 -08:00
/*
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,
2022-12-27 13:22:07 -08:00
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) {
2022-12-27 13:22:07 -08:00
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 );
}
}
}
2022-12-27 13:22:07 -08:00
bool rgb_matrix_indicators_user(void) {
if (keyboard_config.disable_layer_led) {
2022-12-27 13:22:07 -08:00
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;
}
2022-12-27 13:22:07 -08:00
return true;
}
2022-12-27 13:22:07 -08:00
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;
};