@ -17,119 +17,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "drashna.h"
# include "drashna.h"
# include "version.h"
# include "version.h"
# include "eeprom.h"
# if (__has_include("secrets.h") && !defined(NO_SECRETS))
# include "tap_dances.h"
# include "secrets.h"
# include "rgb_stuff.h"
# else
// `PROGMEM const char secret[][x]` may work better, but it takes up more space in the firmware
// And I'm not familiar enough to know which is better or why...
PROGMEM const char secret [ ] [ 64 ] = {
" test1 " ,
" test2 " ,
" test3 " ,
" test4 " ,
" test5 "
} ;
# endif
float tone_copy [ ] [ 2 ] = SONG ( SCROLL_LOCK_ON_SOUND ) ;
float tone_copy [ ] [ 2 ] = SONG ( SCROLL_LOCK_ON_SOUND ) ;
float tone_paste [ ] [ 2 ] = SONG ( SCROLL_LOCK_OFF_SOUND ) ;
float tone_paste [ ] [ 2 ] = SONG ( SCROLL_LOCK_OFF_SOUND ) ;
static uint16_t copy_paste_timer ;
static uint16_t copy_paste_timer ;
userspace_config_t userspace_config ;
userspace_config_t userspace_config ;
// Helper Functions
// Helper Functions
void tap ( uint16_t keycode ) { register_code ( keycode ) ; unregister_code ( keycode ) ; } ;
# ifdef RGBLIGHT_ENABLE
void rgblight_sethsv_default_helper ( uint8_t index ) {
uint8_t default_layer = eeconfig_read_default_layer ( ) ;
if ( default_layer & ( 1UL < < _COLEMAK ) ) {
rgblight_sethsv_at ( 300 , 255 , 255 , index ) ;
rgblight_sethsv_at ( 300 , 255 , 255 , index ) ;
}
else if ( default_layer & ( 1UL < < _DVORAK ) ) {
rgblight_sethsv_at ( 120 , 255 , 255 , index ) ;
rgblight_sethsv_at ( 120 , 255 , 255 , index ) ;
}
else if ( default_layer & ( 1UL < < _WORKMAN ) ) {
rgblight_sethsv_at ( 43 , 255 , 255 , index ) ;
rgblight_sethsv_at ( 43 , 255 , 255 , index ) ;
}
else {
rgblight_sethsv_at ( 180 , 255 , 255 , index ) ;
rgblight_sethsv_at ( 180 , 255 , 255 , index ) ;
}
}
# endif // RGBLIGHT_ENABLE
// ========================================= TAP DANCE =========================================
# ifdef TAP_DANCE_ENABLE
//define diablo macro timer variables
static uint16_t diablo_timer [ 4 ] ;
static uint8_t diablo_times [ ] = { 0 , 1 , 3 , 5 , 10 , 30 } ;
static uint8_t diablo_key_time [ 4 ] ;
// has the correct number of seconds elapsed (as defined by diablo_times)
bool check_dtimer ( uint8_t dtimer ) { return ( timer_elapsed ( diablo_timer [ dtimer ] ) < ( diablo_key_time [ dtimer ] * 1000 ) ) ? false : true ; } ;
// Cycle through the times for the macro, starting at 0, for disabled.
// Max of six values, so don't exceed
void diablo_tapdance_master ( qk_tap_dance_state_t * state , void * user_data , uint8_t diablo_key ) {
if ( state - > count > = 7 ) {
diablo_key_time [ diablo_key ] = diablo_times [ 0 ] ;
reset_tap_dance ( state ) ;
} else {
diablo_key_time [ diablo_key ] = diablo_times [ state - > count - 1 ] ;
}
}
// Would rather have one function for all of this, but no idea how to do that...
// This block is for all of the gaming macros, as they were all doing
void diablo_tapdance1 ( qk_tap_dance_state_t * state , void * user_data ) { diablo_tapdance_master ( state , user_data , 0 ) ; }
// the same thing, but with differring text sent.
void diablo_tapdance2 ( qk_tap_dance_state_t * state , void * user_data ) { diablo_tapdance_master ( state , user_data , 1 ) ; }
bool send_game_macro ( const char * str , keyrecord_t * record , bool override ) {
void diablo_tapdance3 ( qk_tap_dance_state_t * state , void * user_data ) { diablo_tapdance_master ( state , user_data , 2 ) ; }
if ( ! record - > event . pressed | | override ) {
void diablo_tapdance4 ( qk_tap_dance_state_t * state , void * user_data ) { diablo_tapdance_master ( state , user_data , 3 ) ; }
clear_keyboard ( ) ;
tap ( userspace_config . is_overwatch ? KC_BSPC : KC_ENTER ) ;
//Tap Dance Definitions
wait_ms ( 50 ) ;
qk_tap_dance_action_t tap_dance_actions [ ] = {
send_string ( str ) ;
// tap once to disable, and more to enable timed micros
wait_ms ( 50 ) ;
[ TD_D3_1 ] = ACTION_TAP_DANCE_FN ( diablo_tapdance1 ) ,
tap ( KC_ENTER ) ;
[ TD_D3_2 ] = ACTION_TAP_DANCE_FN ( diablo_tapdance2 ) ,
[ TD_D3_3 ] = ACTION_TAP_DANCE_FN ( diablo_tapdance3 ) ,
[ TD_D3_4 ] = ACTION_TAP_DANCE_FN ( diablo_tapdance4 ) ,
} ;
// Sends the key press to system, but only if on the Diablo layer
void send_diablo_keystroke ( uint8_t diablo_key ) {
if ( biton32 ( layer_state ) = = _DIABLO ) {
switch ( diablo_key ) {
case 0 :
tap ( KC_1 ) ; break ;
case 1 :
tap ( KC_2 ) ; break ;
case 2 :
tap ( KC_3 ) ; break ;
case 3 :
tap ( KC_4 ) ; break ;
}
}
}
if ( override ) wait_ms ( 3000 ) ;
return false ;
}
}
// Checks each of the 4 timers/keys to see if enough time has elapsed
void tap ( uint16_t keycode ) { register_code ( keycode ) ; unregister_code ( keycode ) ; } ;
// Runs the "send string" command if enough time has passed, and resets the timer.
void run_diablo_macro_check ( void ) {
uint8_t dtime ;
for ( dtime = 0 ; dtime < 4 ; dtime + + ) {
if ( check_dtimer ( dtime ) & & diablo_key_time [ dtime ] ) {
diablo_timer [ dtime ] = timer_read ( ) ;
send_diablo_keystroke ( dtime ) ;
}
}
}
# endif // TAP_DANCE_ENABLE
// Add reconfigurable functions here, for keymap customization
// Add reconfigurable functions here, for keymap customization
@ -147,6 +64,11 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true ;
return true ;
}
}
__attribute__ ( ( weak ) )
bool process_record_secrets ( uint16_t keycode , keyrecord_t * record ) {
return true ;
}
__attribute__ ( ( weak ) )
__attribute__ ( ( weak ) )
uint32_t layer_state_set_keymap ( uint32_t state ) {
uint32_t layer_state_set_keymap ( uint32_t state ) {
return state ;
return state ;
@ -159,9 +81,12 @@ void led_set_keymap(uint8_t usb_led) {}
// Call user matrix init, set default RGB colors and then
// Call user matrix init, set default RGB colors and then
// call the keymap's init function
// call the keymap's init function
void matrix_init_user ( void ) {
void matrix_init_user ( void ) {
uint8_t default_layer = eeconfig_read_default_layer ( ) ;
userspace_config . raw = eeprom_read_byte ( EECONFIG_USERSPACE ) ;
userspace_config . raw = eeprom_read_byte ( EECONFIG_USERSPACE ) ;
# ifdef AUDIO_CLICKY
clicky_enable = userspace_config . clicky_enable ;
# endif
# ifdef BOOTLOADER_CATERINA
# ifdef BOOTLOADER_CATERINA
DDRD & = ~ ( 1 < < 5 ) ;
DDRD & = ~ ( 1 < < 5 ) ;
PORTD & = ~ ( 1 < < 5 ) ;
PORTD & = ~ ( 1 < < 5 ) ;
@ -170,39 +95,15 @@ void matrix_init_user(void) {
PORTB & = ~ ( 1 < < 0 ) ;
PORTB & = ~ ( 1 < < 0 ) ;
# endif
# endif
if ( userspace_config . rgb_layer_change ) {
# ifdef RGBLIGHT_ENABLE
rgblight_enable ( ) ;
# endif // RGBLIGHT_ENABLE
if ( default_layer & ( 1UL < < _COLEMAK ) ) {
# ifdef RGBLIGHT_ENABLE
rgblight_sethsv_magenta ( ) ;
# endif // RGBLIGHT_ENABLE
} else if ( default_layer & ( 1UL < < _DVORAK ) ) {
# ifdef RGBLIGHT_ENABLE
rgblight_sethsv_green ( ) ;
# endif // RGBLIGHT_ENABLE
} else if ( default_layer & ( 1UL < < _WORKMAN ) ) {
# ifdef RGBLIGHT_ENABLE
rgblight_sethsv_goldenrod ( ) ;
# endif // RGBLIGHT_ENABLE
} else {
# ifdef RGBLIGHT_ENABLE
rgblight_sethsv_teal ( ) ;
# endif // RGBLIGHT_ENABLE
}
}
# ifdef AUDIO_CLICKY
# if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
clicky_enable = userspace_config . clicky_enable ;
# endif
# if ( defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) )
set_unicode_input_mode ( UC_WINC ) ;
set_unicode_input_mode ( UC_WINC ) ;
# endif //UNICODE_ENABLE
# endif //UNICODE_ENABLE
matrix_init_rgb ( ) ;
matrix_init_keymap ( ) ;
matrix_init_keymap ( ) ;
}
}
// No global matrix scan code, so just run keymap's matrix
// No global matrix scan code, so just run keymap's matrix
// scan function
// scan function
void matrix_scan_user ( void ) {
void matrix_scan_user ( void ) {
@ -211,24 +112,14 @@ void matrix_scan_user(void) {
run_diablo_macro_check ( ) ;
run_diablo_macro_check ( ) ;
# endif // TAP_DANCE_ENABLE
# endif // TAP_DANCE_ENABLE
# ifdef RGBLIGHT_ENABLE
matrix_scan_rgb ( ) ;
# endif // RGBLIGHT_ENABLE
matrix_scan_keymap ( ) ;
matrix_scan_keymap ( ) ;
}
}
// This block is for all of the gaming macros, as they were all doing
// the same thing, but with differring text sent.
bool send_game_macro ( const char * str , keyrecord_t * record , bool override ) {
if ( ! record - > event . pressed | | override ) {
clear_keyboard ( ) ;
tap ( userspace_config . is_overwatch ? KC_BSPC : KC_ENTER ) ;
wait_ms ( 50 ) ;
send_string ( str ) ;
wait_ms ( 50 ) ;
tap ( KC_ENTER ) ;
}
if ( override ) wait_ms ( 3000 ) ;
return false ;
}
// Defines actions tor my global custom keycodes. Defined in drashna.h file
// Defines actions tor my global custom keycodes. Defined in drashna.h file
@ -236,10 +127,9 @@ bool send_game_macro(const char *str, keyrecord_t *record, bool override) {
bool process_record_user ( uint16_t keycode , keyrecord_t * record ) {
bool process_record_user ( uint16_t keycode , keyrecord_t * record ) {
// If console is enabled, it will print the matrix position and status of each key pressed
// If console is enabled, it will print the matrix position and status of each key pressed
# ifdef CONSOLE _ENABLE
# ifdef KEYLOGGER _ENABLE
xprintf ( " KL: row: %u, column: %u, pressed: %u \n " , record - > event . key . col , record - > event . key . row , record - > event . pressed ) ;
xprintf ( " KL: row: %u, column: %u, pressed: %u \n " , record - > event . key . col , record - > event . key . row , record - > event . pressed ) ;
# endif //CONSOLE_ENABLE
# endif //KEYLOGGER_ENABLE
switch ( keycode ) {
switch ( keycode ) {
case KC_QWERTY :
case KC_QWERTY :
@ -287,8 +177,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case KC_RESET : // Custom RESET code that sets RGBLights to RED
case KC_RESET : // Custom RESET code that sets RGBLights to RED
if ( ! record - > event . pressed ) {
if ( ! record - > event . pressed ) {
# ifdef RGBLIGHT_ENABLE
# ifdef RGBLIGHT_ENABLE
rgblight_enable ( ) ;
rgblight_enable _noeeprom ( ) ;
rgblight_mode ( 1 ) ;
rgblight_mode _noeeprom ( 1 ) ;
rgblight_setrgb_red ( ) ;
rgblight_setrgb_red ( ) ;
# endif // RGBLIGHT_ENABLE
# endif // RGBLIGHT_ENABLE
reset_keyboard ( ) ;
reset_keyboard ( ) ;
@ -300,6 +190,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case EPRM : // Resets EEPROM
case EPRM : // Resets EEPROM
if ( record - > event . pressed ) {
if ( record - > event . pressed ) {
eeconfig_init ( ) ;
eeconfig_init ( ) ;
default_layer_set ( 1UL < < eeconfig_read_default_layer ( ) ) ;
layer_state_set ( layer_state ) ;
}
}
return false ;
return false ;
break ;
break ;
@ -310,24 +202,24 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return false ;
return false ;
break ;
break ;
/* Code has been depreciated
case KC_SECRET_1 . . . KC_SECRET_5 : // Secrets! Externally defined strings, not stored in repo
case KC_SECRET_1 . . . KC_SECRET_5 : // Secrets! Externally defined strings, not stored in repo
if ( ! record - > event . pressed ) {
if ( ! record - > event . pressed ) {
clear_oneshot_layer_state ( ONESHOT_OTHER_KEY_PRESSED ) ;
clear_oneshot_layer_state ( ONESHOT_OTHER_KEY_PRESSED ) ;
send_string _P ( secret[ keycode - KC_SECRET_1 ] ) ;
send_string ( decoy_ secret[ keycode - KC_SECRET_1 ] ) ;
}
}
return false ;
return false ;
break ;
break ;
*/
// These are a serious of gaming macros.
// These are a serious of gaming macros.
// Only enables for the viterbi, basically,
// Only enables for the viterbi, basically,
// to save on firmware space, since it's limited.
// to save on firmware space, since it's limited.
# if !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_orthodox_rev3) || defined(KEYBOARD_ergodox_ez) || defined(KEYBOARD_iris_rev2))
# if def MACROS_ENABLED
case KC_OVERWATCH : // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
case KC_OVERWATCH : // Toggle's if we hit "ENTER" or "BACKSPACE" to input macros
if ( record - > event . pressed ) { userspace_config . is_overwatch ^ = 1 ; eeprom_update_byte ( EECONFIG_USERSPACE , userspace_config . raw ) ; }
if ( record - > event . pressed ) { userspace_config . is_overwatch ^ = 1 ; eeprom_update_byte ( EECONFIG_USERSPACE , userspace_config . raw ) ; }
# ifdef RGBLIGHT_ENABLE
# ifdef RGBLIGHT_ENABLE
userspace_config . is_overwatch ? rgblight_mode ( 17 ) : rgblight_mode ( 18 ) ;
userspace_config . is_overwatch ? rgblight_mode _noeeprom ( 17 ) : rgblight_mode _noeeprom ( 18 ) ;
# endif //RGBLIGHT_ENABLE
# endif //RGBLIGHT_ENABLE
return false ; break ;
return false ; break ;
case KC_SALT :
case KC_SALT :
@ -353,40 +245,19 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return send_game_macro ( " OMG!!! C9!!! " , record , false ) ;
return send_game_macro ( " OMG!!! C9!!! " , record , false ) ;
case KC_GGEZ :
case KC_GGEZ :
return send_game_macro ( " That was a fantastic game, though it was a bit easy. Try harder next time! " , record , false ) ;
return send_game_macro ( " That was a fantastic game, though it was a bit easy. Try harder next time! " , record , false ) ;
# endif // !(defined(KEYBOARD_orthodox_rev1) || defined(KEYBOARD_orthodox_rev3) || defined(KEYBOARD_ergodox_ez))
# endif // MACROS_ENABLED
# ifdef TAP_DANCE_ENABLE
case KC_DIABLO_CLEAR : // reset all Diablo timers, disabling them
case KC_DIABLO_CLEAR : // reset all Diablo timers, disabling them
# ifdef TAP_DANCE_ENABLE
if ( record - > event . pressed ) {
if ( record - > event . pressed ) {
uint8_t dtime ;
uint8_t dtime ;
for ( dtime = 0 ; dtime < 4 ; dtime + + ) {
for ( dtime = 0 ; dtime < 4 ; dtime + + ) {
diablo_key_time [ dtime ] = diablo_times [ 0 ] ;
diablo_key_time [ dtime ] = diablo_times [ 0 ] ;
}
}
}
}
# endif // TAP_DANCE_ENABLE#endif
return false ; break ;
return false ; break ;
# endif // TAP_DANCE_ENABLE
case KC_RGB_T : // This allows me to use underglow as layer indication, or as normal
# ifdef RGBLIGHT_ENABLE
if ( record - > event . pressed ) {
userspace_config . rgb_layer_change ^ = 1 ;
eeprom_update_byte ( EECONFIG_USERSPACE , userspace_config . raw ) ;
if ( userspace_config . rgb_layer_change ) {
layer_state_set ( layer_state ) ; // This is needed to immediately set the layer color (looks better)
}
}
# endif // RGBLIGHT_ENABLE
return false ; break ;
# ifdef RGBLIGHT_ENABLE
case RGB_MODE_FORWARD . . . RGB_MODE_GRADIENT : // quantum_keycodes.h L400 for definitions
if ( record - > event . pressed ) { //This disables layer indication, as it's assumed that if you're changing this ... you want that disabled
userspace_config . rgb_layer_change = false ;
eeprom_update_byte ( EECONFIG_USERSPACE , userspace_config . raw ) ;
}
return true ; break ;
# endif // RGBLIGHT_ENABLE
case KC_CCCV : // One key copy/paste
case KC_CCCV : // One key copy/paste
@ -443,7 +314,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
# endif // UNICODE_ENABLE
# endif // UNICODE_ENABLE
}
}
return process_record_keymap ( keycode , record ) ;
return process_record_keymap ( keycode , record ) & & process_record_secrets ( keycode , record ) & & process_record_user_rgb ( keycode , record ) ;
}
}
@ -452,111 +323,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
// on layer change, no matter where the change was initiated
// on layer change, no matter where the change was initiated
// Then runs keymap's layer change check
// Then runs keymap's layer change check
uint32_t layer_state_set_user ( uint32_t state ) {
uint32_t layer_state_set_user ( uint32_t state ) {
uint8_t default_layer = eeconfig_read_default_layer ( ) ;
state = update_tri_layer_state ( state , _RAISE , _LOWER , _ADJUST ) ;
state = update_tri_layer_state ( state , _RAISE , _LOWER , _ADJUST ) ;
switch ( biton32 ( state ) ) {
case _MACROS :
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) {
rgblight_sethsv_orange ( ) ;
userspace_config . is_overwatch ? rgblight_mode ( 17 ) : rgblight_mode ( 18 ) ;
}
# endif // RGBLIGHT_ENABLE
break ;
case _MEDIA :
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) {
rgblight_sethsv_chartreuse ( ) ;
rgblight_mode ( 22 ) ;
}
# endif // RGBLIGHT_ENABLE
break ;
case _GAMEPAD :
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) {
rgblight_sethsv_orange ( ) ;
rgblight_mode ( 17 ) ;
}
# endif // RGBLIGHT_ENABLE
break ;
case _DIABLO :
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) {
rgblight_sethsv_red ( ) ;
rgblight_mode ( 5 ) ;
}
# endif // RGBLIGHT_ENABLE
break ;
case _RAISE :
# ifdef RGBLIGHT_ENABLE
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) {
state = layer_state_set_rgb ( state ) ;
rgblight_sethsv_yellow ( ) ;
rgblight_mode ( 5 ) ;
}
# endif // RGBLIGHT_ENABLE
break ;
case _LOWER :
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) {
rgblight_sethsv_orange ( ) ;
rgblight_mode ( 5 ) ;
}
# endif // RGBLIGHT_ENABLE
break ;
case _ADJUST :
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) {
rgblight_sethsv_red ( ) ;
rgblight_mode ( 23 ) ;
}
# endif // RGBLIGHT_ENABLE
break ;
default : // for any other layers, or the default layer
if ( default_layer & ( 1UL < < _COLEMAK ) ) {
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) { rgblight_sethsv_magenta ( ) ; }
# endif // RGBLIGHT_ENABLE
}
else if ( default_layer & ( 1UL < < _DVORAK ) ) {
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) { rgblight_sethsv_green ( ) ; }
# endif // RGBLIGHT_ENABLE
# endif // RGBLIGHT_ENABLE
}
else if ( default_layer & ( 1UL < < _WORKMAN ) ) {
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) { rgblight_sethsv_goldenrod ( ) ; }
# endif // RGBLIGHT_ENABLE
}
else {
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) { rgblight_sethsv_teal ( ) ; }
# endif // RGBLIGHT_ENABLE
}
if ( biton32 ( state ) = = _MODS ) { // If the non-OSM layer is enabled, then breathe
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) { rgblight_mode ( 2 ) ; }
# endif // RGBLIGHT_ENABLE
} else { // otherwise, stay solid
# ifdef RGBLIGHT_ENABLE
if ( userspace_config . rgb_layer_change ) { rgblight_mode ( 1 ) ; }
# endif // RGBLIGHT_ENABLE
}
break ;
}
return layer_state_set_keymap ( state ) ;
return layer_state_set_keymap ( state ) ;
}
}