2 Commits
Author SHA1 Message Date
gisle 582bf3f46b decrease sensitivity in hue2 (should fix double press, regular check over-updating and massive update storms when regular checks find a lot of incongruences), and fix rare race condition
continuous-integration/drone/push Build is passing
2022-02-19 10:06:40 +01:00
gisle c72a7c3f43 fix xy color conversion using srgb instead of rgb.
continuous-integration/drone/push Build is passing
2022-02-18 17:01:37 +01:00
2 changed files with 16 additions and 2 deletions
+15 -1
View File
@@ -55,6 +55,7 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
absences := make(map[int]time.Time) absences := make(map[int]time.Time)
lastPress := make(map[string]time.Time) lastPress := make(map[string]time.Time)
lastUpdate := time.Now()
needFull := false needFull := false
for { for {
@@ -62,6 +63,10 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
case <-ctx.Done(): case <-ctx.Done():
return ctx.Err() return ctx.Err()
case <-lightRefreshTimer.C: case <-lightRefreshTimer.C:
if time.Since(lastUpdate) < time.Second*10 {
continue
}
if needFull { if needFull {
err := b.RefreshAll(ctx) err := b.RefreshAll(ctx)
if err != nil { if err != nil {
@@ -79,9 +84,16 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
return err return err
} }
if updated > 0 { if updated > 0 {
// Force this to cool for 30 seconds unless a manual update occurs.
if updated > 10 {
lastUpdate = time.Now().Add(time.Second * 15)
}
log.Println(fmt.Sprintf("[Bridge %d]", b.externalID), "Updated", updated, "hue services (regular check)") log.Println(fmt.Sprintf("[Bridge %d]", b.externalID), "Updated", updated, "hue services (regular check)")
} }
case <-b.needsUpdate: case <-b.needsUpdate:
lastUpdate = time.Now()
updated, err := b.MakeCongruent(ctx) updated, err := b.MakeCongruent(ctx)
if err != nil { if err != nil {
return err return err
@@ -125,9 +137,11 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
continue continue
} }
b.mu.Lock()
if b.resources[patch.Owner.ID] == nil { if b.resources[patch.Owner.ID] == nil {
needFull = true needFull = true
} }
b.mu.Unlock()
device, deviceOK := b.devices[patch.Owner.ID] device, deviceOK := b.devices[patch.Owner.ID]
if !deviceOK || device.ID == 0 { if !deviceOK || device.ID == 0 {
@@ -141,7 +155,7 @@ func (b *Bridge) Run(ctx context.Context, eventCh chan<- models.Event) error {
} else if patch.Button.LastEvent == "long_release" { } else if patch.Button.LastEvent == "long_release" {
valid = false valid = false
} else { } else {
valid = lastPress[patch.ID].Unix() != data.CreationTime.Unix() valid = data.CreationTime.Sub(lastPress[patch.ID]) >= time.Second*2
} }
if valid { if valid {
+1 -1
View File
@@ -177,7 +177,7 @@ func hsToXY(hue, sat float64) ColorXY {
green := float64(green255) / 255.0 green := float64(green255) / 255.0
blue := float64(blue255) / 255.0 blue := float64(blue255) / 255.0
return screenRGBToXY(red, green, blue) return rgbToXY(red, green, blue)
} }
func rgbToXY(red float64, green float64, blue float64) ColorXY { func rgbToXY(red float64, green float64, blue float64) ColorXY {