]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Macro/PartialMap/macro.c
Added layerList and layerState functions
[kiibohd-controller.git] / Macro / PartialMap / macro.c
1 /* Copyright (C) 2014 by Jacob Alexander
2  *
3  * This file is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This file is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 // ----- Includes -----
18
19 // Compiler Includes
20 #include <Lib/MacroLib.h>
21
22 // Project Includes
23 #include <cli.h>
24 #include <led.h>
25 #include <print.h>
26 #include <scan_loop.h>
27 #include <output_com.h>
28
29 // Keymaps
30 #include "usb_hid.h"
31 #include <defaultMap.h>
32 #include "generatedKeymap.h" // TODO Use actual generated version
33
34 // Local Includes
35 #include "macro.h"
36
37
38
39 // ----- Function Declarations -----
40
41 void cliFunc_capList   ( char* args );
42 void cliFunc_capSelect ( char* args );
43 void cliFunc_keyPress  ( char* args );
44 void cliFunc_keyRelease( char* args );
45 void cliFunc_layerList ( char* args );
46 void cliFunc_layerState( char* args );
47 void cliFunc_macroDebug( char* args );
48 void cliFunc_macroList ( char* args );
49 void cliFunc_macroProc ( char* args );
50 void cliFunc_macroShow ( char* args );
51 void cliFunc_macroStep ( char* args );
52
53
54
55 // ----- Variables -----
56
57 // Macro Module command dictionary
58 char*       macroCLIDictName = "Macro Module Commands";
59 CLIDictItem macroCLIDict[] = {
60         { "capList",     "Prints an indexed list of all non USB keycode capabilities.", cliFunc_capList },
61         { "capSelect",   "Triggers the specified capabilities. First two args are state and stateType." NL "\t\t\033[35mK11\033[0m Keyboard Capability 0x0B", cliFunc_capSelect },
62         { "keyPress",    "Send key-presses to the macro module. Held until released. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyPress },
63         { "keyRelease",  "Release a key-press from the macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyRelease },
64         { "layerList",   "List available layers.", cliFunc_layerList },
65         { "layerState",  "Modify specified indexed layer state <layer> <state byte>." NL "\t\t\033[35mL2\033[0m Indexed Layer 0x02" NL "\t\t0 Off, 1 Shift, 2 Latch, 4 Lock States", cliFunc_layerState },
66         { "macroDebug",  "Disables/Enables sending USB keycodes to the Output Module and prints U/K codes.", cliFunc_macroDebug },
67         { "macroList",   "List the defined trigger and result macros.", cliFunc_macroList },
68         { "macroProc",   "Pause/Resume macro processing.", cliFunc_macroProc },
69         { "macroShow",   "Show the macro corresponding to the given index." NL "\t\t\033[35mT16\033[0m Indexed Trigger Macro 0x10, \033[35mR12\033[0m Indexed Result Macro 0x0C", cliFunc_macroShow },
70         { "macroStep",   "Do N macro processing steps. Defaults to 1.", cliFunc_macroStep },
71         { 0, 0, 0 } // Null entry for dictionary end
72 };
73
74
75 // Macro debug flag - If set, clears the USB Buffers after signalling processing completion
76 uint8_t macroDebugMode = 0;
77
78 // Macro pause flag - If set, the macro module pauses processing, unless unset, or the step counter is non-zero
79 uint8_t macroPauseMode = 0;
80
81 // Macro step counter - If non-zero, the step counter counts down every time the macro module does one processing loop
82 unsigned int macroStepCounter = 0;
83
84
85 // Key Trigger List Buffer
86 //  * Item 1: scan code
87 //  * Item 2: state
88 //    ...
89 uint8_t macroTriggerListBuffer[MaxScanCode * 2] = { 0 }; // Each key has a state to be cached
90 uint8_t macroTriggerListBufferSize = 0;
91
92 // TODO, figure out a good way to scale this array size without wasting too much memory, but not rejecting macros
93 //       Possibly could be calculated by the KLL compiler
94 // XXX It may be possible to calculate the worst case using the KLL compiler
95 TriggerMacro *triggerMacroPendingList[TriggerMacroNum];
96
97
98
99 // ----- Functions -----
100
101 // Looks up the trigger list for the given scan code (from the active layer)
102 unsigned int *Macro_layerLookup( uint8_t scanCode )
103 {
104         // TODO - No layer fallthrough lookup
105         return default_scanMap[ scanCode ];
106 }
107
108
109 // Update the scancode key state
110 // States:
111 //   * 0x00 - Reserved
112 //   * 0x01 - Pressed
113 //   * 0x02 - Held
114 //   * 0x03 - Released
115 //   * 0x04 - Unpressed (this is currently ignored)
116 inline void Macro_keyState( uint8_t scanCode, uint8_t state )
117 {
118         // Only add to macro trigger list if one of three states
119         switch ( state )
120         {
121         case 0x01: // Pressed
122         case 0x02: // Held
123         case 0x03: // Released
124                 macroTriggerListBuffer[ macroTriggerListBufferSize++ ] = scanCode;
125                 macroTriggerListBuffer[ macroTriggerListBufferSize++ ] = state;
126                 break;
127         }
128 }
129
130
131 // Update the scancode analog state
132 // States:
133 //   * 0x00      - Reserved
134 //   * 0x01      - Released
135 //   * 0x02-0xFF - Analog value (low to high)
136 inline void Macro_analogState( uint8_t scanCode, uint8_t state )
137 {
138         // TODO
139 }
140
141
142 // Update led state
143 // States:
144 //   * 0x00 - Reserved
145 //   * 0x01 - On
146 //   * 0x02 - Off
147 inline void Macro_ledState( uint8_t ledCode, uint8_t state )
148 {
149         // TODO
150 }
151
152
153 // Evaluate/Update the TriggerMacro
154 void Macro_evalTriggerMacro( TriggerMacro *triggerMacro )
155 {
156         // Which combo in the sequence is being evaluated
157         unsigned int comboPos = triggerMacro->pos;
158
159         // If combo length is more than 1, cancel trigger macro if an incorrect key is found
160         uint8_t comboLength = triggerMacro->guide[ comboPos ];
161
162         // Iterate over list of keys currently pressed
163         for ( uint8_t keyPressed = 0; keyPressed < macroTriggerListBufferSize; keyPressed += 2 )
164         {
165                 // Compare with keys in combo
166                 for ( unsigned int comboKey = 0; comboKey < comboLength; comboKey++ )
167                 {
168                         // Lookup key in combo
169                         uint8_t guideKey = triggerMacro->guide[ comboPos + comboKey + 2 ]; // TODO Only Press/Hold/Release atm
170
171                         // Sequence Case
172                         if ( comboLength == 1 )
173                         {
174                                 // If key matches and only 1 key pressed, increment the TriggerMacro combo position
175                                 if ( guideKey == macroTriggerListBuffer[ keyPressed ] && macroTriggerListBufferSize == 1 )
176                                 {
177                                         triggerMacro->pos += comboLength * 2 + 1;
178                                         // TODO check if TriggerMacro is finished, register ResultMacro
179                                         return;
180                                 }
181
182                                 // If key does not match or more than 1 key pressed, reset the TriggerMacro combo position
183                                 triggerMacro->pos = 0;
184                                 return;
185                         }
186                         // Combo Case
187                         else
188                         {
189                                 // TODO
190                         }
191                 }
192         }
193 }
194
195
196
197
198 /*
199 inline void Macro_bufferAdd( uint8_t byte )
200 {
201         // Make sure we haven't overflowed the key buffer
202         // Default function for adding keys to the KeyIndex_Buffer, does a DefaultMap_Lookup
203         if ( KeyIndex_BufferUsed < KEYBOARD_BUFFER )
204         {
205                 uint8_t key = DefaultMap_Lookup[byte];
206                 for ( uint8_t c = 0; c < KeyIndex_BufferUsed; c++ )
207                 {
208                         // Key already in the buffer
209                         if ( KeyIndex_Buffer[c] == key )
210                                 return;
211                 }
212
213                 // Add to the buffer
214                 KeyIndex_Buffer[KeyIndex_BufferUsed++] = key;
215         }
216 }
217
218 inline void Macro_bufferRemove( uint8_t byte )
219 {
220         uint8_t key = DefaultMap_Lookup[byte];
221
222         // Check for the released key, and shift the other keys lower on the buffer
223         for ( uint8_t c = 0; c < KeyIndex_BufferUsed; c++ )
224         {
225                 // Key to release found
226                 if ( KeyIndex_Buffer[c] == key )
227                 {
228                         // Shift keys from c position
229                         for ( uint8_t k = c; k < KeyIndex_BufferUsed - 1; k++ )
230                                 KeyIndex_Buffer[k] = KeyIndex_Buffer[k + 1];
231
232                         // Decrement Buffer
233                         KeyIndex_BufferUsed--;
234
235                         return;
236                 }
237         }
238
239         // Error case (no key to release)
240         erro_msg("Could not find key to release: ");
241         printHex( key );
242 }
243 */
244
245 inline void Macro_finishWithUSBBuffer( uint8_t sentKeys )
246 {
247 }
248
249 inline void Macro_process()
250 {
251         // Only do one round of macro processing between Output Module timer sends
252         if ( USBKeys_Sent != 0 )
253                 return;
254
255         // If the pause flag is set, only process if the step counter is non-zero
256         if ( macroPauseMode && macroStepCounter == 0 )
257         {
258                 return;
259         }
260         // Proceed, decrementing the step counter
261         else
262         {
263                 macroStepCounter--;
264         }
265
266         // Loop through macro trigger buffer
267         for ( uint8_t index = 0; index < macroTriggerListBufferSize; index += 2 )
268         {
269                 // Get scanCode, first item of macroTriggerListBuffer pairs
270                 uint8_t scanCode = macroTriggerListBuffer[ index ];
271
272                 // Lookup trigger list for this key
273                 unsigned int *triggerList = Macro_layerLookup( scanCode );
274
275                 // The first element is the length of the trigger list
276                 unsigned int triggerListSize = triggerList[0];
277
278                 // Loop through the trigger list
279                 for ( unsigned int trigger = 0; trigger < triggerListSize; trigger++ )
280                 {
281                         // Lookup TriggerMacro
282                         TriggerMacro *triggerMacro = (TriggerMacro*)triggerList[ trigger + 1 ];
283
284                         // Get triggered state of scan code, second item of macroTriggerListBuffer pairs
285                         uint8_t state = macroTriggerListBuffer[ index + 1 ];
286
287                         // Evaluate Macro
288                         Macro_evalTriggerMacro( triggerMacro );
289                 }
290         }
291
292
293
294
295
296         /* TODO
297         // Loop through input buffer
298         for ( uint8_t index = 0; index < KeyIndex_BufferUsed && !macroDebugMode; index++ )
299         {
300                 //print(" KEYS: ");
301                 //printInt8( KeyIndex_BufferUsed );
302                 // Get the keycode from the buffer
303                 uint8_t key = KeyIndex_Buffer[index];
304
305                 // Set the modifier bit if this key is a modifier
306                 if ( (key & KEY_LCTRL) == KEY_LCTRL ) // AND with 0xE0
307                 {
308                         USBKeys_Modifiers |= 1 << (key ^ KEY_LCTRL); // Left shift 1 by key XOR 0xE0
309
310                         // Modifier processed, move on to the next key
311                         continue;
312                 }
313
314                 // Too many keys
315                 if ( USBKeys_Sent >= USBKeys_MaxSize )
316                 {
317                         warn_msg("USB Key limit reached");
318                         errorLED( 1 );
319                         break;
320                 }
321
322                 // Allow ignoring keys with 0's
323                 if ( key != 0 )
324                 {
325                         USBKeys_Array[USBKeys_Sent++] = key;
326                 }
327                 else
328                 {
329                         // Key was not mapped
330                         erro_msg( "Key not mapped... - " );
331                         printHex( key );
332                         errorLED( 1 );
333                 }
334         }
335         */
336
337         // Signal buffer that we've used it
338         Scan_finishedWithBuffer( KeyIndex_BufferUsed );
339
340         // If Macro debug mode is set, clear the USB Buffer
341         if ( macroDebugMode )
342         {
343                 USBKeys_Modifiers = 0;
344                 USBKeys_Sent = 0;
345         }
346 }
347
348 inline void Macro_setup()
349 {
350         // Register Macro CLI dictionary
351         CLI_registerDictionary( macroCLIDict, macroCLIDictName );
352
353         // Disable Macro debug mode
354         macroDebugMode = 0;
355
356         // Disable Macro pause flag
357         macroPauseMode = 0;
358
359         // Set Macro step counter to zero
360         macroStepCounter = 0;
361
362         // Make sure macro trigger buffer is empty
363         macroTriggerListBufferSize = 0;
364 }
365
366
367 // ----- CLI Command Functions -----
368
369 void cliFunc_capList( char* args )
370 {
371         print( NL );
372         info_msg("Capabilities List");
373
374         // Iterate through all of the capabilities and display them
375         for ( unsigned int cap = 0; cap < CapabilitiesNum; cap++ )
376         {
377                 print( NL "\t" );
378                 printHex( cap );
379                 print(" - ");
380
381                 // Display/Lookup Capability Name (utilize debug mode of capability)
382                 void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func);
383                 capability( 0xFF, 0xFF, 0 );
384         }
385 }
386
387 void cliFunc_capSelect( char* args )
388 {
389         // Parse code from argument
390         char* curArgs;
391         char* arg1Ptr;
392         char* arg2Ptr = args;
393
394         // Total number of args to scan (must do a lookup if a keyboard capability is selected)
395         unsigned int totalArgs = 2; // Always at least two args
396         unsigned int cap = 0;
397
398         // Arguments used for keyboard capability function
399         unsigned int argSetCount = 0;
400         uint8_t *argSet = (uint8_t*)args;
401
402         // Process all args
403         for ( unsigned int c = 0; argSetCount < totalArgs; c++ )
404         {
405                 curArgs = arg2Ptr;
406                 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
407
408                 // Stop processing args if no more are found
409                 // Extra arguments are ignored
410                 if ( *arg1Ptr == '\0' )
411                         break;
412
413                 // For the first argument, choose the capability
414                 if ( c == 0 ) switch ( arg1Ptr[0] )
415                 {
416                 // Keyboard Capability
417                 case 'K':
418                         // Determine capability index
419                         cap = decToInt( &arg1Ptr[1] );
420
421                         // Lookup the number of args
422                         totalArgs += CapabilitiesList[ cap ].argCount;
423                         continue;
424                 }
425
426                 // Because allocating memory isn't doable, and the argument count is arbitrary
427                 // The argument pointer is repurposed as the argument list (much smaller anyways)
428                 argSet[ argSetCount++ ] = (uint8_t)decToInt( arg1Ptr );
429
430                 // Once all the arguments are prepared, call the keyboard capability function
431                 if ( argSetCount == totalArgs )
432                 {
433                         // Indicate that the capability was called
434                         print( NL );
435                         info_msg("K");
436                         printInt8( cap );
437                         print(" - ");
438                         printHex( argSet[0] );
439                         print(" - ");
440                         printHex( argSet[1] );
441                         print(" - ");
442                         printHex( argSet[2] );
443                         print( "..." NL );
444
445                         void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func);
446                         capability( argSet[0], argSet[1], &argSet[2] );
447                 }
448         }
449 }
450
451 void cliFunc_keyPress( char* args )
452 {
453         // Parse codes from arguments
454         char* curArgs;
455         char* arg1Ptr;
456         char* arg2Ptr = args;
457
458         // Process all args
459         for ( ;; )
460         {
461                 curArgs = arg2Ptr;
462                 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
463
464                 // Stop processing args if no more are found
465                 if ( *arg1Ptr == '\0' )
466                         break;
467
468                 // Ignore non-Scancode numbers
469                 switch ( arg1Ptr[0] )
470                 {
471                 // Scancode
472                 case 'S':
473                         Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x01 ); // Press scancode
474                         break;
475                 }
476         }
477 }
478
479 void cliFunc_keyRelease( char* args )
480 {
481         // Parse codes from arguments
482         char* curArgs;
483         char* arg1Ptr;
484         char* arg2Ptr = args;
485
486         // Process all args
487         for ( ;; )
488         {
489                 curArgs = arg2Ptr;
490                 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
491
492                 // Stop processing args if no more are found
493                 if ( *arg1Ptr == '\0' )
494                         break;
495
496                 // Ignore non-Scancode numbers
497                 switch ( arg1Ptr[0] )
498                 {
499                 // Scancode
500                 case 'S':
501                         Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x03 ); // Release scancode
502                         break;
503                 }
504         }
505 }
506
507 void cliFunc_layerList( char* args )
508 {
509         print( NL );
510         info_msg("Layer List");
511
512         // Iterate through all of the layers and display them
513         for ( unsigned int layer = 0; layer < LayerNum; layer++ )
514         {
515                 print( NL "\t" );
516                 printHex( layer );
517                 print(" - ");
518
519                 // Display layer name
520                 dPrint( LayerIndex[ layer ].name );
521
522                 // Default map
523                 if ( layer == 0 )
524                         print(" \033[1m(default)\033[0m");
525
526                 // Layer State
527                 print( NL "\t\t Layer State: " );
528                 printHex( LayerIndex[ layer ].state );
529
530                 // Max Index
531                 print(" Max Index: ");
532                 printHex( LayerIndex[ layer ].max );
533         }
534 }
535
536 void cliFunc_layerState( char* args )
537 {
538         // Parse codes from arguments
539         char* curArgs;
540         char* arg1Ptr;
541         char* arg2Ptr = args;
542
543         uint8_t arg1 = 0;
544         uint8_t arg2 = 0;
545
546         // Process first two args
547         for ( uint8_t c = 0; c < 2; c++ )
548         {
549                 curArgs = arg2Ptr;
550                 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
551
552                 // Stop processing args if no more are found
553                 if ( *arg1Ptr == '\0' )
554                         break;
555
556                 switch ( c )
557                 {
558                 // First argument (e.g. L1)
559                 case 0:
560                         if ( arg1Ptr[0] != 'L' )
561                                 return;
562
563                         arg1 = (uint8_t)decToInt( &arg1Ptr[1] );
564                         break;
565                 // Second argument (e.g. 4)
566                 case 1:
567                         arg2 = (uint8_t)decToInt( arg1Ptr );
568
569                         // Display operation (to indicate that it worked)
570                         print( NL );
571                         info_msg("Setting Layer L");
572                         printInt8( arg1 );
573                         print(" to - ");
574                         printHex( arg2 );
575
576                         // Set the layer state
577                         LayerIndex[ arg1 ].state = arg2;
578                         break;
579                 }
580         }
581 }
582
583 void cliFunc_macroDebug( char* args )
584 {
585         // Toggle macro debug mode
586         macroDebugMode = macroDebugMode ? 0 : 1;
587
588         print( NL );
589         info_msg("Macro Debug Mode: ");
590         printInt8( macroDebugMode );
591 }
592
593 void cliFunc_macroList( char* args )
594 {
595         // Show available trigger macro indices
596         print( NL );
597         info_msg("Trigger Macros Range: T0 -> T");
598         printInt16( (uint16_t)TriggerMacroNum - 1 ); // Hopefully large enough :P (can't assume 32-bit)
599
600         // Show available result macro indices
601         print( NL );
602         info_msg("Result  Macros Range: R0 -> R");
603         printInt16( (uint16_t)ResultMacroNum - 1 ); // Hopefully large enough :P (can't assume 32-bit)
604
605         // Show Trigger to Result Macro Links
606         print( NL );
607         info_msg("Trigger : Result Macro Pairs");
608         for ( unsigned int macro = 0; macro < TriggerMacroNum; macro++ )
609         {
610                 print( NL );
611                 print("\tT");
612                 printInt16( (uint16_t)macro ); // Hopefully large enough :P (can't assume 32-bit)
613                 print(" : R");
614                 printInt16( (uint16_t)TriggerMacroList[ macro ].result ); // Hopefully large enough :P (can't assume 32-bit)
615         }
616 }
617
618 void cliFunc_macroProc( char* args )
619 {
620         // Toggle macro pause mode
621         macroPauseMode = macroPauseMode ? 0 : 1;
622
623         print( NL );
624         info_msg("Macro Processing Mode: ");
625         printInt8( macroPauseMode );
626 }
627
628 void macroDebugShowTrigger( unsigned int index )
629 {
630         // Only proceed if the macro exists
631         if ( index >= TriggerMacroNum )
632                 return;
633
634         // Trigger Macro Show
635         TriggerMacro *macro = &TriggerMacroList[ index ];
636
637         print( NL );
638         info_msg("Trigger Macro Index: ");
639         printInt16( (uint16_t)index ); // Hopefully large enough :P (can't assume 32-bit)
640         print( NL );
641
642         // Read the comboLength for combo in the sequence (sequence of combos)
643         unsigned int pos = 0;
644         uint8_t comboLength = macro->guide[ pos ];
645
646         // Iterate through and interpret the guide
647         while ( comboLength != 0 )
648         {
649                 // Initial position of the combo
650                 unsigned int comboPos = ++pos;
651
652                 // Iterate through the combo
653                 while ( pos < comboLength * TriggerGuideSize + comboPos )
654                 {
655                         // Assign TriggerGuide element (key type, state and scancode)
656                         TriggerGuide *guide = (TriggerGuide*)(&macro->guide[ pos ]);
657
658                         // Display guide information about trigger key
659                         printHex( guide->scancode );
660                         print("|");
661                         printHex( guide->type );
662                         print("|");
663                         printHex( guide->state );
664
665                         // Increment position
666                         pos += TriggerGuideSize;
667
668                         // Only show combo separator if there are combos left in the sequence element
669                         if ( pos < comboLength * TriggerGuideSize + comboPos )
670                                 print("+");
671                 }
672
673                 // Read the next comboLength
674                 comboLength = macro->guide[ pos ];
675
676                 // Only show sequence separator if there is another combo to process
677                 if ( comboLength != 0 )
678                         print(";");
679         }
680
681         // Display current position
682         print( NL "Position: " );
683         printInt16( (uint16_t)macro->pos ); // Hopefully large enough :P (can't assume 32-bit)
684
685         // Display result macro index
686         print( NL "Result Macro Index: " );
687         printInt16( (uint16_t)macro->result ); // Hopefully large enough :P (can't assume 32-bit)
688 }
689
690 void macroDebugShowResult( unsigned int index )
691 {
692         // Only proceed if the macro exists
693         if ( index >= ResultMacroNum )
694                 return;
695
696         // Trigger Macro Show
697         ResultMacro *macro = &ResultMacroList[ index ];
698
699         print( NL );
700         info_msg("Result Macro Index: ");
701         printInt16( (uint16_t)index ); // Hopefully large enough :P (can't assume 32-bit)
702         print( NL );
703
704         // Read the comboLength for combo in the sequence (sequence of combos)
705         unsigned int pos = 0;
706         uint8_t comboLength = macro->guide[ pos++ ];
707
708         // Iterate through and interpret the guide
709         while ( comboLength != 0 )
710         {
711                 // Function Counter, used to keep track of the combos processed
712                 unsigned int funcCount = 0;
713
714                 // Iterate through the combo
715                 while ( funcCount < comboLength )
716                 {
717                         // Assign TriggerGuide element (key type, state and scancode)
718                         ResultGuide *guide = (ResultGuide*)(&macro->guide[ pos ]);
719
720                         // Display Function Index
721                         printHex( guide->index );
722                         print("|");
723
724                         // Display Function Ptr Address
725                         printHex( (unsigned int)CapabilitiesList[ guide->index ].func );
726                         print("|");
727
728                         // Display/Lookup Capability Name (utilize debug mode of capability)
729                         void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func);
730                         capability( 0xFF, 0xFF, 0 );
731
732                         // Display Argument(s)
733                         print("(");
734                         for ( unsigned int arg = 0; arg < CapabilitiesList[ guide->index ].argCount; arg++ )
735                         {
736                                 // Arguments are only 8 bit values
737                                 printHex( (&guide->args)[ arg ] );
738
739                                 // Only show arg separator if there are args left
740                                 if ( arg + 1 < CapabilitiesList[ guide->index ].argCount )
741                                         print(",");
742                         }
743                         print(")");
744
745                         // Increment position
746                         pos += ResultGuideSize( guide );
747
748                         // Increment function count
749                         funcCount++;
750
751                         // Only show combo separator if there are combos left in the sequence element
752                         if ( funcCount < comboLength )
753                                 print("+");
754                 }
755
756                 // Read the next comboLength
757                 comboLength = macro->guide[ pos++ ];
758
759                 // Only show sequence separator if there is another combo to process
760                 if ( comboLength != 0 )
761                         print(";");
762         }
763
764         // Display current position
765         print( NL "Position: " );
766         printInt16( (uint16_t)macro->pos ); // Hopefully large enough :P (can't assume 32-bit)
767
768         // Display final trigger state/type
769         print( NL "Final Trigger State (State/Type): " );
770         printHex( macro->state );
771         print("/");
772         printHex( macro->stateType );
773 }
774
775 void cliFunc_macroShow( char* args )
776 {
777         // Parse codes from arguments
778         char* curArgs;
779         char* arg1Ptr;
780         char* arg2Ptr = args;
781
782         // Process all args
783         for ( ;; )
784         {
785                 curArgs = arg2Ptr;
786                 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
787
788                 // Stop processing args if no more are found
789                 if ( *arg1Ptr == '\0' )
790                         break;
791
792                 // Ignore invalid codes
793                 switch ( arg1Ptr[0] )
794                 {
795                 // Indexed Trigger Macro
796                 case 'T':
797                         macroDebugShowTrigger( decToInt( &arg1Ptr[1] ) );
798                         break;
799                 // Indexed Result Macro
800                 case 'R':
801                         macroDebugShowResult( decToInt( &arg1Ptr[1] ) );
802                         break;
803                 }
804         }
805 }
806
807 void cliFunc_macroStep( char* args )
808 {
809         // Parse number from argument
810         //  NOTE: Only first argument is used
811         char* arg1Ptr;
812         char* arg2Ptr;
813         CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
814
815         // Set the macro step counter, negative int's are cast to uint
816         macroStepCounter = (unsigned int)decToInt( arg1Ptr );
817 }
818