extended function to find connected blinkstick(s)
This commit is contained in:
parent
323e3b0b5e
commit
2a7386d262
1 changed files with 15 additions and 12 deletions
|
@ -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');
|
||||
// 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];
|
||||
}
|
||||
resolve(led);
|
||||
});
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue