multiple bug fixes, now powering off all connected blinksticks

This commit is contained in:
Daniel Sommer 2022-03-07 23:19:18 +01:00
parent a2fc7cbcfe
commit e2a2804419
4 changed files with 17 additions and 3 deletions

View file

@ -26,7 +26,7 @@ async function main() {
if (await cli.handleArguments()) {
util.exit();
}
await controller.mapBlinkSticks();
controller.mapBlinkSticks();
logger.info(await server.start());
server.handleRequests();
}

View file

@ -11,7 +11,7 @@ async function handleArguments() {
continue;
case constants.ARG_LIST:
case constants.ARG_LIST_SHORT:
logger.info('blinksticks: ' + JSON.stringify(await controller.findBlinkstick('strip11', true)));
logger.info('blinksticks: ' + JSON.stringify(await controller.getBlinkstick(constants.ALL, false)));
handled++;
break;
}

View file

@ -47,7 +47,7 @@ function mapBlinkSticks(filter) {
break;
}
}
if (blinksticks.length === 0) {
if (blinksticks.size === 0) {
if (filter) {
throw new Error('could not find any blinkstick matching the given serial(s)');
} else {
@ -124,6 +124,16 @@ async function complex(config) {
// power the blinkstick (or just a specific led) off
async function powerOff(config) {
config.timestamp = new Date().getTime();
if (config.blinkstick === constants.ALL) {
const promises = [];
const blinkstickNames = Array.from(blinksticks.keys());
for (let index = 0; index < blinkstickNames.length; index++) {
const tmp = JSON.parse(JSON.stringify(config));
tmp.blinkstick = blinkstickNames[index];
promises.push(powerOff(tmp));
}
return await Promise.allSettled(promises);
}
let indexes = getIndices(config);
if (config.options.index === constants.ALL) {
LEDAnimations.set(constants.ALL, { stop: new Date().getTime() });
@ -324,6 +334,7 @@ function isInfiniteAnimation(config) {
// exports
module.exports = {
getBlinkstick,
mapBlinkSticks,
simple,
complex,

View file

@ -99,6 +99,9 @@ async function handleComplexAnimation(config, response) {
async function handlePowerOff(config, response) {
try {
if (config.blinkstick === undefined) {
config.blinkstick = constants.ALL;
}
response.end(JSON.stringify(await controller.powerOff(config)));
} catch (err) {
response.status(500);