1 /* Copyright (C) 2014 by Jacob Alexander
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
22 // ----- Includes -----
25 #include <Lib/MacroLib.h>
31 #include <scan_loop.h>
32 #include <output_com.h>
36 #include <defaultMap.h>
43 // ----- Function Declarations -----
45 void cliFunc_capList ( char* args );
46 void cliFunc_capSelect ( char* args );
47 void cliFunc_lookComb ( char* args );
48 void cliFunc_lookDefault( char* args );
49 void cliFunc_lookPartial( char* args );
50 void cliFunc_macroDebug ( char* args );
54 // ----- Variables -----
56 // Output Module command dictionary
57 char* macroCLIDictName = "Macro Module Commands";
58 CLIDictItem macroCLIDict[] = {
59 { "capList", "Prints an indexed list of all non USB keycode capabilities.", cliFunc_capList },
60 { "capSelect", "Triggers the specified capability. U10 is USB Code 0x0A (G). K11 is keyboard capability 0x0B.", cliFunc_capSelect },
61 { "lookComb", "Do a lookup on the Combined map. S10 specifies Scancode 0x0A. U10 specified USB keycode 0x0A.", cliFunc_lookComb },
62 { "lookDefault", "Do a lookup on the Default map. S10 specifies Scancode 0x0A. USB keycodes are not valid.", cliFunc_lookDefault },
63 { "lookPartial", "Do a lookup on the layered partial map. S10 specifies Scancode 0x0A. U10 specifies USB keycode 0x0A.", cliFunc_lookPartial },
64 { "macroDebug", "Disables/Enables sending USB keycodes to the Output Module and prints U/K codes.", cliFunc_macroDebug },
65 { 0, 0, 0 } // Null entry for dictionary end
70 // ----- Functions -----
72 inline void Macro_bufferAdd( uint8_t byte )
74 // Make sure we haven't overflowed the key buffer
75 // Default function for adding keys to the KeyIndex_Buffer, does a DefaultMap_Lookup
76 if ( KeyIndex_BufferUsed < KEYBOARD_BUFFER )
78 KeyIndex_Buffer[KeyIndex_BufferUsed++] = DefaultMap_Lookup[byte];
82 inline void Macro_finishWithUSBBuffer( uint8_t sentKeys )
86 inline void Macro_process()
88 // Only do one round of macro processing between Output Module timer sends
89 if ( USBKeys_Sent != 0 )
92 // Loop through input buffer
93 for ( uint8_t index = 0; index < KeyIndex_BufferUsed; index++ )
95 // Get the keycode from the buffer
96 uint8_t key = KeyIndex_Buffer[index];
98 // Set the modifier bit if this key is a modifier
99 if ( key & KEY_LCTRL ) // AND with 0xE0
101 USBKeys_Modifiers |= 1 << (key ^ KEY_LCTRL); // Left shift 1 by key XOR 0xE0
103 // Modifier processed, move on to the next key
108 if ( USBKeys_Sent >= USBKeys_MaxSize )
110 info_print("USB Key limit reached");
115 // Allow ignoring keys with 0's
118 USBKeys_Array[USBKeys_Sent++] = key;
122 // Key was not mapped
123 // TODO Add dead key map
124 erro_dPrint( "Key not mapped... - " );
130 // Signal buffer that we've used it
131 Scan_finishedWithBuffer( KeyIndex_BufferUsed );
134 inline void Macro_setup()
136 // Register Macro CLI dictionary
137 CLI_registerDictionary( macroCLIDict, macroCLIDictName );
141 // ----- CLI Command Functions -----
143 void cliFunc_capList( char* args )
148 void cliFunc_capSelect( char* args )
153 void cliFunc_lookComb( char* args )
158 void cliFunc_lookDefault( char* args )
163 void cliFunc_lookPartial( char* args )
168 void cliFunc_macroDebug( char* args )