fixed stopping of multiple active animations

This commit is contained in:
Daniel Sommer 2022-02-24 14:53:17 +01:00
parent b6c2e04db2
commit 9ae6acba36

View file

@ -12,7 +12,6 @@ const MODE_POWEROFF = 'poweroff';
const LEDS_ANIMATED = []; const LEDS_ANIMATED = [];
const LEDS_STOP = []; const LEDS_STOP = [];
// find connected blinkstick(s) // find connected blinkstick(s)
async function findBlinkstick(index) { async function findBlinkstick(index) {
let blinksticks = blinkstick.findAll(); let blinksticks = blinkstick.findAll();
@ -33,12 +32,9 @@ async function simple(config) {
config.timestamp = new Date().getTime(); config.timestamp = new Date().getTime();
let indices = getIndices(config); let indices = getIndices(config);
for (let index = 0; index < indices.length; index++) { for (let index = 0; index < indices.length; index++) {
try { await setLedAnimated(indices[index]);
await setLedAnimated(indices[index]); await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]);
await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]); await clearLedState(indices[index]);
} finally {
await clearLedState(indices[index]);
}
} }
return { return {
status: 'ok', status: 'ok',
@ -56,16 +52,13 @@ async function complex(config) {
} }
let indices = getIndices(config); let indices = getIndices(config);
for (let index = 0; index < indices.length; index++) { for (let index = 0; index < indices.length; index++) {
try { if (shouldLedFinish(config)) {
if (shouldLedFinish(config)) {
return {status: 'ok', time: (new Date().getTime() - config.timestamp) + 'ms'};
}
await setLedAnimated(indices[index]);
await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]);
config.repetitions.done++;
} finally {
await clearLedState(indices[index]); await clearLedState(indices[index]);
return {status: 'ok', time: (new Date().getTime() - config.timestamp) + 'ms'};
} }
await setLedAnimated(indices[index]);
await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]);
config.repetitions.done++;
} }
return complex(config); return complex(config);
} }
@ -74,7 +67,7 @@ async function complex(config) {
async function powerOff(config) { async function powerOff(config) {
config.timestamp = new Date().getTime(); config.timestamp = new Date().getTime();
let indices = getIndices(config); let indices = getIndices(config);
await forceStop(indices); await forceStop();
for (let index = 0; index < indices.length; index++) { for (let index = 0; index < indices.length; index++) {
await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]); await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]);
logger.info('led \'' + indices[index] + '\' powered off'); logger.info('led \'' + indices[index] + '\' powered off');
@ -121,7 +114,12 @@ async function singleAnimation(config, index) {
async function stopLedsAccordingly(config) { async function stopLedsAccordingly(config) {
if (config.options.index === LEDS_ALL) { if (config.options.index === LEDS_ALL) {
return await powerOff({id: Math.random(), mode: MODE_POWEROFF, color: '#000000', options: {index: LEDS_ALL}}); return await powerOff({
id: Math.random(),
mode: MODE_POWEROFF,
color: '#000000',
options: {index: LEDS_ALL}
});
} }
return stopLedAnimation(config.options.index); return stopLedAnimation(config.options.index);
} }