simplify more

This commit is contained in:
Felix Roos 2025-02-02 22:18:56 +01:00
parent 95b1548e5f
commit b87b2aff9a
No known key found for this signature in database

View File

@ -117,15 +117,13 @@ function normalize(value = 0, min = 0, max = 1, exp = 1) {
return Math.pow(normalized, exp); return Math.pow(normalized, exp);
} }
function mapCC(mapping, value) { function mapCC(mapping, value) {
const ccs = []; return Object.keys(value)
const matches = Object.entries(value).filter(([key]) => !!mapping[getControlName(key)]); .filter((key) => !!mapping[getControlName(key)])
matches.forEach((match) => { .map((key) => {
const control = match[0]; const { ccn, min = 0, max = 1, exp = 1 } = mapping[key];
const { ccn, min = 0, max = 1, exp = 1 } = mapping[control]; const ccv = normalize(value[key], min, max, exp);
const ccv = normalize(value[control], min, max, exp); return { ccn, ccv };
ccs.push({ ccn, ccv }); });
});
return ccs;
} }
// sends a cc message to the given device on the given channel // sends a cc message to the given device on the given channel