Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a turbo feature to coffee keymap #21291

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions keyboards/kprepublic/bm40hsrgb/keymaps/coffee/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#define LAYER_STATE_8BIT

#define TURBO_ENABLE
#define HOLD_ON_OTHER_KEY_PRESS

// RGB Matrix effects disable
#ifdef RGB_MATRIX_ENABLE
# define UNDERGLOW_DISABLE
Expand Down
135 changes: 134 additions & 1 deletion keyboards/kprepublic/bm40hsrgb/keymaps/coffee/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ void dynamic_macro_record_end_user(int8_t direction) {
#define MCR_SWT KC_NO
#endif // DYNAMIC_MACRO_ENABLE

#ifdef TURBO_ENABLE
static bool turbo_active = false; // Only changed by TRBO_ST
static uint16_t turbo_keycode = KC_NO; // turbo_active can't be true if this is KC_NO
static bool turbo_key_pressed = false;
static bool turbo_keycode_selecting = false; // Determine new keycode or delay mode switch
static bool turbo_ms_delay_direction = true; // True is raise the delay, false is lower it
static uint16_t turbo_ms_delay_direction_indicator = 0;
static uint16_t turbo_ms_delay = 100; // Start at sending keycodes 10 times a second
static uint16_t turbo_timer; // Changed semi automatically
/*
* Because the KC's are wrapped in `LT()` they won't be interpreted as KC_NO or KC_TRNS
* Instead they'll just be like any other custom KC which will let me use them how I want
*/
#define TRBO_ST LT(_CTR, KC_NO )
#define TRBO_TI LT(_CTR, KC_TRNS)
#else
#define TRBO_ST KC_NO
#define TRBO_TI KC_NO
#endif

const uint16_t PROGMEM keymaps[_END][MATRIX_ROWS][MATRIX_COLS] = {
[_MAIN] = LAYOUT_planck_mit(
KC_ESC , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_BSPC,
Expand All @@ -67,7 +87,7 @@ const uint16_t PROGMEM keymaps[_END][MATRIX_ROWS][MATRIX_COLS] = {
XXXXXXX, RGB_SPD, RGB_VAI, RGB_SPI, RGB_HUI, RGB_SAI, XXXXXXX, XXXXXXX, KC_VOLU, XXXXXXX, XXXXXXX, MCR_REC,
XXXXXXX, RGB_RMOD,RGB_VAD, RGB_MOD, RGB_HUD, RGB_SAD, XXXXXXX, KC_MPRV, KC_MPLY, KC_MNXT, XXXXXXX, MCR_PLY,
XXXXXXX, XXXXXXX, RGB_TOG, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_VOLD, XXXXXXX, XXXXXXX, MCR_SWT,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, TOG_MSE, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
XXXXXXX, XXXXXXX, XXXXXXX, TRBO_TI, TRBO_ST, TOG_MSE, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX
)
#ifdef MOUSEKEY_ENABLE
,[_MSE] = LAYOUT_planck_mit(
Expand Down Expand Up @@ -117,12 +137,68 @@ bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
if (RECORDING) { RGB_MATRIX_INDICATOR_SET_COLOR(pos, BRIGHTNESS, 0, 0); }
break;
#endif // DYNAMIC_MACRO_ENABLE

#ifdef TURBO_ENABLE
case TRBO_ST:
if (turbo_keycode_selecting) {
RGB_MATRIX_INDICATOR_SET_COLOR(pos, BRIGHTNESS, BRIGHTNESS, BRIGHTNESS);
} else {
if (turbo_active) {
if (turbo_key_pressed) {
RGB_MATRIX_INDICATOR_SET_COLOR(pos, BRIGHTNESS, BRIGHTNESS, BRIGHTNESS);
} else {
RGB_MATRIX_INDICATOR_SET_COLOR(pos, 0, 0, 0);
}
}
}
break;

case TRBO_TI:
if (turbo_ms_delay_direction_indicator != 0) {
uint8_t time = timer_elapsed(turbo_ms_delay_direction_indicator) / 200;
if (time > 0) {
if ((time % 2) == 1) {
if (turbo_ms_delay_direction) {
RGB_MATRIX_INDICATOR_SET_COLOR(pos, 0, BRIGHTNESS, 0);
} else {
RGB_MATRIX_INDICATOR_SET_COLOR(pos, BRIGHTNESS, 0, 0);
}
} else {
RGB_MATRIX_INDICATOR_SET_COLOR(pos, 0, 0, 0);
}
if (time >= 6) {
turbo_ms_delay_direction_indicator = 0;
}
}
}
break;
#endif

}
}
return false;
}
#endif

#ifdef TURBO_ENABLE
void housekeeping_task_user(void) {
if (turbo_active) {
if (turbo_key_pressed) {
if (timer_elapsed(turbo_timer) > turbo_ms_delay) {
unregister_code(turbo_keycode);
turbo_key_pressed = false;
turbo_timer = timer_read();
}
} else {
if (timer_elapsed(turbo_timer) > (turbo_ms_delay / 2)) {
register_code(turbo_keycode);
turbo_key_pressed = true;
}
}
}
}
#endif

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
#ifdef DYNAMIC_MACRO_ENABLE
if (keycode == MCR_REC) {keycode = REC;}
Expand All @@ -145,6 +221,23 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
#endif // MOUSEKEY_ENABLE

#ifdef TURBO_ENABLE
if (record->event.pressed) {
if (turbo_keycode_selecting) {
if (IS_BASIC_KEYCODE(keycode) ||
IS_MODIFIER_KEYCODE(keycode) ||
IS_JOYSTICK_KEYCODE(keycode) ||
IS_MOUSE_KEYCODE(keycode))
{
unregister_code(turbo_keycode);
turbo_key_pressed = false;
turbo_keycode = keycode;
turbo_keycode_selecting = false;
}
}
}
#endif

switch (keycode) {
#ifdef DYNAMIC_MACRO_ENABLE
case MCR_SWT:
Expand All @@ -162,6 +255,46 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return false;
#endif // DYNAMIC_MACRO_ENABLE

#ifdef TURBO_ENABLE
case TRBO_ST:
if (record->event.pressed) {
if (!record->tap.count) {
turbo_keycode_selecting = !turbo_keycode_selecting;
} else {
if (turbo_keycode != KC_NO) {
if (!turbo_active) {
turbo_keycode_selecting = false;
turbo_active = true;
} else {
unregister_code(turbo_keycode);
turbo_key_pressed = false;
turbo_active = false;
}
}
}
}
return false;

case TRBO_TI:
if (record->event.pressed) {
if (!record->tap.count) {
turbo_ms_delay_direction = !turbo_ms_delay_direction;
turbo_ms_delay_direction_indicator = timer_read();
} else {
if (turbo_ms_delay_direction)
turbo_ms_delay += 20;
else
turbo_ms_delay -= 20;

if (turbo_ms_delay > 500) // half a second
turbo_ms_delay = 500;
if (turbo_ms_delay < 60) // Around 16 times a second
turbo_ms_delay = 60;
}
}
return false;
#endif

default:
return true; //Process all other keycodes normally
}
Expand Down
14 changes: 8 additions & 6 deletions keyboards/kprepublic/bm40hsrgb/keymaps/coffee/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ The secondary layer ( `_SUB` ) is for syntax, F keys, and number keys
| 4 | _ | _ | | _ | _ | _ | <- | _ | | | | |

The control layer ( `_CTR` ) is for lighting, media, and macros
| row | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|-----|---|-------|------|-------|------|---------|-----|------|------|------|----|---------|
| 1 | | SPD- | BRI+ | SPD+ | HUE+ | SAT+ | | | VOL+ | | | MCR_REC |
| 2 | | EFCT- | BRI- | EFCT+ | HUE- | SAT- | | PREV | PLAY | NEXT | | MCR_PLY |
| 3 | | | TOG | | | | | | VOL- | | | MCR_SWT |
| 4 | | | | | | MSE_TOG | <- | | | | | |
| row | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|-----|---|-------|------|---------|---------|---------|-----|------|------|------|----|---------|
| 1 | | SPD- | BRI+ | SPD+ | HUE+ | SAT+ | | | VOL+ | | | MCR_REC |
| 2 | | EFCT- | BRI- | EFCT+ | HUE- | SAT- | | PREV | PLAY | NEXT | | MCR_PLY |
| 3 | | | TOG | | | | | | VOL- | | | MCR_SWT |
| 4 | | | | TRBO_TI | TRBO_ST | MSE_TOG | <- | | | | | |

The mouse layer ( `_MSE` ) is for making the keyboard function as a mouse as well
| row | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
Expand Down Expand Up @@ -67,6 +67,8 @@ The mouse layer ( `_MSE` ) is for making the keyboard function as a mouse as wel
| SCR_D | Mouse scroll down |
| ACL_U | Raise mouse/scroll speed |
| ACL_D | Lower mouse/scroll speed |
| TRBO_ST | Set turbo key (Hold), start/stop turbo (Tap) |
| TRBO_TI | Turbo speed +/- (Hold to switch direction) |

## Compiling

Expand Down