Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

macro.c 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Copyright (C) 2014 by Jacob Alexander
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. // ----- Includes -----
  22. // Compiler Includes
  23. #include <Lib/MacroLib.h>
  24. // Project Includes
  25. #include <cli.h>
  26. #include <led.h>
  27. #include <print.h>
  28. #include <scan_loop.h>
  29. #include <output_com.h>
  30. // Keymaps
  31. #include "usb_hid.h"
  32. #include <defaultMap.h>
  33. // Local Includes
  34. #include "macro.h"
  35. // ----- Function Declarations -----
  36. void cliFunc_capList ( char* args );
  37. void cliFunc_capSelect ( char* args );
  38. void cliFunc_lookComb ( char* args );
  39. void cliFunc_lookDefault( char* args );
  40. void cliFunc_lookPartial( char* args );
  41. void cliFunc_macroDebug ( char* args );
  42. // ----- Variables -----
  43. // Output Module command dictionary
  44. char* macroCLIDictName = "Macro Module Commands";
  45. CLIDictItem macroCLIDict[] = {
  46. { "capList", "Prints an indexed list of all non USB keycode capabilities.", cliFunc_capList },
  47. { "capSelect", "Triggers the specified capability. U10 is USB Code 0x0A (G). K11 is keyboard capability 0x0B.", cliFunc_capSelect },
  48. { "lookComb", "Do a lookup on the Combined map. S10 specifies Scancode 0x0A. U10 specified USB keycode 0x0A.", cliFunc_lookComb },
  49. { "lookDefault", "Do a lookup on the Default map. S10 specifies Scancode 0x0A. USB keycodes are not valid.", cliFunc_lookDefault },
  50. { "lookPartial", "Do a lookup on the layered partial map. S10 specifies Scancode 0x0A. U10 specifies USB keycode 0x0A.", cliFunc_lookPartial },
  51. { "macroDebug", "Disables/Enables sending USB keycodes to the Output Module and prints U/K codes.", cliFunc_macroDebug },
  52. { 0, 0, 0 } // Null entry for dictionary end
  53. };
  54. // ----- Functions -----
  55. inline void Macro_bufferAdd( uint8_t byte )
  56. {
  57. // Make sure we haven't overflowed the key buffer
  58. // Default function for adding keys to the KeyIndex_Buffer, does a DefaultMap_Lookup
  59. if ( KeyIndex_BufferUsed < KEYBOARD_BUFFER )
  60. {
  61. KeyIndex_Buffer[KeyIndex_BufferUsed++] = DefaultMap_Lookup[byte];
  62. }
  63. }
  64. inline void Macro_finishWithUSBBuffer( uint8_t sentKeys )
  65. {
  66. }
  67. inline void Macro_process()
  68. {
  69. // Only do one round of macro processing between Output Module timer sends
  70. if ( USBKeys_Sent != 0 )
  71. return;
  72. // Loop through input buffer
  73. for ( uint8_t index = 0; index < KeyIndex_BufferUsed; index++ )
  74. {
  75. // Get the keycode from the buffer
  76. uint8_t key = KeyIndex_Buffer[index];
  77. // Set the modifier bit if this key is a modifier
  78. if ( key & KEY_LCTRL ) // AND with 0xE0
  79. {
  80. USBKeys_Modifiers |= 1 << (key ^ KEY_LCTRL); // Left shift 1 by key XOR 0xE0
  81. // Modifier processed, move on to the next key
  82. continue;
  83. }
  84. // Too many keys
  85. if ( USBKeys_Sent >= USBKeys_MaxSize )
  86. {
  87. info_print("USB Key limit reached");
  88. errorLED( 1 );
  89. break;
  90. }
  91. // Allow ignoring keys with 0's
  92. if ( key != 0 )
  93. {
  94. USBKeys_Array[USBKeys_Sent++] = key;
  95. }
  96. else
  97. {
  98. // Key was not mapped
  99. // TODO Add dead key map
  100. erro_dPrint( "Key not mapped... - " );
  101. printHex( key );
  102. errorLED( 1 );
  103. }
  104. }
  105. // Signal buffer that we've used it
  106. Scan_finishedWithBuffer( KeyIndex_BufferUsed );
  107. }
  108. inline void Macro_setup()
  109. {
  110. // Register Macro CLI dictionary
  111. CLI_registerDictionary( macroCLIDict, macroCLIDictName );
  112. }
  113. // ----- CLI Command Functions -----
  114. void cliFunc_capList( char* args )
  115. {
  116. // TODO
  117. }
  118. void cliFunc_capSelect( char* args )
  119. {
  120. // TODO
  121. }
  122. void cliFunc_lookComb( char* args )
  123. {
  124. // TODO
  125. }
  126. void cliFunc_lookDefault( char* args )
  127. {
  128. // TODO
  129. }
  130. void cliFunc_lookPartial( char* args )
  131. {
  132. // TODO
  133. }
  134. void cliFunc_macroDebug( char* args )
  135. {
  136. // TODO
  137. }