-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
82 lines (69 loc) · 2.35 KB
/
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
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
package main
import (
"context"
mykeyboard "github.com/jedipunkz/mygobot/pkg/keyboard"
myremo "github.com/jedipunkz/myremo/pkg/remo"
"github.com/spf13/viper"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/keyboard"
)
type serverCommand struct{}
func (c *serverCommand) Help() string {
return "Usage: remo-numpad server"
}
func (c *serverCommand) Synopsis() string {
return "server boot"
}
func (c *serverCommand) Run(args []string) int {
token := viper.GetString("token")
r := myremo.NewRemo(token)
mykeyboard := mykeyboard.NewMyKeyboard()
k := newKeys()
ctx := context.Background()
work := func() {
mykeyboard.KeyDriver.On(keyboard.Key, func(data interface{}) {
pushedKey := data.(keyboard.KeyEvent)
switch pushedKey.Key {
case keyboard.Zero:
r.SendSignalByAplSig(k.Keys["0"].Appliance, k.Keys["0"].Signal, ctx)
case keyboard.One:
r.SendSignalByAplSig(k.Keys["1"].Appliance, k.Keys["1"].Signal, ctx)
case keyboard.Two:
r.SendSignalByAplSig(k.Keys["2"].Appliance, k.Keys["2"].Signal, ctx)
case keyboard.Three:
r.SendSignalByAplSig(k.Keys["3"].Appliance, k.Keys["3"].Signal, ctx)
case keyboard.Four:
r.SendSignalByAplSig(k.Keys["4"].Appliance, k.Keys["4"].Signal, ctx)
case keyboard.Five:
r.SendSignalByAplSig(k.Keys["5"].Appliance, k.Keys["5"].Signal, ctx)
case keyboard.Six:
r.SendSignalByAplSig(k.Keys["6"].Appliance, k.Keys["6"].Signal, ctx)
case keyboard.Seven:
r.SendSignalByAplSig(k.Keys["7"].Appliance, k.Keys["7"].Signal, ctx)
case keyboard.Eight:
r.SendSignalByAplSig(k.Keys["8"].Appliance, k.Keys["8"].Signal, ctx)
case keyboard.Nine:
r.SendSignalByAplSig(k.Keys["9"].Appliance, k.Keys["9"].Signal, ctx)
case keyboard.Escape:
r.SendSignalByAplSig(k.Esc.Appliance, k.Esc.Signal, ctx)
case keyboard.Hyphen:
r.SendSignalByAplSig(k.Hyphen.Appliance, k.Hyphen.Signal, ctx)
case keyboard.Asterisk:
r.SendSignalByAplSig(k.Asterisk.Appliance, k.Asterisk.Signal, ctx)
case keyboard.Plus:
r.SendSignalByAplSig(k.Plus.Appliance, k.Plus.Signal, ctx)
case keyboard.Slash:
r.SendSignalByAplSig(k.Slash.Appliance, k.Slash.Signal, ctx)
case keyboard.Dot:
r.SendSignalByAplSig(k.Dot.Appliance, k.Dot.Signal, ctx)
}
})
}
robot := gobot.NewRobot("keyboardkbot",
[]gobot.Connection{},
[]gobot.Device{mykeyboard.KeyDriver},
work,
)
robot.Start()
return 0
}