Updated comments
This commit is contained in:
parent
01a6a7c028
commit
20dd6914dc
@ -29,12 +29,23 @@
|
||||
* Keyboard/Mouse based on standard teensy "Keypad" library for button scanning, standard teensy
|
||||
* "usb_keyboard" library for HID keyboard/mouse usb data communication.
|
||||
*
|
||||
* ---------------------------------------------------------------------------------------------
|
||||
* | Tab/Fn2 | Q | W | E | R | T | | Y | U | I | O | P | Å |
|
||||
* | Ctrl/Esc | A | S | D | F | G | | H | J | K | L | Ö | Ä |
|
||||
* | Shift/Del | Z | X | C | V | B | | N | M | , | . | - | Shift/Enter |
|
||||
* -----------------| M1/M2 | Alt | BSpc/Fn1 | | Spc/Fn1 | AltGr | Win |--------------------
|
||||
* -------------------------- -------------------------
|
||||
* Features:
|
||||
*
|
||||
* * 42 keys "Split" keyboard layout. 36 finger keys and 6 thumb keys.
|
||||
* * Function buttons with total of four key-layer support (Primary + 2fn layers + Game mode).
|
||||
* * Mouse movement, wheel up, wheel down, left button, right button and middle button support
|
||||
* * Caps Lock warning indication (if activated)
|
||||
* * Status indication -
|
||||
* - 0 LED off = Normal mode
|
||||
* - 1 LED constant on = Game mode
|
||||
* - 2 LED flashing = Caps Lock activated
|
||||
* * Game mode: Replaces all layer keys with a "Game mode KEY". Configurable for each key
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
@ -125,7 +136,8 @@ Button buttons[NBR_OF_BUTTONS] =
|
||||
// byte kp_colPins[KP_COLS] = {12, 11, 10, 9, 8, 7, 26, 25, 24, 23, 22, 21};
|
||||
|
||||
// // @formatter:off
|
||||
// Key ID corresponding with the physical design of the actual keyboard.
|
||||
// /* Keymap config -----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
// Key ID corresponding with the physical design of the actual keyboard. */
|
||||
// char kp_keys[KP_ROWS][KP_COLS] = {
|
||||
// {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
|
||||
// {13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24},
|
||||
@ -133,14 +145,12 @@ Button buttons[NBR_OF_BUTTONS] =
|
||||
// {0, 0, 0, 37, 38, 39, 40, 41, 42, 0, 0, 0}};
|
||||
|
||||
// Keypad kp_keypad = Keypad(makeKeymap(kp_keys), kp_rowPins, kp_colPins, KP_ROWS, KP_COLS);
|
||||
|
||||
// // Button keymap.
|
||||
// // Valid "Fn0 (hold) key" when using tap mode are: KEY_LEFT_SHIFT, KEY_RIGHT_SHIFT, KEY_LEFT_CTRL, KEY_RIGHT_CTRL, KEY_RIGHT_ALT, KEY_LEFT_GUI, KEY_RIGHT_GUI, KEY_FN1, KEY_FN2
|
||||
// // Fn1 and Fn2 keys are N/A when using tap mode and should me defined as NO_KEY.
|
||||
// // "GM replace key" will override all layer keys (Fn0, Fn1, Fn2) both tap and hold while game mode are active.
|
||||
// /* Valid "Fn0 (hold) key" when using tap mode are: KEY_LEFT_SHIFT, KEY_RIGHT_SHIFT, KEY_LEFT_CTRL, KEY_RIGHT_CTRL, KEY_RIGHT_ALT, KEY_LEFT_GUI, KEY_RIGHT_GUI, KEY_FN1, KEY_FN2
|
||||
// Fn1 and Fn2 keys are N/A when using tap mode and should me defined as NO_KEY.
|
||||
// "GM replace key" will override all layer keys (Fn0, Fn1, Fn2) both tap and hold while game mode are active. */
|
||||
// Button buttons[NBR_OF_BUTTONS] =
|
||||
// {
|
||||
// // key ID Fn0 (hold) key Fn0 tap key Fn1 key Fn2 key GM replace key tap enable
|
||||
// /* key ID Fn0 (hold) key Fn0 tap key Fn1 key Fn2 key GM replace key tap enable */
|
||||
// {1, KEY_FN2, KEY_TAB, NO_KEY, NO_KEY, NO_KEY, true, IDLE, false, 0, false, false, 0, 0, false},
|
||||
// {2, KEY_Q, NO_KEY, KEY_F1, KEY_F12, NO_KEY, false, IDLE, false, 0, false, false, 0, 0, false},
|
||||
// {3, KEY_W, NO_KEY, KEY_F2, KEY_F13, NO_KEY, false, IDLE, false, 0, false, false, 0, 0, false},
|
||||
@ -201,15 +211,21 @@ int mouse_wheel = 0;
|
||||
bool game_mode = false;
|
||||
bool key_pressed = false;
|
||||
|
||||
/**
|
||||
Converts a color code to its numerical value.
|
||||
|
||||
@param colorCode color code to convert.
|
||||
@return the numerical value of the color code.
|
||||
*/
|
||||
bool set_key(uint16_t keycode, uint8_t kstate)
|
||||
{
|
||||
// Abort if keycode is invalid
|
||||
/* Abort if keycode is invalid */
|
||||
if (keycode == NO_KEY || keycode == KEY_FN1 || keycode == KEY_FN2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mouse buttons
|
||||
/* Mouse buttons */
|
||||
if (keycode >= KEY_M1 && keycode <= KEY_M3)
|
||||
{
|
||||
if (kstate == RELEASED)
|
||||
@ -222,20 +238,7 @@ bool set_key(uint16_t keycode, uint8_t kstate)
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle game mode
|
||||
else if (keycode == KEY_GM)
|
||||
{
|
||||
if (kstate == PRESSED && game_mode == true)
|
||||
{
|
||||
game_mode = false;
|
||||
}
|
||||
else if (kstate == PRESSED && game_mode == false)
|
||||
{
|
||||
game_mode = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Mouse wheel
|
||||
/* Mouse wheel */
|
||||
else if ((keycode == KEY_MWU || keycode == KEY_MWD))
|
||||
{
|
||||
if (kstate == RELEASED)
|
||||
@ -255,7 +258,20 @@ bool set_key(uint16_t keycode, uint8_t kstate)
|
||||
}
|
||||
}
|
||||
|
||||
// Normal keyboard keys
|
||||
/* Toggle game mode */
|
||||
else if (keycode == KEY_GM)
|
||||
{
|
||||
if (kstate == PRESSED && game_mode == true)
|
||||
{
|
||||
game_mode = false;
|
||||
}
|
||||
else if (kstate == PRESSED && game_mode == false)
|
||||
{
|
||||
game_mode = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Normal keyboard keys */
|
||||
else
|
||||
{
|
||||
if (kstate == RELEASED)
|
||||
@ -271,13 +287,19 @@ bool set_key(uint16_t keycode, uint8_t kstate)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
Converts a color code to its numerical value.
|
||||
|
||||
@param colorCode color code to convert.
|
||||
@return the numerical value of the color code.
|
||||
*/
|
||||
void scan_buttons()
|
||||
{
|
||||
// Scan keypad
|
||||
/* Scan keypad */
|
||||
if (kp_keypad.getKeys())
|
||||
{
|
||||
|
||||
// Enter bootloader if all four corner-buttons is pressed together
|
||||
Enter bootloader if all four corner-buttons is pressed together
|
||||
int reboot = 0;
|
||||
for (int i = 0; i < LIST_MAX; i++)
|
||||
{
|
||||
@ -303,7 +325,7 @@ void scan_buttons()
|
||||
_reboot_Teensyduino_();
|
||||
}
|
||||
|
||||
// Check for FN mode
|
||||
/* Check for FN mode */
|
||||
int fn_mode = 0;
|
||||
for (int i = 0; i < LIST_MAX; i++)
|
||||
{
|
||||
@ -327,7 +349,7 @@ void scan_buttons()
|
||||
}
|
||||
}
|
||||
|
||||
// Process key press
|
||||
/* Process key press */
|
||||
for (int i = 0; i < LIST_MAX; i++)
|
||||
{
|
||||
if (kp_keypad.key[i].kstate == PRESSED)
|
||||
@ -336,11 +358,11 @@ void scan_buttons()
|
||||
{
|
||||
if (buttons[j].keypad_kchar == kp_keypad.key[i].kchar && kp_keypad.key[i].stateChanged == true)
|
||||
{
|
||||
// Tap state:
|
||||
// 0 = idle (not pressed for a while)
|
||||
// 1 = pressed
|
||||
// 2 = released within timeout, pressing tap key
|
||||
// 3 = pressed again within timeout, holding tap key
|
||||
/* Tap state:
|
||||
0 = idle (not pressed for a while)
|
||||
1 = pressed
|
||||
2 = released within timeout, pressing tap key
|
||||
3 = pressed again within timeout, holding tap key */
|
||||
if (buttons[j].tap_enable && buttons[j].tap_state == 0 && (game_mode == false || buttons[j].gm_keycode == NO_KEY))
|
||||
{
|
||||
buttons[j].tap_timeout_timestamp = current_timestamp + TAP_TIMEOUT;
|
||||
@ -368,11 +390,11 @@ void scan_buttons()
|
||||
{
|
||||
if (buttons[j].keypad_kchar == kp_keypad.key[i].kchar && kp_keypad.key[i].stateChanged == true)
|
||||
{
|
||||
// Tap state:
|
||||
// 0 = idle (not pressed for a while)
|
||||
// 1 = pressed
|
||||
// 2 = released within timeout, pressing tap key
|
||||
// 3 = pressed again within timeout, holding tap key
|
||||
/* Tap state:
|
||||
0 = idle (not pressed for a while)
|
||||
1 = pressed
|
||||
2 = released within timeout, pressing tap key
|
||||
3 = pressed again within timeout, holding tap key */
|
||||
if (buttons[j].tap_enable && buttons[j].tap_state == 1 && (game_mode == false || buttons[j].gm_keycode == NO_KEY))
|
||||
{
|
||||
buttons[j].tap_release_timestamp = current_timestamp + TAP_TIMEOUT + 10;
|
||||
@ -391,7 +413,7 @@ void scan_buttons()
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any "non tap keys" has been pressed
|
||||
/* Check if any "non tap keys" has been pressed */
|
||||
for (int i = 0; i < NBR_OF_BUTTONS; i++)
|
||||
{
|
||||
if (buttons[i].run_keycode == true && buttons[i].tap_enable == false && buttons[i].kstate == PRESSED)
|
||||
@ -406,27 +428,27 @@ void scan_buttons()
|
||||
}
|
||||
}
|
||||
|
||||
// Execute key commands
|
||||
/* Execute key commands */
|
||||
for (int i = 0; i < NBR_OF_BUTTONS; i++)
|
||||
{
|
||||
// Check if key should be processed
|
||||
/* Check if key should be processed */
|
||||
if (buttons[i].run_keycode == true)
|
||||
{
|
||||
// Check if key pressed or released
|
||||
/* Check if key pressed or released */
|
||||
if (buttons[i].kstate == PRESSED)
|
||||
{
|
||||
// Check if key is in tap mode and not in game mode
|
||||
/* Check if key is in tap mode and not in game mode */
|
||||
if (buttons[i].tap_enable == true && (game_mode == false || buttons[i].gm_keycode == NO_KEY))
|
||||
{
|
||||
if (buttons[i].tap_state == 1)
|
||||
{
|
||||
if (buttons[i].hold_direct == true)
|
||||
{
|
||||
// Press hold key if "hold direct" is enabled (tap state = 1)
|
||||
/* Press hold key if "hold direct" is enabled (tap state = 1) */
|
||||
set_key(buttons[i].keycode, PRESSED);
|
||||
}
|
||||
|
||||
// Reset tap inhibit flag
|
||||
/* Reset tap inhibit flag */
|
||||
buttons[i].tap_inhibit = false;
|
||||
}
|
||||
}
|
||||
@ -452,12 +474,12 @@ void scan_buttons()
|
||||
}
|
||||
else if (buttons[i].kstate == RELEASED)
|
||||
{
|
||||
// Check if key is in tap mode
|
||||
/* Check if key is in tap mode */
|
||||
if (buttons[i].tap_enable == true && (game_mode == false || buttons[i].gm_keycode == NO_KEY))
|
||||
{
|
||||
if (buttons[i].tap_state == 2)
|
||||
{
|
||||
// Press tap key if no other keys are pressed (tap state = 2)
|
||||
/* Press tap key if no other keys are pressed (tap state = 2) */
|
||||
set_key(buttons[i].tap_keycode, RELEASED); // Fix for not send press and hold for the tap key
|
||||
set_key(buttons[i].keycode, RELEASED);
|
||||
if (buttons[i].tap_inhibit == false)
|
||||
@ -467,7 +489,7 @@ void scan_buttons()
|
||||
}
|
||||
else
|
||||
{
|
||||
// Release all keys (tap state = 0,1,3)
|
||||
/* Release all keys (tap state = 0,1,3) */
|
||||
set_key(buttons[i].keycode, RELEASED);
|
||||
set_key(buttons[i].tap_keycode, RELEASED);
|
||||
buttons[i].tap_state = 0;
|
||||
@ -487,16 +509,16 @@ void scan_buttons()
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reset run_keycode flag
|
||||
/* Reset run_keycode flag */
|
||||
buttons[i].run_keycode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Status indication
|
||||
// 0 = off (normal)
|
||||
// 1 = constant on (Game mode)
|
||||
// 2 = blinking (CapsLock)
|
||||
/* Status indication
|
||||
0 = off (normal)
|
||||
1 = constant on (Game mode)
|
||||
2 = blinking (CapsLock) */
|
||||
if (keyboard_leds & (1 << USB_LED_CAPS_LOCK))
|
||||
{
|
||||
status_led_mode = 2;
|
||||
@ -522,18 +544,18 @@ void loop()
|
||||
|
||||
current_timestamp = millis();
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Scan buttons 5ms
|
||||
// ----------------------------------------------------------
|
||||
/* ----------------------------------------------------------
|
||||
Scan buttons 5ms
|
||||
---------------------------------------------------------- */
|
||||
if (current_timestamp >= button_timestamp)
|
||||
{
|
||||
button_timestamp = current_timestamp + 5;
|
||||
scan_buttons();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Fn tap timeout TAP_TIMEOUT
|
||||
// ----------------------------------------------------------
|
||||
/* ----------------------------------------------------------
|
||||
Fn tap timeout TAP_TIMEOUT
|
||||
---------------------------------------------------------- */
|
||||
for (int i = 0; i < NBR_OF_BUTTONS; i++)
|
||||
{
|
||||
if (current_timestamp >= buttons[i].tap_timeout_timestamp && buttons[i].tap_timeout_enable)
|
||||
@ -554,9 +576,9 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Fn tap release TAP_TIMEOUT + 10ms
|
||||
// ----------------------------------------------------------
|
||||
/* ----------------------------------------------------------
|
||||
Fn tap release TAP_TIMEOUT + 10ms
|
||||
---------------------------------------------------------- */
|
||||
for (int i = 0; i < NBR_OF_BUTTONS; i++)
|
||||
{
|
||||
if (current_timestamp >= buttons[i].tap_release_timestamp && buttons[i].tap_release_enable)
|
||||
@ -567,18 +589,18 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Update mouse wheel 20ms
|
||||
// ----------------------------------------------------------
|
||||
/* ----------------------------------------------------------
|
||||
Update mouse wheel 20ms
|
||||
---------------------------------------------------------- */
|
||||
if (current_timestamp >= mouse_wheel_timestamp && mouse_wheel != 0)
|
||||
{
|
||||
Mouse.move(0, 0, mouse_wheel);
|
||||
mouse_wheel_timestamp = current_timestamp + 20;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// Update indicator 200ms
|
||||
// ----------------------------------------------------------
|
||||
/* ----------------------------------------------------------
|
||||
Update indicator 200ms
|
||||
---------------------------------------------------------- */
|
||||
if (current_timestamp >= indicator_timestamp)
|
||||
{
|
||||
if (status_led_mode == 2 && status_led_on == false)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user