diff --git a/config.json b/config.json index cae30eb..96f10b1 100644 --- a/config.json +++ b/config.json @@ -25,9 +25,19 @@ "host": "192.168.1.70", "port": 3000, "colors": { - "BigMuffPi": "#065535", - "Overdrive": "#ffcc55", - "StompBox_fuzz": "#C767B0" - } + "BigMuffPi": { + "enabled": "#008800", + "bypassed": "002200" + }, + "Overdrive": { + "enabled": "#888800", + "bypassed": "#222200" + }, + "StompBox_fuzz": { + "enabled": "#7700AA", + "bypassed": "#220022" + } + }, + "Bypass": "#333333" } } \ No newline at end of file diff --git a/libs/blinky.js b/libs/blinky.js index ef5f77e..79bd655 100644 --- a/libs/blinky.js +++ b/libs/blinky.js @@ -53,16 +53,16 @@ async function setPedalStatus(pedal) { if (bypass.name !== CONTROL_BYPASS) { continue; } - const args = { - blinkstick: "strip", - index: pedal.id - }; - let mode = 'poweroff'; - if (bypass.value !== undefined && bypass.value > 0) { - mode = 'set'; - args.color = getPedalColorByName(pedal.name); - } - return httpPOST(global.config.blinky.host, global.config.blinky.port, mode, args); + return httpPOST( + global.config.blinky.host, + global.config.blinky.port, + 'set', + { + blinkstick: "strip", + index: pedal.id, + color: getPedalColor(pedal.name, (bypass.value === undefined || bypass.value === 0)) + } + ); } } @@ -108,8 +108,14 @@ async function setBypass(bypassActive) { } } -function getPedalColorByName(name) { - return global.config.blinky?.colors[name] || 'random'; +function getPedalColor(name, bypassed) { + let color; + if (bypassed) { + color = global.config.blinky?.colors[name]?.bypassed || global.config.blinky?.colors['Bypass'] || '#333333'; + } else { + color = global.config.blinky?.colors[name]?.enabled || 'random'; + } + return color; } module.exports = { diff --git a/libs/util.js b/libs/util.js index 5e1c6c4..a6a2162 100644 --- a/libs/util.js +++ b/libs/util.js @@ -12,7 +12,7 @@ function timeDiff(startTime) { } function clone(object) { - var clone = {}; + let clone = {}; for (key in object) { clone[key] = object[key]; } @@ -52,13 +52,13 @@ function httpRequest(host, port, path, method, args) { if (!response) { return reject('no response from host for ' + requestName); } - var responseData = ""; + let responseData = ""; response.on('data', function (data) { responseData += data; }); response.on('end', function () { logger.debug(requestName + ' returned status code \'' + response.statusCode + '\' and data \'' + responseData + '\''); - var fn = resolve; + let fn = resolve; if (response.statusCode != 200) { fn = reject; } @@ -84,10 +84,25 @@ function httpRequest(host, port, path, method, args) { } function toHex(value) { - var hex = Number(value).toString(16); + let hex = Number(value).toString(16); return hex; } +function hexToRGB(hex) { + let validHEXInput = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + if (!validHEXInput) { + return; + } + let output = [ + { + red: parseInt(validHEXInput[1], 16), + green: parseInt(validHEXInput[2], 16), + blue: parseInt(validHEXInput[3], 16), + }, + ]; + return output; +} + function sortById(array) { return array.sort(function (a, b) { return a.id - b.id; @@ -131,6 +146,7 @@ module.exports = { httpGET, httpPOST, toHex, + hexToRGB, sortById, fileExists, resolvePath