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",
"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"
}
}

View file

@ -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 = {

View file

@ -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