comparison Macro/PartialMap/macro.c @ 377:dbbdedccc275

Adding layer rotation (next/prev) capability - Requires kll update - Including udev id update
author Jacob Alexander <haata@kiibohd.com>
date Mon, 28 Sep 2015 19:58:39 -0700
parents 23104e8e24f4
children 5f085e29a66c
comparison
equal deleted inserted replaced
376:47f89f1bfdb7 377:dbbdedccc275
168 // ----- Capabilities ----- 168 // ----- Capabilities -----
169 169
170 // Sets the given layer with the specified layerState 170 // Sets the given layer with the specified layerState
171 void Macro_layerState( uint8_t state, uint8_t stateType, uint16_t layer, uint8_t layerState ) 171 void Macro_layerState( uint8_t state, uint8_t stateType, uint16_t layer, uint8_t layerState )
172 { 172 {
173 // Ignore if layer does not exist 173 // Ignore if layer does not exist or trying to manipulate layer 0/Default layer
174 if ( layer >= LayerNum ) 174 if ( layer >= LayerNum || layer == 0 )
175 return; 175 return;
176 176
177 // Is layer in the LayerIndexStack? 177 // Is layer in the LayerIndexStack?
178 uint8_t inLayerIndexStack = 0; 178 uint8_t inLayerIndexStack = 0;
179 uint16_t stackItem = 0; 179 uint16_t stackItem = 0;
348 348
349 Macro_layerState( state, stateType, layer, 0x01 ); 349 Macro_layerState( state, stateType, layer, 0x01 );
350 } 350 }
351 351
352 352
353 // Rotate layer to next/previous
354 // Uses state variable to keep track of the current layer position
355 // Layers are still evaluated using the layer stack
356 uint16_t Macro_rotationLayer;
357 void Macro_layerRotate_capability( uint8_t state, uint8_t stateType, uint8_t *args )
358 {
359 // Display capability name
360 if ( stateType == 0xFF && state == 0xFF )
361 {
362 print("Macro_layerRotate(previous)");
363 return;
364 }
365
366 // Only use capability on press
367 // TODO Analog
368 // XXX Could also be on release, but that's sorta dumb -HaaTa
369 if ( stateType == 0x00 && state != 0x01 ) // All normal key conditions except press
370 return;
371
372 // Unset previous rotation layer if not 0
373 if ( Macro_rotationLayer != 0 )
374 {
375 Macro_layerState( state, stateType, Macro_rotationLayer, 0x04 );
376 }
377
378 // Get direction of rotation, 0, next, non-zero previous
379 uint8_t direction = *args;
380
381 // Next
382 if ( !direction )
383 {
384 Macro_rotationLayer++;
385
386 // Invalid layer
387 if ( Macro_rotationLayer >= LayerNum )
388 Macro_rotationLayer = 0;
389 }
390 // Previous
391 else
392 {
393 Macro_rotationLayer--;
394
395 // Layer wrap
396 if ( Macro_rotationLayer >= LayerNum )
397 Macro_rotationLayer = LayerNum - 1;
398 }
399
400 // Toggle the computed layer rotation
401 Macro_layerState( state, stateType, Macro_rotationLayer, 0x04 );
402 }
403
404
353 405
354 // ----- Functions ----- 406 // ----- Functions -----
355 407
356 // Looks up the trigger list for the given scan code (from the active layer) 408 // Looks up the trigger list for the given scan code (from the active layer)
357 // NOTE: Calling function must handle the NULL pointer case 409 // NOTE: Calling function must handle the NULL pointer case
396 nat_ptr_t **map = (nat_ptr_t**)layer->triggerMap; 448 nat_ptr_t **map = (nat_ptr_t**)layer->triggerMap;
397 449
398 // Determine if layer has key defined 450 // Determine if layer has key defined
399 // Make sure scanCode is between layer first and last scancodes 451 // Make sure scanCode is between layer first and last scancodes
400 if ( map != 0 452 if ( map != 0
401 && scanCode <= layer->last 453 && scanCode <= layer->last
402 && scanCode >= layer->first 454 && scanCode >= layer->first
403 && *map[ scanCode - layer->first ] != 0 ) 455 && *map[ scanCode - layer->first ] != 0 )
404 { 456 {
405 // Set the layer cache 457 // Set the layer cache
406 macroTriggerListLayerCache[ scanCode ] = macroLayerIndexStack[ layerIndex ]; 458 macroTriggerListLayerCache[ scanCode ] = macroLayerIndexStack[ layerIndex ];
407 459
408 return map[ scanCode - layer->first ]; 460 return map[ scanCode - layer->first ];
416 // Lookup default layer 468 // Lookup default layer
417 const Layer *layer = &LayerIndex[0]; 469 const Layer *layer = &LayerIndex[0];
418 470
419 // Make sure scanCode is between layer first and last scancodes 471 // Make sure scanCode is between layer first and last scancodes
420 if ( map != 0 472 if ( map != 0
421 && scanCode <= layer->last 473 && scanCode <= layer->last
422 && scanCode >= layer->first 474 && scanCode >= layer->first
423 && *map[ scanCode - layer->first ] != 0 ) 475 && *map[ scanCode - layer->first ] != 0 )
424 { 476 {
425 // Set the layer cache to default map 477 // Set the layer cache to default map
426 macroTriggerListLayerCache[ scanCode ] = 0; 478 macroTriggerListLayerCache[ scanCode ] = 0;
427 479
428 return map[ scanCode - layer->first ]; 480 return map[ scanCode - layer->first ];
890 if ( macro->guide[ record->pos + macro->guide[ record->pos ] * TriggerGuideSize + 1 ] == 0 ) 942 if ( macro->guide[ record->pos + macro->guide[ record->pos ] * TriggerGuideSize + 1 ] == 0 )
891 return TriggerMacroEval_DoResultAndRemove; 943 return TriggerMacroEval_DoResultAndRemove;
892 } 944 }
893 // If passing and in Waiting state, set macro state to Press 945 // If passing and in Waiting state, set macro state to Press
894 else if ( overallVote & TriggerMacroVote_Pass 946 else if ( overallVote & TriggerMacroVote_Pass
895 && ( record->state == TriggerMacro_Waiting || record->state == TriggerMacro_Press ) ) 947 && ( record->state == TriggerMacro_Waiting || record->state == TriggerMacro_Press ) )
896 { 948 {
897 record->state = TriggerMacro_Press; 949 record->state = TriggerMacro_Press;
898 950
899 // If in press state, and this is the final combo, send request for ResultMacro 951 // If in press state, and this is the final combo, send request for ResultMacro
900 // Check to see if the result macro only has a single element 952 // Check to see if the result macro only has a single element
1210 macroStepCounter = 0; 1262 macroStepCounter = 0;
1211 1263
1212 // Make sure macro trigger buffer is empty 1264 // Make sure macro trigger buffer is empty
1213 macroTriggerListBufferSize = 0; 1265 macroTriggerListBufferSize = 0;
1214 1266
1267 // Set the current rotated layer to 0
1268 Macro_rotationLayer = 0;
1269
1215 // Initialize TriggerMacro states 1270 // Initialize TriggerMacro states
1216 for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ ) 1271 for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
1217 { 1272 {
1218 TriggerMacroRecordList[ macro ].pos = 0; 1273 TriggerMacroRecordList[ macro ].pos = 0;
1219 TriggerMacroRecordList[ macro ].state = TriggerMacro_Waiting; 1274 TriggerMacroRecordList[ macro ].state = TriggerMacro_Waiting;