2011-07-20 21:32:52 +06: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/>.
|
|
|
|
*/
|
2011-02-12 21:15:51 +06:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <util/delay.h>
|
2012-10-09 11:36:13 +06:00
|
|
|
#include "keycode.h"
|
2011-02-12 21:15:51 +06:00
|
|
|
#include "host.h"
|
|
|
|
#include "print.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "timer.h"
|
2012-10-05 23:23:12 +06:00
|
|
|
#include "keyboard.h"
|
2011-09-22 13:56:36 +06:00
|
|
|
#include "bootloader.h"
|
2011-02-12 21:15:51 +06:00
|
|
|
#include "command.h"
|
2012-10-16 08:20:49 +06:00
|
|
|
#ifdef MOUSEKEY_ENABLE
|
|
|
|
#include "mousekey.h"
|
|
|
|
#endif
|
2011-02-12 21:15:51 +06:00
|
|
|
|
|
|
|
#ifdef HOST_PJRC
|
|
|
|
# include "usb_keyboard.h"
|
2011-09-17 19:39:50 +06:00
|
|
|
# ifdef EXTRAKEY_ENABLE
|
2011-02-12 21:15:51 +06:00
|
|
|
# include "usb_extra.h"
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-09-17 19:39:50 +06:00
|
|
|
#ifdef HOST_VUSB
|
|
|
|
# include "usbdrv.h"
|
|
|
|
#endif
|
|
|
|
|
2011-02-12 21:15:51 +06:00
|
|
|
|
2012-10-16 08:20:49 +06:00
|
|
|
static bool command_common(uint8_t code);
|
2012-10-17 00:44:01 +06:00
|
|
|
static void command_common_help(void);
|
|
|
|
static bool command_console(uint8_t code);
|
|
|
|
static void command_console_help(void);
|
2012-10-17 21:10:20 +06:00
|
|
|
#ifdef MOUSEKEY_ENABLE
|
2012-10-17 00:44:01 +06:00
|
|
|
static bool mousekey_console(uint8_t code);
|
|
|
|
static void mousekey_console_help(void);
|
2012-10-17 21:10:20 +06:00
|
|
|
#endif
|
2012-10-17 00:44:01 +06:00
|
|
|
|
2012-10-17 21:10:20 +06:00
|
|
|
static uint8_t numkey2num(uint8_t code);
|
2011-02-12 21:15:51 +06:00
|
|
|
static void switch_layer(uint8_t layer);
|
2012-10-16 08:20:49 +06:00
|
|
|
static void clear_keyboard(void);
|
2011-02-12 21:15:51 +06:00
|
|
|
|
2012-10-17 00:44:01 +06:00
|
|
|
|
|
|
|
typedef enum { ONESHOT, CONSOLE, MOUSEKEY } cmdstate_t;
|
|
|
|
static cmdstate_t state = ONESHOT;
|
2011-02-12 21:15:51 +06:00
|
|
|
|
2011-09-17 19:39:50 +06:00
|
|
|
|
2012-10-16 08:20:49 +06:00
|
|
|
bool command_proc(uint8_t code)
|
|
|
|
{
|
2012-10-17 00:44:01 +06:00
|
|
|
switch (state) {
|
|
|
|
case ONESHOT:
|
|
|
|
if (!IS_COMMAND())
|
|
|
|
return false;
|
|
|
|
return (command_extra(code) || command_common(code));
|
|
|
|
case CONSOLE:
|
|
|
|
command_console(code);
|
|
|
|
break;
|
2012-10-17 21:10:20 +06:00
|
|
|
#ifdef MOUSEKEY_ENABLE
|
2012-10-17 00:44:01 +06:00
|
|
|
case MOUSEKEY:
|
|
|
|
mousekey_console(code);
|
|
|
|
break;
|
2012-10-17 21:10:20 +06:00
|
|
|
#endif
|
2012-10-17 00:44:01 +06:00
|
|
|
default:
|
|
|
|
state = ONESHOT;
|
|
|
|
return false;
|
2011-09-17 19:39:50 +06:00
|
|
|
}
|
2012-10-17 00:44:01 +06:00
|
|
|
return true;
|
2011-09-17 19:39:50 +06:00
|
|
|
}
|
|
|
|
|
2012-10-17 00:44:01 +06:00
|
|
|
/* This allows to define extra commands. return false when not processed. */
|
2012-10-16 08:20:49 +06:00
|
|
|
bool command_extra(uint8_t code) __attribute__ ((weak));
|
|
|
|
bool command_extra(uint8_t code)
|
2011-09-17 19:39:50 +06:00
|
|
|
{
|
2012-10-16 08:20:49 +06:00
|
|
|
return false;
|
2011-09-17 19:39:50 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-17 00:44:01 +06:00
|
|
|
/***********************************************************
|
|
|
|
* Command common
|
|
|
|
***********************************************************/
|
|
|
|
static void command_common_help(void)
|
|
|
|
{
|
|
|
|
print_enable = true;
|
|
|
|
print("\n\n----- Command Help -----\n");
|
|
|
|
print("c: enter console mode\n");
|
|
|
|
print("d: toggle debug enable\n");
|
|
|
|
print("x: toggle matrix debug\n");
|
|
|
|
print("k: toggle keyboard debug\n");
|
|
|
|
print("m: toggle mouse debug\n");
|
|
|
|
print("p: toggle print enable\n");
|
|
|
|
print("v: print device version & info\n");
|
|
|
|
print("t: print timer count\n");
|
|
|
|
print("s: print status\n");
|
|
|
|
#ifdef NKRO_ENABLE
|
|
|
|
print("n: toggle NKRO\n");
|
|
|
|
#endif
|
|
|
|
print("0/F10: switch to Layer0 \n");
|
|
|
|
print("1/F1: switch to Layer1 \n");
|
|
|
|
print("2/F2: switch to Layer2 \n");
|
|
|
|
print("3/F3: switch to Layer3 \n");
|
|
|
|
print("4/F4: switch to Layer4 \n");
|
|
|
|
print("PScr: power down/remote wake-up\n");
|
2012-10-17 21:10:20 +06:00
|
|
|
print("Caps: Lock Keyboard(Child Proof)\n");
|
2012-10-17 00:44:01 +06:00
|
|
|
print("Paus: jump to bootloader\n");
|
|
|
|
}
|
|
|
|
|
2012-10-16 08:20:49 +06:00
|
|
|
static bool command_common(uint8_t code)
|
2011-09-17 19:39:50 +06:00
|
|
|
{
|
2012-10-17 21:10:20 +06:00
|
|
|
static host_driver_t *host_driver = 0;
|
2012-10-16 08:20:49 +06:00
|
|
|
switch (code) {
|
2012-10-17 21:10:20 +06:00
|
|
|
case KC_CAPSLOCK:
|
|
|
|
if (host_get_driver()) {
|
|
|
|
host_driver = host_get_driver();
|
|
|
|
host_set_driver(0);
|
|
|
|
print("Locked.\n");
|
|
|
|
} else {
|
|
|
|
host_set_driver(host_driver);
|
|
|
|
print("Unlocked.\n");
|
|
|
|
}
|
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_H:
|
2012-10-17 00:44:01 +06:00
|
|
|
case KC_SLASH: /* ? */
|
|
|
|
command_common_help();
|
2011-02-12 21:15:51 +06:00
|
|
|
break;
|
2012-10-17 00:44:01 +06:00
|
|
|
case KC_C:
|
|
|
|
print_enable = true;
|
|
|
|
debug_matrix = false;
|
|
|
|
debug_keyboard = false;
|
|
|
|
debug_mouse = false;
|
|
|
|
debug_enable = false;
|
|
|
|
command_console_help();
|
|
|
|
print("\nEnter Console Mode\n");
|
|
|
|
print("C> ");
|
|
|
|
state = CONSOLE;
|
|
|
|
break;
|
|
|
|
case KC_PAUSE:
|
2012-10-16 08:20:49 +06:00
|
|
|
clear_keyboard();
|
2012-10-17 00:44:01 +06:00
|
|
|
print("\n\nJump to bootloader... ");
|
2011-02-12 21:15:51 +06:00
|
|
|
_delay_ms(1000);
|
2011-09-22 13:56:36 +06:00
|
|
|
bootloader_jump(); // not return
|
|
|
|
print("not supported.\n");
|
2011-02-12 21:15:51 +06:00
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_D:
|
2011-02-12 21:15:51 +06:00
|
|
|
if (debug_enable) {
|
2012-10-17 00:44:01 +06:00
|
|
|
print("\nDEBUG: disabled.\n");
|
|
|
|
debug_matrix = false;
|
2011-02-12 21:15:51 +06:00
|
|
|
debug_keyboard = false;
|
2012-10-17 00:44:01 +06:00
|
|
|
debug_mouse = false;
|
|
|
|
debug_enable = false;
|
|
|
|
} else {
|
|
|
|
print("\nDEBUG: enabled.\n");
|
|
|
|
debug_matrix = true;
|
|
|
|
debug_keyboard = true;
|
|
|
|
debug_mouse = true;
|
|
|
|
debug_enable = true;
|
2011-02-12 21:15:51 +06:00
|
|
|
}
|
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_X: // debug matrix toggle
|
2011-02-12 21:15:51 +06:00
|
|
|
debug_matrix = !debug_matrix;
|
2012-10-17 00:44:01 +06:00
|
|
|
if (debug_matrix) {
|
|
|
|
print("\nDEBUG: matrix enabled.\n");
|
|
|
|
debug_enable = true;
|
|
|
|
} else {
|
|
|
|
print("\nDEBUG: matrix disabled.\n");
|
|
|
|
}
|
2011-02-12 21:15:51 +06:00
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_K: // debug keyboard toggle
|
2011-02-12 21:15:51 +06:00
|
|
|
debug_keyboard = !debug_keyboard;
|
2012-10-17 00:44:01 +06:00
|
|
|
if (debug_keyboard) {
|
|
|
|
print("\nDEBUG: keyboard enabled.\n");
|
|
|
|
debug_enable = true;
|
|
|
|
} else {
|
|
|
|
print("\nDEBUG: keyboard disabled.\n");
|
|
|
|
}
|
2011-02-12 21:15:51 +06:00
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_M: // debug mouse toggle
|
2011-02-12 21:15:51 +06:00
|
|
|
debug_mouse = !debug_mouse;
|
2012-10-17 00:44:01 +06:00
|
|
|
if (debug_mouse) {
|
|
|
|
print("\nDEBUG: mouse enabled.\n");
|
|
|
|
debug_enable = true;
|
|
|
|
} else {
|
|
|
|
print("\nDEBUG: mouse disabled.\n");
|
|
|
|
}
|
2011-02-12 21:15:51 +06:00
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_V: // print version & information
|
2012-10-17 00:44:01 +06:00
|
|
|
print("\n\n----- Version -----\n");
|
2011-02-12 21:15:51 +06:00
|
|
|
print(STR(DESCRIPTION) "\n");
|
2012-10-17 00:44:01 +06:00
|
|
|
print(STR(MANUFACTURER) "(" STR(VENDOR_ID) ")/");
|
|
|
|
print(STR(PRODUCT) "(" STR(PRODUCT_ID) ") ");
|
|
|
|
print("VERSION: " STR(DEVICE_VER) "\n");
|
2011-02-12 21:15:51 +06:00
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_T: // print timer
|
2012-10-17 00:44:01 +06:00
|
|
|
print("timer: "); phex16(timer_count>>16); phex16(timer_count); print("\n");
|
2011-02-12 21:15:51 +06:00
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_P: // print toggle
|
2012-10-17 00:44:01 +06:00
|
|
|
if (print_enable) {
|
2011-02-12 21:15:51 +06:00
|
|
|
print("print disabled.\n");
|
2012-10-17 00:44:01 +06:00
|
|
|
print_enable = false;
|
2011-02-12 21:15:51 +06:00
|
|
|
} else {
|
2012-10-17 00:44:01 +06:00
|
|
|
print_enable = true;
|
2011-02-12 21:15:51 +06:00
|
|
|
print("print enabled.\n");
|
|
|
|
}
|
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_S:
|
2012-10-17 00:44:01 +06:00
|
|
|
print("\n\n----- Status -----\n");
|
2012-06-29 13:48:36 +06:00
|
|
|
print("host_keyboard_leds:"); phex(host_keyboard_leds()); print("\n");
|
2011-02-12 21:15:51 +06:00
|
|
|
#ifdef HOST_PJRC
|
|
|
|
print("UDCON: "); phex(UDCON); print("\n");
|
|
|
|
print("UDIEN: "); phex(UDIEN); print("\n");
|
|
|
|
print("UDINT: "); phex(UDINT); print("\n");
|
2011-03-09 21:50:27 +06:00
|
|
|
print("usb_keyboard_leds:"); phex(usb_keyboard_leds); print("\n");
|
|
|
|
print("usb_keyboard_protocol: "); phex(usb_keyboard_protocol); print("\n");
|
|
|
|
print("usb_keyboard_idle_config:"); phex(usb_keyboard_idle_config); print("\n");
|
|
|
|
print("usb_keyboard_idle_count:"); phex(usb_keyboard_idle_count); print("\n");
|
2011-09-17 19:39:50 +06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HOST_VUSB
|
|
|
|
# if USB_COUNT_SOF
|
|
|
|
print("usbSofCount: "); phex(usbSofCount); print("\n");
|
|
|
|
# endif
|
2011-02-12 21:15:51 +06:00
|
|
|
#endif
|
|
|
|
break;
|
2011-09-17 19:39:50 +06:00
|
|
|
#ifdef NKRO_ENABLE
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_N:
|
2011-02-12 21:15:51 +06:00
|
|
|
keyboard_nkro = !keyboard_nkro;
|
|
|
|
if (keyboard_nkro)
|
2011-09-17 19:39:50 +06:00
|
|
|
print("NKRO: enabled\n");
|
2011-02-12 21:15:51 +06:00
|
|
|
else
|
2011-09-17 19:39:50 +06:00
|
|
|
print("NKRO: disabled\n");
|
2011-02-12 21:15:51 +06:00
|
|
|
break;
|
|
|
|
#endif
|
2011-09-17 19:39:50 +06:00
|
|
|
#ifdef EXTRAKEY_ENABLE
|
2012-10-17 00:44:01 +06:00
|
|
|
case KC_PSCREEN:
|
|
|
|
// TODO: Power key should take this feature? otherwise any key during suspend.
|
2011-05-21 07:28:57 +06:00
|
|
|
#ifdef HOST_PJRC
|
2011-02-12 21:15:51 +06:00
|
|
|
if (suspend && remote_wakeup) {
|
|
|
|
usb_remote_wakeup();
|
|
|
|
} else {
|
2011-05-21 07:28:57 +06:00
|
|
|
host_system_send(SYSTEM_POWER_DOWN);
|
2011-06-30 22:10:55 +06:00
|
|
|
host_system_send(0);
|
|
|
|
_delay_ms(500);
|
2011-02-12 21:15:51 +06:00
|
|
|
}
|
2011-05-21 07:28:57 +06:00
|
|
|
#else
|
|
|
|
host_system_send(SYSTEM_POWER_DOWN);
|
2012-10-17 21:10:20 +06:00
|
|
|
_delay_ms(100);
|
2011-06-30 22:10:55 +06:00
|
|
|
host_system_send(0);
|
|
|
|
_delay_ms(500);
|
2011-05-21 07:28:57 +06:00
|
|
|
#endif
|
2011-02-12 21:15:51 +06:00
|
|
|
break;
|
|
|
|
#endif
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_0:
|
2012-10-16 08:20:49 +06:00
|
|
|
case KC_F10:
|
2011-02-12 21:15:51 +06:00
|
|
|
switch_layer(0);
|
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_1:
|
2012-10-16 08:20:49 +06:00
|
|
|
case KC_F1:
|
2011-02-12 21:15:51 +06:00
|
|
|
switch_layer(1);
|
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_2:
|
2012-10-16 08:20:49 +06:00
|
|
|
case KC_F2:
|
2011-02-12 21:15:51 +06:00
|
|
|
switch_layer(2);
|
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_3:
|
2012-10-16 08:20:49 +06:00
|
|
|
case KC_F3:
|
2011-02-12 21:15:51 +06:00
|
|
|
switch_layer(3);
|
|
|
|
break;
|
2012-10-09 11:36:13 +06:00
|
|
|
case KC_4:
|
2012-10-16 08:20:49 +06:00
|
|
|
case KC_F4:
|
2011-02-12 21:15:51 +06:00
|
|
|
switch_layer(4);
|
|
|
|
break;
|
|
|
|
default:
|
2012-10-17 00:44:01 +06:00
|
|
|
print("?");
|
2012-10-16 08:20:49 +06:00
|
|
|
return false;
|
2011-02-12 21:15:51 +06:00
|
|
|
}
|
2012-10-16 08:20:49 +06:00
|
|
|
return true;
|
2011-02-12 21:15:51 +06:00
|
|
|
}
|
|
|
|
|
2012-10-17 00:44:01 +06:00
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* Command console
|
|
|
|
***********************************************************/
|
|
|
|
static void command_console_help(void)
|
2011-02-12 21:15:51 +06:00
|
|
|
{
|
2012-10-17 00:44:01 +06:00
|
|
|
print_enable = true;
|
|
|
|
print("\n\n----- Console Help -----\n");
|
|
|
|
print("ESC/q: quit\n");
|
|
|
|
#ifdef MOUSEKEY_ENABLE
|
|
|
|
print("m: mousekey\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool command_console(uint8_t code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case KC_H:
|
|
|
|
case KC_SLASH: /* ? */
|
|
|
|
command_console_help();
|
|
|
|
break;
|
|
|
|
case KC_Q:
|
|
|
|
case KC_ESC:
|
|
|
|
print("\nQuit Console Mode\n");
|
|
|
|
state = ONESHOT;
|
|
|
|
return false;
|
|
|
|
#ifdef MOUSEKEY_ENABLE
|
|
|
|
case KC_M:
|
|
|
|
mousekey_console_help();
|
|
|
|
print("\nEnter Mousekey Console\n");
|
|
|
|
print("M0>");
|
|
|
|
state = MOUSEKEY;
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
print("?");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
print("C> ");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MOUSEKEY_ENABLE
|
|
|
|
/***********************************************************
|
|
|
|
* Mousekey console
|
|
|
|
***********************************************************/
|
|
|
|
static uint8_t mousekey_param = 0;
|
|
|
|
|
|
|
|
static void mousekey_param_print(void)
|
|
|
|
{
|
|
|
|
print("\n\n----- Mousekey Parameters -----\n");
|
|
|
|
print("1: mk_delay(*10ms): "); pdec(mk_delay); print("\n");
|
|
|
|
print("2: mk_interval(ms): "); pdec(mk_interval); print("\n");
|
|
|
|
print("3: mk_max_speed: "); pdec(mk_max_speed); print("\n");
|
|
|
|
print("4: mk_time_to_max: "); pdec(mk_time_to_max); print("\n");
|
|
|
|
print("5: mk_wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
|
|
|
|
print("6: mk_wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mousekey_param_inc(uint8_t param, uint8_t inc)
|
|
|
|
{
|
|
|
|
switch (param) {
|
|
|
|
case 1:
|
|
|
|
if (mk_delay + inc < UINT8_MAX)
|
|
|
|
mk_delay += inc;
|
|
|
|
else
|
|
|
|
mk_delay = UINT8_MAX;
|
|
|
|
print("mk_delay = "); pdec(mk_delay); print("\n");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (mk_interval + inc < UINT8_MAX)
|
|
|
|
mk_interval += inc;
|
|
|
|
else
|
|
|
|
mk_interval = UINT8_MAX;
|
|
|
|
print("mk_interval = "); pdec(mk_interval); print("\n");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (mk_max_speed + inc < UINT8_MAX)
|
|
|
|
mk_max_speed += inc;
|
|
|
|
else
|
|
|
|
mk_max_speed = UINT8_MAX;
|
|
|
|
print("mk_max_speed = "); pdec(mk_max_speed); print("\n");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (mk_time_to_max + inc < UINT8_MAX)
|
|
|
|
mk_time_to_max += inc;
|
|
|
|
else
|
|
|
|
mk_time_to_max = UINT8_MAX;
|
|
|
|
print("mk_time_to_max = "); pdec(mk_time_to_max); print("\n");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if (mk_wheel_max_speed + inc < UINT8_MAX)
|
|
|
|
mk_wheel_max_speed += inc;
|
|
|
|
else
|
|
|
|
mk_wheel_max_speed = UINT8_MAX;
|
|
|
|
print("mk_wheel_max_speed = "); pdec(mk_wheel_max_speed); print("\n");
|
|
|
|
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("mk_wheel_time_to_max = "); pdec(mk_wheel_time_to_max); print("\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mousekey_param_dec(uint8_t param, uint8_t dec)
|
|
|
|
{
|
|
|
|
switch (param) {
|
|
|
|
case 1:
|
|
|
|
if (mk_delay > dec)
|
|
|
|
mk_delay -= dec;
|
|
|
|
else
|
|
|
|
mk_delay = 0;
|
|
|
|
print("mk_delay = "); pdec(mk_delay); print("\n");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (mk_interval > dec)
|
|
|
|
mk_interval -= dec;
|
|
|
|
else
|
|
|
|
mk_interval = 0;
|
|
|
|
print("mk_interval = "); pdec(mk_interval); print("\n");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (mk_max_speed > dec)
|
|
|
|
mk_max_speed -= dec;
|
|
|
|
else
|
|
|
|
mk_max_speed = 0;
|
|
|
|
print("mk_max_speed = "); pdec(mk_max_speed); print("\n");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (mk_time_to_max > dec)
|
|
|
|
mk_time_to_max -= dec;
|
|
|
|
else
|
|
|
|
mk_time_to_max = 0;
|
|
|
|
print("mk_time_to_max = "); pdec(mk_time_to_max); print("\n");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
if (mk_wheel_max_speed > dec)
|
|
|
|
mk_wheel_max_speed -= dec;
|
|
|
|
else
|
|
|
|
mk_wheel_max_speed = 0;
|
|
|
|
print("mk_wheel_max_speed = "); pdec(mk_wheel_max_speed); print("\n");
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if (mk_wheel_time_to_max > dec)
|
|
|
|
mk_wheel_time_to_max -= dec;
|
|
|
|
else
|
|
|
|
mk_wheel_time_to_max = 0;
|
|
|
|
print("mk_wheel_time_to_max = "); pdec(mk_wheel_time_to_max); print("\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mousekey_console_help(void)
|
|
|
|
{
|
|
|
|
print("\n\n----- Mousekey Parameters Help -----\n");
|
|
|
|
print("ESC/q: quit\n");
|
|
|
|
print("1: select mk_delay(*10ms)\n");
|
|
|
|
print("2: select mk_interval(ms)\n");
|
|
|
|
print("3: select mk_max_speed\n");
|
|
|
|
print("4: select mk_time_to_max\n");
|
|
|
|
print("5: select mk_wheel_max_speed\n");
|
|
|
|
print("6: select mk_wheel_time_to_max\n");
|
|
|
|
print("p: print prameters\n");
|
|
|
|
print("d: set default values\n");
|
|
|
|
print("up: increase prameters(+1)\n");
|
|
|
|
print("down: decrease prameters(-1)\n");
|
|
|
|
print("pgup: increase prameters(+10)\n");
|
|
|
|
print("pgdown: decrease prameters(-10)\n");
|
|
|
|
print("\nspeed = delta * max_speed * (repeat / time_to_max)\n");
|
|
|
|
print("where delta: cursor="); pdec(MOUSEKEY_MOVE_DELTA);
|
|
|
|
print(", wheel="); pdec(MOUSEKEY_WHEEL_DELTA); print("\n");
|
|
|
|
print("See http://en.wikipedia.org/wiki/Mouse_keys\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool mousekey_console(uint8_t code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case KC_H:
|
|
|
|
case KC_SLASH: /* ? */
|
|
|
|
mousekey_console_help();
|
|
|
|
break;
|
|
|
|
case KC_Q:
|
|
|
|
case KC_ESC:
|
|
|
|
mousekey_param = 0;
|
|
|
|
print("\nQuit Mousekey Console\n");
|
|
|
|
print("C> ");
|
|
|
|
state = CONSOLE;
|
|
|
|
return false;
|
|
|
|
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:
|
|
|
|
case KC_7:
|
|
|
|
case KC_8:
|
|
|
|
case KC_9:
|
|
|
|
case KC_0:
|
2012-10-17 21:10:20 +06:00
|
|
|
mousekey_param = numkey2num(code);
|
2012-10-17 00:44:01 +06:00
|
|
|
print("selected parameter: "); pdec(mousekey_param); print("\n");
|
|
|
|
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:
|
|
|
|
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;
|
|
|
|
mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
|
|
|
|
print("set default values.\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
print("?");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
print("M"); pdec(mousekey_param); print("> ");
|
|
|
|
return true;
|
|
|
|
}
|
2011-02-12 21:15:51 +06:00
|
|
|
#endif
|
2012-10-17 00:44:01 +06:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* Utilities
|
|
|
|
***********************************************************/
|
2012-10-17 21:10:20 +06:00
|
|
|
static uint8_t numkey2num(uint8_t code)
|
2012-10-17 00:44:01 +06:00
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return 0;
|
2011-02-12 21:15:51 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void switch_layer(uint8_t layer)
|
|
|
|
{
|
|
|
|
print("current_layer: "); phex(current_layer); print("\n");
|
|
|
|
print("default_layer: "); phex(default_layer); print("\n");
|
|
|
|
current_layer = layer;
|
|
|
|
default_layer = layer;
|
|
|
|
print("switch to Layer: "); phex(layer); print("\n");
|
|
|
|
}
|
2012-10-16 08:20:49 +06:00
|
|
|
|
|
|
|
static void clear_keyboard(void)
|
|
|
|
{
|
|
|
|
host_clear_keys();
|
2012-10-17 00:44:01 +06:00
|
|
|
host_clear_mods();
|
2012-10-16 08:20:49 +06:00
|
|
|
host_send_keyboard_report();
|
|
|
|
|
|
|
|
host_system_send(0);
|
|
|
|
host_consumer_send(0);
|
|
|
|
|
|
|
|
#ifdef MOUSEKEY_ENABLE
|
|
|
|
mousekey_clear();
|
|
|
|
mousekey_send();
|
|
|
|
#endif
|
|
|
|
}
|