Skip to content

Commit

Permalink
core: refactor/rename internal name of Master type
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Oct 15, 2016
1 parent 64ae34f commit 458c750
Show file tree
Hide file tree
Showing 169 changed files with 225 additions and 228 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
master := gobot.NewMaster()

firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
led := gpio.NewLedDriver(firmataAdaptor, "13")
Expand All @@ -50,9 +50,9 @@ func main() {
work,
)

gbot.AddRobot(robot)
master.AddRobot(robot)

gbot.Start()
master.Start()
}
```

Expand All @@ -70,7 +70,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
master := gobot.NewMaster()

adaptor := sphero.NewAdaptor("/dev/rfcomm0")
driver := sphero.NewSpheroDriver(adaptor)
Expand All @@ -87,9 +87,9 @@ func main() {
work,
)

gbot.AddRobot(robot)
master.AddRobot(robot)

gbot.Start()
master.Start()
}
```

Expand Down Expand Up @@ -197,14 +197,14 @@ Gobot includes a RESTful API to query the status of any robot running within a g
To activate the API, require the `github.com/hybridgroup/gobot/api` package and instantiate the `API` like this:

```go
gbot := gobot.NewGobot()
api.NewAPI(gbot).Start()
master := gobot.NewMaster()
api.NewAPI(master).Start()
```

You can also specify the api host and port, and turn on authentication:
```go
gbot := gobot.NewGobot()
server := api.NewAPI(gbot)
master := gobot.NewMaster()
server := api.NewAPI(master)
server.Port = "4000"
server.AddHandler(api.BasicAuth("gort", "klatuu"))
server.Start()
Expand Down
32 changes: 16 additions & 16 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

// API represents an API server
type API struct {
gobot *gobot.Gobot
master *gobot.Master
router *pat.PatternServeMux
Host string
Port string
Expand All @@ -27,9 +27,9 @@ type API struct {
}

// NewAPI returns a new api instance
func NewAPI(g *gobot.Gobot) *API {
func NewAPI(m *gobot.Master) *API {
return &API{
gobot: g,
master: m,
router: pat.New(),
Port: "3000",
start: func(a *API) {
Expand Down Expand Up @@ -163,20 +163,20 @@ func (a *API) robeaux(res http.ResponseWriter, req *http.Request) {
// mcp returns MCP route handler.
// Writes JSON with gobot representation
func (a *API) mcp(res http.ResponseWriter, req *http.Request) {
a.writeJSON(map[string]interface{}{"MCP": gobot.NewJSONGobot(a.gobot)}, res)
a.writeJSON(map[string]interface{}{"MCP": gobot.NewJSONMaster(a.master)}, res)
}

// mcpCommands returns commands route handler.
// Writes JSON with global commands representation
func (a *API) mcpCommands(res http.ResponseWriter, req *http.Request) {
a.writeJSON(map[string]interface{}{"commands": gobot.NewJSONGobot(a.gobot).Commands}, res)
a.writeJSON(map[string]interface{}{"commands": gobot.NewJSONMaster(a.master).Commands}, res)
}

// robots returns route handler.
// Writes JSON with robots representation
func (a *API) robots(res http.ResponseWriter, req *http.Request) {
jsonRobots := []*gobot.JSONRobot{}
a.gobot.Robots().Each(func(r *gobot.Robot) {
a.master.Robots().Each(func(r *gobot.Robot) {
jsonRobots = append(jsonRobots, gobot.NewJSONRobot(r))
})
a.writeJSON(map[string]interface{}{"robots": jsonRobots}, res)
Expand Down Expand Up @@ -205,7 +205,7 @@ func (a *API) robotCommands(res http.ResponseWriter, req *http.Request) {
// robotDevices returns devices route handler.
// Writes JSON with robot devices representation
func (a *API) robotDevices(res http.ResponseWriter, req *http.Request) {
if robot := a.gobot.Robot(req.URL.Query().Get(":robot")); robot != nil {
if robot := a.master.Robot(req.URL.Query().Get(":robot")); robot != nil {
jsonDevices := []*gobot.JSONDevice{}
robot.Devices().Each(func(d gobot.Device) {
jsonDevices = append(jsonDevices, gobot.NewJSONDevice(d))
Expand Down Expand Up @@ -237,10 +237,10 @@ func (a *API) robotDeviceEvent(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Cache-Control", "no-cache")
res.Header().Set("Connection", "keep-alive")

device := a.gobot.Robot(req.URL.Query().Get(":robot")).
device := a.master.Robot(req.URL.Query().Get(":robot")).
Device(req.URL.Query().Get(":device"))

if event := a.gobot.Robot(req.URL.Query().Get(":robot")).
if event := a.master.Robot(req.URL.Query().Get(":robot")).
Device(req.URL.Query().Get(":device")).(gobot.Eventer).
Event(req.URL.Query().Get(":event")); len(event) > 0 {
device.(gobot.Eventer).On(event, func(data interface{}) {
Expand Down Expand Up @@ -279,7 +279,7 @@ func (a *API) robotDeviceCommands(res http.ResponseWriter, req *http.Request) {
// writes JSON with robot connections representation
func (a *API) robotConnections(res http.ResponseWriter, req *http.Request) {
jsonConnections := []*gobot.JSONConnection{}
if robot := a.gobot.Robot(req.URL.Query().Get(":robot")); robot != nil {
if robot := a.master.Robot(req.URL.Query().Get(":robot")); robot != nil {
robot.Connections().Each(func(c gobot.Connection) {
jsonConnections = append(jsonConnections, gobot.NewJSONConnection(c))
})
Expand All @@ -302,7 +302,7 @@ func (a *API) robotConnection(res http.ResponseWriter, req *http.Request) {

// executeMcpCommand calls a global command associated to requested route
func (a *API) executeMcpCommand(res http.ResponseWriter, req *http.Request) {
a.executeCommand(a.gobot.Command(req.URL.Query().Get(":command")),
a.executeCommand(a.master.Command(req.URL.Query().Get(":command")),
res,
req,
)
Expand All @@ -315,7 +315,7 @@ func (a *API) executeRobotDeviceCommand(res http.ResponseWriter, req *http.Reque
a.writeJSON(map[string]interface{}{"error": err.Error()}, res)
} else {
a.executeCommand(
a.gobot.Robot(req.URL.Query().Get(":robot")).
a.master.Robot(req.URL.Query().Get(":robot")).
Device(req.URL.Query().Get(":device")).(gobot.Commander).
Command(req.URL.Query().Get(":command")),
res,
Expand All @@ -330,7 +330,7 @@ func (a *API) executeRobotCommand(res http.ResponseWriter, req *http.Request) {
a.writeJSON(map[string]interface{}{"error": err.Error()}, res)
} else {
a.executeCommand(
a.gobot.Robot(req.URL.Query().Get(":robot")).
a.master.Robot(req.URL.Query().Get(":robot")).
Command(req.URL.Query().Get(":command")),
res,
req,
Expand Down Expand Up @@ -369,7 +369,7 @@ func (a *API) Debug() {
}

func (a *API) jsonRobotFor(name string) (jrobot *gobot.JSONRobot, err error) {
if robot := a.gobot.Robot(name); robot != nil {
if robot := a.master.Robot(name); robot != nil {
jrobot = gobot.NewJSONRobot(robot)
} else {
err = errors.New("No Robot found with the name " + name)
Expand All @@ -378,7 +378,7 @@ func (a *API) jsonRobotFor(name string) (jrobot *gobot.JSONRobot, err error) {
}

func (a *API) jsonDeviceFor(robot string, name string) (jdevice *gobot.JSONDevice, err error) {
if device := a.gobot.Robot(robot).Device(name); device != nil {
if device := a.master.Robot(robot).Device(name); device != nil {
jdevice = gobot.NewJSONDevice(device)
} else {
err = errors.New("No Device found with the name " + name)
Expand All @@ -387,7 +387,7 @@ func (a *API) jsonDeviceFor(robot string, name string) (jdevice *gobot.JSONDevic
}

func (a *API) jsonConnectionFor(robot string, name string) (jconnection *gobot.JSONConnection, err error) {
if connection := a.gobot.Robot(robot).Connection(name); connection != nil {
if connection := a.master.Robot(robot).Connection(name); connection != nil {
jconnection = gobot.NewJSONConnection(connection)
} else {
err = errors.New("No Connection found with the name " + name)
Expand Down
12 changes: 6 additions & 6 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

func initTestAPI() *API {
log.SetOutput(NullReadWriteCloser{})
g := gobot.NewGobot()
g := gobot.NewMaster()
a := NewAPI(g)
a.start = func(m *API) {}
a.Start()
Expand Down Expand Up @@ -371,22 +371,22 @@ func TestRobotDeviceEvent(t *testing.T) {
server := httptest.NewServer(a)
defer server.Close()

eventsUrl := "/api/robots/Robot1/devices/Device1/events/"
eventsURL := "/api/robots/Robot1/devices/Device1/events/"

// known event
respc := make(chan *http.Response, 1)
go func() {
resp, _ := http.Get(server.URL + eventsUrl + "TestEvent")
resp, _ := http.Get(server.URL + eventsURL + "TestEvent")
respc <- resp
}()

event := a.gobot.Robot("Robot1").
event := a.master.Robot("Robot1").
Device("Device1").(gobot.Eventer).
Event("TestEvent")

go func() {
time.Sleep(time.Millisecond * 5)
a.gobot.Robot("Robot1").
a.master.Robot("Robot1").
Device("Device1").(gobot.Eventer).Publish(event, "event-data")
}()

Expand All @@ -409,7 +409,7 @@ func TestRobotDeviceEvent(t *testing.T) {
server.CloseClientConnections()

// unknown event
response, _ := http.Get(server.URL + eventsUrl + "UnknownEvent")
response, _ := http.Get(server.URL + eventsURL + "UnknownEvent")

var body map[string]interface{}
json.NewDecoder(response.Body).Decode(&body)
Expand Down
2 changes: 1 addition & 1 deletion api/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Example:
)
func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()
// Starts the API server on default port 3000
api.NewAPI(gbot).Start()
Expand Down
2 changes: 1 addition & 1 deletion cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ import (
)
func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()
conn := {{.Package}}.New{{.UpperName}}Adaptor()
dev := {{.Package}}.New{{.UpperName}}Driver(conn)
Expand Down
6 changes: 3 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Basic Setup
)
func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()
robot := gobot.NewRobot("Eve", func() {
gobot.Every(500*time.Millisecond, func() {
Expand All @@ -43,7 +43,7 @@ Blinking an LED (Hello Eve!)
)
func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()
firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0")
led := gpio.NewLedDriver(firmataAdaptor, "led", "13")
Expand Down Expand Up @@ -81,7 +81,7 @@ web service.
)
func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()
// Starts the API server on default port 3000
api.NewAPI(gbot).Start()
Expand Down
2 changes: 1 addition & 1 deletion examples/ardrone.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

ardroneAdaptor := ardrone.NewAdaptor()
drone := ardrone.NewDriver(ardroneAdaptor)
Expand Down
2 changes: 1 addition & 1 deletion examples/ardrone_face_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())

gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

_, currentfile, _, _ := runtime.Caller(0)
cascade := path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml")
Expand Down
2 changes: 1 addition & 1 deletion examples/ardrone_ps3.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type pair struct {
}

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

joystickAdaptor := joystick.NewAdaptor()
stick := joystick.NewDriver(joystickAdaptor,
Expand Down
2 changes: 1 addition & 1 deletion examples/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

e := audio.NewAdaptor()
laser := audio.NewDriver(e, "./examples/laser.mp3")
Expand Down
2 changes: 1 addition & 1 deletion examples/batty.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

api.NewAPI(gbot).Start()

Expand Down
2 changes: 1 addition & 1 deletion examples/beaglebone_blink.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewLedDriver(beagleboneAdaptor, "P9_12")
Expand Down
2 changes: 1 addition & 1 deletion examples/beaglebone_blink_usr_led.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewLedDriver(beagleboneAdaptor, "usr0")
Expand Down
2 changes: 1 addition & 1 deletion examples/beaglebone_blinkm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()
beagleboneAdaptor := beaglebone.NewAdaptor()
blinkm := i2c.NewBlinkMDriver(beagleboneAdaptor)

Expand Down
2 changes: 1 addition & 1 deletion examples/beaglebone_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

beagleboneAdaptor := beaglebone.NewAdaptor()
button := gpio.NewButtonDriver(beagleboneAdaptor, "P8_9")
Expand Down
2 changes: 1 addition & 1 deletion examples/beaglebone_direct_pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewDirectPinDriver(beagleboneAdaptor, "P8_10")
Expand Down
2 changes: 1 addition & 1 deletion examples/beaglebone_led_brightness.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()
beagleboneAdaptor := beaglebone.NewAdaptor()
led := gpio.NewLedDriver(beagleboneAdaptor, "P9_14")

Expand Down
2 changes: 1 addition & 1 deletion examples/beaglebone_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

beagleboneAdaptor := beaglebone.NewAdaptor()
sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "P9_33")
Expand Down
2 changes: 1 addition & 1 deletion examples/beaglebone_makey_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
gbot := gobot.NewGobot()
gbot := gobot.NewMaster()

beagleboneAdaptor := beaglebone.NewAdaptor()
button := gpio.NewMakeyButtonDriver(beagleboneAdaptor, "P8_9")
Expand Down
Loading

0 comments on commit 458c750

Please sign in to comment.