]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Macro processing is now feature complete.
authorJacob Alexander <haata@kiibohd.com>
Wed, 6 Aug 2014 19:18:06 +0000 (12:18 -0700)
committerJacob Alexander <haata@kiibohd.com>
Wed, 6 Aug 2014 19:18:06 +0000 (12:18 -0700)
- Basic features only (there are still some extra options that can be added)
- Not tested
- ResultMacro processor is complete
- Layer enabling capability not yet complete
- USB Key output capability not yet complete

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

index afeddb0c38fbe4fd4003687de6def9b1c24c1bc9..c2cfb4e35bb81b28d1e51bdc9648de193a08ad5f 100644 (file)
@@ -51,7 +51,7 @@ typedef struct ResultMacro {
 } ResultMacro;
 
 // Guide, key element
-#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ guidePtr->index ].argCount
+#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
 typedef struct ResultGuide {
        uint8_t index;
        uint8_t args; // This is used as an array pointer (but for packing purposes, must be 8 bit)
index a1e6a34dd21e84130609d6e129db26a27f367a90..5c3798cdd55290666dcfef47db0500daf3987819 100644 (file)
@@ -71,6 +71,11 @@ typedef enum TriggerMacroEval {
        TriggerMacroEval_Remove,
 } TriggerMacroEval;
 
+typedef enum ResultMacroEval {
+       ResultMacroEval_DoNothing,
+       ResultMacroEval_Remove,
+} ResultMacroEval;
+
 
 
 // ----- Variables -----
@@ -242,7 +247,7 @@ inline uint8_t Macro_isLongResultMacro( ResultMacro *macro )
        // Check the second sequence combo length
        // If non-zero return 1 (long sequence)
        // 0 otherwise (short sequence)
-       return macro->guide[ macro->guide[0] * ResultGuideSize( ((ResultGuide*)macro->guide) ) ] > 0 ? 1 : 0;
+       return macro->guide[ macro->guide[0] * ResultGuideSize( (ResultGuide*)macro->guide ) ] > 0 ? 1 : 0;
 }
 
 
@@ -418,9 +423,51 @@ inline TriggerMacroEval Macro_evalTriggerMacro( unsigned int triggerMacroIndex )
 
 
 // Evaluate/Update ResultMacro
-void Macro_evalResultMacro( unsigned int resultMacroIndex )
+inline ResultMacroEval Macro_evalResultMacro( unsigned int resultMacroIndex )
 {
-       // TODO
+       // Lookup ResultMacro
+       ResultMacro *macro = &ResultMacroList[ resultMacroIndex ];
+
+       // Current Macro position
+       unsigned int pos = macro->pos;
+
+       // Length of combo being processed
+       uint8_t comboLength = macro->guide[ pos ];
+
+       // If no combo items are left, remove the ResultMacro from the pending list
+       if ( comboLength == 0 )
+       {
+               return ResultMacroEval_Remove;
+       }
+
+       // Function Counter, used to keep track of the combo items processed
+       unsigned int funcCount = 0;
+
+       // Combo Item Position within the guide
+       unsigned int comboItem = pos + 1;
+
+       // Iterate through the Result Combo
+       while ( funcCount < comboLength )
+       {
+               // Assign TriggerGuide element (key type, state and scancode)
+               ResultGuide *guide = (ResultGuide*)(&macro->guide[ pos ]);
+
+               // Do lookup on capability function
+               void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func);
+
+               // Call capability
+               capability( macro->state, macro->stateType, &guide->args );
+
+               // Increment counters
+               funcCount++;
+               comboItem += ResultGuideSize( (ResultGuide*)(&macro->guide[ comboItem ]) );
+       }
+
+       // Move to next item in the sequence
+       macro->pos = comboItem;
+
+       // If the ResultMacro is finished, it will be removed on the next iteration
+       return ResultMacroEval_DoNothing;
 }
 
 
@@ -515,15 +562,34 @@ inline void Macro_process()
                }
        }
 
-       // Update the macroResultMacroPendingListSize with the tail pointer
+       // Update the macroTriggerMacroPendingListSize with the tail pointer
        macroTriggerMacroPendingListSize = macroTriggerMacroPendingListTail;
 
+
+       // Tail pointer for macroResultMacroPendingList
+       // Macros must be explicitly re-added
+       unsigned int macroResultMacroPendingListTail = 0;
+
        // Iterate through the pending ResultMacros, processing each of them
        for ( unsigned int macro = 0; macro < macroResultMacroPendingListSize; macro++ )
        {
-               Macro_evalResultMacro( macroResultMacroPendingList[ macro ] );
+               switch ( Macro_evalResultMacro( macroResultMacroPendingList[ macro ] ) )
+               {
+               // Re-add macros to pending list
+               case ResultMacroEval_DoNothing:
+               default:
+                       macroResultMacroPendingList[ macroResultMacroPendingListTail++ ] = macroResultMacroPendingList[ macro ];
+                       break;
+
+               // Remove Macro from Pending List, nothing to do, removing by default
+               case ResultMacroEval_Remove:
+                       break;
+               }
        }
 
+       // Update the macroResultMacroPendingListSize with the tail pointer
+       macroResultMacroPendingListSize = macroResultMacroPendingListTail;
+
        /* TODO
        // Loop through input buffer
        for ( uint8_t index = 0; index < KeyIndex_BufferUsed && !macroDebugMode; index++ )
@@ -552,9 +618,11 @@ inline void Macro_process()
        }
        */
 
-       // Signal buffer that we've used it TODO
-       Scan_finishedWithMacro( 0 );
-       //Scan_finishedWithBuffer( KeyIndex_BufferUsed );
+       // Signal buffer that we've used it
+       Scan_finishedWithMacro( macroTriggerListBufferSize );
+
+       // Reset TriggerList buffer
+       macroTriggerListBufferSize = 0;
 
        // If Macro debug mode is set, clear the USB Buffer
        if ( macroDebugMode )