From 37bd68e9de150e2eb83fd2872cf2553967f21d8c Mon Sep 17 00:00:00 2001 From: velvettear Date: Thu, 24 Feb 2022 15:24:08 +0100 Subject: [PATCH] some more fixes --- libs/blinkstick.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libs/blinkstick.js b/libs/blinkstick.js index a4a5edb..274b2ab 100644 --- a/libs/blinkstick.js +++ b/libs/blinkstick.js @@ -58,6 +58,9 @@ async function complex(config) { } await setLedAnimated(indices[index]); await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]); + if (config.options.index === LEDS_ALL) { + await clearLedState(indices[index]); + } config.repetitions.done++; } return complex(config); @@ -67,7 +70,7 @@ async function complex(config) { async function powerOff(config) { config.timestamp = new Date().getTime(); let indices = getIndices(config); - await forceStop(); + await forceStop(config.options.index); for (let index = 0; index < indices.length; index++) { await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]); logger.info('led \'' + indices[index] + '\' powered off'); @@ -124,10 +127,18 @@ async function stopLedsAccordingly(config) { return stopLedAnimation(config.options.index); } -async function forceStop() { - LEDS_STOP.push(LEDS_ALL); +async function forceStop(index) { + if (index === LEDS_ALL) { + LEDS_STOP.push(LEDS_ALL); + return await new Promise((resolve, reject) => { + waitForAllAnimationsEnd(() => { + resolve(); + }); + }); + } + setLedStopping(index); return await new Promise((resolve, reject) => { - waitForAllAnimationsEnd(() => { + waitForAnimationEnd(index, () => { resolve(); }); });