Compare commits
5 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a056317203 | ||
![]() |
106e21441d | ||
![]() |
b4c1951b0d | ||
![]() |
d63886954c | ||
![]() |
775e4eab8f |
6 changed files with 181 additions and 94 deletions
|
@ -64,7 +64,7 @@ endif ()
|
||||||
|
|
||||||
#| Configure DefaultMap if specified
|
#| Configure DefaultMap if specified
|
||||||
if ( NOT "${DefaultMap}" STREQUAL "" )
|
if ( NOT "${DefaultMap}" STREQUAL "" )
|
||||||
set ( DefaultMap_Args -d )
|
set ( DefaultMap_Args --default )
|
||||||
|
|
||||||
string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
|
string ( REPLACE " " ";" MAP_LIST ${DefaultMap} ) # Change spaces to semicolons
|
||||||
foreach ( MAP ${MAP_LIST} )
|
foreach ( MAP ${MAP_LIST} )
|
||||||
|
@ -83,7 +83,7 @@ endif ()
|
||||||
if ( NOT "${PartialMaps}" STREQUAL "" )
|
if ( NOT "${PartialMaps}" STREQUAL "" )
|
||||||
# For each partial layer
|
# For each partial layer
|
||||||
foreach ( MAP ${PartialMaps} )
|
foreach ( MAP ${PartialMaps} )
|
||||||
set ( PartialMap_Args ${PartialMap_Args} -p )
|
set ( PartialMap_Args ${PartialMap_Args} --partial )
|
||||||
|
|
||||||
# Combine each layer
|
# Combine each layer
|
||||||
string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
|
string ( REPLACE " " ";" MAP_LIST ${MAP} ) # Change spaces to semicolons
|
||||||
|
|
|
@ -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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -64,6 +64,15 @@ typedef uint16_t nat_ptr_t;
|
||||||
|
|
||||||
// ----- Structs -----
|
// ----- 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
|
// -- Result Macro
|
||||||
// Defines the sequence of combinations to as the Result of Trigger 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
|
// For RAM optimization reasons, ResultMacro has been split into ResultMacro and ResultMacroRecord structures
|
||||||
|
@ -72,23 +81,28 @@ typedef uint16_t nat_ptr_t;
|
||||||
// Default Args (always sent): key state/analog of last key
|
// Default Args (always sent): key state/analog of last key
|
||||||
// Combo Length of 0 signifies end of sequence
|
// Combo Length of 0 signifies end of sequence
|
||||||
//
|
//
|
||||||
|
// ResultMacro.type -> <Type of macro>
|
||||||
// ResultMacro.guide -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
|
// ResultMacro.guide -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
|
||||||
|
// ResultMacro.record -> Pointer to ResultMacroRecord if MacroType_Normal
|
||||||
//
|
//
|
||||||
// ResultMacroRecord.pos -> <current combo position>
|
// ResultMacroRecord.pos -> <current combo position>
|
||||||
// ResultMacroRecord.state -> <last key state>
|
// ResultMacroRecord.state -> <last key state>
|
||||||
// ResultMacroRecord.stateType -> <last key state type>
|
// ResultMacroRecord.stateType -> <last key state type>
|
||||||
|
|
||||||
// ResultMacro struct, one is created per ResultMacro, no duplicates
|
// ResultMacroRecord struct, one is created per ResultMacro, no duplicates, if a MacroType_Normal
|
||||||
typedef struct ResultMacro {
|
|
||||||
const uint8_t *guide;
|
|
||||||
} ResultMacro;
|
|
||||||
|
|
||||||
typedef struct ResultMacroRecord {
|
typedef struct ResultMacroRecord {
|
||||||
var_uint_t pos;
|
var_uint_t pos;
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
uint8_t stateType;
|
uint8_t stateType;
|
||||||
} ResultMacroRecord;
|
} 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
|
// Guide, key element
|
||||||
#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
|
#define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
|
||||||
typedef struct ResultGuide {
|
typedef struct ResultGuide {
|
||||||
|
@ -117,8 +131,10 @@ typedef struct ResultGuide {
|
||||||
//
|
//
|
||||||
// Combo Length of 0 signifies end of sequence
|
// Combo Length of 0 signifies end of sequence
|
||||||
//
|
//
|
||||||
|
// TriggerMacro.type -> <Type of macro>
|
||||||
// TriggerMacro.guide -> [<combo length>|<key1 type>|<key1 state>|<key1>...<keyn type>|<keyn state>|<keyn>|<combo length>...|0]
|
// TriggerMacro.guide -> [<combo length>|<key1 type>|<key1 state>|<key1>...<keyn type>|<keyn state>|<keyn>|<combo length>...|0]
|
||||||
// TriggerMacro.result -> <index to result macro>
|
// TriggerMacro.result -> <index to result macro>
|
||||||
|
// TriggerMacro.record -> Pointer to TriggrMacroRecord if MacroType_Normal
|
||||||
//
|
//
|
||||||
// TriggerMacroRecord.pos -> <current combo position>
|
// TriggerMacroRecord.pos -> <current combo position>
|
||||||
// TriggerMacroRecord.state -> <status of the macro pos>
|
// TriggerMacroRecord.state -> <status of the macro pos>
|
||||||
|
@ -130,17 +146,20 @@ typedef enum TriggerMacroState {
|
||||||
TriggerMacro_Waiting, // Awaiting user input
|
TriggerMacro_Waiting, // Awaiting user input
|
||||||
} TriggerMacroState;
|
} TriggerMacroState;
|
||||||
|
|
||||||
// TriggerMacro struct, one is created per TriggerMacro, no duplicates
|
// TriggerMacroRecord struct, one is created per TriggerMacro, no duplicates, if a MacroType_Normal
|
||||||
typedef struct TriggerMacro {
|
|
||||||
const uint8_t *guide;
|
|
||||||
const var_uint_t result;
|
|
||||||
} TriggerMacro;
|
|
||||||
|
|
||||||
typedef struct TriggerMacroRecord {
|
typedef struct TriggerMacroRecord {
|
||||||
var_uint_t pos;
|
var_uint_t pos;
|
||||||
TriggerMacroState state;
|
TriggerMacroState state;
|
||||||
} TriggerMacroRecord;
|
} 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
|
// Guide, key element
|
||||||
#define TriggerGuideSize sizeof( TriggerGuide )
|
#define TriggerGuideSize sizeof( TriggerGuide )
|
||||||
typedef struct TriggerGuide {
|
typedef struct TriggerGuide {
|
||||||
|
@ -165,15 +184,20 @@ typedef struct Capability {
|
||||||
|
|
||||||
// -- Result Macros
|
// -- Result Macros
|
||||||
|
|
||||||
// Guide_RM / Define_RM Pair
|
// Guide_RM / Record_RM / Define_RM
|
||||||
// Guide_RM( index ) = result;
|
// Guide_RM( index ) = result;
|
||||||
// * index - Result Macro index number
|
// * index - Result Macro index number
|
||||||
// * result - Result Macro guide (see ResultMacro)
|
// * result - Result Macro guide (see ResultMacro)
|
||||||
|
// Record_RM( index );
|
||||||
|
// * index - Result Macro index number
|
||||||
// Define_RM( index );
|
// Define_RM( index );
|
||||||
// * index - Result Macro index number
|
// * 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 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
|
// -- Result Macro List
|
||||||
|
@ -185,15 +209,19 @@ typedef struct Capability {
|
||||||
|
|
||||||
// -- Trigger Macros
|
// -- Trigger Macros
|
||||||
|
|
||||||
// Guide_TM / Define_TM Trigger Setup
|
// Guide_TM / Record_TM / Define_TM Trigger Setup
|
||||||
// Guide_TM( index ) = trigger;
|
// Guide_TM( index ) = trigger;
|
||||||
// * index - Trigger Macro index number
|
// * index - Trigger Macro index number
|
||||||
// * trigger - Trigger Macro guide (see TriggerMacro)
|
// * trigger - Trigger Macro guide (see TriggerMacro)
|
||||||
|
// Record_TM( index );
|
||||||
|
// * index - Trigger Macro index number
|
||||||
// Define_TM( index, result );
|
// Define_TM( index, result );
|
||||||
// * index - Trigger Macro index number
|
// * index - Trigger Macro index number
|
||||||
// * result - Result Macro index number which is triggered by this Trigger Macro
|
// * result - Result Macro index number which is triggered by this Trigger Macro
|
||||||
#define Guide_TM( index ) const uint8_t tm##index##_guide[]
|
#define Guide_TM( index ) const uint8_t tm##index##_guide[]
|
||||||
#define Define_TM( index, result ) { 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
|
// -- Trigger Macro List
|
29
Macro/Common/setup.cmake
Normal file
29
Macro/Common/setup.cmake
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
###| CMake Kiibohd Controller Macro Module |###
|
||||||
|
#
|
||||||
|
# Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller
|
||||||
|
#
|
||||||
|
# Released into the Public Domain
|
||||||
|
#
|
||||||
|
###
|
||||||
|
|
||||||
|
###
|
||||||
|
# Sub-module flag, cannot be included stand-alone
|
||||||
|
#
|
||||||
|
set ( SubModule 1 )
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Module C files
|
||||||
|
#
|
||||||
|
set ( Module_SRCS
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Compiler Family Compatibility
|
||||||
|
#
|
||||||
|
set ( ModuleCompatibility
|
||||||
|
arm
|
||||||
|
avr
|
||||||
|
)
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include <scan_loop.h>
|
#include <scan_loop.h>
|
||||||
|
|
||||||
// Keymaps
|
// Keymaps
|
||||||
#include "usb_hid.h"
|
#include <usb_hid.h>
|
||||||
#include <generatedKeymap.h> // Generated using kll at compile time, in build directory
|
#include <generatedKeymap.h> // Generated using kll at compile time, in build directory
|
||||||
|
|
||||||
// Local Includes
|
// Local Includes
|
||||||
|
@ -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
|
// 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
|
// Possibly could be calculated by the KLL compiler
|
||||||
// XXX It may be possible to calculate the worst case using 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;
|
uint16_t macroTriggerMacroPendingListSize = 0;
|
||||||
|
|
||||||
// Layer Index Stack
|
// Layer Index Stack
|
||||||
// * When modifying layer state and the state is non-0x0, the stack must be adjusted
|
// * 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;
|
uint16_t macroLayerIndexStackSize = 0;
|
||||||
|
|
||||||
// Pending Result Macro Index List
|
// Pending Result Macro Index List
|
||||||
// * Any result macro that needs processing from a previous macro processing loop
|
// * 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;
|
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
|
// Append result macro to pending list, checking for duplicates
|
||||||
// Do nothing if duplicate
|
// Do nothing if duplicate
|
||||||
inline void Macro_appendResultMacroToPendingList( const TriggerMacro *triggerMacro )
|
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;
|
uint8_t scanCode = ((TriggerGuide*)&triggerMacro->guide[ pos - TriggerGuideSize ])->scanCode;
|
||||||
|
|
||||||
// Lookup scanCode in buffer list for the current state and stateType
|
// Lookup scanCode in buffer list for the current state and stateType
|
||||||
|
TriggerGuide *guide = 0;
|
||||||
for ( uint8_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ )
|
for ( uint8_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ )
|
||||||
{
|
{
|
||||||
if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode )
|
if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode )
|
||||||
{
|
{
|
||||||
ResultMacroRecordList[ resultMacroIndex ].state = macroTriggerListBuffer[ keyIndex ].state;
|
guide = ¯oTriggerListBuffer[ keyIndex ];
|
||||||
ResultMacroRecordList[ resultMacroIndex ].stateType = macroTriggerListBuffer[ keyIndex ].type;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
// Reset the macro position
|
// Reset the macro position
|
||||||
ResultMacroRecordList[ resultMacroIndex ].pos = 0;
|
ResultMacroList[ resultMacroIndex ].record->pos = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
erro_print("Invalid MacroType. This is a bug");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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 ];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 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 ];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -644,7 +670,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex )
|
||||||
{
|
{
|
||||||
// Lookup TriggerMacro
|
// Lookup TriggerMacro
|
||||||
const TriggerMacro *macro = &TriggerMacroList[ triggerMacroIndex ];
|
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
|
// Check if macro has finished and should be incremented sequence elements
|
||||||
if ( record->state == TriggerMacro_Release )
|
if ( record->state == TriggerMacro_Release )
|
||||||
|
@ -666,7 +692,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this is a long Trigger Macro
|
// 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
|
// 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
|
// 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 )
|
if ( macro->guide[ pos + comboLength + 1 ] == 0 )
|
||||||
{
|
{
|
||||||
// Long result macro (more than 1 combo)
|
// 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
|
// Only ever trigger result once, on press
|
||||||
if ( overallVote == TriggerMacroVote_Pass )
|
if ( overallVote == TriggerMacroVote_Pass )
|
||||||
|
@ -764,7 +790,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex )
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Only trigger result once, on press, if long trigger (more than 1 combo)
|
// 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;
|
return TriggerMacroEval_DoResultAndRemove;
|
||||||
}
|
}
|
||||||
|
@ -797,7 +823,13 @@ inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex )
|
||||||
{
|
{
|
||||||
// Lookup ResultMacro
|
// Lookup ResultMacro
|
||||||
const ResultMacro *macro = &ResultMacroList[ resultMacroIndex ];
|
const ResultMacro *macro = &ResultMacroList[ resultMacroIndex ];
|
||||||
ResultMacroRecord *record = &ResultMacroRecordList[ 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
|
// Current Macro position
|
||||||
var_uint_t pos = record->pos;
|
var_uint_t pos = record->pos;
|
||||||
|
@ -805,28 +837,11 @@ inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex )
|
||||||
// Length of combo being processed
|
// Length of combo being processed
|
||||||
uint8_t comboLength = macro->guide[ pos ];
|
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
|
// Combo Item Position within the guide
|
||||||
var_uint_t comboItem = pos + 1;
|
var_uint_t comboItem = pos + 1;
|
||||||
|
|
||||||
// Iterate through the Result Combo
|
// Evaluate ResultCombo
|
||||||
while ( funcCount < comboLength )
|
comboItem = Macro_evalResultMacroCombo( macro->guide, comboItem, comboLength, record->state, record->stateType );
|
||||||
{
|
|
||||||
// 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 ]) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move to next item in the sequence
|
// Move to next item in the sequence
|
||||||
record->pos = comboItem;
|
record->pos = comboItem;
|
||||||
|
@ -889,8 +904,8 @@ inline void Macro_updateTriggerMacroPendingList()
|
||||||
macroTriggerMacroPendingList[ macroTriggerMacroPendingListSize++ ] = triggerMacroIndex;
|
macroTriggerMacroPendingList[ macroTriggerMacroPendingListSize++ ] = triggerMacroIndex;
|
||||||
|
|
||||||
// Reset macro position
|
// Reset macro position
|
||||||
TriggerMacroRecordList[ triggerMacroIndex ].pos = 0;
|
TriggerMacroList[ triggerMacroIndex ].record->pos = 0;
|
||||||
TriggerMacroRecordList[ triggerMacroIndex ].state = TriggerMacro_Waiting;
|
TriggerMacroList[ triggerMacroIndex ].record->state = TriggerMacro_Waiting;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1011,16 +1026,22 @@ inline void Macro_setup()
|
||||||
// Initialize TriggerMacro states
|
// Initialize TriggerMacro states
|
||||||
for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
|
for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
|
||||||
{
|
{
|
||||||
TriggerMacroRecordList[ macro ].pos = 0;
|
if ( TriggerMacroList[ macro ].type == MacroType_Normal )
|
||||||
TriggerMacroRecordList[ macro ].state = TriggerMacro_Waiting;
|
{
|
||||||
|
TriggerMacroList[ macro ].record->pos = 0;
|
||||||
|
TriggerMacroList[ macro ].record->state = TriggerMacro_Waiting;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize ResultMacro states
|
// Initialize ResultMacro states
|
||||||
for ( var_uint_t macro = 0; macro < ResultMacroNum; macro++ )
|
for ( var_uint_t macro = 0; macro < ResultMacroNum; macro++ )
|
||||||
{
|
{
|
||||||
ResultMacroRecordList[ macro ].pos = 0;
|
if ( ResultMacroList[ macro ].type == MacroType_Normal )
|
||||||
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 +1379,7 @@ void macroDebugShowTrigger( var_uint_t index )
|
||||||
|
|
||||||
// Trigger Macro Show
|
// Trigger Macro Show
|
||||||
const TriggerMacro *macro = &TriggerMacroList[ index ];
|
const TriggerMacro *macro = &TriggerMacroList[ index ];
|
||||||
TriggerMacroRecord *record = &TriggerMacroRecordList[ index ];
|
TriggerMacroRecord *record = TriggerMacroList[ index ].record;
|
||||||
|
|
||||||
print( NL );
|
print( NL );
|
||||||
info_msg("Trigger Macro Index: ");
|
info_msg("Trigger Macro Index: ");
|
||||||
|
@ -1430,7 +1451,7 @@ void macroDebugShowResult( var_uint_t index )
|
||||||
|
|
||||||
// Trigger Macro Show
|
// Trigger Macro Show
|
||||||
const ResultMacro *macro = &ResultMacroList[ index ];
|
const ResultMacro *macro = &ResultMacroList[ index ];
|
||||||
ResultMacroRecord *record = &ResultMacroRecordList[ index ];
|
ResultMacroRecord *record = ResultMacroList[ index ].record;
|
||||||
|
|
||||||
print( NL );
|
print( NL );
|
||||||
info_msg("Result Macro Index: ");
|
info_msg("Result Macro Index: ");
|
||||||
|
@ -1502,11 +1523,14 @@ void macroDebugShowResult( var_uint_t index )
|
||||||
printInt16( (uint16_t)record->pos ); // Hopefully large enough :P (can't assume 32-bit)
|
printInt16( (uint16_t)record->pos ); // Hopefully large enough :P (can't assume 32-bit)
|
||||||
|
|
||||||
// Display final trigger state/type
|
// Display final trigger state/type
|
||||||
|
if ( macro->type == MacroType_Normal )
|
||||||
|
{
|
||||||
print( NL "Final Trigger State (State/Type): " );
|
print( NL "Final Trigger State (State/Type): " );
|
||||||
printHex( record->state );
|
printHex( record->state );
|
||||||
print("/");
|
print("/");
|
||||||
printHex( record->stateType );
|
printHex( record->stateType );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void cliFunc_macroShow( char* args )
|
void cliFunc_macroShow( char* args )
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
# Written by Jacob Alexander in 2014-2015 for the Kiibohd Controller
|
||||||
#
|
#
|
||||||
|
@ -7,6 +7,12 @@
|
||||||
###
|
###
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
# Required Sub-modules
|
||||||
|
#
|
||||||
|
AddModule ( Macro Common )
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Module C files
|
# Module C files
|
||||||
#
|
#
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue