From 24550a5b80e1a626a7d8090746c0cfda2bfb4b23 Mon Sep 17 00:00:00 2001 From: DmitryBlinov Date: Fri, 19 Feb 2021 22:07:11 +0200 Subject: [PATCH] garland: implement commands queue --- code/espurna/garland.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/code/espurna/garland.cpp b/code/espurna/garland.cpp index 36b385dc..7dfb2692 100644 --- a/code/espurna/garland.cpp +++ b/code/espurna/garland.cpp @@ -337,15 +337,20 @@ void garlandLoop(void) { unsigned long currentAnimRunTime = millis() - _lastTimeUpdate; if (currentAnimRunTime > _currentAnimDuration && scene.finishedAnimCycle()) { - unsigned int newAnimInd = _currentAnimInd; - while (newAnimInd == _currentAnimInd) newAnimInd = secureRandom(1, animsSize()); + if (!_commands.empty()) { + executeCommand(_commands.front()); + _commands.pop(); + } else { + unsigned int newAnimInd = _currentAnimInd; + while (newAnimInd == _currentAnimInd) newAnimInd = secureRandom(1, animsSize()); - unsigned int newPalInd = _currentPaletteInd; - while (newPalInd == _currentPaletteInd) newPalInd = secureRandom(palsSize()); + unsigned int newPalInd = _currentPaletteInd; + while (newPalInd == _currentPaletteInd) newPalInd = secureRandom(palsSize()); - unsigned long newAnimDuration = secureRandom(EFFECT_UPDATE_INTERVAL_MIN, EFFECT_UPDATE_INTERVAL_MAX); + unsigned long newAnimDuration = secureRandom(EFFECT_UPDATE_INTERVAL_MIN, EFFECT_UPDATE_INTERVAL_MAX); - setupScene(newAnimInd, newPalInd, newAnimDuration); + setupScene(newAnimInd, newPalInd, newAnimDuration); + } } }