Skip to content

Commit

Permalink
Rename Gobot struct to Master
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Nov 25, 2013
1 parent 17e0d39 commit 787269c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 59 deletions.
4 changes: 2 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type api struct{}

func Api(bot *Gobot) {
func Api(bot *Master) {
a := new(api)
m := martini.Classic()

Expand Down Expand Up @@ -44,7 +44,7 @@ func Api(bot *Gobot) {
go m.Run()
}

func (a *api) executeCommand(bot *Gobot, params martini.Params, res http.ResponseWriter, req *http.Request) string {
func (a *api) executeCommand(bot *Master, params martini.Params, res http.ResponseWriter, req *http.Request) string {
decoder := json.NewDecoder(req.Body)
var body map[string]interface{}
decoder.Decode(&body)
Expand Down
2 changes: 1 addition & 1 deletion examples/sphero_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func main() {
bot := gobot.NewGobot()
bot := gobot.GobotMaster()
gobot.Api(bot)

spheros := map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion examples/sphero_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func main() {
bot := gobot.NewGobot()
bot := gobot.GobotMaster()

spheros := map[string]string{
"Sphero-BPO": "127.0.0.1:4560",
Expand Down
55 changes: 0 additions & 55 deletions gobot.go

This file was deleted.

55 changes: 55 additions & 0 deletions master.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package gobot

import "time"

type Master struct {
Robots []Robot
}

func GobotMaster() *Master {
m := new(Master)
return m
}

func (m *Master) Start() {
for s := range m.Robots {
go m.Robots[s].Start()
}

for {
time.Sleep(10 * time.Millisecond)
}
}

func (m *Master) FindRobot(name string) *Robot {
for s := range m.Robots {
if m.Robots[s].Name == name {
return &m.Robots[s]
}
}
return nil
}
func (m *Master) FindRobotDevice(name string, device string) *Device {
for r := range m.Robots {
if m.Robots[r].Name == name {
for d := range m.Robots[r].devices {
if m.Robots[r].devices[d].Name == device {
return m.Robots[r].devices[d]
}
}
}
}
return nil
}
func (m *Master) FindRobotConnection(name string, connection string) *Connection {
for r := range m.Robots {
if m.Robots[r].Name == name {
for c := range m.Robots[r].connections {
if m.Robots[r].connections[c].Name == connection {
return m.Robots[r].connections[c]
}
}
}
}
return nil
}

0 comments on commit 787269c

Please sign in to comment.