- // Copy each of the TriggerGuides to the TriggerListBuffer
- for ( uint8_t c = 0; c < num; c++ )
- macroTriggerListBuffer[ macroTriggerListBufferSize++ ] = ((TriggerGuide*)triggers)[ c ];
+ TriggerGuide *trigger = (TriggerGuide*)trigger_ptr;
+
+ // Error checking
+ uint8_t error = 0;
+ switch ( trigger->type )
+ {
+ case 0x00: // Normal key
+ switch ( trigger->state )
+ {
+ case 0x00:
+ case 0x01:
+ case 0x02:
+ case 0x03:
+ break;
+ default:
+ erro_msg("Invalid key state - ");
+ error = 1;
+ break;
+ }
+ break;
+
+ // Invalid TriggerGuide type
+ default:
+ erro_msg("Invalid type - ");
+ error = 1;
+ break;
+ }
+
+ // Check if ScanCode is out of range
+ if ( trigger->scanCode > MaxScanCode )
+ {
+ warn_msg("ScanCode is out of range/not defined - ");
+ error = 1;
+ }
+
+ // Display TriggerGuide
+ if ( error )
+ {
+ printHex( trigger->type );
+ print(" ");
+ printHex( trigger->state );
+ print(" ");
+ printHex( trigger->scanCode );
+ print( NL );
+ return;
+ }
+
+ // 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++ )
+ {
+ // Check if the same ScanCode
+ if ( macroInterconnectCache[ c ].scanCode == trigger->scanCode )
+ {
+ // Update the state
+ macroInterconnectCache[ c ].state = trigger->state;
+ return;
+ }
+ }
+
+ // If not in the list, add it
+ macroInterconnectCache[ macroInterconnectCacheSize++ ] = *trigger;