comparison Macro/PartialMap/macro.c @ 297:c86eb7d0a693

Fixing releasing Function key and holding layered key - Pressed key will remain on the same layer until released regardless of the layer changes that happen in the meantime
author Jacob Alexander <haata@kiibohd.com>
date Sun, 01 Mar 2015 21:04:33 -0800
parents e6c753528873
children ecd2ae35d25c
comparison
equal deleted inserted replaced
296:413c6b2b21d0 297:c86eb7d0a693
1 /* Copyright (C) 2014 by Jacob Alexander 1 /* Copyright (C) 2014-2015 by Jacob Alexander
2 * 2 *
3 * This file is free software: you can redistribute it and/or modify 3 * This file is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or 5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version. 6 * (at your option) any later version.
119 119
120 // Macro step counter - If non-zero, the step counter counts down every time the macro module does one processing loop 120 // Macro step counter - If non-zero, the step counter counts down every time the macro module does one processing loop
121 uint16_t macroStepCounter = 0; 121 uint16_t macroStepCounter = 0;
122 122
123 123
124 // Key Trigger List Buffer 124 // Key Trigger List Buffer and Layer Cache
125 // The layer cache is set on press only, hold and release events refer to the value set on press
125 TriggerGuide macroTriggerListBuffer[ MaxScanCode ]; 126 TriggerGuide macroTriggerListBuffer[ MaxScanCode ];
126 uint8_t macroTriggerListBufferSize = 0; 127 uint8_t macroTriggerListBufferSize = 0;
128 var_uint_t macroTriggerListLayerCache[ MaxScanCode ];
127 129
128 // Pending Trigger Macro Index List 130 // Pending Trigger Macro Index List
129 // * Any trigger macros that need processing from a previous macro processing loop 131 // * Any trigger macros that need processing from a previous macro processing loop
130 // TODO, figure out a good way to scale this array size without wasting too much memory, but not rejecting macros 132 // TODO, figure out a good way to scale this array size without wasting too much memory, but not rejecting macros
131 // Possibly could be calculated by the KLL compiler 133 // Possibly could be calculated by the KLL compiler
309 311
310 // ----- Functions ----- 312 // ----- Functions -----
311 313
312 // Looks up the trigger list for the given scan code (from the active layer) 314 // Looks up the trigger list for the given scan code (from the active layer)
313 // NOTE: Calling function must handle the NULL pointer case 315 // NOTE: Calling function must handle the NULL pointer case
314 nat_ptr_t *Macro_layerLookup( uint8_t scanCode, uint8_t latch_expire ) 316 nat_ptr_t *Macro_layerLookup( TriggerGuide *guide, uint8_t latch_expire )
315 { 317 {
318 uint8_t scanCode = guide->scanCode;
319
320 // TODO Analog
321 // If a normal key, and not pressed, do a layer cache lookup
322 if ( guide->type == 0x00 && guide->state != 0x01 )
323 {
324 // Cached layer
325 var_uint_t cachedLayer = macroTriggerListLayerCache[ scanCode ];
326
327 // Lookup map, then layer
328 nat_ptr_t **map = (nat_ptr_t**)LayerIndex[ cachedLayer ].triggerMap;
329 const Layer *layer = &LayerIndex[ cachedLayer ];
330
331 return map[ scanCode - layer->first ];
332 }
333
316 // If no trigger macro is defined at the given layer, fallthrough to the next layer 334 // If no trigger macro is defined at the given layer, fallthrough to the next layer
317 for ( uint16_t layerIndex = 0; layerIndex < macroLayerIndexStackSize; layerIndex++ ) 335 for ( uint16_t layerIndex = 0; layerIndex < macroLayerIndexStackSize; layerIndex++ )
318 { 336 {
319 // Lookup Layer 337 // Lookup Layer
320 const Layer *layer = &LayerIndex[ macroLayerIndexStack[ layerIndex ] ]; 338 const Layer *layer = &LayerIndex[ macroLayerIndexStack[ layerIndex ] ];
340 if ( map != 0 358 if ( map != 0
341 && scanCode <= layer->last 359 && scanCode <= layer->last
342 && scanCode >= layer->first 360 && scanCode >= layer->first
343 && *map[ scanCode - layer->first ] != 0 ) 361 && *map[ scanCode - layer->first ] != 0 )
344 { 362 {
363 // Set the layer cache
364 macroTriggerListLayerCache[ scanCode ] = macroLayerIndexStack[ layerIndex ];
365
345 return map[ scanCode - layer->first ]; 366 return map[ scanCode - layer->first ];
346 } 367 }
347 } 368 }
348 } 369 }
349 370
357 if ( map != 0 378 if ( map != 0
358 && scanCode <= layer->last 379 && scanCode <= layer->last
359 && scanCode >= layer->first 380 && scanCode >= layer->first
360 && *map[ scanCode - layer->first ] != 0 ) 381 && *map[ scanCode - layer->first ] != 0 )
361 { 382 {
383 // Set the layer cache to default map
384 macroTriggerListLayerCache[ scanCode ] = 0;
385
362 return map[ scanCode - layer->first ]; 386 return map[ scanCode - layer->first ];
363 } 387 }
364 388
365 // Otherwise no defined Trigger Macro 389 // Otherwise no defined Trigger Macro
366 erro_msg("Scan Code has no defined Trigger Macro: "); 390 erro_msg("Scan Code has no defined Trigger Macro: ");
834 // TODO Analog 858 // TODO Analog
835 // If this is a release case, indicate to layer lookup for possible latch expiry 859 // If this is a release case, indicate to layer lookup for possible latch expiry
836 uint8_t latch_expire = macroTriggerListBuffer[ key ].state == 0x03; 860 uint8_t latch_expire = macroTriggerListBuffer[ key ].state == 0x03;
837 861
838 // Lookup Trigger List 862 // Lookup Trigger List
839 nat_ptr_t *triggerList = Macro_layerLookup( macroTriggerListBuffer[ key ].scanCode, latch_expire ); 863 nat_ptr_t *triggerList = Macro_layerLookup( &macroTriggerListBuffer[ key ], latch_expire );
840 864
841 // Number of Triggers in list 865 // Number of Triggers in list
842 nat_ptr_t triggerListSize = triggerList[0]; 866 nat_ptr_t triggerListSize = triggerList[0];
843 867
844 // Iterate over triggerList to see if any TriggerMacros need to be added 868 // Iterate over triggerList to see if any TriggerMacros need to be added