From a3c892ee58f8b20a988f7bd5bbad97171867bbd0 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Tue, 4 Apr 2017 13:38:51 +0200 Subject: [PATCH] examples: correct build errors in all current examples Signed-off-by: deadprogram --- ...lebone_led_brightness_with_analog_input.go | 3 +- examples/dragonboard_button.go | 6 +-- ...edison_led_brightness_with_analog_input.go | 2 +- examples/firmata_integration.go | 5 +- ...irmata_led_brightness_with_analog_input.go | 5 +- examples/firmata_mpl115a2.go | 7 ++- examples/firmata_ssd1306.go | 48 +++++++++++++++++++ examples/mqtt_driver_ping.go | 2 +- 8 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 examples/firmata_ssd1306.go diff --git a/examples/beaglebone_led_brightness_with_analog_input.go b/examples/beaglebone_led_brightness_with_analog_input.go index c4d8b19a..566f4fcb 100644 --- a/examples/beaglebone_led_brightness_with_analog_input.go +++ b/examples/beaglebone_led_brightness_with_analog_input.go @@ -8,13 +8,14 @@ import ( "fmt" "gobot.io/x/gobot" + "gobot.io/x/gobot/drivers/aio" "gobot.io/x/gobot/drivers/gpio" "gobot.io/x/gobot/platforms/beaglebone" ) func main() { beagleboneAdaptor := beaglebone.NewAdaptor() - sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "P9_33") + sensor := aio.NewAnalogSensorDriver(beagleboneAdaptor, "P9_33") led := gpio.NewLedDriver(beagleboneAdaptor, "P9_14") work := func() { diff --git a/examples/dragonboard_button.go b/examples/dragonboard_button.go index 2af0ccac..3aa8c981 100644 --- a/examples/dragonboard_button.go +++ b/examples/dragonboard_button.go @@ -17,17 +17,17 @@ func main() { button := gpio.NewButtonDriver(dragonAdaptor, "GPIO_A") work := func() { - gobot.On(button.Event("push"), func(data interface{}) { + button.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("button pressed") }) - gobot.On(button.Event("release"), func(data interface{}) { + button.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("button released") }) } robot := gobot.NewRobot("buttonBot", - []gobot.Connection{chipAdaptor}, + []gobot.Connection{dragonAdaptor}, []gobot.Device{button}, work, ) diff --git a/examples/edison_led_brightness_with_analog_input.go b/examples/edison_led_brightness_with_analog_input.go index 2bfbf51e..bab82445 100644 --- a/examples/edison_led_brightness_with_analog_input.go +++ b/examples/edison_led_brightness_with_analog_input.go @@ -35,5 +35,5 @@ func main() { work, ) - master.Start() + robot.Start() } diff --git a/examples/firmata_integration.go b/examples/firmata_integration.go index a0716446..f9c00391 100644 --- a/examples/firmata_integration.go +++ b/examples/firmata_integration.go @@ -9,6 +9,7 @@ import ( "time" "gobot.io/x/gobot" + "gobot.io/x/gobot/drivers/aio" "gobot.io/x/gobot/drivers/gpio" "gobot.io/x/gobot/platforms/firmata" ) @@ -18,7 +19,7 @@ func main() { led1 := gpio.NewLedDriver(firmataAdaptor, "3") led2 := gpio.NewLedDriver(firmataAdaptor, "4") button := gpio.NewButtonDriver(firmataAdaptor, "2") - sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "0") + sensor := aio.NewAnalogSensorDriver(firmataAdaptor, "0") work := func() { gobot.Every(1*time.Second, func() { @@ -33,7 +34,7 @@ func main() { button.On(gpio.ButtonRelease, func(data interface{}) { led2.Off() }) - sensor.On(gpio.Data, func(data interface{}) { + sensor.On(aio.Data, func(data interface{}) { fmt.Println("sensor", data) }) } diff --git a/examples/firmata_led_brightness_with_analog_input.go b/examples/firmata_led_brightness_with_analog_input.go index c8c233bf..78870c57 100644 --- a/examples/firmata_led_brightness_with_analog_input.go +++ b/examples/firmata_led_brightness_with_analog_input.go @@ -8,17 +8,18 @@ import ( "fmt" "gobot.io/x/gobot" + "gobot.io/x/gobot/drivers/aio" "gobot.io/x/gobot/drivers/gpio" "gobot.io/x/gobot/platforms/firmata" ) func main() { firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") - sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "0") + sensor := aio.NewAnalogSensorDriver(firmataAdaptor, "0") led := gpio.NewLedDriver(firmataAdaptor, "3") work := func() { - sensor.On(gpio.Data, func(data interface{}) { + sensor.On(aio.Data, func(data interface{}) { brightness := uint8( gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255), ) diff --git a/examples/firmata_mpl115a2.go b/examples/firmata_mpl115a2.go index d4ade35f..607f2ada 100644 --- a/examples/firmata_mpl115a2.go +++ b/examples/firmata_mpl115a2.go @@ -19,8 +19,11 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - fmt.Println("Pressure", mpl115a2.Pressure()) - fmt.Println("Temperature", mpl115a2.Temperature()) + press, _ := mpl115a2.Pressure() + fmt.Println("Pressure", press) + + temp, _ := mpl115a2.Temperature() + fmt.Println("Temperature", temp) }) } diff --git a/examples/firmata_ssd1306.go b/examples/firmata_ssd1306.go new file mode 100644 index 00000000..47bae04d --- /dev/null +++ b/examples/firmata_ssd1306.go @@ -0,0 +1,48 @@ +// +build example +// +// Do not build by default. + +package main + +import ( + "fmt" + "os" + "time" + + "gobot.io/x/gobot" + "gobot.io/x/gobot/drivers/i2c" + "gobot.io/x/gobot/platforms/firmata" +) + +func main() { + + r := firmata.NewAdaptor(os.Args[1]) + oled := i2c.NewSSD1306Driver(r, i2c.WithAddress(0x3c)) + + stage := false + + work := func() { + + gobot.Every(1*time.Second, func() { + fmt.Println("displaying") + oled.Clear() + if stage { + for x := 0; x < oled.Buffer.Width; x += 5 { + for y := 0; y < oled.Buffer.Height; y++ { + oled.Set(x, y, 1) + } + } + } + stage = !stage + oled.Display() + }) + } + + robot := gobot.NewRobot("ssd1306Robot", + []gobot.Connection{r}, + []gobot.Device{oled}, + work, + ) + + robot.Start() +} diff --git a/examples/mqtt_driver_ping.go b/examples/mqtt_driver_ping.go index fc30d96f..7d4905cc 100644 --- a/examples/mqtt_driver_ping.go +++ b/examples/mqtt_driver_ping.go @@ -47,7 +47,7 @@ func main() { robot := gobot.NewRobot("mqttBot", []gobot.Connection{mqttAdaptor}, - []gobot.Devices{helloDriver, holaDriver}, + []gobot.Device{helloDriver, holaDriver}, work, )