2015-04-10 01:32:04 +09:00
/*
Copyright 2011 Jun Wako <wakojun@gmail.com>
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 <stdint.h>
# include <stdbool.h>
2016-07-01 17:04:53 +03:00
# include "wait.h"
2015-04-10 01:32:04 +09:00
# include "keycode.h"
# include "host.h"
# include "keymap.h"
# include "print.h"
# include "debug.h"
# include "util.h"
# include "timer.h"
# include "keyboard.h"
# include "bootloader.h"
# include "action_layer.h"
# include "action_util.h"
# include "eeconfig.h"
# include "sleep_led.h"
# include "led.h"
# include "command.h"
2016-05-24 11:56:53 -04:00
# include "quantum.h"
2016-08-08 11:27:15 +03:00
# include "version.h"
2015-04-10 01:32:04 +09:00
2019-10-17 17:48:58 +01:00
# ifdef BACKLIGHT_ENABLE
# include "backlight.h"
# endif
2020-05-19 04:29:20 -07:00
# if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
2019-08-30 11:19:03 -07:00
# include "mousekey.h"
2015-04-10 01:32:04 +09:00
# endif
2016-04-17 20:14:37 -05:00
# ifdef AUDIO_ENABLE
2019-08-30 11:19:03 -07:00
# include "audio.h"
2016-04-17 20:14:37 -05:00
# endif /* AUDIO_ENABLE */
2015-04-10 01:32:04 +09:00
static bool command_common ( uint8_t code ) ;
static void command_common_help ( void ) ;
2016-03-28 00:03:21 -05:00
static void print_version ( void ) ;
static void print_status ( void ) ;
2015-04-10 01:32:04 +09:00
static bool command_console ( uint8_t code ) ;
static void command_console_help ( void ) ;
2020-05-19 04:29:20 -07:00
# if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
2015-04-10 01:32:04 +09:00
static bool mousekey_console ( uint8_t code ) ;
static void mousekey_console_help ( void ) ;
# endif
static void switch_default_layer ( uint8_t layer ) ;
command_state_t command_state = ONESHOT ;
2019-08-30 11:19:03 -07:00
bool command_proc ( uint8_t code ) {
2015-04-10 01:32:04 +09:00
switch ( command_state ) {
case ONESHOT :
2019-08-30 11:19:03 -07:00
if ( ! IS_COMMAND ( ) ) return false ;
2015-04-10 01:32:04 +09:00
return ( command_extra ( code ) | | command_common ( code ) ) ;
break ;
case CONSOLE :
if ( IS_COMMAND ( ) )
return ( command_extra ( code ) | | command_common ( code ) ) ;
else
return ( command_console_extra ( code ) | | command_console ( code ) ) ;
break ;
2020-05-19 04:29:20 -07:00
# if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
2015-04-10 01:32:04 +09:00
case MOUSEKEY :
mousekey_console ( code ) ;
break ;
# endif
default :
command_state = ONESHOT ;
return false ;
}
return true ;
}
/* TODO: Refactoring is needed. */
/* This allows to define extra commands. return false when not processed. */
2019-08-30 11:19:03 -07:00
bool command_extra ( uint8_t code ) __attribute__ ( ( weak ) ) ;
bool command_extra ( uint8_t code ) {
2016-07-01 17:04:53 +03:00
( void ) code ;
2015-04-10 01:32:04 +09:00
return false ;
}
2019-08-30 11:19:03 -07:00
bool command_console_extra ( uint8_t code ) __attribute__ ( ( weak ) ) ;
bool command_console_extra ( uint8_t code ) {
2016-07-01 17:04:53 +03:00
( void ) code ;
2015-04-10 01:32:04 +09:00
return false ;
}
/***********************************************************
* Command common
***********************************************************/
2019-08-30 11:19:03 -07:00
static void command_common_help ( void ) {
print ( " \n \t - Magic - \n " STR ( MAGIC_KEY_DEBUG ) " : Debug Message Toggle \n " STR ( MAGIC_KEY_DEBUG_MATRIX ) " : Matrix Debug Mode Toggle - Show keypresses in matrix grid \n " STR ( MAGIC_KEY_DEBUG_KBD ) " : Keyboard Debug Toggle - Show keypress report \n " STR ( MAGIC_KEY_DEBUG_MOUSE ) " : Debug Mouse Toggle \n " STR ( MAGIC_KEY_VERSION ) " : Version \n " STR ( MAGIC_KEY_STATUS ) " : Status \n " STR ( MAGIC_KEY_CONSOLE ) " : Activate Console Mode \n "
2016-04-17 12:54:32 -05:00
2016-03-28 00:03:21 -05:00
# if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
2019-08-30 11:19:03 -07:00
STR ( MAGIC_KEY_LAYER0 ) " : Switch to Layer 0 \n " STR ( MAGIC_KEY_LAYER1 ) " : Switch to Layer 1 \n " STR ( MAGIC_KEY_LAYER2 ) " : Switch to Layer 2 \n " STR ( MAGIC_KEY_LAYER3 ) " : Switch to Layer 3 \n " STR ( MAGIC_KEY_LAYER4 ) " : Switch to Layer 4 \n " STR ( MAGIC_KEY_LAYER5 ) " : Switch to Layer 5 \n " STR ( MAGIC_KEY_LAYER6 ) " : Switch to Layer 6 \n " STR ( MAGIC_KEY_LAYER7 ) " : Switch to Layer 7 \n " STR ( MAGIC_KEY_LAYER8 ) " : Switch to Layer 8 \n " STR ( MAGIC_KEY_LAYER9 ) " : Switch to Layer 9 \n "
2016-03-28 00:03:21 -05:00
# endif
2016-04-17 12:54:32 -05:00
# if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
2019-08-30 11:19:03 -07:00
" F1-F10: Switch to Layer 0-9 (F10 = L0) \n "
2016-03-28 00:03:21 -05:00
# endif
2016-04-17 12:54:32 -05:00
# if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
2019-08-30 11:19:03 -07:00
" 0-9: Switch to Layer 0-9 \n "
2016-03-28 00:03:21 -05:00
# endif
2019-08-30 11:19:03 -07:00
STR ( MAGIC_KEY_LAYER0_ALT ) " : Switch to Layer 0 (alternate) \n "
2019-02-18 07:23:32 +01:00
2019-08-30 11:19:03 -07:00
STR ( MAGIC_KEY_BOOTLOADER ) " : Jump to Bootloader \n " STR ( MAGIC_KEY_BOOTLOADER_ALT ) " : Jump to Bootloader (alternate) \n "
2015-05-13 15:29:30 +09:00
# ifdef KEYBOARD_LOCK_ENABLE
2019-08-30 11:19:03 -07:00
STR ( MAGIC_KEY_LOCK ) " : Lock Keyboard \n "
2015-05-13 15:29:30 +09:00
# endif
2019-08-30 11:19:03 -07:00
STR ( MAGIC_KEY_EEPROM ) " : Print EEPROM Settings \n " STR ( MAGIC_KEY_EEPROM_CLEAR ) " : Clear EEPROM \n "
2015-05-13 15:29:30 +09:00
2015-04-10 01:32:04 +09:00
# ifdef NKRO_ENABLE
2019-08-30 11:19:03 -07:00
STR ( MAGIC_KEY_NKRO ) " : NKRO Toggle \n "
2015-05-13 15:29:30 +09:00
# endif
# ifdef SLEEP_LED_ENABLE
2019-08-30 11:19:03 -07:00
STR ( MAGIC_KEY_SLEEP_LED ) " : Sleep LED Test \n "
2015-04-10 01:32:04 +09:00
# endif
2015-05-13 15:29:30 +09:00
) ;
2015-04-10 01:32:04 +09:00
}
2019-08-30 11:19:03 -07:00
static void print_version ( void ) {
// print version & information
2016-03-28 00:03:21 -05:00
print ( " \n \t - Version - \n " ) ;
print ( " VID: " STR ( VENDOR_ID ) " ( " STR ( MANUFACTURER ) " ) "
2019-08-30 11:19:03 -07:00
" PID: " STR ( PRODUCT_ID ) " ( " STR ( PRODUCT ) " ) "
" VER: " STR ( DEVICE_VER ) " \n " ) ;
2018-12-15 14:31:56 +09:00
print ( " BUILD: ( " __DATE__ " ) \n " ) ;
2020-12-31 15:20:56 +09:00
# ifndef SKIP_VERSION
2020-02-29 12:00:00 -08:00
# ifdef PROTOCOL_CHIBIOS
print ( " CHIBIOS: " STR ( CHIBIOS_VERSION ) " , CONTRIB: " STR ( CHIBIOS_CONTRIB_VERSION ) " \n " ) ;
# endif
2018-12-15 14:31:56 +09:00
# endif
2016-03-28 00:03:21 -05:00
/* build options */
print ( " OPTIONS: "
# ifdef PROTOCOL_LUFA
2019-08-30 11:19:03 -07:00
" LUFA "
2016-03-28 00:03:21 -05:00
# endif
# ifdef PROTOCOL_VUSB
2019-08-30 11:19:03 -07:00
" VUSB "
2016-03-28 00:03:21 -05:00
# endif
# ifdef BOOTMAGIC_ENABLE
2019-08-30 11:19:03 -07:00
" BOOTMAGIC "
2016-03-28 00:03:21 -05:00
# endif
# ifdef MOUSEKEY_ENABLE
2019-08-30 11:19:03 -07:00
" MOUSEKEY "
2016-03-28 00:03:21 -05:00
# endif
# ifdef EXTRAKEY_ENABLE
2019-08-30 11:19:03 -07:00
" EXTRAKEY "
2016-03-28 00:03:21 -05:00
# endif
# ifdef CONSOLE_ENABLE
2019-08-30 11:19:03 -07:00
" CONSOLE "
2016-03-28 00:03:21 -05:00
# endif
# ifdef COMMAND_ENABLE
2019-08-30 11:19:03 -07:00
" COMMAND "
2016-03-28 00:03:21 -05:00
# endif
# ifdef NKRO_ENABLE
2019-08-30 11:19:03 -07:00
" NKRO "
2016-03-28 00:03:21 -05:00
# endif
2020-08-22 01:21:06 -07:00
# ifdef LTO_ENABLE
2020-02-29 12:00:00 -08:00
" LTO "
# endif
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
" " STR ( BOOTLOADER_SIZE ) " \n " ) ;
2016-03-28 00:03:21 -05:00
print ( " GCC: " STR ( __GNUC__ ) " . " STR ( __GNUC_MINOR__ ) " . " STR ( __GNUC_PATCHLEVEL__ )
2016-07-01 17:04:53 +03:00
# if defined(__AVR__)
2019-08-30 11:19:03 -07:00
" AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ " AVR_ARCH: avr " STR ( __AVR_ARCH__ )
2016-07-01 17:04:53 +03:00
# endif
2019-08-30 11:19:03 -07:00
" \n " ) ;
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
return ;
2016-03-28 00:03:21 -05:00
}
2019-08-30 11:19:03 -07:00
static void print_status ( void ) {
2016-03-28 00:03:21 -05:00
print ( " \n \t - Status - \n " ) ;
print_val_hex8 ( host_keyboard_leds ( ) ) ;
2017-01-21 12:30:06 -05:00
# ifndef PROTOCOL_VUSB
2017-01-21 17:09:17 -05:00
// these aren't set on the V-USB protocol, so we just ignore them for now
2016-03-28 00:03:21 -05:00
print_val_hex8 ( keyboard_protocol ) ;
print_val_hex8 ( keyboard_idle ) ;
2017-01-21 12:30:06 -05:00
# endif
2016-03-28 00:03:21 -05:00
# ifdef NKRO_ENABLE
2016-09-06 23:19:01 -05:00
print_val_hex8 ( keymap_config . nkro ) ;
2016-03-28 00:03:21 -05:00
# endif
2016-07-01 17:04:53 +03:00
print_val_hex32 ( timer_read32 ( ) ) ;
2019-08-30 11:19:03 -07:00
return ;
2016-03-28 00:03:21 -05:00
}
2019-08-30 11:19:03 -07:00
static void print_eeconfig ( void ) {
2016-09-12 20:20:31 -05:00
// Print these variables if NO_PRINT or USER_PRINT are not defined.
# if !defined(NO_PRINT) && !defined(USER_PRINT)
2019-08-30 11:19:03 -07:00
print ( " default_layer: " ) ;
print_dec ( eeconfig_read_default_layer ( ) ) ;
print ( " \n " ) ;
2015-04-10 01:32:04 +09:00
debug_config_t dc ;
dc . raw = eeconfig_read_debug ( ) ;
2019-08-30 11:19:03 -07:00
print ( " debug_config.raw: " ) ;
print_hex8 ( dc . raw ) ;
print ( " \n " ) ;
print ( " .enable: " ) ;
print_dec ( dc . enable ) ;
print ( " \n " ) ;
print ( " .matrix: " ) ;
print_dec ( dc . matrix ) ;
print ( " \n " ) ;
print ( " .keyboard: " ) ;
print_dec ( dc . keyboard ) ;
print ( " \n " ) ;
print ( " .mouse: " ) ;
print_dec ( dc . mouse ) ;
print ( " \n " ) ;
2015-04-10 01:32:04 +09:00
keymap_config_t kc ;
kc . raw = eeconfig_read_keymap ( ) ;
2019-08-30 11:19:03 -07:00
print ( " keymap_config.raw: " ) ;
print_hex8 ( kc . raw ) ;
print ( " \n " ) ;
print ( " .swap_control_capslock: " ) ;
print_dec ( kc . swap_control_capslock ) ;
print ( " \n " ) ;
print ( " .capslock_to_control: " ) ;
print_dec ( kc . capslock_to_control ) ;
print ( " \n " ) ;
print ( " .swap_lctl_lgui: " ) ;
print_dec ( kc . swap_lctl_lgui ) ;
print ( " \n " ) ;
print ( " .swap_rctl_rgui: " ) ;
print_dec ( kc . swap_rctl_rgui ) ;
print ( " \n " ) ;
print ( " .swap_lalt_lgui: " ) ;
print_dec ( kc . swap_lalt_lgui ) ;
print ( " \n " ) ;
print ( " .swap_ralt_rgui: " ) ;
print_dec ( kc . swap_ralt_rgui ) ;
print ( " \n " ) ;
print ( " .no_gui: " ) ;
print_dec ( kc . no_gui ) ;
print ( " \n " ) ;
print ( " .swap_grave_esc: " ) ;
print_dec ( kc . swap_grave_esc ) ;
print ( " \n " ) ;
print ( " .swap_backslash_backspace: " ) ;
print_dec ( kc . swap_backslash_backspace ) ;
print ( " \n " ) ;
print ( " .nkro: " ) ;
print_dec ( kc . nkro ) ;
print ( " \n " ) ;
# ifdef BACKLIGHT_ENABLE
2015-04-10 01:32:04 +09:00
backlight_config_t bc ;
bc . raw = eeconfig_read_backlight ( ) ;
2019-08-30 11:19:03 -07:00
print ( " backlight_config.raw: " ) ;
print_hex8 ( bc . raw ) ;
print ( " \n " ) ;
print ( " .enable: " ) ;
print_dec ( bc . enable ) ;
print ( " \n " ) ;
print ( " .level: " ) ;
print_dec ( bc . level ) ;
print ( " \n " ) ;
# endif /* BACKLIGHT_ENABLE */
2016-04-17 12:54:32 -05:00
# endif /* !NO_PRINT */
2015-04-10 01:32:04 +09:00
}
2019-08-30 11:19:03 -07:00
static bool command_common ( uint8_t code ) {
2016-03-28 00:03:21 -05:00
# ifdef KEYBOARD_LOCK_ENABLE
2015-04-10 01:32:04 +09:00
static host_driver_t * host_driver = 0 ;
2016-03-28 00:03:21 -05:00
# endif
2015-04-10 01:32:04 +09:00
switch ( code ) {
# ifdef SLEEP_LED_ENABLE
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
// test breathing sleep LED
2016-03-28 00:03:21 -05:00
case MAGIC_KC ( MAGIC_KEY_SLEEP_LED ) :
print ( " Sleep LED Test \n " ) ;
2015-04-10 01:32:04 +09:00
sleep_led_toggle ( ) ;
led_set ( host_keyboard_leds ( ) ) ;
break ;
# endif
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
// print stored eeprom config
2016-04-17 12:54:32 -05:00
case MAGIC_KC ( MAGIC_KEY_EEPROM ) :
2015-04-10 01:32:04 +09:00
print ( " eeconfig: \n " ) ;
print_eeconfig ( ) ;
break ;
2019-02-18 07:23:32 +01:00
2019-08-30 11:19:03 -07:00
// clear eeprom
2019-02-18 07:23:32 +01:00
case MAGIC_KC ( MAGIC_KEY_EEPROM_CLEAR ) :
print ( " Clearing EEPROM \n " ) ;
2019-08-30 11:19:03 -07:00
eeconfig_init ( ) ;
2019-02-18 07:23:32 +01:00
break ;
2016-03-28 00:03:21 -05:00
2015-05-13 15:29:30 +09:00
# ifdef KEYBOARD_LOCK_ENABLE
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
// lock/unlock keyboard
2016-03-28 00:03:21 -05:00
case MAGIC_KC ( MAGIC_KEY_LOCK ) :
2015-04-10 01:32:04 +09:00
if ( host_get_driver ( ) ) {
host_driver = host_get_driver ( ) ;
clear_keyboard ( ) ;
host_set_driver ( 0 ) ;
print ( " Locked. \n " ) ;
} else {
host_set_driver ( host_driver ) ;
print ( " Unlocked. \n " ) ;
}
break ;
2015-05-13 15:29:30 +09:00
# endif
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
// print help
2019-02-18 07:23:32 +01:00
case MAGIC_KC ( MAGIC_KEY_HELP ) :
case MAGIC_KC ( MAGIC_KEY_HELP_ALT ) :
2015-04-10 01:32:04 +09:00
command_common_help ( ) ;
break ;
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
// activate console
2016-03-28 00:03:21 -05:00
case MAGIC_KC ( MAGIC_KEY_CONSOLE ) :
2015-04-10 01:32:04 +09:00
debug_matrix = false ;
debug_keyboard = false ;
debug_mouse = false ;
debug_enable = false ;
command_console_help ( ) ;
print ( " C> " ) ;
command_state = CONSOLE ;
break ;
2016-03-28 00:03:21 -05:00
// jump to bootloader
case MAGIC_KC ( MAGIC_KEY_BOOTLOADER ) :
2019-02-18 07:23:32 +01:00
case MAGIC_KC ( MAGIC_KEY_BOOTLOADER_ALT ) :
2016-03-28 00:03:21 -05:00
print ( " \n \n Jumping to bootloader... " ) ;
2020-05-25 20:16:33 +08:00
reset_keyboard ( ) ;
2015-04-10 01:32:04 +09:00
break ;
2016-03-28 00:03:21 -05:00
// debug toggle
case MAGIC_KC ( MAGIC_KEY_DEBUG ) :
debug_enable = ! debug_enable ;
2015-04-10 01:32:04 +09:00
if ( debug_enable ) {
2016-03-28 00:03:21 -05:00
print ( " \n debug: on \n " ) ;
} else {
2015-09-20 10:51:30 +09:00
print ( " \n debug: off \n " ) ;
2016-10-23 23:00:43 -05:00
debug_matrix = false ;
debug_keyboard = false ;
debug_mouse = false ;
2015-04-10 01:32:04 +09:00
}
break ;
2016-03-28 00:03:21 -05:00
// debug matrix toggle
2016-04-17 12:54:32 -05:00
case MAGIC_KC ( MAGIC_KEY_DEBUG_MATRIX ) :
2015-04-10 01:32:04 +09:00
debug_matrix = ! debug_matrix ;
if ( debug_matrix ) {
2015-05-13 15:29:30 +09:00
print ( " \n matrix: on \n " ) ;
2015-04-10 01:32:04 +09:00
debug_enable = true ;
} else {
2015-05-13 15:29:30 +09:00
print ( " \n matrix: off \n " ) ;
2015-04-10 01:32:04 +09:00
}
break ;
2016-03-28 00:03:21 -05:00
// debug keyboard toggle
2016-04-17 12:54:32 -05:00
case MAGIC_KC ( MAGIC_KEY_DEBUG_KBD ) :
2015-04-10 01:32:04 +09:00
debug_keyboard = ! debug_keyboard ;
if ( debug_keyboard ) {
2015-05-13 15:29:30 +09:00
print ( " \n keyboard: on \n " ) ;
2015-04-10 01:32:04 +09:00
debug_enable = true ;
} else {
2015-05-13 15:29:30 +09:00
print ( " \n keyboard: off \n " ) ;
2015-04-10 01:32:04 +09:00
}
break ;
2016-03-28 00:03:21 -05:00
// debug mouse toggle
case MAGIC_KC ( MAGIC_KEY_DEBUG_MOUSE ) :
2015-04-10 01:32:04 +09:00
debug_mouse = ! debug_mouse ;
if ( debug_mouse ) {
2015-05-13 15:29:30 +09:00
print ( " \n mouse: on \n " ) ;
2015-04-10 01:32:04 +09:00
debug_enable = true ;
} else {
2019-08-30 11:19:03 -07:00
print ( " \n mouse: off \n " ) ;
2015-04-10 01:32:04 +09:00
}
break ;
2015-05-13 15:29:30 +09:00
2019-08-30 11:19:03 -07:00
// print version
2016-03-28 00:03:21 -05:00
case MAGIC_KC ( MAGIC_KEY_VERSION ) :
2019-08-30 11:19:03 -07:00
print_version ( ) ;
break ;
2015-04-10 01:32:04 +09:00
2019-08-30 11:19:03 -07:00
// print status
case MAGIC_KC ( MAGIC_KEY_STATUS ) :
print_status ( ) ;
2015-04-10 01:32:04 +09:00
break ;
2016-03-28 00:03:21 -05:00
2015-04-10 01:32:04 +09:00
# ifdef NKRO_ENABLE
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
// NKRO toggle
2016-03-28 00:03:21 -05:00
case MAGIC_KC ( MAGIC_KEY_NKRO ) :
2019-08-30 11:19:03 -07:00
clear_keyboard ( ) ; // clear to prevent stuck keys
2016-09-06 23:19:01 -05:00
keymap_config . nkro = ! keymap_config . nkro ;
if ( keymap_config . nkro ) {
2015-05-13 15:29:30 +09:00
print ( " NKRO: on \n " ) ;
2016-07-01 17:04:53 +03:00
} else {
2015-05-13 15:29:30 +09:00
print ( " NKRO: off \n " ) ;
2016-07-01 17:04:53 +03:00
}
2015-04-10 01:32:04 +09:00
break ;
# endif
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
// switch layers
2016-03-28 00:03:21 -05:00
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER0_ALT ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 0 ) ;
break ;
# if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER0 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 0 ) ;
break ;
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER1 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 1 ) ;
break ;
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER2 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 2 ) ;
break ;
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER3 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 3 ) ;
break ;
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER4 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 4 ) ;
break ;
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER5 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 5 ) ;
break ;
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER6 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 6 ) ;
break ;
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER7 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 7 ) ;
break ;
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER8 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 8 ) ;
break ;
2019-08-30 11:19:03 -07:00
case MAGIC_KC ( MAGIC_KEY_LAYER9 ) :
2016-03-28 00:03:21 -05:00
switch_default_layer ( 9 ) ;
break ;
# endif
# if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
case KC_F1 . . . KC_F9 :
switch_default_layer ( ( code - KC_F1 ) + 1 ) ;
break ;
2015-05-13 15:29:30 +09:00
case KC_F10 :
2015-04-10 01:32:04 +09:00
switch_default_layer ( 0 ) ;
break ;
2016-03-28 00:03:21 -05:00
# endif
# if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
2015-04-10 01:32:04 +09:00
case KC_1 . . . KC_9 :
switch_default_layer ( ( code - KC_1 ) + 1 ) ;
break ;
2016-03-28 00:03:21 -05:00
case KC_0 :
switch_default_layer ( 0 ) ;
2015-04-10 01:32:04 +09:00
break ;
2016-03-28 00:03:21 -05:00
# endif
2015-04-10 01:32:04 +09:00
default :
print ( " ? " ) ;
return false ;
}
return true ;
}
/***********************************************************
* Command console
***********************************************************/
2019-08-30 11:19:03 -07:00
static void command_console_help ( void ) {
2015-05-13 15:29:30 +09:00
print ( " \n \t - Console - \n "
" ESC/q: quit \n "
2015-04-10 01:32:04 +09:00
# ifdef MOUSEKEY_ENABLE
2015-05-13 15:29:30 +09:00
" m: mousekey \n "
2015-04-10 01:32:04 +09:00
# endif
2015-05-13 15:29:30 +09:00
) ;
2015-04-10 01:32:04 +09:00
}
2019-08-30 11:19:03 -07:00
static bool command_console ( uint8_t code ) {
2015-04-10 01:32:04 +09:00
switch ( code ) {
case KC_H :
case KC_SLASH : /* ? */
command_console_help ( ) ;
break ;
case KC_Q :
case KC_ESC :
command_state = ONESHOT ;
return false ;
2020-05-19 04:29:20 -07:00
# if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
2015-04-10 01:32:04 +09:00
case KC_M :
mousekey_console_help ( ) ;
2015-05-13 15:29:30 +09:00
print ( " M> " ) ;
2015-04-10 01:32:04 +09:00
command_state = MOUSEKEY ;
return true ;
# endif
default :
print ( " ? " ) ;
return false ;
}
print ( " C> " ) ;
return true ;
}
2020-05-19 04:29:20 -07:00
# if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
2015-04-10 01:32:04 +09:00
/***********************************************************
* Mousekey console
***********************************************************/
static uint8_t mousekey_param = 0 ;
2019-08-30 11:19:03 -07:00
static void mousekey_param_print ( void ) {
2016-09-12 20:20:31 -05:00
// Print these variables if NO_PRINT or USER_PRINT are not defined.
2019-08-30 11:19:03 -07:00
# if !defined(NO_PRINT) && !defined(USER_PRINT)
2015-05-13 15:29:30 +09:00
print ( " \n \t - Values - \n " ) ;
2019-08-30 11:19:03 -07:00
print ( " 1: delay(*10ms): " ) ;
pdec ( mk_delay ) ;
print ( " \n " ) ;
print ( " 2: interval(ms): " ) ;
pdec ( mk_interval ) ;
print ( " \n " ) ;
print ( " 3: max_speed: " ) ;
pdec ( mk_max_speed ) ;
print ( " \n " ) ;
print ( " 4: time_to_max: " ) ;
pdec ( mk_time_to_max ) ;
print ( " \n " ) ;
print ( " 5: wheel_max_speed: " ) ;
pdec ( mk_wheel_max_speed ) ;
print ( " \n " ) ;
print ( " 6: wheel_time_to_max: " ) ;
pdec ( mk_wheel_time_to_max ) ;
print ( " \n " ) ;
# endif /* !NO_PRINT */
2015-04-10 01:32:04 +09:00
}
2015-05-13 15:29:30 +09:00
//#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n");
2019-08-30 11:19:03 -07:00
# define PRINT_SET_VAL(v) xprintf(# v " = %d\n", (v))
static void mousekey_param_inc ( uint8_t param , uint8_t inc ) {
2015-04-10 01:32:04 +09:00
switch ( param ) {
case 1 :
if ( mk_delay + inc < UINT8_MAX )
mk_delay + = inc ;
else
mk_delay = UINT8_MAX ;
PRINT_SET_VAL ( mk_delay ) ;
break ;
case 2 :
if ( mk_interval + inc < UINT8_MAX )
mk_interval + = inc ;
else
mk_interval = UINT8_MAX ;
PRINT_SET_VAL ( mk_interval ) ;
break ;
case 3 :
if ( mk_max_speed + inc < UINT8_MAX )
mk_max_speed + = inc ;
else
mk_max_speed = UINT8_MAX ;
PRINT_SET_VAL ( mk_max_speed ) ;
break ;
case 4 :
if ( mk_time_to_max + inc < UINT8_MAX )
mk_time_to_max + = inc ;
else
mk_time_to_max = UINT8_MAX ;
PRINT_SET_VAL ( mk_time_to_max ) ;
break ;
case 5 :
if ( mk_wheel_max_speed + inc < UINT8_MAX )
mk_wheel_max_speed + = inc ;
else
mk_wheel_max_speed = UINT8_MAX ;
PRINT_SET_VAL ( mk_wheel_max_speed ) ;
break ;
case 6 :
if ( mk_wheel_time_to_max + inc < UINT8_MAX )
mk_wheel_time_to_max + = inc ;
else
mk_wheel_time_to_max = UINT8_MAX ;
PRINT_SET_VAL ( mk_wheel_time_to_max ) ;
break ;
}
}
2019-08-30 11:19:03 -07:00
static void mousekey_param_dec ( uint8_t param , uint8_t dec ) {
2015-04-10 01:32:04 +09:00
switch ( param ) {
case 1 :
if ( mk_delay > dec )
mk_delay - = dec ;
else
mk_delay = 0 ;
PRINT_SET_VAL ( mk_delay ) ;
break ;
case 2 :
if ( mk_interval > dec )
mk_interval - = dec ;
else
mk_interval = 0 ;
PRINT_SET_VAL ( mk_interval ) ;
break ;
case 3 :
if ( mk_max_speed > dec )
mk_max_speed - = dec ;
else
mk_max_speed = 0 ;
PRINT_SET_VAL ( mk_max_speed ) ;
break ;
case 4 :
if ( mk_time_to_max > dec )
mk_time_to_max - = dec ;
else
mk_time_to_max = 0 ;
PRINT_SET_VAL ( mk_time_to_max ) ;
break ;
case 5 :
if ( mk_wheel_max_speed > dec )
mk_wheel_max_speed - = dec ;
else
mk_wheel_max_speed = 0 ;
PRINT_SET_VAL ( mk_wheel_max_speed ) ;
break ;
case 6 :
if ( mk_wheel_time_to_max > dec )
mk_wheel_time_to_max - = dec ;
else
mk_wheel_time_to_max = 0 ;
PRINT_SET_VAL ( mk_wheel_time_to_max ) ;
break ;
}
}
2019-08-30 11:19:03 -07:00
static void mousekey_console_help ( void ) {
2015-05-13 15:29:30 +09:00
print ( " \n \t - Mousekey - \n "
" ESC/q: quit \n "
" 1: delay(*10ms) \n "
" 2: interval(ms) \n "
" 3: max_speed \n "
" 4: time_to_max \n "
" 5: wheel_max_speed \n "
" 6: wheel_time_to_max \n "
" \n "
" p: print values \n "
" d: set defaults \n "
" up: +1 \n "
" down: -1 \n "
" pgup: +10 \n "
" pgdown: -10 \n "
" \n "
" speed = delta * max_speed * (repeat / time_to_max) \n " ) ;
2016-04-17 12:54:32 -05:00
xprintf ( " where delta: cursor=%d, wheel=%d \n "
2019-08-30 11:19:03 -07:00
" See http://en.wikipedia.org/wiki/Mouse_keys \n " ,
MOUSEKEY_MOVE_DELTA , MOUSEKEY_WHEEL_DELTA ) ;
2015-04-10 01:32:04 +09:00
}
2019-08-30 11:19:03 -07:00
static bool mousekey_console ( uint8_t code ) {
2015-04-10 01:32:04 +09:00
switch ( code ) {
case KC_H :
case KC_SLASH : /* ? */
mousekey_console_help ( ) ;
break ;
case KC_Q :
case KC_ESC :
2015-05-13 15:29:30 +09:00
if ( mousekey_param ) {
mousekey_param = 0 ;
} else {
print ( " C> " ) ;
command_state = CONSOLE ;
return false ;
}
break ;
2015-04-10 01:32:04 +09:00
case KC_P :
mousekey_param_print ( ) ;
break ;
case KC_1 :
case KC_2 :
case KC_3 :
case KC_4 :
case KC_5 :
case KC_6 :
mousekey_param = numkey2num ( code ) ;
break ;
case KC_UP :
mousekey_param_inc ( mousekey_param , 1 ) ;
break ;
case KC_DOWN :
mousekey_param_dec ( mousekey_param , 1 ) ;
break ;
case KC_PGUP :
mousekey_param_inc ( mousekey_param , 10 ) ;
break ;
case KC_PGDN :
mousekey_param_dec ( mousekey_param , 10 ) ;
break ;
case KC_D :
2019-08-30 11:19:03 -07:00
mk_delay = MOUSEKEY_DELAY / 10 ;
mk_interval = MOUSEKEY_INTERVAL ;
mk_max_speed = MOUSEKEY_MAX_SPEED ;
mk_time_to_max = MOUSEKEY_TIME_TO_MAX ;
mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED ;
2015-04-10 01:32:04 +09:00
mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX ;
2015-05-13 15:29:30 +09:00
print ( " set default \n " ) ;
2015-04-10 01:32:04 +09:00
break ;
default :
print ( " ? " ) ;
return false ;
}
2016-07-01 17:04:53 +03:00
if ( mousekey_param ) {
2015-05-13 15:29:30 +09:00
xprintf ( " M%d> " , mousekey_param ) ;
2016-07-01 17:04:53 +03:00
} else {
2019-08-30 11:19:03 -07:00
print ( " M> " ) ;
2016-07-01 17:04:53 +03:00
}
2015-04-10 01:32:04 +09:00
return true ;
}
# endif
/***********************************************************
* Utilities
***********************************************************/
2019-08-30 11:19:03 -07:00
uint8_t numkey2num ( uint8_t code ) {
2015-04-10 01:32:04 +09:00
switch ( code ) {
2019-08-30 11:19:03 -07:00
case KC_1 :
return 1 ;
case KC_2 :
return 2 ;
case KC_3 :
return 3 ;
case KC_4 :
return 4 ;
case KC_5 :
return 5 ;
case KC_6 :
return 6 ;
case KC_7 :
return 7 ;
case KC_8 :
return 8 ;
case KC_9 :
return 9 ;
case KC_0 :
return 0 ;
2015-04-10 01:32:04 +09:00
}
return 0 ;
}
2019-08-30 11:19:03 -07:00
static void switch_default_layer ( uint8_t layer ) {
2015-05-13 15:29:30 +09:00
xprintf ( " L%d \n " , layer ) ;
2019-08-30 11:19:03 -07:00
default_layer_set ( 1UL < < layer ) ;
2015-04-10 01:32:04 +09:00
clear_keyboard ( ) ;
}