forked from mcuadros/go-rpi-rgb-led-matrix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.go
54 lines (41 loc) · 924 Bytes
/
server.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
package rpc
import (
"fmt"
"image/color"
"log"
"net"
"net/http"
"net/rpc"
"gopkg.in/RockKeeper/go-rpi-rgb-led-matrix.v1"
)
type RPCMatrix struct {
m rgbmatrix.Matrix
}
type GeometryArgs struct{}
type GeometryReply struct{ Width, Height int }
func (m *RPCMatrix) Geometry(_ *GeometryArgs, reply *GeometryReply) error {
w, h := m.m.Geometry()
reply.Width = w
reply.Height = h
return nil
}
type ApplyArgs struct{ Colors []color.Color }
type ApplyReply struct{}
func (m *RPCMatrix) Apply(args *ApplyArgs, reply *ApplyReply) error {
return m.m.Apply(args.Colors)
}
type CloseArgs struct{}
type CloseReply struct{}
func (m *RPCMatrix) Close(_ *CloseArgs, _ *CloseReply) error {
return m.m.Close()
}
func Serve(m rgbmatrix.Matrix) {
rpc.Register(&RPCMatrix{m})
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":1234")
if e != nil {
log.Fatal("listen error:", e)
}
fmt.Println(l)
http.Serve(l, nil)
}