Big overhaul to Drashna keymaps and userspace (#3097)

* Optimize secrets code

* Orthodox tweaks

* rules.mk features

* Minor cleanup

* Revert mod bits

* Force Hold breaks One Shot Tap Toggle

* Cleanup

* Moke keymaps more consistent

* minor ergodox tweak

* More OSM for the Orthodox

* Cleanup of userspace

* Toggle Secrets

* Add hidden process record for super secret macros

* Make sure secret macros always compiles

* finish up making them super secret

* Add ColinTA's rgb twinkle as WIP

* Optimize RGB Twinkling for typing

Also, tweak RGB indicators.

AND WTF, I HAVE NO IDEA WHY THE INDICATORS ONLY WORK AS IS.  The logical method for getting them working doesn't ... and it's beyond bizarre

* Make console logging more configurable

* Indicator travisty

* Clean up userspace rgb code

* Optimize RGB Twinking to work on default layer only, and to base it's color on the curent hue

* Eff it... rgblight_sethsv_at runs at every matrix scan

* RGB Twinkle cleanup

* Update Iris code for new board

* Move RGB Indicator and RGB Twinkle into userspace

* Move RGB Indicator code to rgb_stuff.c

* Major cleanup of RGB Code in userspace

* Additional cleanup of RGB code in userspace

* Use noeeprom functions to save my boards!

* Enable RGB Sleep on all boards now

* Add old iris board

* tapping tweak

* Use byte 19 for eeprom to prepare for possible merge of eeconfig function pr

* Add code to fix default layer after eeprom reset
This commit is contained in:
Drashna Jaelre
2018-05-31 22:11:06 -07:00
committed by Jack Humbert
parent 8eaf23ae81
commit 3d1349b280
21 changed files with 738 additions and 505 deletions

View File

@ -17,120 +17,37 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "drashna.h"
#include "version.h"
#if (__has_include("secrets.h") && !defined(NO_SECRETS))
#include "secrets.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
#include "eeprom.h"
#include "tap_dances.h"
#include "rgb_stuff.h"
float tone_copy[][2] = SONG(SCROLL_LOCK_ON_SOUND);
float tone_paste[][2] = SONG(SCROLL_LOCK_OFF_SOUND);
static uint16_t copy_paste_timer;
userspace_config_t userspace_config;
// Helper Functions
// 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;
}
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...
void diablo_tapdance1(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 0); }
void diablo_tapdance2(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 1); }
void diablo_tapdance3(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 2); }
void diablo_tapdance4(qk_tap_dance_state_t *state, void *user_data) { diablo_tapdance_master(state, user_data, 3); }
//Tap Dance Definitions
qk_tap_dance_action_t tap_dance_actions[] = {
// tap once to disable, and more to enable timed micros
[TD_D3_1] = ACTION_TAP_DANCE_FN(diablo_tapdance1),
[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;
}
}
}
// Checks each of the 4 timers/keys to see if enough time has elapsed
// 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
// This allows for a global, userspace functions, and continued
@ -147,6 +64,11 @@ bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true;
}
__attribute__ ((weak))
bool process_record_secrets(uint16_t keycode, keyrecord_t *record) {
return true;
}
__attribute__ ((weak))
uint32_t layer_state_set_keymap (uint32_t 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 the keymap's init function
void matrix_init_user(void) {
uint8_t default_layer = eeconfig_read_default_layer();
userspace_config.raw = eeprom_read_byte(EECONFIG_USERSPACE);
#ifdef AUDIO_CLICKY
clicky_enable = userspace_config.clicky_enable;
#endif
#ifdef BOOTLOADER_CATERINA
DDRD &= ~(1<<5);
PORTD &= ~(1<<5);
@ -170,39 +95,15 @@ void matrix_init_user(void) {
PORTB &= ~(1<<0);
#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
clicky_enable = userspace_config.clicky_enable;
#endif
#if ( defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) )
#if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
set_unicode_input_mode(UC_WINC);
#endif //UNICODE_ENABLE
matrix_init_rgb();
matrix_init_keymap();
}
// No global matrix scan code, so just run keymap's matrix
// scan function
void matrix_scan_user(void) {
@ -211,24 +112,14 @@ void matrix_scan_user(void) {
run_diablo_macro_check();
#endif // TAP_DANCE_ENABLE
#ifdef RGBLIGHT_ENABLE
matrix_scan_rgb();
#endif // RGBLIGHT_ENABLE
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
@ -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) {
// 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);
#endif //CONSOLE_ENABLE
#endif //KEYLOGGER_ENABLE
switch (keycode) {
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
if (!record->event.pressed) {
#ifdef RGBLIGHT_ENABLE
rgblight_enable();
rgblight_mode(1);
rgblight_enable_noeeprom();
rgblight_mode_noeeprom(1);
rgblight_setrgb_red();
#endif // RGBLIGHT_ENABLE
reset_keyboard();
@ -300,6 +190,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case EPRM: // Resets EEPROM
if (record->event.pressed) {
eeconfig_init();
default_layer_set(1UL<<eeconfig_read_default_layer());
layer_state_set(layer_state);
}
return false;
break;
@ -310,24 +202,24 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return false;
break;
case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
if (!record->event.pressed) {
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
send_string_P(secret[keycode - KC_SECRET_1]);
}
return false;
break;
/* Code has been depreciated
case KC_SECRET_1 ... KC_SECRET_5: // Secrets! Externally defined strings, not stored in repo
if (!record->event.pressed) {
clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
send_string(decoy_secret[keycode - KC_SECRET_1]);
}
return false;
break;
*/
// These are a serious of gaming macros.
// Only enables for the viterbi, basically,
// 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))
#ifdef MACROS_ENABLED
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); }
#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
return false; break;
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);
case KC_GGEZ:
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
#ifdef TAP_DANCE_ENABLE
if (record->event.pressed) {
uint8_t dtime;
for (dtime = 0; dtime < 4; dtime++) {
diablo_key_time[dtime] = diablo_times[0];
}
}
#endif // TAP_DANCE_ENABLE#endif
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
@ -443,7 +314,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
#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
// Then runs keymap's layer change check
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);
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);
}
state = layer_state_set_rgb(state);
#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
if (userspace_config.rgb_layer_change) {
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
}
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);
}