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