display pedal color by state

This commit is contained in:
Daniel Sommer 2022-03-14 22:37:42 +01:00
parent 4697dcb6ff
commit 5c8a141e68
3 changed files with 52 additions and 20 deletions

View file

@ -25,9 +25,19 @@
"host": "192.168.1.70", "host": "192.168.1.70",
"port": 3000, "port": 3000,
"colors": { "colors": {
"BigMuffPi": "#065535", "BigMuffPi": {
"Overdrive": "#ffcc55", "enabled": "#008800",
"StompBox_fuzz": "#C767B0" "bypassed": "002200"
} },
"Overdrive": {
"enabled": "#888800",
"bypassed": "#222200"
},
"StompBox_fuzz": {
"enabled": "#7700AA",
"bypassed": "#220022"
}
},
"Bypass": "#333333"
} }
} }

View file

@ -53,16 +53,16 @@ async function setPedalStatus(pedal) {
if (bypass.name !== CONTROL_BYPASS) { if (bypass.name !== CONTROL_BYPASS) {
continue; continue;
} }
const args = { return httpPOST(
blinkstick: "strip", global.config.blinky.host,
index: pedal.id global.config.blinky.port,
}; 'set',
let mode = 'poweroff'; {
if (bypass.value !== undefined && bypass.value > 0) { blinkstick: "strip",
mode = 'set'; index: pedal.id,
args.color = getPedalColorByName(pedal.name); color: getPedalColor(pedal.name, (bypass.value === undefined || bypass.value === 0))
} }
return httpPOST(global.config.blinky.host, global.config.blinky.port, mode, args); );
} }
} }
@ -108,8 +108,14 @@ async function setBypass(bypassActive) {
} }
} }
function getPedalColorByName(name) { function getPedalColor(name, bypassed) {
return global.config.blinky?.colors[name] || 'random'; 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 = { module.exports = {

View file

@ -12,7 +12,7 @@ function timeDiff(startTime) {
} }
function clone(object) { function clone(object) {
var clone = {}; let clone = {};
for (key in object) { for (key in object) {
clone[key] = object[key]; clone[key] = object[key];
} }
@ -52,13 +52,13 @@ function httpRequest(host, port, path, method, args) {
if (!response) { if (!response) {
return reject('no response from host for ' + requestName); return reject('no response from host for ' + requestName);
} }
var responseData = ""; let responseData = "";
response.on('data', function (data) { response.on('data', function (data) {
responseData += data; responseData += data;
}); });
response.on('end', function () { response.on('end', function () {
logger.debug(requestName + ' returned status code \'' + response.statusCode + '\' and data \'' + responseData + '\''); logger.debug(requestName + ' returned status code \'' + response.statusCode + '\' and data \'' + responseData + '\'');
var fn = resolve; let fn = resolve;
if (response.statusCode != 200) { if (response.statusCode != 200) {
fn = reject; fn = reject;
} }
@ -84,10 +84,25 @@ function httpRequest(host, port, path, method, args) {
} }
function toHex(value) { function toHex(value) {
var hex = Number(value).toString(16); let hex = Number(value).toString(16);
return hex; 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) { function sortById(array) {
return array.sort(function (a, b) { return array.sort(function (a, b) {
return a.id - b.id; return a.id - b.id;
@ -131,6 +146,7 @@ module.exports = {
httpGET, httpGET,
httpPOST, httpPOST,
toHex, toHex,
hexToRGB,
sortById, sortById,
fileExists, fileExists,
resolvePath resolvePath