]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Macro/PartialMap/macro.c
Merge branch 'master' of github.com:kiibohd/controller
[kiibohd-controller.git] / Macro / PartialMap / macro.c
index 690231cc889628b158ca6dac33ab86be0509318b..dc5175154080659c51291e2d869deecc23d569fc 100644 (file)
@@ -135,7 +135,7 @@ uint16_t macroStepCounter = 0;
 // Key Trigger List Buffer and Layer Cache
 // The layer cache is set on press only, hold and release events refer to the value set on press
 TriggerGuide macroTriggerListBuffer[ MaxScanCode ];
-uint8_t macroTriggerListBufferSize = 0;
+var_uint_t macroTriggerListBufferSize = 0;
 var_uint_t macroTriggerListLayerCache[ MaxScanCode ];
 
 // Pending Trigger Macro Index List
@@ -422,7 +422,22 @@ nat_ptr_t *Macro_layerLookup( TriggerGuide *guide, uint8_t latch_expire )
                nat_ptr_t **map = (nat_ptr_t**)LayerIndex[ cachedLayer ].triggerMap;
                const Layer *layer = &LayerIndex[ cachedLayer ];
 
-               return map[ scanCode - layer->first ];
+               // Cache trigger list before attempting to expire latch
+               nat_ptr_t *trigger_list = map[ scanCode - layer->first ];
+
+               // Check if latch has been pressed for this layer
+               uint8_t latch = LayerState[ cachedLayer ] & 0x02;
+               if ( latch && latch_expire )
+               {
+                       Macro_layerState( 0, 0, cachedLayer, 0x02 );
+#if defined(ConnectEnabled_define) && defined(LCDEnabled_define)
+                       // Evaluate the layerStack capability if available (LCD + Interconnect)
+                       extern void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args );
+                       LCD_layerStack_capability( 0, 0, 0 );
+#endif
+               }
+
+               return trigger_list;
        }
 
        // If no trigger macro is defined at the given layer, fallthrough to the next layer
@@ -542,7 +557,7 @@ inline void Macro_interconnectAdd( void *trigger_ptr )
 
        // Add trigger to the Interconnect Cache
        // During each processing loop, a scancode may be re-added depending on it's state
-       for ( uint8_t c = 0; c < macroInterconnectCacheSize; c++ )
+       for ( var_uint_t c = 0; c < macroInterconnectCacheSize; c++ )
        {
                // Check if the same ScanCode
                if ( macroInterconnectCache[ c ].scanCode == trigger->scanCode )
@@ -684,7 +699,7 @@ inline void Macro_appendResultMacroToPendingList( const TriggerMacro *triggerMac
        uint8_t scanCode = ((TriggerGuide*)&triggerMacro->guide[ pos - TriggerGuideSize ])->scanCode;
 
        // Lookup scanCode in buffer list for the current state and stateType
-       for ( uint8_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ )
+       for ( var_uint_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ )
        {
                if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode )
                {
@@ -890,7 +905,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex )
 
                TriggerMacroVote vote = TriggerMacroVote_Invalid;
                // Iterate through the key buffer, comparing to each key in the combo
-               for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ )
+               for ( var_uint_t key = 0; key < macroTriggerListBufferSize; key++ )
                {
                        // Lookup key information
                        TriggerGuide *keyInfo = &macroTriggerListBuffer[ key ];
@@ -1050,7 +1065,7 @@ inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex )
 inline void Macro_updateTriggerMacroPendingList()
 {
        // Iterate over the macroTriggerListBuffer to add any new Trigger Macros to the pending list
-       for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ )
+       for ( var_uint_t key = 0; key < macroTriggerListBufferSize; key++ )
        {
                // TODO LED States
                // TODO Analog Switches
@@ -1363,6 +1378,19 @@ void cliFunc_capSelect( char* args )
                        printHex( argSet[2] );
                        print( "..." NL );
 
+                       // Make sure this isn't the reload capability
+                       // If it is, and the remote reflash define is not set, ignore
+                       if ( flashModeEnabled_define == 0 ) for ( uint32_t cap = 0; cap < CapabilitiesNum; cap++ )
+                       {
+                               if ( CapabilitiesList[ cap ].func == (const void*)Output_flashMode_capability )
+                               {
+                                       print( NL );
+                                       warn_print("flashModeEnabled not set, cancelling firmware reload...");
+                                       info_msg("Set flashModeEnabled to 1 in your kll configuration.");
+                                       return;
+                               }
+                       }
+
                        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] );
                }
@@ -1558,7 +1586,7 @@ void cliFunc_macroList( char* args )
        info_msg("Pending Key Events: ");
        printInt16( (uint16_t)macroTriggerListBufferSize );
        print(" : ");
-       for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ )
+       for ( var_uint_t key = 0; key < macroTriggerListBufferSize; key++ )
        {
                printHex( macroTriggerListBuffer[ key ].scanCode );
                print(" ");