-
Notifications
You must be signed in to change notification settings - Fork 8
/
sphero.go
46 lines (37 loc) · 858 Bytes
/
sphero.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
package main
import (
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot-sphero"
)
func NewSphero(name, port string) Sphero {
return &sphero{Name: "Gundam", Port: port}
}
type Sphero interface {
Start()
Stop()
SetRGB(r, g, b uint8)
}
type sphero struct {
Name string
Port string
device *gobotSphero.SpheroDriver
connection *gobotSphero.SpheroAdaptor
}
func (s *sphero) Start() {
s.connection = new(gobotSphero.SpheroAdaptor)
s.connection.Name = "sphero"
s.connection.Port = s.Port
s.device = gobotSphero.NewSphero(s.connection)
s.device.Name = s.Name
robot := gobot.Robot{
Connections: []gobot.Connection{s.connection},
Devices: []gobot.Device{s.device},
}
robot.Start()
}
func (s *sphero) Stop() {
s.connection.Disconnect()
}
func (s *sphero) SetRGB(r, g, b uint8) {
s.device.SetRGB(r, g, b)
}