Mercurial > louis > kiibohd-controller
comparison Macro/PartialMap/macro.c @ 410:8fa2619aa60e
Fix a handful of infinite loops that occur if you have more than 254 macros
author | Kevin Frei <freik@fb.com> |
---|---|
date | Sat, 02 Jan 2016 17:43:05 -0800 |
parents | d8f61e15aca1 |
children | 0f7a6b593dc4 |
comparison
equal
deleted
inserted
replaced
399:3437e2246259 | 410:8fa2619aa60e |
---|---|
133 | 133 |
134 | 134 |
135 // Key Trigger List Buffer and Layer Cache | 135 // Key Trigger List Buffer and Layer Cache |
136 // The layer cache is set on press only, hold and release events refer to the value set on press | 136 // The layer cache is set on press only, hold and release events refer to the value set on press |
137 TriggerGuide macroTriggerListBuffer[ MaxScanCode ]; | 137 TriggerGuide macroTriggerListBuffer[ MaxScanCode ]; |
138 uint8_t macroTriggerListBufferSize = 0; | 138 var_uint_t macroTriggerListBufferSize = 0; |
139 var_uint_t macroTriggerListLayerCache[ MaxScanCode ]; | 139 var_uint_t macroTriggerListLayerCache[ MaxScanCode ]; |
140 | 140 |
141 // Pending Trigger Macro Index List | 141 // Pending Trigger Macro Index List |
142 // * Any trigger macros that need processing from a previous macro processing loop | 142 // * Any trigger macros that need processing from a previous macro processing loop |
143 // TODO, figure out a good way to scale this array size without wasting too much memory, but not rejecting macros | 143 // TODO, figure out a good way to scale this array size without wasting too much memory, but not rejecting macros |
555 return; | 555 return; |
556 } | 556 } |
557 | 557 |
558 // Add trigger to the Interconnect Cache | 558 // Add trigger to the Interconnect Cache |
559 // During each processing loop, a scancode may be re-added depending on it's state | 559 // During each processing loop, a scancode may be re-added depending on it's state |
560 for ( uint8_t c = 0; c < macroInterconnectCacheSize; c++ ) | 560 for ( var_uint_t c = 0; c < macroInterconnectCacheSize; c++ ) |
561 { | 561 { |
562 // Check if the same ScanCode | 562 // Check if the same ScanCode |
563 if ( macroInterconnectCache[ c ].scanCode == trigger->scanCode ) | 563 if ( macroInterconnectCache[ c ].scanCode == trigger->scanCode ) |
564 { | 564 { |
565 // Update the state | 565 // Update the state |
697 } | 697 } |
698 | 698 |
699 uint8_t scanCode = ((TriggerGuide*)&triggerMacro->guide[ pos - TriggerGuideSize ])->scanCode; | 699 uint8_t scanCode = ((TriggerGuide*)&triggerMacro->guide[ pos - TriggerGuideSize ])->scanCode; |
700 | 700 |
701 // Lookup scanCode in buffer list for the current state and stateType | 701 // Lookup scanCode in buffer list for the current state and stateType |
702 for ( uint8_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ ) | 702 for ( var_uint_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ ) |
703 { | 703 { |
704 if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode ) | 704 if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode ) |
705 { | 705 { |
706 ResultMacroRecordList[ resultMacroIndex ].state = macroTriggerListBuffer[ keyIndex ].state; | 706 ResultMacroRecordList[ resultMacroIndex ].state = macroTriggerListBuffer[ keyIndex ].state; |
707 ResultMacroRecordList[ resultMacroIndex ].stateType = macroTriggerListBuffer[ keyIndex ].type; | 707 ResultMacroRecordList[ resultMacroIndex ].stateType = macroTriggerListBuffer[ keyIndex ].type; |
903 // Assign TriggerGuide element (key type, state and scancode) | 903 // Assign TriggerGuide element (key type, state and scancode) |
904 TriggerGuide *guide = (TriggerGuide*)(¯o->guide[ comboItem ]); | 904 TriggerGuide *guide = (TriggerGuide*)(¯o->guide[ comboItem ]); |
905 | 905 |
906 TriggerMacroVote vote = TriggerMacroVote_Invalid; | 906 TriggerMacroVote vote = TriggerMacroVote_Invalid; |
907 // Iterate through the key buffer, comparing to each key in the combo | 907 // Iterate through the key buffer, comparing to each key in the combo |
908 for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ ) | 908 for ( var_uint_t key = 0; key < macroTriggerListBufferSize; key++ ) |
909 { | 909 { |
910 // Lookup key information | 910 // Lookup key information |
911 TriggerGuide *keyInfo = ¯oTriggerListBuffer[ key ]; | 911 TriggerGuide *keyInfo = ¯oTriggerListBuffer[ key ]; |
912 | 912 |
913 // If vote is a pass (>= 0x08, no more keys in the combo need to be looked at) | 913 // If vote is a pass (>= 0x08, no more keys in the combo need to be looked at) |
1063 | 1063 |
1064 // Update pending trigger list | 1064 // Update pending trigger list |
1065 inline void Macro_updateTriggerMacroPendingList() | 1065 inline void Macro_updateTriggerMacroPendingList() |
1066 { | 1066 { |
1067 // Iterate over the macroTriggerListBuffer to add any new Trigger Macros to the pending list | 1067 // Iterate over the macroTriggerListBuffer to add any new Trigger Macros to the pending list |
1068 for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ ) | 1068 for ( var_uint_t key = 0; key < macroTriggerListBufferSize; key++ ) |
1069 { | 1069 { |
1070 // TODO LED States | 1070 // TODO LED States |
1071 // TODO Analog Switches | 1071 // TODO Analog Switches |
1072 // Only add TriggerMacro to pending list if key was pressed (not held, released or off) | 1072 // Only add TriggerMacro to pending list if key was pressed (not held, released or off) |
1073 if ( macroTriggerListBuffer[ key ].state == 0x00 && macroTriggerListBuffer[ key ].state != 0x01 ) | 1073 if ( macroTriggerListBuffer[ key ].state == 0x00 && macroTriggerListBuffer[ key ].state != 0x01 ) |
1584 // Show pending key events | 1584 // Show pending key events |
1585 print( NL ); | 1585 print( NL ); |
1586 info_msg("Pending Key Events: "); | 1586 info_msg("Pending Key Events: "); |
1587 printInt16( (uint16_t)macroTriggerListBufferSize ); | 1587 printInt16( (uint16_t)macroTriggerListBufferSize ); |
1588 print(" : "); | 1588 print(" : "); |
1589 for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ ) | 1589 for ( var_uint_t key = 0; key < macroTriggerListBufferSize; key++ ) |
1590 { | 1590 { |
1591 printHex( macroTriggerListBuffer[ key ].scanCode ); | 1591 printHex( macroTriggerListBuffer[ key ].scanCode ); |
1592 print(" "); | 1592 print(" "); |
1593 } | 1593 } |
1594 | 1594 |