From e2a28044190917a2e66a2546b6e2b911822d6d29 Mon Sep 17 00:00:00 2001 From: velvettear Date: Mon, 7 Mar 2022 23:19:18 +0100 Subject: [PATCH] multiple bug fixes, now powering off all connected blinksticks --- blinky.js | 2 +- libs/cli.js | 2 +- libs/controller.js | 13 ++++++++++++- libs/server.js | 3 +++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/blinky.js b/blinky.js index 8df2513..b7225be 100644 --- a/blinky.js +++ b/blinky.js @@ -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(); } diff --git a/libs/cli.js b/libs/cli.js index 2dac6d3..6908887 100644 --- a/libs/cli.js +++ b/libs/cli.js @@ -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; } diff --git a/libs/controller.js b/libs/controller.js index bdd693b..c5db499 100644 --- a/libs/controller.js +++ b/libs/controller.js @@ -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, diff --git a/libs/server.js b/libs/server.js index 2296356..5bde9b8 100644 --- a/libs/server.js +++ b/libs/server.js @@ -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);