+
+ // State Table Output Debug
+ if ( matrixDebugStateCounter > 0 )
+ {
+ // Decrement counter
+ matrixDebugStateCounter--;
+
+ // Output stats on number of scans being done per USB send
+ print( NL );
+ info_msg("Max scans: ");
+ printHex( matrixMaxScans );
+ print( NL );
+ info_msg("Previous scans: ");
+ printHex( matrixPrevScans );
+ print( NL );
+
+ // Output current scan number
+ info_msg("Scan Number: ");
+ printHex( scanNum );
+ print( NL );
+
+ // Display the state info for each key
+ print("<key>:<previous state><current state> <active count> <inactive count>");
+ for ( uint8_t key = 0; key < Matrix_maxKeys; key++ )
+ {
+ // Every 4 keys, put a newline
+ if ( key % 4 == 0 )
+ print( NL );
+
+ print("\033[1m0x");
+ printHex_op( key, 2 );
+ print("\033[0m");
+ print(":");
+ Matrix_keyPositionDebug( Matrix_scanArray[ key ].prevState );
+ Matrix_keyPositionDebug( Matrix_scanArray[ key ].curState );
+ print(" 0x");
+ printHex_op( Matrix_scanArray[ key ].activeCount, 4 );
+ print(" 0x");
+ printHex_op( Matrix_scanArray[ key ].inactiveCount, 4 );
+ print(" ");
+ }
+
+ print( NL );
+ }
+}
+
+
+// ----- CLI Command Functions -----
+
+void cliFunc_matrixDebug ( char* args )
+{
+ // Parse number from argument
+ // NOTE: Only first argument is used
+ char* arg1Ptr;
+ char* arg2Ptr;
+ CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
+
+ // Set the matrix debug flag depending on the argument
+ // If no argument, set to scan code only
+ // If set to T, set to state transition
+ switch ( arg1Ptr[0] )
+ {
+ // T as argument
+ case 'T':
+ case 't':
+ matrixDebugMode = matrixDebugMode != 2 ? 2 : 0;
+ break;
+
+ // No argument
+ case '\0':
+ matrixDebugMode = matrixDebugMode != 1 ? 1 : 0;
+ break;
+
+ // Invalid argument
+ default:
+ return;
+ }
+
+ print( NL );
+ info_msg("Matrix Debug Mode: ");
+ printInt8( matrixDebugMode );
+}
+
+void cliFunc_matrixState ( char* args )
+{
+ // Parse number from argument
+ // NOTE: Only first argument is used
+ char* arg1Ptr;
+ char* arg2Ptr;
+ CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
+
+ // Default to 1 if no argument is given
+ matrixDebugStateCounter = 1;
+
+ if ( arg1Ptr[0] != '\0' )
+ {
+ matrixDebugStateCounter = (uint16_t)numToInt( arg1Ptr );
+ }