-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (71 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"github.com/e-asphyx/rpiws"
"github.com/e-asphyx/tpm2net"
"log"
"net"
"os"
"os/signal"
"syscall"
)
const (
ListenAddr = ":65506"
VirtualWidth = 44
VirtualHeight = 44
Oversample = 8
)
func main() {
// Layout manager
layout := HexLayout{
EdgeLen: 6,
InvertOddRows: true,
}
// WS281x driver
wsDriver := rpiws.Driver{
Freq: rpiws.WS2811_TARGET_FREQ,
Dmanum: 5,
Channel: [rpiws.RPI_PWM_CHANNELS]rpiws.Channel{
rpiws.Channel{
Gpionum: 18,
Count: int32(layout.NumCells()),
Brightness: 255,
},
},
}
err := wsDriver.Init()
if err != nil {
log.Fatal(err)
}
defer wsDriver.Fini()
output := NewWSOutput(&wsDriver, 0)
handler := TPMHandler{
VirtualWidth: VirtualWidth,
VirtualHeight: VirtualHeight,
Oversample: Oversample,
Layout: &layout,
Output: output,
}
// TPM2Net server
server := tpm2net.Server{
MaxPacketNum: 0,
MaxPacketSize: VirtualWidth * VirtualHeight * 3,
}
sigch := make(chan os.Signal, 1)
signal.Notify(sigch, syscall.SIGINT, syscall.SIGTERM)
conn, err := net.ListenPacket("udp", ListenAddr)
if err != nil {
log.Fatal(err)
}
/*---------------------------------------------------------------*/
log.Println("Ready")
notify := make(chan int)
go func() {
server.Serve(conn, &handler)
notify <- 1
}()
<-sigch
conn.Close()
<-notify
output.Stop()
log.Println("Bye")
}