]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Added capSelect function that can arbitrary run a keyboard capability
authorJacob Alexander <haata@kiibohd.com>
Fri, 25 Jul 2014 17:53:33 +0000 (10:53 -0700)
committerJacob Alexander <haata@kiibohd.com>
Fri, 25 Jul 2014 17:53:33 +0000 (10:53 -0700)
- Made changes to the capabities/macro data structure to specify the capability arg count in the capability list
- Remove the arg count from the result macro struct (as it is redundant)

Macro/PartialMap/generatedKeymap.h
Macro/PartialMap/macro.c

index 41f326319e386a7f3bb3dd62465453a35009c035..291668e7964f9c1e03509b231a0f7138378d5278 100644 (file)
@@ -37,7 +37,7 @@
 // Default Args (always sent): key state/analog of last key
 // Combo Length of 0 signifies end of sequence
 //
-// ResultMacro.guide     -> [<combo length>|<function pointer>|<arg count>|<arg1>|<argn>|<function pointer>|...|<combo length>|...|0]
+// ResultMacro.guide     -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
 // ResultMacro.pos       -> <current combo position>
 // ResultMacro.state     -> <last key state>
 // ResultMacro.stateType -> <last key state type>
@@ -50,10 +50,9 @@ typedef struct ResultMacro {
 } ResultMacro;
 
 // Guide, key element
-#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + guidePtr->argCount
+#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ guidePtr->index ].argCount
 typedef struct ResultGuide {
        uint8_t index;
-       uint8_t argCount;
        uint8_t args; // This is used as an array pointer (but for packing purposes, must be 8 bit)
 } ResultGuide;
 
@@ -99,7 +98,6 @@ typedef struct TriggerGuide {
 
 // ----- Macros -----
 
-#define debugPrint_cap( arg ) 0, 1, arg
 void debugPrint_capability( uint8_t state, uint8_t stateType, uint8_t *args )
 {
        // Display capability name
@@ -116,10 +114,9 @@ void debugPrint_capability( uint8_t state, uint8_t stateType, uint8_t *args )
        printHex( state );
        print(" )  arg ( ");
        printHex( args[0] );
-       print( " )" NL );
+       print(" )");
 }
 
-#define debugPrint2_cap( arg1, arg2 ) 1, 2, arg1, arg2
 void debugPrint2_capability( uint8_t state, uint8_t stateType, uint8_t *args )
 {
        // Display capability name
@@ -138,17 +135,23 @@ void debugPrint2_capability( uint8_t state, uint8_t stateType, uint8_t *args )
        printHex( args[0] );
        print(" )  arg2 ( ");
        printHex( args[1] );
-       print( " )" NL );
+       print(" )");
 }
 
+// Capability
+typedef struct Capability {
+       void *func;
+       uint8_t argCount;
+} Capability;
+
 // Total Number of Capabilities
-#define CapabilitiesNum sizeof( CapabilitiesList ) / 4
+#define CapabilitiesNum sizeof( void* ) / 4 + sizeof( uint8_t )
 
 // Indexed Capabilities Table
 // TODO Should be moved to the Scan Module
-void *CapabilitiesList[] = {
-       debugPrint_capability,
-       debugPrint2_capability,
+Capability CapabilitiesList[] = {
+       { debugPrint_capability, 1 },
+       { debugPrint2_capability, 2 },
 };
 
 
@@ -164,10 +167,10 @@ void *CapabilitiesList[] = {
 #define Guide_RM( index ) static uint8_t rm##index##_guide[]
 #define Define_RM( index ) { rm##index##_guide, 0, 0, 0 }
 
-Guide_RM( 0 ) = { 1, debugPrint_cap( 0xDA ), 0 };
-Guide_RM( 1 ) = { 1, debugPrint_cap( 0xBE ), 1, debugPrint_cap( 0xEF ), 0 };
-Guide_RM( 2 ) = { 2, debugPrint_cap( 0xFA ), debugPrint_cap( 0xAD ), 0 };
-Guide_RM( 3 ) = { 1, debugPrint2_cap( 0xCA, 0xFE ), 0 };
+Guide_RM( 0 ) = { 1, 0, 0xDA, 0 };
+Guide_RM( 1 ) = { 1, 0, 0xBE, 1, 0, 0xEF, 0 };
+Guide_RM( 2 ) = { 2, 0, 0xFA, 0, 0xAD, 0 };
+Guide_RM( 3 ) = { 1, 1, 0xCA, 0xFE, 0 };
 
 // Total number of result macros (rm's)
 // Used to create pending rm's table
index 3f033d4ffef6d3231036184f158c7f6ed3f8e3a1..a587b107abfdb12c52ee178a4a51ea2659acf049 100644 (file)
@@ -59,7 +59,7 @@ void cliFunc_macroStep ( char* args );
 char*       macroCLIDictName = "Macro Module Commands";
 CLIDictItem macroCLIDict[] = {
        { "capList",     "Prints an indexed list of all non USB keycode capabilities.", cliFunc_capList },
-       { "capSelect",   "Triggers the specified capability." NL "\t\t\033[35mU10\033[0m USB Code 0x0A, \033[35mK11\033[0m Keyboard Capability 0x0B", cliFunc_capSelect },
+       { "capSelect",   "Triggers the specified capabilities. First two args are state and stateType." NL "\t\t\033[35mK11\033[0m Keyboard Capability 0x0B", cliFunc_capSelect },
        { "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 },
        { "keyRelease",  "Release a key-press from the macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyRelease },
        { "layerLatch",  "Latch the specified indexed layer." NL "\t\t\033[35mL15\033[0m Indexed Layer 0x0F", cliFunc_layerLatch },
@@ -381,7 +381,7 @@ void cliFunc_capList( char* args )
                print(" - ");
 
                // Display/Lookup Capability Name (utilize debug mode of capability)
-               void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ]);
+               void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func);
                capability( 0xFF, 0xFF, 0 );
        }
 }
@@ -389,27 +389,64 @@ void cliFunc_capList( char* args )
 void cliFunc_capSelect( char* args )
 {
        // Parse code from argument
-       //  NOTE: Only first argument is used
+       char* curArgs;
        char* arg1Ptr;
-       char* arg2Ptr;
-       CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
+       char* arg2Ptr = args;
+
+       // Total number of args to scan (must do a lookup if a keyboard capability is selected)
+       unsigned int totalArgs = 2; // Always at least two args
+       unsigned int cap = 0;
 
-       // Depending on the first character, the lookup changes
-       switch ( arg1Ptr[0] )
+       // Arguments used for keyboard capability function
+       unsigned int argSetCount = 0;
+       uint8_t *argSet = (uint8_t*)args;
+
+       // Process all args
+       for ( unsigned int c = 0; argSetCount < totalArgs; c++ )
        {
-       // Keyboard Capability
-       case 'K':
-               // TODO
-               break;
+               curArgs = arg2Ptr;
+               CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
 
-       // USB Code
-       case 'U':
-               // Just add the key to the USB Buffer
-               if ( KeyIndex_BufferUsed < KEYBOARD_BUFFER )
+               // Stop processing args if no more are found
+               // Extra arguments are ignored
+               if ( *arg1Ptr == '\0' )
+                       break;
+
+               // For the first argument, choose the capability
+               if ( c == 0 ) switch ( arg1Ptr[0] )
                {
-                       KeyIndex_Buffer[KeyIndex_BufferUsed++] = decToInt( &arg1Ptr[1] );
+               // Keyboard Capability
+               case 'K':
+                       // Determine capability index
+                       cap = decToInt( &arg1Ptr[1] );
+
+                       // Lookup the number of args
+                       totalArgs += CapabilitiesList[ cap ].argCount;
+                       continue;
+               }
+
+               // Because allocating memory isn't doable, and the argument count is arbitrary
+               // The argument pointer is repurposed as the argument list (much smaller anyways)
+               argSet[ argSetCount++ ] = (uint8_t)decToInt( arg1Ptr );
+
+               // Once all the arguments are prepared, call the keyboard capability function
+               if ( argSetCount == totalArgs )
+               {
+                       // Indicate that the capability was called
+                       print( NL );
+                       info_msg("K");
+                       printInt8( cap );
+                       print(" - ");
+                       printHex( argSet[0] );
+                       print(" - ");
+                       printHex( argSet[1] );
+                       print(" - ");
+                       printHex( argSet[2] );
+                       print( "..." NL );
+
+                       void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func);
+                       capability( argSet[0], argSet[1], &argSet[2] );
                }
-               break;
        }
 }
 
@@ -626,22 +663,22 @@ void macroDebugShowResult( unsigned int index )
                        print("|");
 
                        // Display Function Ptr Address
-                       printHex( (unsigned int)CapabilitiesList[ guide->index ] );
+                       printHex( (unsigned int)CapabilitiesList[ guide->index ].func );
                        print("|");
 
                        // Display/Lookup Capability Name (utilize debug mode of capability)
-                       void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ]);
+                       void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func);
                        capability( 0xFF, 0xFF, 0 );
 
                        // Display Argument(s)
                        print("(");
-                       for ( unsigned int arg = 0; arg < guide->argCount; arg++ )
+                       for ( unsigned int arg = 0; arg < CapabilitiesList[ guide->index ].argCount; arg++ )
                        {
                                // Arguments are only 8 bit values
                                printHex( (&guide->args)[ arg ] );
 
                                // Only show arg separator if there are args left
-                               if ( arg + 1 < guide->argCount )
+                               if ( arg + 1 < CapabilitiesList[ guide->index ].argCount )
                                        print(",");
                        }
                        print(")");