keybrd library is an open source library for creating custom-keyboard firmware.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
Tento repozitář je archivovaný. Můžete prohlížet soubory, klonovat, ale nemůžete nahrávat a vytvářet nové úkoly a požadavky na natažení.

keybrd_3d_sublayerNested.ino 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* keybrd_3d_sublayerNested.ino
  2. This sketch:
  3. is firmware for a simple 2-layer keyboard
  4. runs on the first two rows and columns of a breadboard keyboard
  5. | Layout | **0** | **1** | **2** |
  6. |:------:|:-----:|:-----:|:-----:|
  7. | **0** | a - 1 | b = | c Num |
  8. | **1** |Normal | Sym | Enter |
  9. normal layer keys are a b c
  10. sym layer keys are brackets [ ] and num
  11. num layer keys are 6 7
  12. The num layer key is located on the sym layer
  13. num layer is active while holding sym+num
  14. Each cell in the table's body represents a key.
  15. The layered keys in column 1 have two layers; one character for each layer.
  16. Letters 'a' and 'b' are on the normal layer. Numbers '1' and '2' are on the fn layer.
  17. Holding the fn key down makes it the active layer. Releasing the fn key restores the normal layer.
  18. */
  19. // ################## GLOBAL ###################
  20. // ================= INCLUDES ==================
  21. //Keys
  22. #include <Code_Sc.h>
  23. #include <Code_Null.h>
  24. #include <LayerState.h>
  25. #include <Code_LayerLock.h>
  26. #include <Code_LayerHold.h>
  27. #include <Key_LayeredKeys.h>
  28. #include <Key_LayeredScSc.h>
  29. //Matrix
  30. #include <Row.h>
  31. #include <Scanner_uC.h>
  32. #include <ScanDelay.h>
  33. // ============ SPEED CONFIGURATION ============
  34. ScanDelay scanDelay(9000);
  35. // ================== SCANNER ==================
  36. uint8_t readPins[] = {14, 15, 16};
  37. uint8_t readPinCount = sizeof(readPins)/sizeof(*readPins);
  38. Scanner_uC scanner(LOW, readPins, readPinCount);
  39. /* =================== CODES ===================
  40. The CODES section instantiates six codes, one for each item in the layout.
  41. */
  42. /* ---------------- LAYER CODE -----------------
  43. enum assigns layerId numbers to the layers.
  44. */
  45. enum layers { NORMAL, SYM };
  46. /* layerState keeps track of the active layer.
  47. */
  48. LayerState layerState;
  49. LayerStateInterface& Key_LayeredKeys::refLayerState = layerState;
  50. /*
  51. NORMAL=0 and FN=1. LayerState's default layerId is 0.
  52. The Code_LayerHold constructor has two parameters:
  53. 1) the layerId that will be active while the key is held down
  54. 2) a LayerState that will keep track of the active layer
  55. When l_fn is pressed, it tells layerState to change the active layer to 1.
  56. When l_fn is released, it tells layerState that layer 1 is released, and layerState restores the default layer.
  57. */
  58. Code_LayerLock l_normal(NORMAL, layerState);
  59. Code_LayerLock l_sym(SYM, layerState);
  60. //sublayer
  61. enum subLayers { SUBSYM, SUBNUM };
  62. LayerState sublayerState;
  63. Code_LayerHold l_num(SUBNUM, sublayerState);
  64. LayerStateInterface& Key_LayeredScSc::refLayerState = sublayerState;
  65. // ---------------- SCAN CODES -----------------
  66. Code_Sc s_a(KEY_A);
  67. Code_Sc s_b(KEY_B);
  68. Code_Sc s_c(KEY_C);
  69. Code_Sc s_minus(KEY_MINUS);
  70. Code_Sc s_equal(KEY_EQUAL);
  71. Code_Sc s_enter(KEY_ENTER);
  72. Code_Sc s_1(KEY_1);
  73. Code_Null code_null;
  74. /* =================== KEYS ====================
  75. Here we pack Codes into keys.
  76. The Key_LayeredKeys constructor takes one array of Code pointers - one Code object per layer.
  77. The Key object names in this sketch start with a "k_" followed by row-column coordinates.
  78. */
  79. Key_LayeredScSc sub_00(KEY_MINUS, KEY_1);
  80. Key* const ptrsCodes_00[] = { &s_a, &sub_00 };
  81. Key_LayeredKeys k_00(ptrsCodes_00);
  82. Key* const ptrsCodes_01[] = { &s_b, &s_equal };
  83. Key_LayeredKeys k_01(ptrsCodes_01);
  84. Key* const ptrsCodes_02[] = { &s_c, &l_num };
  85. Key_LayeredKeys k_02(ptrsCodes_02);
  86. /* HOW LAYERED OBJECTS WORK
  87. When a Key_LayeredKeys object is pressed, it gets the active layer id from layerState.
  88. It then uses the layer id as an array index to call the Code of the active layer.
  89. The Code object then sends its scancode over USB.
  90. */
  91. /* =================== ROWS ====================
  92. Here we pack Key pointers into row objects.
  93. Codes are a kind of Key that only have one layer.
  94. So rows can contain a mix of codes and multi-layered keys.
  95. Arrays ptrsKeys_0[] and ptrsKeys_1[] contain both Code pointers and Key pointers.
  96. */
  97. Key* const ptrsKeys_0[] = { &k_00, &k_01, &k_02 };
  98. uint8_t keyCount_0 = sizeof(ptrsKeys_0)/sizeof(*ptrsKeys_0);
  99. Row row_0(scanner, 0, ptrsKeys_0, keyCount_0);
  100. Key* const ptrsKeys_1[] = { &l_normal, &l_sym, &s_enter };
  101. uint8_t keyCount_1 = sizeof(ptrsKeys_1)/sizeof(*ptrsKeys_1);
  102. Row row_1(scanner, 1, ptrsKeys_1, keyCount_1);
  103. // ################### MAIN ####################
  104. void setup()
  105. {
  106. Keyboard.begin();
  107. }
  108. void loop()
  109. {
  110. row_0.process();
  111. row_1.process();
  112. scanDelay.delay();
  113. }