fpsvogel

Felipe's sketch for Atreus

Apr 2nd, 2021 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.53 KB | None | 0 0
  1. /* -*- mode: c++ -*-
  2.  * Atreus -- Chrysalis-enabled Sketch for the Keyboardio Atreus
  3.  * Copyright (C) 2018, 2019  Keyboard.io, Inc
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or
  8.  * (at your option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program; if not, write to the Free Software Foundation, Inc.,
  17.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18.  */
  19.  
  20. #ifndef BUILD_INFORMATION
  21. #define BUILD_INFORMATION "locally built"
  22. #endif
  23.  
  24. #include "Kaleidoscope.h"
  25. #include "Kaleidoscope-Macros.h"
  26. #include "Kaleidoscope-OneShot.h"
  27. #include "Kaleidoscope-Qukeys.h"
  28. #include "Kaleidoscope-HostOS.h"
  29. #include "Kaleidoscope-Unicode.h"
  30.  
  31. #define SHIFT(n) ShiftToLayer(n)
  32.  
  33. // Macros
  34. enum {
  35.   MACRO_QWERTY,
  36.   MACRO_VERSION_INFO,
  37.   EM_DASH,
  38.   EN_DASH,
  39.   LEFT_SINGLE_QUOTE,
  40.   RIGHT_SINGLE_QUOTE,
  41.   LEFT_DOUBLE_QUOTE,
  42.   RIGHT_DOUBLE_QUOTE,
  43.   ELLIPSIS,
  44.   SMILEY,
  45.   SAD,
  46.   THINK,
  47.   THUMB,
  48.   HI_FIVE,
  49.   SWEAT
  50. };
  51.  
  52. #define Key_Exclamation LSHIFT(Key_1)
  53. #define Key_At LSHIFT(Key_2)
  54. #define Key_Hash LSHIFT(Key_3)
  55. #define Key_Dollar LSHIFT(Key_4)
  56. #define Key_Percent LSHIFT(Key_5)
  57. #define Key_Caret LSHIFT(Key_6)
  58. #define Key_And LSHIFT(Key_7)
  59. #define Key_Star LSHIFT(Key_8)
  60. #define Key_Plus LSHIFT(Key_Equals)
  61. #define Key_Pipe LSHIFT(Key_Backslash)
  62. #define Key_Question LSHIFT(Key_Slash)
  63. #define Key_Colon LSHIFT(Key_P)  // P is ; in Colemak
  64. #define Key_Underscore LSHIFT(Key_Minus)
  65. #define Key_DoubleQuote LSHIFT(Key_Quote)
  66. #define Key_RightAngleBracket LSHIFT(Key_Period)
  67.  
  68. // Layers
  69. enum {
  70.   QWERTY,
  71.   FUN,
  72.   UPPER,
  73.   SUPER
  74. };
  75.  
  76. /* *INDENT-OFF* */
  77. KEYMAPS(
  78.   [QWERTY] = KEYMAP_STACKED
  79.   (
  80.        Key_Q   ,Key_W        ,Key_E      ,Key_R         ,Key_T
  81.       ,Key_A   ,Key_S        ,Key_D      ,Key_F         ,Key_G
  82.       ,Key_Z   ,Key_X        ,Key_C      ,Key_V         ,Key_B         ,Key_Backslash
  83.       ,Key_Esc ,Key_CapsLock ,Key_Delete ,Key_Backspace ,Key_LeftShift ,Key_Tab
  84.  
  85.                      ,Key_Y     ,Key_U    ,Key_I     ,Key_O      ,Key_Minus
  86.                      ,Key_H     ,Key_J    ,Key_K     ,Key_L      ,Key_Semicolon
  87.        ,Key_Backtick ,Key_N     ,Key_M    ,Key_Comma ,Key_Period ,Key_Quote
  88.        ,Key_Enter    ,Key_Space ,OSL(FUN) ,Key_Tab   ,Key_Enter  ,Key_LeftGui
  89.   ),
  90.  
  91.   [FUN] = KEYMAP_STACKED
  92.   (
  93.        Key_5                ,Key_6                 ,Key_7                ,Key_8         ,Key_9
  94.       ,Key_0                ,Key_1                 ,Key_2                ,Key_3         ,Key_4
  95.       ,M(LEFT_DOUBLE_QUOTE) ,M(RIGHT_DOUBLE_QUOTE) ,M(LEFT_SINGLE_QUOTE) ,M(THUMB)      ,M(SWEAT)      ,M(RIGHT_SINGLE_QUOTE)
  96.       ,Key_RightControl     ,___                   ,Key_Delete           ,Key_Backspace ,Key_LeftShift ,Key_LeftControl
  97.       // RightControl is remapped to Calculator in SharpKeys
  98.  
  99.                    ,M(HI_FIVE) ,Key_PageUp    ,Key_UpArrow   ,Key_PageDown   ,Key_Minus
  100.                    ,Key_Home   ,Key_LeftArrow ,Key_DownArrow ,Key_RightArrow ,Key_End
  101.       ,M(THINK)    ,M(SAD)     ,M(SMILEY)     ,Key_Comma     ,Key_Period     ,M(ELLIPSIS)
  102.       ,Key_LeftAlt ,Key_Space  ,___           ,Key_Tab       ,Key_Enter      ,___
  103.    ),
  104.  
  105.   [UPPER] = KEYMAP_STACKED
  106.   (
  107.        M(EM_DASH)        ,M(EN_DASH)      ,Key_At        ,Key_Hash    ,Key_Percent
  108.       ,Key_Question      ,Key_Exclamation ,Key_Colon     ,Key_Equals  ,Key_Slash
  109.       ,Key_PcApplication ,Key_Pipe        ,Key_And       ,Key_P       ,Key_Dollar    ,___  // P is ; in Colemak
  110.       ,Key_ScrollLock    ,Key_PrintScreen ,Key_Backspace ,___         ,Key_LeftShift ,Key_LeftControl
  111.       // Application, ScrollLock, and PrintScreen are remapped to Volume Up/Down and Mute in SharpKeys
  112.       // (Key_VolumeUp, Key_VolumeDown, and Key_Mute do not work for me)
  113.  
  114.                    ,Key_Caret ,Key_LeftBracket      ,Key_RightBracket      ,___                   ,Key_Underscore
  115.                    ,Key_Star  ,Key_LeftParen        ,Key_RightParen        ,___                   ,___
  116.       ,___         ,Key_Plus  ,Key_LeftCurlyBracket ,Key_RightCurlyBracket ,Key_RightAngleBracket ,Key_DoubleQuote
  117.       ,Key_LeftAlt ,Key_Space ,XXX                  ,Key_Backspace         ,Key_Enter             ,___
  118.    ),
  119.  
  120.   [SUPER] = KEYMAP_STACKED
  121.   (
  122.        Key_F13 ,Key_F14 ,Key_F15 ,Key_F16   ,Key_F11
  123.       ,Key_F17 ,Key_F18 ,Key_F19 ,Key_F20   ,Key_F5
  124.       ,Key_F21 ,Key_F22 ,Key_F23 ,Key_F24   ,Key_F2        ,Key_F3
  125.       ,Key_F12 ,___     ,___     ,___       ,Key_LeftShift ,Key_LeftControl
  126.  
  127.                    ,___ ,Key_F12 ,Key_F11 ,Key_F10 ,Key_F9
  128.                    ,___ ,Key_F8  ,Key_F7  ,Key_F6  ,Key_F5
  129.       ,Key_F4      ,___ ,Key_F4  ,Key_F3  ,Key_F2  ,Key_F1
  130.       ,Key_LeftAlt ,___ ,___     ,___     ,___     ,___
  131.    )
  132. )
  133. /* *INDENT-ON* */
  134.  
  135. KALEIDOSCOPE_INIT_PLUGINS(
  136.   Qukeys,
  137.   OneShot,
  138.   Macros,
  139.   HostOS,
  140.   Unicode
  141. );
  142.  
  143. static void unicode(uint32_t character, uint8_t keyState) {
  144.   if (keyToggledOn(keyState)) {
  145.     Unicode.type(character);
  146.   }
  147. }
  148.  
  149. const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
  150.   switch (macroIndex) {
  151.   case MACRO_QWERTY:
  152.     // This macro is currently unused, but is kept around for compatibility
  153.     // reasons. We used to use it in place of `MoveToLayer(QWERTY)`, but no
  154.     // longer do. We keep it so that if someone still has the old layout with
  155.     // the macro in EEPROM, it will keep working after a firmware update.
  156.     Layer.move(QWERTY);
  157.     break;
  158.   case MACRO_VERSION_INFO:
  159.     if (keyToggledOn(keyState)) {
  160.       Macros.type(PSTR("Keyboardio Atreus - Kaleidoscope "));
  161.       Macros.type(PSTR(BUILD_INFORMATION));
  162.     }
  163.     break;
  164.   case EM_DASH:
  165.     unicode(0x2014, keyState);
  166.     break;
  167.   case EN_DASH:
  168.     unicode(0x2013, keyState);
  169.     break;
  170.   case LEFT_SINGLE_QUOTE:
  171.     unicode(0x2018, keyState);
  172.     break;
  173.   case RIGHT_SINGLE_QUOTE:
  174.     unicode(0x2019, keyState);
  175.     break;
  176.   case LEFT_DOUBLE_QUOTE:
  177.     unicode(0x201C, keyState);
  178.     break;
  179.   case RIGHT_DOUBLE_QUOTE:
  180.     unicode(0x201D, keyState);
  181.     break;
  182.   case ELLIPSIS:
  183.     unicode(0x2026, keyState);
  184.     break;
  185.   case SAD:
  186.     unicode(0x1F61E, keyState);
  187.     break;
  188.   case SMILEY:
  189.     unicode(0x1F642, keyState);
  190.     break;
  191.   case THINK:
  192.     unicode(0x1F914, keyState);
  193.     break;
  194.   case THUMB:
  195.     unicode(0x1F44D, keyState);
  196.     break;
  197.   case HI_FIVE:
  198.     unicode(0x1F64C, keyState);
  199.     break;
  200.   case SWEAT:
  201.     unicode(0x1F605, keyState);
  202.     break;
  203.   }
  204.  
  205.   return MACRO_NONE;
  206. }
  207.  
  208. void setup() {
  209.   QUKEYS(
  210.     kaleidoscope::plugin::Qukey(0, KeyAddr(3, 1), SHIFT(SUPER)),      // CapsLock/Super
  211.     kaleidoscope::plugin::Qukey(0, KeyAddr(3, 3), SHIFT(UPPER)),      // Backspace/Upper
  212.     kaleidoscope::plugin::Qukey(0, KeyAddr(3, 5), Key_LeftControl),   // Tab/Ctrl
  213.     kaleidoscope::plugin::Qukey(0, KeyAddr(3, 6), Key_LeftAlt),       // Enter/Alt
  214.   )
  215.   Qukeys.setHoldTimeout(250);  // a lower value than this causes modifier or primary key sometimes not to register when they should
  216.   Qukeys.setOverlapThreshold(20);
  217.   Qukeys.setMinimumHoldTime(20);
  218.   Qukeys.setMinimumPriorInterval(200);
  219.   Qukeys.activate();
  220.  
  221.   Kaleidoscope.setup();
  222. }
  223.  
  224. void loop() {
  225.   Kaleidoscope.loop();
  226. }
Add Comment
Please, Sign In to add comment