Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnthonySimek: Brightness fix + ReadMe.md typo #56

Merged
merged 2 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Homebridge Simple WLED

Hombridge Plugin for WLED Strip ([WLED-Project by Aircoookie](https://github.com/Aircoookie/WLED))
Homebridge Plugin for WLED Strip ([WLED-Project by Aircoookie](https://github.com/Aircoookie/WLED))

### ❓HELP
For faster support and Informations join my discord https://discord.gg/qpbUtZCB2H
Expand Down
41 changes: 20 additions & 21 deletions src/wled-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class WLED {

this.lightService.getCharacteristic(this.hap.Characteristic.Hue)
.on(CharacteristicEventTypes.GET, (callback: CharacteristicGetCallback) => {
let colorArray = this.HSVtoRGB(this.hue, this.saturation, this.currentBrightnessToPercent());
let colorArray = this.HSVtoRGB(this.hue, this.saturation);
this.colorArray = colorArray;
if (this.debug)
this.log("Current hue: " + this.hue + "%");
Expand All @@ -243,7 +243,7 @@ export class WLED {

this.hue = value as number;
this.turnOffAllEffects();
let colorArray = this.HSVtoRGB(this.hue, this.saturation, this.currentBrightnessToPercent());
let colorArray = this.HSVtoRGB(this.hue, this.saturation);

this.host.forEach((host) => {
httpSendData(`http://${host}/json`, "POST", { "bri": this.brightness, "seg": [{ "col": [colorArray] }] }, (error: any, response: any) => { if (error) this.log("Error while changing color of WLED " + this.name + " (" + host + ")"); });
Expand Down Expand Up @@ -341,13 +341,13 @@ export class WLED {
this.turnOffWLED();
return;
}
let colorArray = this.HSVtoRGB(this.hue, this.saturation, this.currentBrightnessToPercent());
let colorArray = this.HSVtoRGB(this.hue, this.saturation);
this.colorArray = colorArray;
if (this.debug)
this.log("COLOR ARRAY BRIGHTNESS: " + colorArray);

this.host.forEach((host) => {
httpSendData(`http://${host}/json`, "POST", { "bri": this.brightness, "seg": [{ "col": [this.colorArray] }] }, (error: any, response: any) => { if (error) return; });
httpSendData(`http://${host}/json`, "POST", { "bri": this.brightness }, (error: any, response: any) => { if (error) return; });
});
}

Expand Down Expand Up @@ -517,36 +517,35 @@ export class WLED {


/* accepts parameters
* h Object = {h:x, s:y, v:z}
* h Object = {h:x, s:y}
* OR
* h, s, v
* h, s
*/
HSVtoRGB(h: any, s: any, v: any): any {
HSVtoRGB(h: any, s: any): any {
h = h / 360;
s = s / 100;
v = v / 100;

var r, g, b, i, f, p, q, t;
if (arguments.length === 1) {
s = h.s, v = h.v, h = h.h;
s = h.s, h = h.h;
}
i = Math.floor(h * 6);
f = h * 6 - i;
p = v * (1 - s);
q = v * (1 - f * s);
t = v * (1 - (1 - f) * s);
p = (1 - s);
q = (1 - f * s);
t = (1 - (1 - f) * s);
switch (i % 6) {
case 0: r = v, g = t, b = p; break;
case 1: r = q, g = v, b = p; break;
case 2: r = p, g = v, b = t; break;
case 3: r = p, g = q, b = v; break;
case 4: r = t, g = p, b = v; break;
case 5: r = v, g = p, b = q; break;
case 0: r = 1, g = t, b = p; break;
case 1: r = q, g = 1, b = p; break;
case 2: r = p, g = 1, b = t; break;
case 3: r = p, g = q, b = 1; break;
case 4: r = t, g = p, b = 1; break;
case 5: r = 1, g = p, b = q; break;
}
return [
Math.round(r * 255),
Math.round(g * 255),
Math.round(b * 255)
Math.round((r as number) * 255),
Math.round((g as number) * 255),
Math.round((b as number) * 255)
];
}

Expand Down