@@ -38,6 +38,8 @@ void InputMacro::preprocess()
3838 if (focusModeOptions.enabled && focusModeOptions.macroLockEnabled ) return ;
3939 Gamepad * gamepad = Storage::getInstance ().GetGamepad ();
4040 uint32_t allPins = ~gpio_get_all ();
41+ macroInputPressed = false ;
42+ uint64_t currentMicros = getMicro ();
4143
4244 if (macroPosition == -1 || inputMacroOptions.macroList [macroPosition].interruptible ) {
4345 int newMacroPosition = -1 ;
@@ -69,10 +71,21 @@ void InputMacro::preprocess()
6971 if (newMacroPosition != macroPosition ||
7072 (newMacroPosition == macroPosition &&
7173 inputMacroOptions.macroList [newMacroPosition].macroType == ON_PRESS &&
72- isMacroRunning)) {
73- reset ();
74- return ;
75- }
74+ isMacroRunning && (macroTriggerDebounceStartTime != 0 || (!prevMacroInputPressed && macroInputPressed)))) {
75+ if (macroTriggerDebounceStartTime == 0 ) {
76+ macroTriggerDebounceStartTime = currentMicros;
77+ }
78+
79+ if (macroTriggerDebounceStartTime != 0 ) {
80+ if (((currentMicros - macroTriggerDebounceStartTime) > 500 )) {
81+ macroTriggerDebounceStartTime = 0 ;
82+ if (macroInputPressed) {
83+ reset ();
84+ return ;
85+ }
86+ }
87+ }
88+ }
7689 }
7790
7891 if (newMacroPosition != -1 && !isMacroRunning) {
@@ -91,8 +104,6 @@ void InputMacro::preprocess()
91104 macroInputPressed = (allPins & 1 << macro.macroTriggerPin );
92105 }
93106
94- uint64_t currentMicros = getMicro ();
95-
96107 if (!isMacroRunning && macroInputPressed && macroTriggerDebounceStartTime == 0 ) {
97108 macroTriggerDebounceStartTime = currentMicros;
98109 return ;
@@ -138,11 +149,11 @@ void InputMacro::preprocess()
138149
139150 MacroInput& macroInput = macro.macroInputs [macroInputPosition];
140151 uint32_t macroInputDuration = macroInput.duration + macroInput.waitDuration ;
152+ macroInputHoldTime = macroInputDuration <= 0 ? INPUT_HOLD_US : macroInputDuration;
141153
142154 if (!isMacroRunning && isMacroTriggerHeld) {
143155 isMacroRunning = true ;
144156 macroStartTime = currentMicros;
145- macroInputHoldTime = macroInputDuration <= 0 ? INPUT_HOLD_US : macroInputDuration;
146157 }
147158
148159 if (!isMacroRunning)
@@ -205,10 +216,7 @@ void InputMacro::preprocess()
205216 isMacroTriggerHeld = isMacroTriggerHeld && isMacroTypeLoopable;
206217 isMacroRunning = isMacroTriggerHeld;
207218 macroPosition = (isMacroTypeLoopable && isMacroTriggerHeld) ? macroPosition : -1 ;
208- if (isMacroTypeLoopable && !isMacroTriggerHeld) {
209- macroStartTime = 0 ;
210- macroInputHoldTime = INPUT_HOLD_US;
211- }
219+ macroStartTime = currentMicros;
212220 }
213221}
214222
0 commit comments