rework color system and make it work with drivers.
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-02-21 19:27:42 +01:00
parent d5cf30ea4b
commit df865574bf
16 changed files with 468 additions and 179 deletions
+21 -9
View File
@@ -10,7 +10,6 @@ import (
"io"
"io/ioutil"
"log"
"math"
"net"
"net/http"
"strconv"
@@ -31,11 +30,12 @@ type bridge struct {
func (b *bridge) Devices() []models.Device {
results := make([]models.Device, 0, len(b.panels))
for i, panel := range b.panels {
// Find normalized RGB and intensity
red := float64(panel.ColorRGBA[0]) / 255.0
green := float64(panel.ColorRGBA[1]) / 255.0
blue := float64(panel.ColorRGBA[2]) / 255.0
hue, sat, value := colorful.LinearRgb(red, green, blue).Hsv()
hue, sat, value := colorful.Color{R: red, G: green, B: blue}.Hsv()
rgb := colorful.Hsv(hue, sat, 1)
shapeType, shapeTypeOK := shapeTypeMap[panel.ShapeType]
if !shapeTypeOK {
@@ -70,10 +70,11 @@ func (b *bridge) Devices() []models.Device {
UserProperties: nil,
State: models.DeviceState{
Power: panel.ColorRGBA[3] == 0,
Color: models.ColorValue{
Hue: math.Mod(hue, 360),
Saturation: sat,
},
Color: models.ColorValue{RGB: &models.ColorRGB{
Red: rgb.R,
Green: rgb.G,
Blue: rgb.B,
}},
Intensity: value,
Temperature: 0,
},
@@ -172,9 +173,20 @@ func (b *bridge) Update(devices []models.Device) {
for _, panel := range b.panels {
if panel.ID == uint16(id) {
if device.State.Power {
color := colorful.Hsv(device.State.Color.Hue, device.State.Color.Saturation, device.State.Intensity)
rgbColor, ok := device.State.Color.ToRGB()
if !ok {
newColor := [4]byte{255, 255, 255, 255}
if newColor != panel.ColorRGBA {
panel.update(newColor, time.Now().Add(time.Millisecond*220))
}
red, green, blue := color.RGB255()
continue
}
rgb := rgbColor.RGB.AtIntensity(device.State.Intensity)
red := byte(rgb.Red * 255.9)
green := byte(rgb.Green * 255.9)
blue := byte(rgb.Blue * 255.9)
newColor := [4]byte{red, green, blue, 255}
if newColor != panel.ColorRGBA {
panel.update(newColor, time.Now().Add(time.Millisecond*220))