From 775e4eab8f4c2305080670355b9d01eb59cfe307 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sat, 27 Sep 2014 11:58:56 -0700 Subject: [PATCH 1/5] Preparing for SimpleMap macro module - Will use only flash memory (no ram usage for each layer or macro) - Only supports combinations, no sequences. --- Macro/{PartialMap => Common}/kll.h | 25 +++++++++++++++++++++++-- Macro/Common/setup.cmake | 24 ++++++++++++++++++++++++ Macro/{PartialMap => Common}/usb_hid.h | 0 Macro/PartialMap/setup.cmake | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) rename Macro/{PartialMap => Common}/kll.h (88%) create mode 100644 Macro/Common/setup.cmake rename Macro/{PartialMap => Common}/usb_hid.h (100%) diff --git a/Macro/PartialMap/kll.h b/Macro/Common/kll.h similarity index 88% rename from Macro/PartialMap/kll.h rename to Macro/Common/kll.h index 492e1ba..ebfbc59 100644 --- a/Macro/PartialMap/kll.h +++ b/Macro/Common/kll.h @@ -64,6 +64,15 @@ typedef uint16_t nat_ptr_t; // ----- Structs ----- +// -- Macro Type +// Defines what type of Macro the struct defines +// Always the first field +typedef enum MacroType { + MacroType_Normal, // Sequence of Combos + MacroType_Simple, // Single combination (no state required) +} MacroType; + + // -- Result Macro // Defines the sequence of combinations to as the Result of Trigger Macro // For RAM optimization reasons, ResultMacro has been split into ResultMacro and ResultMacroRecord structures @@ -72,7 +81,9 @@ typedef uint16_t nat_ptr_t; // Default Args (always sent): key state/analog of last key // Combo Length of 0 signifies end of sequence // -// ResultMacro.guide -> [|||||...||...|0] +// ResultMacro.type -> +// ResultMacro.guide -> [|||||...||...|0] +// ResultMacro.triggerKey -> // // ResultMacroRecord.pos -> // ResultMacroRecord.state -> @@ -80,7 +91,9 @@ typedef uint16_t nat_ptr_t; // ResultMacro struct, one is created per ResultMacro, no duplicates typedef struct ResultMacro { + const MacroType type; const uint8_t *guide; + const uint8_t triggerKey; } ResultMacro; typedef struct ResultMacroRecord { @@ -117,6 +130,7 @@ typedef struct ResultGuide { // // Combo Length of 0 signifies end of sequence // +// TriggerMacro.type -> // TriggerMacro.guide -> [|||...|||...|0] // TriggerMacro.result -> // @@ -132,6 +146,7 @@ typedef enum TriggerMacroState { // TriggerMacro struct, one is created per TriggerMacro, no duplicates typedef struct TriggerMacro { + const MacroType type; const uint8_t *guide; const var_uint_t result; } TriggerMacro; @@ -190,10 +205,16 @@ typedef struct Capability { // * index - Trigger Macro index number // * trigger - Trigger Macro guide (see TriggerMacro) // Define_TM( index, result ); +// +// * index - Trigger Macro index number +// * result - Result Macro index number which is triggered by this Trigger Macro +// Define_STM( index, result ); +// // * index - Trigger Macro index number // * result - Result Macro index number which is triggered by this Trigger Macro #define Guide_TM( index ) const uint8_t tm##index##_guide[] -#define Define_TM( index, result ) { tm##index##_guide, result } +#define Define_TM( index, result ) { MacroType_Normal, tm##index##_guide, result } +#define Define_STM( index, result ) { MacroType_Simple, tm##index##_guide, result } // -- Trigger Macro List diff --git a/Macro/Common/setup.cmake b/Macro/Common/setup.cmake new file mode 100644 index 0000000..80207d5 --- /dev/null +++ b/Macro/Common/setup.cmake @@ -0,0 +1,24 @@ +###| CMake Kiibohd Controller Macro Module |### +# +# Written by Jacob Alexander in 2014 for the Kiibohd Controller +# +# Released into the Public Domain +# +### + +### +# Warning, that this module is not meant to be built stand-alone +# +message( FATAL_ERROR +"The 'Common' module is not a stand-alone module, and requires further setup." +) + +### +# Module C files +# + + +### +# Module Specific Options +# + diff --git a/Macro/PartialMap/usb_hid.h b/Macro/Common/usb_hid.h similarity index 100% rename from Macro/PartialMap/usb_hid.h rename to Macro/Common/usb_hid.h diff --git a/Macro/PartialMap/setup.cmake b/Macro/PartialMap/setup.cmake index 7f72689..750f974 100644 --- a/Macro/PartialMap/setup.cmake +++ b/Macro/PartialMap/setup.cmake @@ -1,4 +1,4 @@ -###| CMake Kiibohd Controller Macro Module |### +###| CMake Kiibohd Controller PartialMap Macro Module |### # # Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller # From d63886954c4f01aeb85dc38242e24bb0613f0f93 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 9 Feb 2015 20:02:19 -0800 Subject: [PATCH 2/5] Using full length kll.py arguments - Helps readability in kll debug output --- Lib/CMake/kll.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/CMake/kll.cmake b/Lib/CMake/kll.cmake index 5d007d2..a81c024 100644 --- a/Lib/CMake/kll.cmake +++ b/Lib/CMake/kll.cmake @@ -64,7 +64,7 @@ endif () #| Configure DefaultMap if specified if ( NOT "${DefaultMap}" STREQUAL "" ) - set ( DefaultMap_Args -d ) + set ( DefaultMap_Args --default ) string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons foreach ( MAP ${MAP_LIST} ) @@ -83,7 +83,7 @@ endif () if ( NOT "${PartialMaps}" STREQUAL "" ) # For each partial layer foreach ( MAP ${PartialMaps} ) - set ( PartialMap_Args ${PartialMap_Args} -p ) + set ( PartialMap_Args ${PartialMap_Args} --partial ) # Combine each layer string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons From b4c1951b0d29088fce3e78b4b012c3e2c2d4653e Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 9 Feb 2015 22:18:01 -0800 Subject: [PATCH 3/5] Adding initial work for SimpleMap style macros - Differentiating between simple and complex macros - Worst case requires more flash - Best case will use a lot less RAM - Requires update to kll compiler --- Macro/Common/kll.h | 73 +++++++++++++++++++----------------- Macro/Common/setup.cmake | 17 ++++++--- Macro/PartialMap/macro.c | 30 +++++++-------- Macro/PartialMap/setup.cmake | 6 +++ 4 files changed, 71 insertions(+), 55 deletions(-) diff --git a/Macro/Common/kll.h b/Macro/Common/kll.h index ebfbc59..2c1c538 100644 --- a/Macro/Common/kll.h +++ b/Macro/Common/kll.h @@ -83,25 +83,25 @@ typedef enum MacroType { // // ResultMacro.type -> // ResultMacro.guide -> [|||||...||...|0] -// ResultMacro.triggerKey -> // // ResultMacroRecord.pos -> // ResultMacroRecord.state -> // ResultMacroRecord.stateType -> -// ResultMacro struct, one is created per ResultMacro, no duplicates -typedef struct ResultMacro { - const MacroType type; - const uint8_t *guide; - const uint8_t triggerKey; -} ResultMacro; - +// ResultMacroRecord struct, one is created per ResultMacro, no duplicates, if a MacroType_Normal typedef struct ResultMacroRecord { var_uint_t pos; - uint8_t state; - uint8_t stateType; + uint8_t state; + uint8_t stateType; } ResultMacroRecord; +// ResultMacro struct, one is created per ResultMacro, no duplicates +typedef const struct ResultMacro { + const MacroType type; + const uint8_t *guide; + ResultMacroRecord *record; +} ResultMacro; + // Guide, key element #define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount typedef struct ResultGuide { @@ -144,18 +144,20 @@ typedef enum TriggerMacroState { TriggerMacro_Waiting, // Awaiting user input } TriggerMacroState; -// TriggerMacro struct, one is created per TriggerMacro, no duplicates -typedef struct TriggerMacro { - const MacroType type; - const uint8_t *guide; - const var_uint_t result; -} TriggerMacro; - +// TriggerMacroRecord struct, one is created per TriggerMacro, no duplicates, if a MacroType_Normal typedef struct TriggerMacroRecord { - var_uint_t pos; + var_uint_t pos; TriggerMacroState state; } TriggerMacroRecord; +// TriggerMacro struct, one is created per TriggerMacro, no duplicates +typedef const struct TriggerMacro { + const MacroType type; + const uint8_t *guide; + const var_uint_t result; + TriggerMacroRecord *record; +} TriggerMacro; + // Guide, key element #define TriggerGuideSize sizeof( TriggerGuide ) typedef struct TriggerGuide { @@ -170,8 +172,8 @@ typedef struct TriggerGuide { // Capability typedef struct Capability { - const void *func; - const uint8_t argCount; + const void *func; + const uint8_t argCount; } Capability; // Total Number of Capabilities @@ -180,15 +182,20 @@ typedef struct Capability { // -- Result Macros -// Guide_RM / Define_RM Pair +// Guide_RM / Record_RM / Define_RM // Guide_RM( index ) = result; // * index - Result Macro index number // * result - Result Macro guide (see ResultMacro) +// Record_RM( index ); +// * index - Result Macro index number // Define_RM( index ); // * index - Result Macro index number -// Must be used after Guide_RM +// Simple macros do not have a record +// Must be used after Guide_RM and Record_RM #define Guide_RM( index ) const uint8_t rm##index##_guide[] -#define Define_RM( index ) { rm##index##_guide } +#define Record_RM( index ) ResultMacroRecord rm##index##_record +#define Define_RM_Normal( index ) { MacroType_Normal, rm##index##_guide, &rm##index##_record } +#define Define_RM_Simple( index ) { MacroType_Simple, rm##index##_guide, 0 } // -- Result Macro List @@ -200,21 +207,19 @@ typedef struct Capability { // -- Trigger Macros -// Guide_TM / Define_TM Trigger Setup +// Guide_TM / Record_TM / Define_TM Trigger Setup // Guide_TM( index ) = trigger; // * index - Trigger Macro index number // * trigger - Trigger Macro guide (see TriggerMacro) -// Define_TM( index, result ); -// +// Record_TM( index ); // * index - Trigger Macro index number -// * result - Result Macro index number which is triggered by this Trigger Macro -// Define_STM( index, result ); -// +// Define_TM( index, result ); // * index - Trigger Macro index number // * result - Result Macro index number which is triggered by this Trigger Macro #define Guide_TM( index ) const uint8_t tm##index##_guide[] -#define Define_TM( index, result ) { MacroType_Normal, tm##index##_guide, result } -#define Define_STM( index, result ) { MacroType_Simple, tm##index##_guide, result } +#define Record_TM( index ) TriggerMacroRecord tm##index##_record +#define Define_TM_Normal( index, result ) { MacroType_Normal, tm##index##_guide, result, &tm##index##_record } +#define Define_TM_Simple( index, result ) { MacroType_Simple, tm##index##_guide, result, 0 } // -- Trigger Macro List @@ -259,9 +264,9 @@ typedef struct Capability { typedef struct Layer { const nat_ptr_t **triggerMap; - const char *name; - const uint8_t first; - const uint8_t last; + const char *name; + const uint8_t first; + const uint8_t last; } Layer; // Layer_IN( map, name, first ); diff --git a/Macro/Common/setup.cmake b/Macro/Common/setup.cmake index 80207d5..513b61a 100644 --- a/Macro/Common/setup.cmake +++ b/Macro/Common/setup.cmake @@ -1,24 +1,29 @@ ###| CMake Kiibohd Controller Macro Module |### # -# Written by Jacob Alexander in 2014 for the Kiibohd Controller +# Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller # # Released into the Public Domain # ### ### -# Warning, that this module is not meant to be built stand-alone +# Sub-module flag, cannot be included stand-alone # -message( FATAL_ERROR -"The 'Common' module is not a stand-alone module, and requires further setup." -) +set ( SubModule 1 ) + ### # Module C files # +set ( Module_SRCS +) ### -# Module Specific Options +# Compiler Family Compatibility # +set ( ModuleCompatibility + arm + avr +) diff --git a/Macro/PartialMap/macro.c b/Macro/PartialMap/macro.c index 5f2cf77..902b1f6 100644 --- a/Macro/PartialMap/macro.c +++ b/Macro/PartialMap/macro.c @@ -26,7 +26,7 @@ #include // Keymaps -#include "usb_hid.h" +#include #include // Generated using kll at compile time, in build directory // Local Includes @@ -485,13 +485,13 @@ inline void Macro_appendResultMacroToPendingList( const TriggerMacro *triggerMac { if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode ) { - ResultMacroRecordList[ resultMacroIndex ].state = macroTriggerListBuffer[ keyIndex ].state; - ResultMacroRecordList[ resultMacroIndex ].stateType = macroTriggerListBuffer[ keyIndex ].type; + ResultMacroList[ resultMacroIndex ].record->state = macroTriggerListBuffer[ keyIndex ].state; + ResultMacroList[ resultMacroIndex ].record->stateType = macroTriggerListBuffer[ keyIndex ].type; } } // Reset the macro position - ResultMacroRecordList[ resultMacroIndex ].pos = 0; + ResultMacroList[ resultMacroIndex ].record->pos = 0; } @@ -644,7 +644,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex ) { // Lookup TriggerMacro const TriggerMacro *macro = &TriggerMacroList[ triggerMacroIndex ]; - TriggerMacroRecord *record = &TriggerMacroRecordList[ triggerMacroIndex ]; + TriggerMacroRecord *record = TriggerMacroList[ triggerMacroIndex ].record; // Check if macro has finished and should be incremented sequence elements if ( record->state == TriggerMacro_Release ) @@ -797,7 +797,7 @@ inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex ) { // Lookup ResultMacro const ResultMacro *macro = &ResultMacroList[ resultMacroIndex ]; - ResultMacroRecord *record = &ResultMacroRecordList[ resultMacroIndex ]; + ResultMacroRecord *record = ResultMacroList[ resultMacroIndex ].record; // Current Macro position var_uint_t pos = record->pos; @@ -889,8 +889,8 @@ inline void Macro_updateTriggerMacroPendingList() macroTriggerMacroPendingList[ macroTriggerMacroPendingListSize++ ] = triggerMacroIndex; // Reset macro position - TriggerMacroRecordList[ triggerMacroIndex ].pos = 0; - TriggerMacroRecordList[ triggerMacroIndex ].state = TriggerMacro_Waiting; + TriggerMacroList[ triggerMacroIndex ].record->pos = 0; + TriggerMacroList[ triggerMacroIndex ].record->state = TriggerMacro_Waiting; } } } @@ -1011,16 +1011,16 @@ inline void Macro_setup() // Initialize TriggerMacro states for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ ) { - TriggerMacroRecordList[ macro ].pos = 0; - TriggerMacroRecordList[ macro ].state = TriggerMacro_Waiting; + TriggerMacroList[ macro ].record->pos = 0; + TriggerMacroList[ macro ].record->state = TriggerMacro_Waiting; } // Initialize ResultMacro states for ( var_uint_t macro = 0; macro < ResultMacroNum; macro++ ) { - ResultMacroRecordList[ macro ].pos = 0; - ResultMacroRecordList[ macro ].state = 0; - ResultMacroRecordList[ macro ].stateType = 0; + ResultMacroList[ macro ].record->pos = 0; + ResultMacroList[ macro ].record->state = 0; + ResultMacroList[ macro ].record->stateType = 0; } } @@ -1358,7 +1358,7 @@ void macroDebugShowTrigger( var_uint_t index ) // Trigger Macro Show const TriggerMacro *macro = &TriggerMacroList[ index ]; - TriggerMacroRecord *record = &TriggerMacroRecordList[ index ]; + TriggerMacroRecord *record = TriggerMacroList[ index ].record; print( NL ); info_msg("Trigger Macro Index: "); @@ -1430,7 +1430,7 @@ void macroDebugShowResult( var_uint_t index ) // Trigger Macro Show const ResultMacro *macro = &ResultMacroList[ index ]; - ResultMacroRecord *record = &ResultMacroRecordList[ index ]; + ResultMacroRecord *record = ResultMacroList[ index ].record; print( NL ); info_msg("Result Macro Index: "); diff --git a/Macro/PartialMap/setup.cmake b/Macro/PartialMap/setup.cmake index 750f974..ba828f6 100644 --- a/Macro/PartialMap/setup.cmake +++ b/Macro/PartialMap/setup.cmake @@ -7,6 +7,12 @@ ### +### +# Required Sub-modules +# +AddModule ( Macro Common ) + + ### # Module C files # From 106e21441d11dc6c013312850b25d414d8ac6bcf Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 9 Feb 2015 23:00:30 -0800 Subject: [PATCH 4/5] Updating documentation. --- Macro/Common/kll.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Macro/Common/kll.h b/Macro/Common/kll.h index 2c1c538..bf3e1de 100644 --- a/Macro/Common/kll.h +++ b/Macro/Common/kll.h @@ -81,8 +81,9 @@ typedef enum MacroType { // Default Args (always sent): key state/analog of last key // Combo Length of 0 signifies end of sequence // -// ResultMacro.type -> -// ResultMacro.guide -> [|||||...||...|0] +// ResultMacro.type -> +// ResultMacro.guide -> [|||||...||...|0] +// ResultMacro.record -> Pointer to ResultMacroRecord if MacroType_Normal // // ResultMacroRecord.pos -> // ResultMacroRecord.state -> @@ -133,6 +134,7 @@ typedef struct ResultGuide { // TriggerMacro.type -> // TriggerMacro.guide -> [|||...|||...|0] // TriggerMacro.result -> +// TriggerMacro.record -> Pointer to TriggrMacroRecord if MacroType_Normal // // TriggerMacroRecord.pos -> // TriggerMacroRecord.state -> From a056317203bb08d086564d34d408e8ed59c59c6c Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Tue, 10 Feb 2015 11:48:18 -0800 Subject: [PATCH 5/5] Basic code for Simple/Normal macro processing - Needs more testing - Simple ResultMacros are called immediately instead of delaying (Normal macros need to be delayed) - Removed old code that determined at runtime if a macro was Simple/Normal (Replaced with a lookup) - Added some flash optimizations --- Macro/Common/kll.h | 2 +- Macro/PartialMap/macro.c | 140 +++++++++++++++++++++++---------------- 2 files changed, 83 insertions(+), 59 deletions(-) diff --git a/Macro/Common/kll.h b/Macro/Common/kll.h index bf3e1de..d6dfd32 100644 --- a/Macro/Common/kll.h +++ b/Macro/Common/kll.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 by Jacob Alexander +/* Copyright (C) 2014-2015 by Jacob Alexander * * This file is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/Macro/PartialMap/macro.c b/Macro/PartialMap/macro.c index 902b1f6..a05552b 100644 --- a/Macro/PartialMap/macro.c +++ b/Macro/PartialMap/macro.c @@ -132,17 +132,17 @@ var_uint_t macroTriggerListLayerCache[ MaxScanCode ]; // TODO, figure out a good way to scale this array size without wasting too much memory, but not rejecting macros // Possibly could be calculated by the KLL compiler // XXX It may be possible to calculate the worst case using the KLL compiler -uint16_t macroTriggerMacroPendingList[ TriggerMacroNum ] = { 0 }; +uint16_t macroTriggerMacroPendingList[ TriggerMacroNum ]; uint16_t macroTriggerMacroPendingListSize = 0; // Layer Index Stack // * When modifying layer state and the state is non-0x0, the stack must be adjusted -uint16_t macroLayerIndexStack[ LayerNum + 1 ] = { 0 }; +uint16_t macroLayerIndexStack[ LayerNum + 1 ]; uint16_t macroLayerIndexStackSize = 0; // Pending Result Macro Index List // * Any result macro that needs processing from a previous macro processing loop -uint16_t macroResultMacroPendingList[ ResultMacroNum ] = { 0 }; +uint16_t macroResultMacroPendingList[ ResultMacroNum ]; uint16_t macroResultMacroPendingListSize = 0; @@ -452,6 +452,32 @@ inline void Macro_ledState( uint8_t ledCode, uint8_t state ) } +// Evaluate a ResultMacro Combination +var_uint_t Macro_evalResultMacroCombo( const uint8_t *guidePos, var_uint_t comboItem, uint8_t comboLength, const uint8_t state, const uint8_t stateType ) +{ + var_uint_t funcCount = 0; + + // Iterate through the Result Combo + while ( funcCount < comboLength ) + { + // Assign TriggerGuide element (key type, state and scancode) + ResultGuide *guide = (ResultGuide*)(&guidePos[ comboItem ]); + + // Do lookup on capability function + void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func); + + // Call capability + capability( state, stateType, &guide->args ); + + // Increment counters + funcCount++; + comboItem += ResultGuideSize( (ResultGuide*)(&guide[ comboItem ]) ); + } + + return comboItem; +} + + // Append result macro to pending list, checking for duplicates // Do nothing if duplicate inline void Macro_appendResultMacroToPendingList( const TriggerMacro *triggerMacro ) @@ -481,40 +507,40 @@ inline void Macro_appendResultMacroToPendingList( const TriggerMacro *triggerMac uint8_t scanCode = ((TriggerGuide*)&triggerMacro->guide[ pos - TriggerGuideSize ])->scanCode; // Lookup scanCode in buffer list for the current state and stateType + TriggerGuide *guide = 0; for ( uint8_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ ) { if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode ) { - ResultMacroList[ resultMacroIndex ].record->state = macroTriggerListBuffer[ keyIndex ].state; - ResultMacroList[ resultMacroIndex ].record->stateType = macroTriggerListBuffer[ keyIndex ].type; + guide = ¯oTriggerListBuffer[ keyIndex ]; + break; } } - // Reset the macro position - ResultMacroList[ resultMacroIndex ].record->pos = 0; -} + // Depending on the type of ResultMacro, either call the capability immediately, or delay + switch ( ResultMacroList[ resultMacroIndex ].type ) + { + // Simple ResultMacro + case MacroType_Simple: + // Call Capability immediately instead of waiting + // This means we don't have to store the state and type information + // (It would be thrown away during this scan cycle anyways) + Macro_evalResultMacroCombo( ResultMacroList[ resultMacroIndex ].guide, 1, ResultMacroList[ resultMacroIndex ].guide[ 0 ], guide->state, guide->type ); + break; + // Complex ResultMacro + case MacroType_Normal: + ResultMacroList[ resultMacroIndex ].record->state = guide->state; + ResultMacroList[ resultMacroIndex ].record->stateType = guide->type; -// Determine if long ResultMacro (more than 1 seqence element) -inline uint8_t Macro_isLongResultMacro( const ResultMacro *macro ) -{ - // Check the second sequence combo length - // If non-zero return non-zero (long sequence) - // 0 otherwise (short sequence) - var_uint_t position = 1; - for ( var_uint_t result = 0; result < macro->guide[0]; result++ ) - position += ResultGuideSize( (ResultGuide*)¯o->guide[ position ] ); - return macro->guide[ position ]; -} + // Reset the macro position + ResultMacroList[ resultMacroIndex ].record->pos = 0; + break; - -// Determine if long TriggerMacro (more than 1 sequence element) -inline uint8_t Macro_isLongTriggerMacro( const TriggerMacro *macro ) -{ - // Check the second sequence combo length - // If non-zero return non-zero (long sequence) - // 0 otherwise (short sequence) - return macro->guide[ macro->guide[0] * TriggerGuideSize + 1 ]; + default: + erro_print("Invalid MacroType. This is a bug"); + break; + } } @@ -666,7 +692,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex ) } // Check if this is a long Trigger Macro - uint8_t longMacro = Macro_isLongTriggerMacro( macro ); + uint8_t longMacro = macro->type == MacroType_Normal; // Iterate through the items in the combo, voting the on the key state // If any of the pressed keys do not match, fail the macro @@ -752,7 +778,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex ) if ( macro->guide[ pos + comboLength + 1 ] == 0 ) { // Long result macro (more than 1 combo) - if ( Macro_isLongResultMacro( &ResultMacroList[ macro->result ] ) ) + if ( ResultMacroList[ macro->result ].type == MacroType_Normal ) { // Only ever trigger result once, on press if ( overallVote == TriggerMacroVote_Pass ) @@ -764,7 +790,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex ) else { // Only trigger result once, on press, if long trigger (more than 1 combo) - if ( Macro_isLongTriggerMacro( macro ) ) + if ( macro->type == MacroType_Normal ) { return TriggerMacroEval_DoResultAndRemove; } @@ -799,34 +825,23 @@ inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex ) const ResultMacro *macro = &ResultMacroList[ resultMacroIndex ]; ResultMacroRecord *record = ResultMacroList[ resultMacroIndex ].record; + // If this is a simple ResultMacro, the capability has already been called, remove + if ( macro->type == MacroType_Simple ) + { + return ResultMacroEval_Remove; + } + // Current Macro position var_uint_t pos = record->pos; // Length of combo being processed uint8_t comboLength = macro->guide[ pos ]; - // Function Counter, used to keep track of the combo items processed - var_uint_t funcCount = 0; - // Combo Item Position within the guide var_uint_t comboItem = pos + 1; - // Iterate through the Result Combo - while ( funcCount < comboLength ) - { - // Assign TriggerGuide element (key type, state and scancode) - ResultGuide *guide = (ResultGuide*)(¯o->guide[ comboItem ]); - - // Do lookup on capability function - void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func); - - // Call capability - capability( record->state, record->stateType, &guide->args ); - - // Increment counters - funcCount++; - comboItem += ResultGuideSize( (ResultGuide*)(¯o->guide[ comboItem ]) ); - } + // Evaluate ResultCombo + comboItem = Macro_evalResultMacroCombo( macro->guide, comboItem, comboLength, record->state, record->stateType ); // Move to next item in the sequence record->pos = comboItem; @@ -1011,16 +1026,22 @@ inline void Macro_setup() // Initialize TriggerMacro states for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ ) { - TriggerMacroList[ macro ].record->pos = 0; - TriggerMacroList[ macro ].record->state = TriggerMacro_Waiting; + if ( TriggerMacroList[ macro ].type == MacroType_Normal ) + { + TriggerMacroList[ macro ].record->pos = 0; + TriggerMacroList[ macro ].record->state = TriggerMacro_Waiting; + } } // Initialize ResultMacro states for ( var_uint_t macro = 0; macro < ResultMacroNum; macro++ ) { - ResultMacroList[ macro ].record->pos = 0; - ResultMacroList[ macro ].record->state = 0; - ResultMacroList[ macro ].record->stateType = 0; + if ( ResultMacroList[ macro ].type == MacroType_Normal ) + { + ResultMacroList[ macro ].record->pos = 0; + ResultMacroList[ macro ].record->state = 0; + ResultMacroList[ macro ].record->stateType = 0; + } } } @@ -1502,10 +1523,13 @@ void macroDebugShowResult( var_uint_t index ) printInt16( (uint16_t)record->pos ); // Hopefully large enough :P (can't assume 32-bit) // Display final trigger state/type - print( NL "Final Trigger State (State/Type): " ); - printHex( record->state ); - print("/"); - printHex( record->stateType ); + if ( macro->type == MacroType_Normal ) + { + print( NL "Final Trigger State (State/Type): " ); + printHex( record->state ); + print("/"); + printHex( record->stateType ); + } } void cliFunc_macroShow( char* args )