-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdevice.go
114 lines (101 loc) · 2.47 KB
/
device.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package pixoo64
import (
"net/http"
"net/netip"
"strconv"
)
type Device struct {
client *Client
channel *Channel
display *Display
}
func (d *Device) Display() *Display {
return d.display
}
func (d *Device) Channel() *Channel {
return d.channel
}
// NewDevice creates a new device with the given address.
func NewDevice(addr netip.Addr) (*Device, error) {
client := &Client{
addr: addr,
httpClient: http.DefaultClient,
}
display, err := NewDisplay(client)
if err != nil {
return nil, err
}
return &Device{
client: client,
channel: &Channel{client: client},
display: display,
}, nil
}
func (d *Device) Alert() error {
return d.PlayBuzzer(500, 500, 3000)
}
func (d *Device) PlayBuzzer(activeTimeInCycle int, offTimeInCycle int, playTotalTime int) error {
var jsonData = []byte(`{
"Command":"Device/PlayBuzzer",
"ActiveTimeInCycle":` + strconv.FormatInt(int64(activeTimeInCycle), 10) + `,
"OffTimeInCycle":` + strconv.FormatInt(int64(offTimeInCycle), 10) + `,
"PlayTotalTime":` + strconv.FormatInt(int64(playTotalTime), 10) + `
}`)
_, err := d.client.Post(jsonData)
if err != nil {
return err
}
return nil
}
type Status int
const (
Stop Status = 0
Start Status = 1
)
func (d *Device) Countdown(minute int, second int, status Status) error {
var jsonData = []byte(` {
"Command":"Tools/SetTimer",
"Minute": ` + strconv.FormatInt(int64(minute), 10) + `,
"Second": ` + strconv.FormatInt(int64(second), 10) + `,
"Status": ` + strconv.FormatInt(int64(status), 10) + `
}`)
_, err := d.client.Post(jsonData)
if err != nil {
return err
}
return nil
}
func (d *Device) Stopwatch(status Status) error {
var jsonData = []byte(` {
"Command":"Tools/SetStopWatch",
"Status": ` + strconv.FormatInt(int64(status), 10) + `
}`)
_, err := d.client.Post(jsonData)
if err != nil {
return err
}
return nil
}
func (d *Device) Scoreboard(blueScore int, redScore int) error {
var jsonData = []byte(` {
"Command":"Tools/SetScoreBoard",
"BlueScore": ` + strconv.FormatInt(int64(blueScore), 10) + `,
"RedScore": ` + strconv.FormatInt(int64(redScore), 10) + `
}`)
_, err := d.client.Post(jsonData)
if err != nil {
return err
}
return nil
}
func (d *Device) Noise(status Status) error {
var jsonData = []byte(` {
"Command":"Tools/SetNoiseStatus",
"NoiseStatus": ` + strconv.FormatInt(int64(status), 10) + `
}`)
_, err := d.client.Post(jsonData)
if err != nil {
return err
}
return nil
}