Skip to content

Commit

Permalink
Update NewLedDriver function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jul 9, 2014
1 parent 546862c commit a94c3c0
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 36 deletions.
5 changes: 3 additions & 2 deletions examples/beaglebone_blink.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)

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

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
led := gpio.NewLedDriver("led", beagleboneAdaptor, "P9_12")
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_12")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
5 changes: 3 additions & 2 deletions examples/beaglebone_led_brightness.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)

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

work := func() {
brightness := uint8(0)
Expand Down
3 changes: 2 additions & 1 deletion examples/beaglebone_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/beaglebone"
"github.com/hybridgroup/gobot/platforms/gpio"
Expand All @@ -12,7 +13,7 @@ func main() {

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "sensor", "P9_33")
led := gpio.NewLedDriver("led", beagleboneAdaptor, "P9_14")
led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14")

work := func() {
gobot.On(sensor.Event("data"), func(data interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion examples/digispark_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
api.NewAPI(gbot).Start()

digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
led := gpio.NewLedDriver("led", digisparkAdaptor, "0")
led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")

robot := gobot.NewRobot("digispark",
[]gobot.Connection{digisparkAdaptor},
Expand Down
6 changes: 4 additions & 2 deletions examples/digispark_blink.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/digispark"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)

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

digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
led := gpio.NewLedDriver("led", digisparkAdaptor, "0")
led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
5 changes: 3 additions & 2 deletions examples/digispark_led_brightness.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/digispark"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)

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

digisparkAdaptor := digispark.NewDigisparkAdaptor("digispark")
led := gpio.NewLedDriver("led", digisparkAdaptor, "0")
led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")

work := func() {
brightness := uint8(0)
Expand Down
5 changes: 3 additions & 2 deletions examples/firmata_blink.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)

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

firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0")
led := gpio.NewLedDriver("led", firmataAdaptor, "13")
led := gpio.NewLedDriver(firmataAdaptor, "led", "13")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
2 changes: 1 addition & 1 deletion examples/firmata_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func main() {
firmataAdaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0")

button := gpio.NewButtonDriver(firmataAdaptor, "myButton", "2")
led := gpio.NewLedDriver("myLed", firmataAdaptor, "13")
led := gpio.NewLedDriver(firmataAdaptor, "myLed", "13")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
Expand Down
5 changes: 3 additions & 2 deletions examples/firmata_led_brightness.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/gpio"
"time"
)

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

firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
led := gpio.NewLedDriver("led", firmataAdaptor, "3")
led := gpio.NewLedDriver(firmataAdaptor, "led", "3")

work := func() {
brightness := uint8(0)
Expand Down
3 changes: 2 additions & 1 deletion examples/firmata_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/gpio"
Expand All @@ -12,7 +13,7 @@ func main() {

firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "sensor", "0")
led := gpio.NewLedDriver("led", firmataAdaptor, "3")
led := gpio.NewLedDriver(firmataAdaptor, "led", "3")

work := func() {
gobot.On(sensor.Event("data"), func(data interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion examples/firmata_makey_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {

firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
button := gpio.NewMakeyButtonDriver(firmataAdaptor, "button", "2")
led := gpio.NewLedDriver("led", firmataAdaptor, "13")
led := gpio.NewLedDriver(firmataAdaptor, "led", "13")

work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
Expand Down
13 changes: 7 additions & 6 deletions examples/firmata_travis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"encoding/json"
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/gpio"
"io/ioutil"
"net/http"
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/gpio"
)

type TravisResponse struct {
Expand Down Expand Up @@ -66,9 +67,9 @@ func main() {
gbot := gobot.NewGobot()

firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
red := gpio.NewLedDriver("red", firmataAdaptor, "7")
green := gpio.NewLedDriver("green", firmataAdaptor, "6")
blue := gpio.NewLedDriver("blue", firmataAdaptor, "5")
red := gpio.NewLedDriver(firmataAdaptor, "red", "7")
green := gpio.NewLedDriver(firmataAdaptor, "green", "6")
blue := gpio.NewLedDriver(firmataAdaptor, "blue", "5")

work := func() {
checkTravis(gbot.Robot("travis"))
Expand Down
5 changes: 3 additions & 2 deletions examples/spark_core_api.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/api"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/spark"
"time"
)

func main() {
gbot := gobot.NewGobot()
api.NewAPI(gbot).Start()

sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token")
led := gpio.NewLedDriver("led", sparkCore, "D7")
led := gpio.NewLedDriver(sparkCore, "led", "D7")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
5 changes: 3 additions & 2 deletions examples/spark_core_blink.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/spark"
"time"
)

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

sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token")
led := gpio.NewLedDriver("led", sparkCore, "D7")
led := gpio.NewLedDriver(sparkCore, "led", "D7")

work := func() {
gobot.Every(1*time.Second, func() {
Expand Down
2 changes: 1 addition & 1 deletion examples/spark_core_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func main() {
gbot := gobot.NewGobot()

sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token")
led := gpio.NewLedDriver("led", sparkCore, "D7")
led := gpio.NewLedDriver(sparkCore, "led", "D7")
button := gpio.NewButtonDriver(sparkCore, "button", "D5")

work := func() {
Expand Down
5 changes: 3 additions & 2 deletions examples/spark_core_led_brithgness.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package main

import (
"time"

"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/gpio"
"github.com/hybridgroup/gobot/platforms/spark"
"time"
)

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

sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token")
led := gpio.NewLedDriver("led", sparkCore, "A1")
led := gpio.NewLedDriver(sparkCore, "led", "A1")

work := func() {
brightness := uint8(0)
Expand Down
12 changes: 6 additions & 6 deletions platforms/gpio/led_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type LedDriver struct {
High bool
}

func NewLedDriver(name string, a PwmDigitalWriter, pin string) *LedDriver {
func NewLedDriver(a PwmDigitalWriter, name string, pin string) *LedDriver {

l := &LedDriver{
Driver: *gobot.NewDriver(
Expand All @@ -21,23 +21,23 @@ func NewLedDriver(name string, a PwmDigitalWriter, pin string) *LedDriver {
High: false,
}

l.Driver.AddCommand("Brightness", func(params map[string]interface{}) interface{} {
l.AddCommand("Brightness", func(params map[string]interface{}) interface{} {
level := byte(params["level"].(float64))
l.Brightness(level)
return nil
})

l.Driver.AddCommand("Toggle", func(params map[string]interface{}) interface{} {
l.AddCommand("Toggle", func(params map[string]interface{}) interface{} {
l.Toggle()
return nil
})

l.Driver.AddCommand("On", func(params map[string]interface{}) interface{} {
l.AddCommand("On", func(params map[string]interface{}) interface{} {
l.On()
return nil
})

l.Driver.AddCommand("Off", func(params map[string]interface{}) interface{} {
l.AddCommand("Off", func(params map[string]interface{}) interface{} {
l.Off()
return nil
})
Expand All @@ -46,7 +46,7 @@ func NewLedDriver(name string, a PwmDigitalWriter, pin string) *LedDriver {
}

func (l *LedDriver) adaptor() PwmDigitalWriter {
return l.Driver.Adaptor().(PwmDigitalWriter)
return l.Adaptor().(PwmDigitalWriter)
}

func (l *LedDriver) Start() bool { return true }
Expand Down

0 comments on commit a94c3c0

Please sign in to comment.