diff options
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r-- | quantum/process_keycode/process_magic.c | 178 | ||||
-rw-r--r-- | quantum/process_keycode/process_magic.h | 20 | ||||
-rw-r--r-- | quantum/process_keycode/process_rgb.c | 141 | ||||
-rw-r--r-- | quantum/process_keycode/process_rgb.h | 20 | ||||
-rw-r--r-- | quantum/process_keycode/process_steno.c | 4 | ||||
-rw-r--r-- | quantum/process_keycode/process_steno.h | 4 | ||||
-rw-r--r-- | quantum/process_keycode/process_terminal.c | 2 |
7 files changed, 364 insertions, 5 deletions
diff --git a/quantum/process_keycode/process_magic.c b/quantum/process_keycode/process_magic.c new file mode 100644 index 0000000000..44dd5f0579 --- /dev/null +++ b/quantum/process_keycode/process_magic.c @@ -0,0 +1,178 @@ +/* Copyright 2019 Jack Humbert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "process_magic.h" + +#ifdef AUDIO_ENABLE +# ifndef AG_NORM_SONG +# define AG_NORM_SONG SONG(AG_NORM_SOUND) +# endif +# ifndef AG_SWAP_SONG +# define AG_SWAP_SONG SONG(AG_SWAP_SOUND) +# endif +# ifndef CG_NORM_SONG +# define CG_NORM_SONG SONG(AG_NORM_SOUND) +# endif +# ifndef CG_SWAP_SONG +# define CG_SWAP_SONG SONG(AG_SWAP_SOUND) +# endif +float ag_norm_song[][2] = AG_NORM_SONG; +float ag_swap_song[][2] = AG_SWAP_SONG; +float cg_norm_song[][2] = CG_NORM_SONG; +float cg_swap_song[][2] = CG_SWAP_SONG; +#endif + +/** + * MAGIC actions (BOOTMAGIC without the boot) + */ +bool process_magic(uint16_t keycode, keyrecord_t *record) { + // skip anything that isn't a keyup + if (record->event.pressed) { + switch (keycode) { + case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI: + case MAGIC_SWAP_LCTL_LGUI ... MAGIC_EE_HANDS_RIGHT: + /* keymap config */ + keymap_config.raw = eeconfig_read_keymap(); + switch (keycode) { + case MAGIC_SWAP_CONTROL_CAPSLOCK: + keymap_config.swap_control_capslock = true; + break; + case MAGIC_CAPSLOCK_TO_CONTROL: + keymap_config.capslock_to_control = true; + break; + case MAGIC_SWAP_LALT_LGUI: + keymap_config.swap_lalt_lgui = true; + break; + case MAGIC_SWAP_RALT_RGUI: + keymap_config.swap_ralt_rgui = true; + break; + case MAGIC_SWAP_LCTL_LGUI: + keymap_config.swap_lctl_lgui = true; + break; + case MAGIC_SWAP_RCTL_RGUI: + keymap_config.swap_rctl_rgui = true; + break; + case MAGIC_NO_GUI: + keymap_config.no_gui = true; + break; + case MAGIC_SWAP_GRAVE_ESC: + keymap_config.swap_grave_esc = true; + break; + case MAGIC_SWAP_BACKSLASH_BACKSPACE: + keymap_config.swap_backslash_backspace = true; + break; + case MAGIC_HOST_NKRO: + clear_keyboard(); // clear first buffer to prevent stuck keys + keymap_config.nkro = true; + break; + case MAGIC_SWAP_ALT_GUI: + keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true; +#ifdef AUDIO_ENABLE + PLAY_SONG(ag_swap_song); +#endif + break; + case MAGIC_SWAP_CTL_GUI: + keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true; +#ifdef AUDIO_ENABLE + PLAY_SONG(cg_swap_song); +#endif + break; + case MAGIC_UNSWAP_CONTROL_CAPSLOCK: + keymap_config.swap_control_capslock = false; + break; + case MAGIC_UNCAPSLOCK_TO_CONTROL: + keymap_config.capslock_to_control = false; + break; + case MAGIC_UNSWAP_LALT_LGUI: + keymap_config.swap_lalt_lgui = false; + break; + case MAGIC_UNSWAP_RALT_RGUI: + keymap_config.swap_ralt_rgui = false; + break; + case MAGIC_UNSWAP_LCTL_LGUI: + keymap_config.swap_lctl_lgui = false; + break; + case MAGIC_UNSWAP_RCTL_RGUI: + keymap_config.swap_rctl_rgui = false; + break; + case MAGIC_UNNO_GUI: + keymap_config.no_gui = false; + break; + case MAGIC_UNSWAP_GRAVE_ESC: + keymap_config.swap_grave_esc = false; + break; + case MAGIC_UNSWAP_BACKSLASH_BACKSPACE: + keymap_config.swap_backslash_backspace = false; + break; + case MAGIC_UNHOST_NKRO: + clear_keyboard(); // clear first buffer to prevent stuck keys + keymap_config.nkro = false; + break; + case MAGIC_UNSWAP_ALT_GUI: + keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false; +#ifdef AUDIO_ENABLE + PLAY_SONG(ag_norm_song); +#endif + break; + case MAGIC_UNSWAP_CTL_GUI: + keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false; +#ifdef AUDIO_ENABLE + PLAY_SONG(cg_norm_song); +#endif + break; + case MAGIC_TOGGLE_ALT_GUI: + keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; + keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui; +#ifdef AUDIO_ENABLE + if (keymap_config.swap_ralt_rgui) { + PLAY_SONG(ag_swap_song); + } else { + PLAY_SONG(ag_norm_song); + } +#endif + break; + case MAGIC_TOGGLE_CTL_GUI: + keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui; + keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui; +#ifdef AUDIO_ENABLE + if (keymap_config.swap_rctl_rgui) { + PLAY_SONG(cg_swap_song); + } else { + PLAY_SONG(cg_norm_song); + } +#endif + break; + case MAGIC_TOGGLE_NKRO: + clear_keyboard(); // clear first buffer to prevent stuck keys + keymap_config.nkro = !keymap_config.nkro; + break; + case MAGIC_EE_HANDS_LEFT: + eeconfig_update_handedness(true); + break; + case MAGIC_EE_HANDS_RIGHT: + eeconfig_update_handedness(false); + break; + } + + eeconfig_update_keymap(keymap_config.raw); + clear_keyboard(); // clear to prevent stuck keys + + return false; + } + } + + // Not a magic keycode so continue processing + return true; +} diff --git a/quantum/process_keycode/process_magic.h b/quantum/process_keycode/process_magic.h new file mode 100644 index 0000000000..1eb39f1455 --- /dev/null +++ b/quantum/process_keycode/process_magic.h @@ -0,0 +1,20 @@ +/* Copyright 2019 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#pragma once + +#include "quantum.h" + +bool process_magic(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c new file mode 100644 index 0000000000..c76166342f --- /dev/null +++ b/quantum/process_keycode/process_rgb.c @@ -0,0 +1,141 @@ +/* Copyright 2019 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "process_rgb.h" +#include "rgb.h" + +typedef void (*rgb_func_pointer)(void); + +/** + * Wrapper for inc/dec rgb keycode + * + * noinline to optimise for firmware size not speed (not in hot path) + */ +static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) { + if (is_shifted) { + dec_func(); + } else { + inc_func(); + } +} + +/** + * Wrapper for animation mode + * - if not in animation family -> jump to that animation + * - otherwise -> wrap round animation speed + * + * noinline to optimise for firmware size not speed (not in hot path) + */ +static void __attribute__((noinline,unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) { + if ((start <= rgblight_get_mode()) && (rgblight_get_mode() < end)) { + rgblight_step(); + } else { + rgblight_mode(start); + } +} + +/** + * Handle keycodes for both rgblight and rgbmatrix + */ +bool process_rgb(const uint16_t keycode, const keyrecord_t *record) { +#ifndef SPLIT_KEYBOARD + if (record->event.pressed) { +#else + // Split keyboards need to trigger on key-up for edge-case issue + if (!record->event.pressed) { +#endif + uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)); + switch (keycode) { + case RGB_TOG: + rgblight_toggle(); + return false; + case RGB_MODE_FORWARD: + handleKeycodeRGB(shifted, rgblight_step, rgblight_step_reverse); + return false; + case RGB_MODE_REVERSE: + handleKeycodeRGB(shifted, rgblight_step_reverse, rgblight_step); + return false; + case RGB_HUI: + handleKeycodeRGB(shifted, rgblight_increase_hue, rgblight_decrease_hue); + return false; + case RGB_HUD: + handleKeycodeRGB(shifted, rgblight_decrease_hue, rgblight_increase_hue); + return false; + case RGB_SAI: + handleKeycodeRGB(shifted, rgblight_increase_sat, rgblight_decrease_sat); + return false; + case RGB_SAD: + handleKeycodeRGB(shifted, rgblight_decrease_sat, rgblight_increase_sat); + return false; + case RGB_VAI: + handleKeycodeRGB(shifted, rgblight_increase_val, rgblight_decrease_val); + return false; + case RGB_VAD: + handleKeycodeRGB(shifted, rgblight_decrease_val, rgblight_increase_val); + return false; + case RGB_SPI: + handleKeycodeRGB(shifted, rgblight_increase_speed, rgblight_decrease_speed); + return false; + case RGB_SPD: + handleKeycodeRGB(shifted, rgblight_decrease_speed, rgblight_increase_speed); + return false; + case RGB_MODE_PLAIN: + rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); + return false; + case RGB_MODE_BREATHE: +#ifdef RGBLIGHT_EFFECT_BREATHING + handleKeycodeRGBMode(RGBLIGHT_MODE_BREATHING, RGBLIGHT_MODE_BREATHING_end); +#endif + return false; + case RGB_MODE_RAINBOW: +#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD + handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_MOOD, RGBLIGHT_MODE_RAINBOW_MOOD_end); +#endif + return false; + case RGB_MODE_SWIRL: +#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL + handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_SWIRL, RGBLIGHT_MODE_RAINBOW_SWIRL_end); +#endif + return false; + case RGB_MODE_SNAKE: +#ifdef RGBLIGHT_EFFECT_SNAKE + handleKeycodeRGBMode(RGBLIGHT_MODE_SNAKE, RGBLIGHT_MODE_SNAKE_end); +#endif + return false; + case RGB_MODE_KNIGHT: +#ifdef RGBLIGHT_EFFECT_KNIGHT + handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end); +#endif + return false; + case RGB_MODE_XMAS: +#ifdef RGBLIGHT_EFFECT_CHRISTMAS + rgblight_mode(RGBLIGHT_MODE_CHRISTMAS); +#endif + return false; + case RGB_MODE_GRADIENT: +#ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT + handleKeycodeRGBMode(RGBLIGHT_MODE_STATIC_GRADIENT, RGBLIGHT_MODE_STATIC_GRADIENT_end); +#endif + return false; + case RGB_MODE_RGBTEST: +#ifdef RGBLIGHT_EFFECT_RGB_TEST + rgblight_mode(RGBLIGHT_MODE_RGB_TEST); +#endif + return false; + } + } + + return true; +} diff --git a/quantum/process_keycode/process_rgb.h b/quantum/process_keycode/process_rgb.h new file mode 100644 index 0000000000..26aca46896 --- /dev/null +++ b/quantum/process_keycode/process_rgb.h @@ -0,0 +1,20 @@ +/* Copyright 2019 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#pragma once + +#include "quantum.h" + +bool process_rgb(const uint16_t keycode, const keyrecord_t *record); diff --git a/quantum/process_keycode/process_steno.c b/quantum/process_keycode/process_steno.c index e0b33ec861..57e279f211 100644 --- a/quantum/process_keycode/process_steno.c +++ b/quantum/process_keycode/process_steno.c @@ -73,7 +73,9 @@ static void steno_clear_state(void) { static void send_steno_state(uint8_t size, bool send_empty) { for (uint8_t i = 0; i < size; ++i) { if (chord[i] || send_empty) { +#ifdef VIRTSER_ENABLE virtser_send(chord[i]); +#endif } } } @@ -105,7 +107,9 @@ static void send_steno_chord(void) { switch (mode) { case STENO_MODE_BOLT: send_steno_state(BOLT_STATE_SIZE, false); +#ifdef VIRTSER_ENABLE virtser_send(0); // terminating byte +#endif break; case STENO_MODE_GEMINI: chord[0] |= 0x80; // Indicate start of packet diff --git a/quantum/process_keycode/process_steno.h b/quantum/process_keycode/process_steno.h index 3675423728..ed049eb13f 100644 --- a/quantum/process_keycode/process_steno.h +++ b/quantum/process_keycode/process_steno.h @@ -18,10 +18,6 @@ #include "quantum.h" -#if defined(STENO_ENABLE) && !defined(VIRTSER_ENABLE) -# error "must have virtser enabled to use steno" -#endif - typedef enum { STENO_MODE_BOLT, STENO_MODE_GEMINI } steno_mode_t; bool process_steno(uint16_t keycode, keyrecord_t *record); diff --git a/quantum/process_keycode/process_terminal.c b/quantum/process_keycode/process_terminal.c index f48f3d702d..7d1eefa9ed 100644 --- a/quantum/process_keycode/process_terminal.c +++ b/quantum/process_keycode/process_terminal.c @@ -61,7 +61,7 @@ void enable_terminal(void) { memset(cmd_buffer, 0, CMD_BUFF_SIZE * 80); for (int i = 0; i < 6; i++) strcpy(arguments[i], ""); // select all text to start over - // SEND_STRING(SS_LCTRL("a")); + // SEND_STRING(SS_LCTL("a")); send_string(terminal_prompt); } |