void start_rgb_light(void) { uint8_t indices[RGBLED_NUM]; uint8_t indices_count = 0; uint8_t min_life = 0xFF; uint8_t min_life_index = -1; for (uint8_t index = 0 ; index < RGBLED_NUM ; ++index ) { if (rgblight_twinkle_is_led_used(index)) { continue; } if (lights[index].enabled) { if (min_life_index == -1 || lights[index].life < min_life) { min_life = lights[index].life; min_life_index = index; } continue; } indices[indices_count] = index; ++indices_count; } uint8_t light_index; if (!indices_count) { light_index = min_life_index; } else { light_index = indices[rand() % indices_count]; } rgblight_fadeout *light = &lights[light_index]; light->enabled = true; light->timer = timer_read(); light->life = 0xC0 + rand() % 0x40; light->hue = rgblight_config.hue + (rand() % 0xB4) - 0x54; rgblight_sethsv_at(light->hue, 255, light->life, light_index); }
uint32_t layer_state_set_keymap (uint32_t state) { uint8_t modifiders = get_mods(); uint8_t led_usb_state = host_keyboard_leds(); uint8_t one_shot = get_oneshot_mods(); if (modifiders & MODS_SHIFT_MASK || led_usb_state & (1<<USB_LED_CAPS_LOCK) || one_shot & MODS_SHIFT_MASK) { rgblight_sethsv_at(0, 255, 255, 5); rgblight_sethsv_at(0, 255, 255, 10); } if (modifiders & MODS_CTRL_MASK || one_shot & MODS_CTRL_MASK) { rgblight_sethsv_at(51, 255, 255, 6); rgblight_sethsv_at(51, 255, 255, 9); } if (modifiders & MODS_ALT_MASK || one_shot & MODS_ALT_MASK) { rgblight_sethsv_at(120, 255, 255, 7); rgblight_sethsv_at(120, 255, 255, 8); } return state; }
void matrix_scan_keymap (void) { static uint8_t current_mods; static uint8_t current_host_leds; static uint8_t current_oneshot_mods; static bool has_status_changed = true; if ( current_mods != get_mods() || current_host_leds != host_keyboard_leds() || current_oneshot_mods != get_oneshot_mods()) { has_status_changed = true; current_mods = get_mods(); current_host_leds = host_keyboard_leds(); current_oneshot_mods = get_oneshot_mods(); } if (has_status_changed) { has_status_changed = false; if (current_mods & MODS_SHIFT_MASK || current_host_leds & (1<<USB_LED_CAPS_LOCK) || current_oneshot_mods & MODS_SHIFT_MASK) { rgblight_sethsv_at(0, 255, 255, 5); rgblight_sethsv_at(0, 255, 255, 10); } else { rgblight_sethsv_default_helper(5); rgblight_sethsv_default_helper(10); } if (current_mods & MODS_CTRL_MASK || current_oneshot_mods & MODS_CTRL_MASK) { rgblight_sethsv_at(51, 255, 255, 6); rgblight_sethsv_at(51, 255, 255, 9); } else { rgblight_sethsv_default_helper(6); rgblight_sethsv_default_helper(9); } if (current_mods & MODS_GUI_MASK || current_oneshot_mods & MODS_GUI_MASK) { rgblight_sethsv_at(120, 255, 255, 7); rgblight_sethsv_at(120, 255, 255, 8); } else { rgblight_sethsv_default_helper(7); rgblight_sethsv_default_helper(8); } } }
void set_rgb_indicators(uint8_t this_mod, uint8_t this_led, uint8_t this_osm) { if (userspace_config.rgb_layer_change && biton32(layer_state) == 0) { if ( (this_mod | this_osm) & MOD_MASK_SHIFT || this_led & (1<<USB_LED_CAPS_LOCK) ) { #ifdef SHFT_LED1 rgblight_sethsv_at(120, 255, 255, SHFT_LED1); #endif // SHFT_LED1 #ifdef SHFT_LED2 rgblight_sethsv_at(120, 255, 255, SHFT_LED2); #endif // SHFT_LED2 } else { #ifdef SHFT_LED1 rgblight_sethsv_default_helper(SHFT_LED1); #endif // SHFT_LED1 #ifdef SHFT_LED2 rgblight_sethsv_default_helper(SHFT_LED2); #endif // SHFT_LED2 } if ( (this_mod | this_osm) & MOD_MASK_CTRL) { #ifdef CTRL_LED1 rgblight_sethsv_at(0, 255, 255, CTRL_LED1); #endif // CTRL_LED1 #ifdef CTRL_LED2 rgblight_sethsv_at(0, 255, 255, CTRL_LED2); #endif // CTRL_LED2 } else { #ifdef CTRL_LED1 rgblight_sethsv_default_helper(CTRL_LED1); #endif // CTRL_LED1 #ifdef CTRL_LED2 rgblight_sethsv_default_helper(CTRL_LED2); #endif // CTRL_LED2 } if ( (this_mod | this_osm) & MOD_MASK_GUI) { #ifdef GUI_LED1 rgblight_sethsv_at(51, 255, 255, GUI_LED1); #endif // GUI_LED1 #ifdef GUI_LED2 rgblight_sethsv_at(51, 255, 255, GUI_LED2); #endif // GUI_LED2 } else { #ifdef GUI_LED1 rgblight_sethsv_default_helper(GUI_LED1); #endif // GUI_LED1 #ifdef GUI_LED2 rgblight_sethsv_default_helper(GUI_LED2); #endif // GUI_LED2 } if ( (this_mod | this_osm) & MOD_MASK_ALT) { #ifdef ALT_LED1 rgblight_sethsv_at(240, 255, 255, ALT_LED1); #endif // ALT_LED1 #ifdef GUI_LED2 rgblight_sethsv_at(240, 255, 255, ALT_LED2); #endif // GUI_LED2 } else { #ifdef GUI_LED1 rgblight_sethsv_default_helper(ALT_LED1); #endif // GUI_LED1 #ifdef GUI_LED2 rgblight_sethsv_default_helper(ALT_LED2); #endif // GUI_LED2 } } }
void rgblight_sethsv_default_helper(uint8_t index) { rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, index); }
bool process_record_user( uint16_t keycode, keyrecord_t *record ){ /* Start of key tap RGB effect */ if ( RGB_TAP_STATE ==true ) { key_index=(record->event.key.col)+(record->event.key.row)*12; /* Change the Hue of the RGB color with the type speed */ if (timer_elapsed(TAP_RGB_timer) >10000){ TAP_RGB_timer=timer_read(); Type_Hue=270; }else if (timer_elapsed(TAP_RGB_timer) >1000){ Type_Hue+=30; if (Type_Hue>270) { Type_Hue=270;} }else{ TAP_RGB_timer=timer_read(); Type_Hue-=10; if (Type_Hue<10) { Type_Hue=10;} } if (key_index>42){ //fix the RGB index of the MIT layout position key_index=key_index-1; } if ( record->event.pressed ) { rgblight_sethsv_at(Type_Hue,255,255,key_index); } else { rgblight_setrgb_at(RGB_TAP_Base_Color,key_index); } } /* End of key tap RGB effect */ switch ( keycode ) { /* save the RGB state when set the new */ case RGB_M_R: save_rgbmode = true; break; case RGB_M_SW: save_rgbmode = true; break; case RGB_M_X: save_rgbmode = true; break; case RGB_M_G: save_rgbmode = true; break; case RGB_MODE_KNIGHT: save_rgbmode = true; break; /* Define a New Keycode: double zero */ case KC_00: if (record->event.pressed) { // Do something when pressed } else { tap_code( KC_0 ); // send 0 tap_code( KC_0 ); // send 0 twice without macro } return false; // Skip all further processing of this key /* when the REST key is pressed the 'R' key will RED,the "Bottom Left"(esc of qmk-dfu) will be GREEN */ case RESET: rgblight_mode( 1 ); rgblight_setrgb( 0, 0, 0 ); rgblight_setrgb_at(128, 0, 0,4); // R rgblight_setrgb_at(6, 128, 24,36); // Bottom Left key break; /* Define a New Keycode: key tap RGB effect toggle */ case RGB_TAP: if ( !(record->event.pressed)) { /* If enable,the 'On' key will be green */ if (RGB_TAP_STATE) { RGB_TAP_STATE=false; rgblight_mode( 1 ); rgblight_setrgb( RGB_TAP_Base_Color ); rgblight_setrgb_at(RGB_TAP_Off_Color,16); // O - on }else{ /* If disenable,the 'oFf' key will be red */ RGB_TAP_STATE=true; rgblight_mode( 1 ); rgblight_setrgb( RGB_TAP_Base_Color ); rgblight_setrgb_at(RGB_TAP_On_Color,9); // F - off } } break; /* special shift keys */ case KC_ENT: s_keycode = KC_QUOT; k_shifted = &ques_shifted; break; case KC_UP: s_keycode = KC_SLSH; k_shifted = &ques_shifted; break; case KC_DOWN: s_keycode = KC_BSLS; k_shifted = &ques_shifted; break; default: return(true); } shifted = get_mods() & (MOD_BIT( KC_LSHIFT ) | MOD_BIT( KC_RSHIFT ) ); /* Keydown. If shift is currently pressed, register its alternate keycode. */ if ( record->event.pressed && shifted ) { *k_shifted = true; register_code( s_keycode ); return(false); /* * Keyup. If shift was pressed back when the key was pressed, unregister * its alternate keycode. */ } else if ( !(record->event.pressed) && *k_shifted ) { *k_shifted = false; unregister_code( s_keycode ); return(false); /* Otherwise, behave as normal. */ } else { return(true); } } // End ofprocess_record_user