]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Scan/DPH/scan_loop.c
Adding example CLI command to DPH module.
[kiibohd-controller.git] / Scan / DPH / scan_loop.c
index c8f928e76e964c1401f9d0e04c83a7182a878d7a..bf939a74389012a42d8675fa7bb3fc106bde72d5 100644 (file)
@@ -21,6 +21,7 @@
 #include <Lib/ScanLib.h>
 
 // Project Includes
+#include <cli.h>
 #include <led.h>
 #include <print.h>
 
 
 // ----- Macros -----
 
-// Make sure we haven't overflowed the buffer
-#define bufferAdd(byte) \
-               if ( KeyIndex_BufferUsed < KEYBOARD_BUFFER ) \
-                       KeyIndex_Buffer[KeyIndex_BufferUsed++] = byte
-
 // Select mux
 #define SET_FULL_MUX(X) ((ADMUX) = (((ADMUX) & ~(FULL_MUX_MASK)) | ((X) & (FULL_MUX_MASK))))
 
 
 
+// ----- Function Declarations -----
+
+void cliFunc_echo   ( char* args );
+
+
+
 // ----- Variables -----
 
 // Buffer used to inform the macro processing module which keys have been detected as pressed
@@ -131,6 +133,14 @@ volatile uint8_t KeyIndex_Buffer[KEYBOARD_BUFFER];
 volatile uint8_t KeyIndex_BufferUsed;
 
 
+// Scan Module command dictionary
+char*       scanCLIDictName = "DPH Module Commands";
+CLIDictItem scanCLIDict[] = {
+       { "echo",    "Example command, echos the arguments.", cliFunc_echo },
+       { 0, 0, 0 } // Null entry for dictionary end
+};
+
+
 // TODO dfj variables...needs cleaning up and commenting
 
 // Variables used to calculate the starting sense value (averaging)
@@ -179,15 +189,15 @@ uint8_t dump_count = 0;
 
 // ----- Function Declarations -----
 
-void dump( void );
+void dump();
 
 void recovery( uint8_t on );
 
 int sampleColumn( uint8_t column );
 
-void capsense_scan( void );
+void capsense_scan();
 
-void setup_ADC( void );
+void setup_ADC();
 
 void strobe_w( uint8_t strobe_num );
 
@@ -198,8 +208,11 @@ uint8_t testColumn( uint8_t strobe );
 // ----- Functions -----
 
 // Initial setup for cap sense controller
-inline void scan_setup()
+inline void Scan_setup()
 {
+       // Register Scan CLI dictionary
+       CLI_registerDictionary( scanCLIDict, scanCLIDictName );
+
        // TODO dfj code...needs cleanup + commenting...
        setup_ADC();
 
@@ -282,7 +295,7 @@ inline void scan_setup()
        // TODO
 #endif
 
-       // TODO all this code should probably be in scan_resetKeyboard
+       // TODO all this code should probably be in Scan_resetKeyboard
        for ( int i = 0; i < total_strobes; ++i)
        {
                cur_keymap[i] = 0;
@@ -299,17 +312,12 @@ inline void scan_setup()
        {
                sampleColumn( strobe_map[i] );
        }
-
-
-       // Reset the keyboard before scanning, we might be in a wierd state
-       // Also sets the KeyIndex_BufferUsed to 0
-       scan_resetKeyboard();
 }
 
 
 // Main Detection Loop
 // This is where the important stuff happens
-inline uint8_t scan_loop()
+inline uint8_t Scan_loop()
 {
        capsense_scan();
 
@@ -342,43 +350,15 @@ inline uint8_t scan_loop()
 
        // Return non-zero if macro and USB processing should be delayed
        // Macro processing will always run if returning 0
-       // USB processing only happens once the USB send timer expires, if it has not, scan_loop will be called
+       // USB processing only happens once the USB send timer expires, if it has not, Scan_loop will be called
        //  after the macro processing has been completed
        return 0;
 }
 
 
-// Reset Keyboard
-void scan_resetKeyboard( void )
-{
-       // Empty buffer, now that keyboard has been reset
-       KeyIndex_BufferUsed = 0;
-}
-
-
-// Send data to keyboard
-// NOTE: Only used for converters, since the scan module shouldn't handle sending data in a controller
-uint8_t scan_sendData( uint8_t dataPayload )
-{
-       return 0;
-}
-
-
-// Reset/Hold keyboard
-// NOTE: Only used for converters, not needed for full controllers
-void scan_lockKeyboard( void )
-{
-}
-
-// NOTE: Only used for converters, not needed for full controllers
-void scan_unlockKeyboard( void )
-{
-}
-
-
 // Signal KeyIndex_Buffer that it has been properly read
 // NOTE: Only really required for implementing "tricks" in converters for odd protocols
-void scan_finishedWithBuffer( uint8_t sentKeys )
+void Scan_finishedWithBuffer( uint8_t sentKeys )
 {
        // Convenient place to clear the KeyIndex_Buffer
        KeyIndex_BufferUsed = 0;
@@ -388,7 +368,7 @@ void scan_finishedWithBuffer( uint8_t sentKeys )
 
 // Signal KeyIndex_Buffer that it has been properly read and sent out by the USB module
 // NOTE: Only really required for implementing "tricks" in converters for odd protocols
-void scan_finishedWithUSBBuffer( uint8_t sentKeys )
+void Scan_finishedWithUSBBuffer( uint8_t sentKeys )
 {
        return;
 }
@@ -864,7 +844,7 @@ uint8_t testColumn( uint8_t strobe )
                                        // Only add the key to the buffer once
                                        // NOTE: Buffer can easily handle multiple adds, just more efficient
                                        //        and nicer debug messages :P
-                                       //bufferAdd( key );
+                                       //Macro_bufferAdd( key );
                                }
 
                                keys_debounce[key]++;
@@ -1010,3 +990,30 @@ void dump(void) {
        dump_count &= 0x0f;
 }
 
+
+// ----- CLI Command Functions -----
+
+// XXX Just an example command showing how to parse arguments (more complex than generally needed)
+void cliFunc_echo( char* args )
+{
+       char* curArgs;
+       char* arg1Ptr;
+       char* arg2Ptr = args;
+
+       // Parse args until a \0 is found
+       while ( 1 )
+       {
+               print( NL ); // No \r\n by default after the command is entered
+
+               curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
+               CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
+
+               // Stop processing args if no more are found
+               if ( *arg1Ptr == '\0' )
+                       break;
+
+               // Print out the arg
+               dPrint( arg1Ptr );
+       }
+}
+