From 4eb0dbb5a43278fbf03f3392a53fe6c6bd5f742c Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Mon, 7 Feb 2022 11:13:12 +0100 Subject: [PATCH] repeat actions cleanup & fix --- wled00/ir.cpp | 76 ++++++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 50 deletions(-) diff --git a/wled00/ir.cpp b/wled00/ir.cpp index 6a8cd919..0358fdfa 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -162,6 +162,7 @@ void decodeIR(uint32_t code) return; } lastValidCode = 0; irTimesRepeated = 0; + lastRepeatableAction = ACTION_NONE; if (decodeIRCustom(code)) return; if (irEnabled == 8) { // any remote configurable with ir.json file decodeIRJson(code); @@ -193,56 +194,31 @@ void decodeIR(uint32_t code) colorUpdated(CALL_MODE_BUTTON); //for notifier, IR is considered a button input } -void applyRepeatActions(){ - - if (irEnabled == 8) - { - decodeIRJson(lastValidCode); - } - else - { - if (lastRepeatableAction == ACTION_BRIGHT_UP) - { - incBrightness(); colorUpdated(CALL_MODE_BUTTON); - } - else if (lastRepeatableAction == ACTION_BRIGHT_DOWN ) - { - decBrightness(); colorUpdated(CALL_MODE_BUTTON); - } - - if (lastRepeatableAction == ACTION_SPEED_UP) - { - changeEffectSpeed(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); - } - else if (lastRepeatableAction == ACTION_SPEED_DOWN ) - { - changeEffectSpeed(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); - } - - if (lastRepeatableAction == ACTION_INTENSITY_UP) - { - changeEffectIntensity(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); - } - else if (lastRepeatableAction == ACTION_INTENSITY_DOWN ) - { - changeEffectIntensity(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); - } - - if (lastValidCode == IR40_WPLUS) - { - relativeChangeWhite(10); colorUpdated(CALL_MODE_BUTTON); - } - else if (lastValidCode == IR40_WMINUS) - { - relativeChangeWhite(-10, 5); colorUpdated(CALL_MODE_BUTTON); - } - else if ((lastValidCode == IR24_ON || lastValidCode == IR40_ON) && irTimesRepeated > 7 ) - { - nightlightActive = true; - nightlightStartTime = millis(); - colorUpdated(CALL_MODE_BUTTON); - } - } +void applyRepeatActions() +{ + if (irEnabled == 8) { + decodeIRJson(lastValidCode); + return; + } else switch (lastRepeatableAction) { + case ACTION_BRIGHT_UP : incBrightness(); colorUpdated(CALL_MODE_BUTTON); return; + case ACTION_BRIGHT_DOWN : decBrightness(); colorUpdated(CALL_MODE_BUTTON); return; + case ACTION_SPEED_UP : changeEffectSpeed(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); return; + case ACTION_SPEED_DOWN : changeEffectSpeed(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); return; + case ACTION_INTENSITY_UP : changeEffectIntensity(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); return; + case ACTION_INTENSITY_DOWN : changeEffectIntensity(lastRepeatableValue); colorUpdated(CALL_MODE_BUTTON); return; + default: break; + } + if (lastValidCode == IR40_WPLUS) { + relativeChangeWhite(10); + colorUpdated(CALL_MODE_BUTTON); + } else if (lastValidCode == IR40_WMINUS) { + relativeChangeWhite(-10, 5); + colorUpdated(CALL_MODE_BUTTON); + } else if ((lastValidCode == IR24_ON || lastValidCode == IR40_ON) && irTimesRepeated > 7 ) { + nightlightActive = true; + nightlightStartTime = millis(); + colorUpdated(CALL_MODE_BUTTON); + } } void decodeIR24(uint32_t code)