-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (48 loc) · 960 Bytes
/
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
package main
import (
"fmt"
"image"
"io"
"log"
"time"
"./imglib"
"./screenshot"
"./serial"
)
func capture(c *screenshot.Connection, s io.ReadWriteCloser) *image.RGBA {
start := time.Now()
img, err := screenshot.CaptureScreen(c)
if err != nil {
panic(err)
}
color, err := imglib.AvgImgColor(img)
if err == nil {
fmt.Println("#" + imglib.GetColorHex(color))
serial.SendColor(s, color)
elapsed := time.Since(start)
log.Printf("Elapsed %g seconds", elapsed.Seconds())
time.Sleep(time.Duration(250 * time.Millisecond))
}
return img
}
func main() {
options := serial.OpenOptions{
PortName: "/dev/ttyACM0",
BaudRate: 9600,
DataBits: 8,
StopBits: 1,
MinimumReadSize: 4,
}
c := screenshot.Connect()
s := serial.Connect(options)
defer c.Close()
defer s.Close()
go func() {
for {
capture(c, s)
}
}()
fmt.Println("Press enter to exit")
var input string
fmt.Scanf("%s", &input)
}