// 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
// Sets the given layer with the specified layerState
void Macro_layerState( uint8_t state, uint8_t stateType, uint16_t layer, uint8_t layerState )
{
- // Ignore if layer does not exist
- if ( layer >= LayerNum )
+ // Ignore if layer does not exist or trying to manipulate layer 0/Default layer
+ if ( layer >= LayerNum || layer == 0 )
return;
// Is layer in the LayerIndexStack?
}
+// Rotate layer to next/previous
+// Uses state variable to keep track of the current layer position
+// Layers are still evaluated using the layer stack
+uint16_t Macro_rotationLayer;
+void Macro_layerRotate_capability( uint8_t state, uint8_t stateType, uint8_t *args )
+{
+ // Display capability name
+ if ( stateType == 0xFF && state == 0xFF )
+ {
+ print("Macro_layerRotate(previous)");
+ return;
+ }
+
+ // Only use capability on press
+ // TODO Analog
+ // XXX Could also be on release, but that's sorta dumb -HaaTa
+ if ( stateType == 0x00 && state != 0x01 ) // All normal key conditions except press
+ return;
+
+ // Unset previous rotation layer if not 0
+ if ( Macro_rotationLayer != 0 )
+ {
+ Macro_layerState( state, stateType, Macro_rotationLayer, 0x04 );
+ }
+
+ // Get direction of rotation, 0, next, non-zero previous
+ uint8_t direction = *args;
+
+ // Next
+ if ( !direction )
+ {
+ Macro_rotationLayer++;
+
+ // Invalid layer
+ if ( Macro_rotationLayer >= LayerNum )
+ Macro_rotationLayer = 0;
+ }
+ // Previous
+ else
+ {
+ Macro_rotationLayer--;
+
+ // Layer wrap
+ if ( Macro_rotationLayer >= LayerNum )
+ Macro_rotationLayer = LayerNum - 1;
+ }
+
+ // Toggle the computed layer rotation
+ Macro_layerState( state, stateType, Macro_rotationLayer, 0x04 );
+}
+
+
// ----- Functions -----
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
- for ( uint16_t layerIndex = 0; layerIndex < macroLayerIndexStackSize; layerIndex++ )
+ for ( uint16_t layerIndex = macroLayerIndexStackSize; layerIndex != 0xFFFF; layerIndex-- )
{
// Lookup Layer
const Layer *layer = &LayerIndex[ macroLayerIndexStack[ layerIndex ] ];
// Determine if layer has key defined
// Make sure scanCode is between layer first and last scancodes
if ( map != 0
- && scanCode <= layer->last
- && scanCode >= layer->first
- && *map[ scanCode - layer->first ] != 0 )
+ && scanCode <= layer->last
+ && scanCode >= layer->first
+ && *map[ scanCode - layer->first ] != 0 )
{
// Set the layer cache
macroTriggerListLayerCache[ scanCode ] = macroLayerIndexStack[ layerIndex ];
// Make sure scanCode is between layer first and last scancodes
if ( map != 0
- && scanCode <= layer->last
- && scanCode >= layer->first
- && *map[ scanCode - layer->first ] != 0 )
+ && scanCode <= layer->last
+ && scanCode >= layer->first
+ && *map[ scanCode - layer->first ] != 0 )
{
// Set the layer cache to default map
macroTriggerListLayerCache[ scanCode ] = 0;
}
// Check if ScanCode is out of range
- if ( scanCode > MaxScanCode )
+ if ( trigger->scanCode > MaxScanCode )
{
warn_msg("ScanCode is out of range/not defined - ");
error = 1;
// 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 )
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 )
{
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 = ¯oTriggerListBuffer[ key ];
}
// If passing and in Waiting state, set macro state to Press
else if ( overallVote & TriggerMacroVote_Pass
- && ( record->state == TriggerMacro_Waiting || record->state == TriggerMacro_Press ) )
+ && ( record->state == TriggerMacro_Waiting || record->state == TriggerMacro_Press ) )
{
record->state = TriggerMacro_Press;
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
// Make sure macro trigger buffer is empty
macroTriggerListBufferSize = 0;
+ // Set the current rotated layer to 0
+ Macro_rotationLayer = 0;
+
// Initialize TriggerMacro states
for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
{
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] );
}
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(" ");