1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00

56 lines
1000 B
Go
Raw Normal View History

2013-10-22 16:45:31 -07:00
package gobot
2013-11-23 09:12:57 -08:00
import "time"
2013-10-22 16:45:31 -07:00
2013-11-23 09:12:57 -08:00
type Gobot struct {
Robots []Robot
2013-10-23 22:00:03 -07:00
}
2013-11-23 09:12:57 -08:00
func NewGobot() *Gobot {
g := new(Gobot)
return g
2013-10-26 16:41:43 -07:00
}
2013-11-23 09:12:57 -08:00
func (g *Gobot) Start() {
for s := range g.Robots {
go g.Robots[s].Start()
2013-11-13 20:44:54 -08:00
}
2013-10-30 18:37:57 -07:00
2013-11-23 09:12:57 -08:00
for {
time.Sleep(10 * time.Millisecond)
}
2013-10-28 20:26:05 -07:00
}
2013-11-23 09:26:54 -08:00
func (g *Gobot) FindRobot(name string) *Robot {
for s := range g.Robots {
if g.Robots[s].Name == name {
return &g.Robots[s]
2013-11-23 09:12:57 -08:00
}
2013-11-13 20:44:54 -08:00
}
return nil
2013-10-28 20:26:05 -07:00
}
2013-11-23 09:26:54 -08:00
func (g *Gobot) FindRobotDevice(name string, device string) *Device {
for r := range g.Robots {
if g.Robots[r].Name == name {
for d := range g.Robots[r].devices {
if g.Robots[r].devices[d].Name == device {
return g.Robots[r].devices[d]
2013-11-23 09:12:57 -08:00
}
}
}
2013-11-13 20:44:54 -08:00
}
2013-11-23 09:12:57 -08:00
return nil
2013-10-29 16:37:10 -07:00
}
2013-11-23 09:26:54 -08:00
func (g *Gobot) FindRobotConnection(name string, connection string) *Connection {
for r := range g.Robots {
if g.Robots[r].Name == name {
for c := range g.Robots[r].connections {
if g.Robots[r].connections[c].Name == connection {
return g.Robots[r].connections[c]
2013-11-23 09:12:57 -08:00
}
}
}
2013-11-13 20:44:54 -08:00
}
2013-11-23 09:12:57 -08:00
return nil
2013-10-30 18:37:57 -07:00
}