// Determine if long ResultMacro (more than 1 seqence element) inline uint8_t Macro_isLongResultMacro( const ResultMacro *macro ) { // Check the second sequence combo length // If non-zero return non-zero (long sequence) // 0 otherwise (short sequence) var_uint_t position = 1; for ( var_uint_t result = 0; result < macro->guide[0]; result++ ) position += ResultGuideSize( (ResultGuide*)¯o->guide[ position ] ); return macro->guide[ position ]; }
// Evaluate/Update ResultMacro ResultMacroEval Macro_evalResultMacro( ResultPendingElem resultElem ) { // Lookup ResultMacro const ResultMacro *macro = &ResultMacroList[ resultElem.index ]; ResultMacroRecord *record = &ResultMacroRecordList[ resultElem.index ]; // Current Macro position var_uint_t pos = record->pos; // Length of combo being processed uint8_t comboLength = macro->guide[ pos ]; // Function Counter, used to keep track of the combo items processed var_uint_t funcCount = 0; // Combo Item Position within the guide var_uint_t comboItem = pos + 1; // Iterate through the Result Combo while ( funcCount < comboLength ) { // Assign TriggerGuide element (key type, state and scancode) ResultGuide *guide = (ResultGuide*)(¯o->guide[ comboItem ]); // Do lookup on capability function void (*capability)(TriggerMacro*, uint8_t, uint8_t, uint8_t*) = \ (void(*)(TriggerMacro*, uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func); // Call capability capability( resultElem.trigger, record->state, record->stateType, &guide->args ); // Increment counters funcCount++; comboItem += ResultGuideSize( (ResultGuide*)(¯o->guide[ comboItem ]) ); } // Move to next item in the sequence record->pos = comboItem; // If the ResultMacro is finished, remove if ( macro->guide[ comboItem ] == 0 ) { record->pos = 0; return ResultMacroEval_Remove; } // Otherwise leave the macro in the list return ResultMacroEval_DoNothing; }
void macroDebugShowResult( var_uint_t index ) { // Only proceed if the macro exists if ( index >= ResultMacroNum ) return; // Trigger Macro Show const ResultMacro *macro = &ResultMacroList[ index ]; print( NL ); info_msg("Result Macro Index: "); printInt16( (uint16_t)index ); // Hopefully large enough :P (can't assume 32-bit) print( NL ); // Read the comboLength for combo in the sequence (sequence of combos) var_uint_t pos = 0; uint8_t comboLength = macro->guide[ pos++ ]; // Iterate through and interpret the guide while ( comboLength != 0 ) { // Function Counter, used to keep track of the combos processed var_uint_t funcCount = 0; // Iterate through the combo while ( funcCount < comboLength ) { // Assign TriggerGuide element (key type, state and scancode) ResultGuide *guide = (ResultGuide*)(¯o->guide[ pos ]); // Display Function Index printHex( guide->index ); print("|"); // Display Function Ptr Address printHex( (nat_ptr_t)CapabilitiesList[ guide->index ].func ); print("|"); // Display/Lookup Capability Name (utilize debug mode of capability) void (*capability)(TriggerMacro*, uint8_t, uint8_t, uint8_t*) = \ (void(*)(TriggerMacro*, uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func); capability( 0, 0xFF, 0xFF, 0 ); // Display Argument(s) print("("); for ( var_uint_t 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 < CapabilitiesList[ guide->index ].argCount ) print(","); } print(")"); // Increment position pos += ResultGuideSize( guide ); // Increment function count funcCount++; // Only show combo separator if there are combos left in the sequence element if ( funcCount < comboLength ) print("+"); } // Read the next comboLength comboLength = macro->guide[ pos++ ]; // Only show sequence separator if there is another combo to process if ( comboLength != 0 ) print(";"); } /* XXX (HaaTa) Fix for ring-buffer record list ResultMacroRecord *record = &ResultMacroRecordList[ index ]; // Display current position print( NL "Position: " ); printInt16( (uint16_t)record->pos ); // Hopefully large enough :P (can't assume 32-bit) print(" "); printInt16( (uint16_t)record->prevPos ); // Display final trigger state/type print( NL "Final Trigger State (State/Type): " ); printHex( record->state ); print("/"); printHex( record->stateType ); */ }