-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
66 lines (58 loc) · 1.08 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
package sopolight
import (
"net"
"net/http"
"strconv"
)
type PatlitePattern struct {
Name string
ID int
}
var Off = PatlitePattern{Name: "off", ID: 0}
var On = PatlitePattern{Name: "on", ID: 1}
type Patlite struct {
Ipaddr net.IP
Red PatlitePattern
Yellow PatlitePattern
Green PatlitePattern
Buzzer PatlitePattern
}
func Init(Ipaddr net.IP) *Patlite {
p := &Patlite{
Ipaddr: Ipaddr,
Red: Off,
Yellow: Off,
Green: Off,
Buzzer: Off,
}
p.SendClearToPatlite()
return p
}
func (p *Patlite) SendClearToPatlite() error {
url := "http://" +
p.Ipaddr.String() +
"/api/control?clear=1"
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}
func (p *Patlite) SendAlertToPatlite() error {
url := "http://" +
p.Ipaddr.String() +
"/api/control?alert=" +
strconv.Itoa(p.Red.ID) +
strconv.Itoa(p.Yellow.ID) +
strconv.Itoa(p.Green.ID) +
"0" + // 青は未使用
"0" + // 白は未使用
strconv.Itoa(p.Buzzer.ID)
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}