multiple bug fixes, now powering off all connected blinksticks
This commit is contained in:
parent
a2fc7cbcfe
commit
e2a2804419
4 changed files with 17 additions and 3 deletions
|
@ -26,7 +26,7 @@ async function main() {
|
||||||
if (await cli.handleArguments()) {
|
if (await cli.handleArguments()) {
|
||||||
util.exit();
|
util.exit();
|
||||||
}
|
}
|
||||||
await controller.mapBlinkSticks();
|
controller.mapBlinkSticks();
|
||||||
logger.info(await server.start());
|
logger.info(await server.start());
|
||||||
server.handleRequests();
|
server.handleRequests();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ async function handleArguments() {
|
||||||
continue;
|
continue;
|
||||||
case constants.ARG_LIST:
|
case constants.ARG_LIST:
|
||||||
case constants.ARG_LIST_SHORT:
|
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++;
|
handled++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ function mapBlinkSticks(filter) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (blinksticks.length === 0) {
|
if (blinksticks.size === 0) {
|
||||||
if (filter) {
|
if (filter) {
|
||||||
throw new Error('could not find any blinkstick matching the given serial(s)');
|
throw new Error('could not find any blinkstick matching the given serial(s)');
|
||||||
} else {
|
} else {
|
||||||
|
@ -124,6 +124,16 @@ async function complex(config) {
|
||||||
// power the blinkstick (or just a specific led) off
|
// power the blinkstick (or just a specific led) off
|
||||||
async function powerOff(config) {
|
async function powerOff(config) {
|
||||||
config.timestamp = new Date().getTime();
|
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);
|
let indexes = getIndices(config);
|
||||||
if (config.options.index === constants.ALL) {
|
if (config.options.index === constants.ALL) {
|
||||||
LEDAnimations.set(constants.ALL, { stop: new Date().getTime() });
|
LEDAnimations.set(constants.ALL, { stop: new Date().getTime() });
|
||||||
|
@ -324,6 +334,7 @@ function isInfiniteAnimation(config) {
|
||||||
|
|
||||||
// exports
|
// exports
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
getBlinkstick,
|
||||||
mapBlinkSticks,
|
mapBlinkSticks,
|
||||||
simple,
|
simple,
|
||||||
complex,
|
complex,
|
||||||
|
|
|
@ -99,6 +99,9 @@ async function handleComplexAnimation(config, response) {
|
||||||
|
|
||||||
async function handlePowerOff(config, response) {
|
async function handlePowerOff(config, response) {
|
||||||
try {
|
try {
|
||||||
|
if (config.blinkstick === undefined) {
|
||||||
|
config.blinkstick = constants.ALL;
|
||||||
|
}
|
||||||
response.end(JSON.stringify(await controller.powerOff(config)));
|
response.end(JSON.stringify(await controller.powerOff(config)));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
response.status(500);
|
response.status(500);
|
||||||
|
|
Loading…
Reference in a new issue