#include QMK_KEYBOARD_H uint8_t flags = 0; #include "keycodes.h" #include "lighting.h" #include "keymap_bepo.h" // The variable is defined in star_key.h // The LED is on when the key is pressed. extern bool is_star; // Set the color at the given position, but limit the intensity void set_color(uint8_t index, uint8_t h, uint8_t s, uint8_t v) { if (v > 20 + rgb_matrix_get_val()) v = 20 + rgb_matrix_get_val(); HSV hsv = {h, s, v}; RGB rgb = hsv_to_rgb(hsv); rgb_matrix_set_color(index, rgb.r, rgb.g, rgb.b); } HSV hsv_of_color(uint8_t h, uint8_t s, uint8_t v) { return (HSV){h, s, v > rgb_matrix_get_val() ? rgb_matrix_get_val():v}; } void lighting_init(void) { rgb_matrix_sethsv_noeeprom(HSV_WHITE); rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_REACTIVE_SIMPLE); } static uint8_t last_flags; static bool one_shot_alt_flag = 0; void oneshot_mods_changed_lighting(uint8_t mods) { one_shot_alt_flag = mods & MOD_MASK_ALT; } void housekeeping_task_lighting(void) { // Colors for the mods HSV const colors[] = { hsv_of_color(HSV_BLACK), // 000 hsv_of_color(55, 255, 255),// 001 hsv_of_color(HSV_RED), // 010 hsv_of_color(HSV_ORANGE),// 011 hsv_of_color(HSV_CYAN), // 100 hsv_of_color(HSV_GREEN), // 101 hsv_of_color(HSV_PURPLE),// 110 hsv_of_color(HSV_WHITE), // 111 }; uint8_t flags = 0; if (get_mods() & MOD_MASK_CTRL) { flags |= 0b001; } if (one_shot_alt_flag || (get_mods() & MOD_MASK_ALT)) { flags |= 0b010; } if ((get_mods() & MOD_MASK_SHIFT) || host_keyboard_led_state().caps_lock) { flags |= 0b100; } uint8_t matrix_mode = rgb_matrix_get_mode(); if (matrix_mode != RGB_MATRIX_BREATHING && host_keyboard_led_state().caps_lock) { rgb_matrix_mode_noeeprom(RGB_MATRIX_BREATHING); } if (flags == last_flags) { return; } last_flags = flags; if (flags) { if (matrix_mode != RGB_MATRIX_SOLID_COLOR) { rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR); } rgb_matrix_sethsv_noeeprom(colors[flags].h, colors[flags].s, rgb_matrix_get_val()); } else if (matrix_mode != RGB_MATRIX_SOLID_REACTIVE_SIMPLE) { rgb_matrix_sethsv_noeeprom(0, 0, rgb_matrix_get_val()); rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_REACTIVE_SIMPLE); } } #define KEY_6 MT(MOD_LCTL, KC_P6) #define KEY_DOWN MT(MOD_RCTL, KC_DOWN) bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { // Activate effects depending of mods for (uint8_t row = 0; row < MATRIX_ROWS; ++row) { for (uint8_t col = 0; col < MATRIX_COLS; ++col) { uint8_t index = g_led_config.matrix_co[row][col]; if (index < led_min || index > led_max || index == NO_LED) continue; uint8_t layer = layer_switch_get_layer((keypos_t){col,row}); uint16_t keycode = keymap_key_to_keycode(layer, (keypos_t){col,row}); if (keycode == KC_O && is_star) { set_color(index, 42, 255, 255); } if (layer == 0) continue; switch (keycode) { case KC_F1 ... KC_F11: set_color(index, 0, 0, 128); break; case KC_P1 ... KC_P0: case KEY_6: set_color(index, 42, 255, 255); break; case BP_CCED: case BP_PERC: case KC_PDOT: // Add a bit of red for the punction symbol set_color(index, 20, 255, 255); break; case KC_RIGHT: case KEY_DOWN: case KC_LEFT ... KC_UP: case KC_PGUP: case KC_PGDN: case KEY_PGDN: set_color(index, 170, 255, 223); break; case KC_HOME: case KC_END: set_color(index, HSV_SPRINGGREEN); break; case KC_BSPC: case AL_SPC: case AL_ENT: set_color(index, HSV_BLUE); break; case QK_RGB_MATRIX_VALUE_UP: case QK_RGB_MATRIX_VALUE_DOWN: set_color(index, HSV_GREEN); break; } } } return false; } n35' href='#n35'>35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#include QMK_KEYBOARD_H
#include "quad_tapdance.h"
#include "enter_dance.h"
static td_tap_t enter_tap_state = {
.state = TD_NONE
};
static bool inhibit_mod = 0;
void enter_dance_process_record(uint16_t keycode, keyrecord_t *record) {
if (enter_tap_state.state == TD_SINGLE_HOLD && record->event.pressed) {
inhibit_mod = 1;
}
return;
}
void enter_finished(tap_dance_state_t *state, void *user_data) {
enter_tap_state.state = cur_dance(state);
switch (enter_tap_state.state) {
case TD_SINGLE_HOLD:
if (get_oneshot_mods() & MOD_MASK_ALT) {
del_oneshot_mods(MOD_MASK_ALT);
//clear_oneshot_mods();
inhibit_mod = 1;
}
register_code(KC_RIGHT_ALT);
break;
default: break;
}
}
void enter_released(tap_dance_state_t *state, void *user_data) {
if (state->finished && state->count > 1)
// Exit prevently, we are sure in the next conditions we don’t fall in
// this case.
return;
else if (!state->finished) {
tap_code16(KC_ENTER);
reset_tap_dance(state);
} else if (!state->interrupted) {
// Final case, the key was keeped pressed without any other action
// in this case, active the one shot key for right alt
if (get_oneshot_mods() & MOD_MASK_ALT) {
del_oneshot_mods(MOD_MASK_ALT);
//clear_oneshot_mods();
} else if (!inhibit_mod) {
set_oneshot_mods(MOD_BIT(KC_RIGHT_ALT));
}
}
inhibit_mod = 0;
}
void enter_reset(tap_dance_state_t *state, void *user_data) {
switch (enter_tap_state.state) {
case TD_SINGLE_HOLD: unregister_code(KC_RIGHT_ALT); break;
default: break;
}
enter_tap_state.state = TD_NONE;
}