-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (43 loc) · 1.39 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"time"
"github.com/Martijn-Faber/ambilight/config"
"github.com/Martijn-Faber/ambilight/internal/block"
"github.com/Martijn-Faber/ambilight/internal/protocol/wled"
"github.com/Martijn-Faber/ambilight/pkg/color"
"github.com/Martijn-Faber/ambilight/pkg/screenshot"
"github.com/Martijn-Faber/ambilight/util"
)
func main() {
config, err := config.Load()
if err != nil {
panic(err)
}
wled.Init(config.WledIp, config.WledPort)
scrWidth, scrHeight, _ := util.GetScreenInfo()
blkSizeX, blkSizeY := block.CalculateBlockSize(scrWidth, scrHeight, config.NumLedsX, config.NumLedsY)
numBlkX, numBlkY := block.CalculateNumBlocks(scrWidth, scrHeight, blkSizeX, blkSizeY)
var prevClrs []color.Rgb
for {
img, err := screenshot.CaptureScreen()
if err != nil {
panic(err)
}
nextClrs := block.GetBlocks(img, blkSizeX, blkSizeY, numBlkX, numBlkY, scrWidth)
if len(prevClrs) == 0 {
prevClrs = nextClrs
}
for i := 0; i < config.InterpolSteps; i++ {
clrs := color.InterpolateColors(prevClrs, nextClrs, (i + 1), config.InterpolSteps)
for _, clr := range clrs {
clrs[i] = color.CorrectColor(clr, color.Rgb{R: config.RCorrection, G: config.GCorrection, B: config.BCorrection})
}
err = wled.Send(clrs)
if err != nil {
panic(err)
}
prevClrs = nextClrs
time.Sleep(time.Duration(config.RefTimeMs/config.InterpolSteps) * time.Millisecond)
}
}
}