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/ScanLib.h>
31 #include <matrix_scan.h>
35 #include "scan_loop.h"
39 // ----- Function Declarations -----
42 void cliFunc_echo( char* args );
46 // ----- Variables -----
48 // Scan Module command dictionary
49 CLIDict_Entry( echo, "Example command, echos the arguments." );
51 CLIDict_Def( scanCLIDict, "Scan Module Commands" ) = {
53 { 0, 0, 0 } // Null entry for dictionary end
56 // Number of scans since the last USB send
57 uint16_t Scan_scanCount = 0;
61 // ----- Functions -----
64 inline void Scan_setup()
66 // Register Scan CLI dictionary
67 CLI_registerDictionary( scanCLIDict, scanCLIDictName );
69 // Setup GPIO pins for matrix scanning
77 // Main Detection Loop
78 inline uint8_t Scan_loop()
80 Matrix_scan( Scan_scanCount++ );
86 // Signal from Macro Module that all keys have been processed (that it knows about)
87 inline void Scan_finishedWithMacro( uint8_t sentKeys )
92 // Signal from Output Module that all keys have been processed (that it knows about)
93 inline void Scan_finishedWithOutput( uint8_t sentKeys )
95 // Reset scan loop indicator (resets each key debounce state)
96 // TODO should this occur after USB send or Macro processing?
102 // ----- Capabilities -----
104 // Custom capability examples
105 // Refer to kll.h in Macros/PartialMap for state and stateType information
106 void CustomAction_action1_capability( uint8_t state, uint8_t stateType, uint8_t *args )
108 // Display capability name
109 // XXX This is required for debug cli to give you a list of capabilities
110 if ( stateType == 0xFF && state == 0xFF )
112 print("CustomAction_action1_capability()");
116 // Prints Action1 info message to the debug cli
117 info_print("Action1");
120 uint8_t CustomAction_blockHold_storage = 0;
121 void CustomAction_blockHold_capability( uint8_t state, uint8_t stateType, uint8_t *args )
123 // Display capability name
124 if ( stateType == 0xFF && state == 0xFF )
126 print("CustomAction_blockHold_capability(usbCode)");
130 // Retrieve 8-bit argument
131 uint8_t key = args[0];
133 // We only care about normal keys
134 if ( stateType == 0x00 )
136 // Block given key if we're in the "Press" or "Hold" state
137 if ( ( state == 0x01 || state == 0x02 )
138 && CustomAction_blockHold_storage == 0 )
140 CustomAction_blockHold_storage = key;
141 info_msg("Blocking Key: ");
145 // Release if in the "Off" or "Release" state and we're blocking
146 else if ( ( state == 0x00 || state == 0x03 )
147 && key == CustomAction_blockHold_storage )
149 info_msg("Unblocking Key: ");
150 printHex( CustomAction_blockHold_storage );
152 CustomAction_blockHold_storage = 0;
157 void CustomAction_blockKey_capability( uint8_t state, uint8_t stateType, uint8_t *args )
159 // Display capability name
160 if ( stateType == 0xFF && state == 0xFF )
162 print("CustomAction_blockKey_capability(usbCode)");
166 // Retrieve 8-bit argument
167 uint8_t key = args[0];
169 // If key is not blocked, process
170 if ( key != CustomAction_blockHold_storage )
172 Output_usbCodeSend_capability( state, stateType, &key );
178 // ----- CLI Command Functions -----
180 // XXX Just an example command showing how to parse arguments (more complex than generally needed)
181 void cliFunc_echo( char* args )
185 char* arg2Ptr = args;
187 // Parse args until a \0 is found
190 print( NL ); // No \r\n by default after the command is entered
192 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
193 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
195 // Stop processing args if no more are found
196 if ( *arg1Ptr == '\0' )