extended function to find connected blinkstick(s)

This commit is contained in:
Daniel Sommer 2022-02-24 10:57:41 +01:00
parent 323e3b0b5e
commit 2a7386d262

View file

@ -15,15 +15,18 @@ const LEDS = new Map();
let stop = false;
// find a connected blinkstick
function findBlinkstick() {
return new Promise((resolve, reject) => {
let led = blinkstick.findFirst();
if (led === undefined) {
reject('could not find any blinkstick');
}
resolve(led);
});
// find connected blinkstick(s)
async function findBlinkstick(index) {
let blinksticks = blinkstick.findAll();
if (blinksticks.length === 0) {
throw new Error('could not find any blinkstick');
}
if (index === undefined) {
index = 0;
}
if (index <= blinksticks.length) {
return blinksticks[index];
}
}
// simple animation (set the color / morph to color)
@ -69,7 +72,6 @@ async function complex(config) {
return complex(config);
} catch (err) {
logger.error(err);
return err;
}
}
@ -91,7 +93,8 @@ async function powerOff(config) {
}
return {status: 'ok', indices: indices, time: (new Date().getTime() - config.timestamp) + 'ms'};
} catch (err) {
return err;
logger.error(err);
throw err;
}
}
@ -126,7 +129,7 @@ async function singleAnimation(config, index) {
}
});
} catch (err) {
return err;
throw err;
}
}