From 4f5d23a3af154cf8fe67f8a3d7923f0fed221fc2 Mon Sep 17 00:00:00 2001 From: Adrian Zankich Date: Fri, 13 Jun 2014 11:19:01 -0700 Subject: [PATCH] Update travis example --- examples/firmata_travis.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/firmata_travis.go b/examples/firmata_travis.go index b37bfdb6..62877744 100644 --- a/examples/firmata_travis.go +++ b/examples/firmata_travis.go @@ -26,10 +26,13 @@ type TravisResponse struct { LastBuildFinishedAt string `json:"last_build_finished_at"` } +func turnOn(robot *gobot.Robot, device string) { + robot.Device(device).Driver.(*gpio.LedDriver).On() +} func resetLeds(robot *gobot.Robot) { - gobot.Call(robot.Device("red").Driver, "Off") - gobot.Call(robot.Device("green").Driver, "Off") - gobot.Call(robot.Device("blue").Driver, "Off") + robot.Device("red").Driver.(*gpio.LedDriver).Off() + robot.Device("green").Driver.(*gpio.LedDriver).Off() + robot.Device("blue").Driver.(*gpio.LedDriver).Off() } func checkTravis(robot *gobot.Robot) { @@ -38,7 +41,7 @@ func checkTravis(robot *gobot.Robot) { name := "gobot" //name := "broken-arrow" fmt.Printf("Checking repo %s/%s\n", user, name) - gobot.Call(robot.Device("blue").Driver, "On") + turnOn(robot, "blue") resp, err := http.Get(fmt.Sprintf("https://api.travis-ci.org/repos/%s/%s.json", user, name)) defer resp.Body.Close() if err != nil { @@ -52,9 +55,9 @@ func checkTravis(robot *gobot.Robot) { json.Unmarshal(body, &travis) resetLeds(robot) if travis.LastBuildStatus == 0 { - gobot.Call(robot.Device("green").Driver, "On") + turnOn(robot, "green") } else { - gobot.Call(robot.Device("red").Driver, "On") + turnOn(robot, "red") } } @@ -72,8 +75,9 @@ func main() { }) } - master.Robots = append(master.Robots, - gobot.NewRobot("travis", []gobot.Connection{firmataAdaptor}, []gobot.Device{red, green, blue}, work)) + master.AddRobot( + gobot.NewRobot("travis", []gobot.Connection{firmataAdaptor}, []gobot.Device{red, green, blue}, work), + ) master.Start() }