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_STOP = [];
// find connected blinkstick(s)
async function findBlinkstick(index) {
let blinksticks = blinkstick.findAll();
@ -33,13 +32,10 @@ async function simple(config) {
config.timestamp = new Date().getTime();
let indices = getIndices(config);
for (let index = 0; index < indices.length; index++) {
try {
await setLedAnimated(indices[index]);
await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]);
} finally {
await clearLedState(indices[index]);
}
}
return {
status: 'ok',
color: config.color,
@ -56,16 +52,13 @@ async function complex(config) {
}
let indices = getIndices(config);
for (let index = 0; index < indices.length; index++) {
try {
if (shouldLedFinish(config)) {
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++;
} finally {
await clearLedState(indices[index]);
}
}
return complex(config);
}
@ -74,7 +67,7 @@ async function complex(config) {
async function powerOff(config) {
config.timestamp = new Date().getTime();
let indices = getIndices(config);
await forceStop(indices);
await forceStop();
for (let index = 0; index < indices.length; index++) {
await singleAnimation(JSON.parse(JSON.stringify(config)), indices[index]);
logger.info('led \'' + indices[index] + '\' powered off');
@ -121,7 +114,12 @@ async function singleAnimation(config, index) {
async function stopLedsAccordingly(config) {
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);
}