diff --git a/.circleci/config.yml b/.circleci/config.yml index 681dcbfa9..6ccfb5b0d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,6 +59,22 @@ jobs: SOME=$(grep -L 'digispark' $(grep -L 'gocv' ${ALL})) for e in ${SOME} ; do go vet "${e}" ; done + "fmt_check_examples": + docker: + - image: golangci/golangci-lint:v1.55.2 + steps: + - checkout + - run: + name: Debug linter version + command: golangci-lint --version + - run: + # digispark needs libusb, opencv needs opencv + name: Check examples for linter issues (except digispark, opencv) + command: | + ALL=$(grep -l -r --include "*.go" 'build example' ./) + SOME=$(grep -L 'digispark' $(grep -L 'gocv' ${ALL})) + for e in ${SOME} ; do golangci-lint run "${e}" --build-tags example --disable forcetypeassert --disable noctx ; done + workflows: version: 2 build: @@ -66,3 +82,4 @@ workflows: - "test_core_and_drivers_with_coverage" - "test_platforms" - "check_examples" + - "fmt_check_examples" diff --git a/Makefile b/Makefile index 0b95c4346..46f532518 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ EXAMPLES_NO_GOCV := $(shell grep -L 'gocv' $(ALL_EXAMPLES)) # used examples EXAMPLES := $(EXAMPLES_NO_GOCV) -.PHONY: test test_race test_cover robeaux version_check fmt_check fmt_fix examples examples_check $(EXAMPLES) +.PHONY: test test_race test_cover robeaux version_check fmt_check fmt_fix examples examples_check examples_fmt_fix $(EXAMPLES) # opencv platform currently skipped to prevent install of preconditions including_except := $(shell go list ./... | grep -v platforms/opencv) @@ -65,9 +65,15 @@ examples: $(EXAMPLES) examples_check: $(MAKE) CHECK=ON examples +examples_fmt_fix: + $(MAKE) CHECK=FMT examples + $(EXAMPLES): ifeq ($(CHECK),ON) go vet ./$@ +else ifeq ($(CHECK),FMT) + gofumpt -l -w ./$@ + golangci-lint run ./$@ --fix --build-tags example --disable forcetypeassert --disable noctx else go build -o /tmp/gobot_examples/$@ ./$@ endif diff --git a/README.md b/README.md index 7970c30f5..4d12f82bb 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -87,7 +89,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` @@ -121,7 +125,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` @@ -141,13 +147,19 @@ import ( func main() { e := edison.NewAdaptor() - e.Connect() + if err := e.Connect(); err != nil { + fmt.Println(err) + } led := gpio.NewLedDriver(e, "13") - led.Start() + if err := led.Start(); err != nil { + fmt.Println(err) + } for { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } time.Sleep(1000 * time.Millisecond) } } @@ -179,7 +191,7 @@ func NewSwarmBot(port string) *gobot.Robot { work := func() { spheroDriver.Stop() - spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { + _ = spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { fmt.Println("Collision Detected!") }) @@ -218,7 +230,9 @@ func main() { master.AddRobot(NewSwarmBot(port)) } - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } ``` diff --git a/doc.go b/doc.go index e20fe04e6..25a8731ab 100644 --- a/doc.go +++ b/doc.go @@ -27,7 +27,9 @@ Here is a "Classic Gobot" program that blinks an LED using an Arduino: work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -37,7 +39,9 @@ Here is a "Classic Gobot" program that blinks an LED using an Arduino: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } # Metal Gobot @@ -55,13 +59,19 @@ pure idiomatic Golang code. For example: func main() { e := edison.NewAdaptor() - e.Connect() + if err := e.Connect(); err != nil { + fmt.Println(err) + } led := gpio.NewLedDriver(e, "13") - led.Start() + if err := led.Start(); err != nil { + fmt.Println(err) + } for { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } time.Sleep(1000 * time.Millisecond) } } @@ -90,7 +100,7 @@ Finally, you can use Master Gobot to add the complete Gobot API or control swarm work := func() { spheroDriver.Stop() - spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { + _ = spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { fmt.Println("Collision Detected!") }) @@ -129,7 +139,9 @@ Finally, you can use Master Gobot to add the complete Gobot API or control swarm master.AddRobot(NewSwarmBot(port)) } - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } Copyright (c) 2013-2018 The Hybrid Group. Licensed under the Apache 2.0 license. diff --git a/drivers/MIGRATION.md b/drivers/MIGRATION.md index 5f5cabdcf..c0fa1a279 100644 --- a/drivers/MIGRATION.md +++ b/drivers/MIGRATION.md @@ -94,7 +94,7 @@ import( adaptor := sphero.NewAdaptor("/dev/rfcomm0") spheroDriver := sphero.NewSpheroDriver(adaptor) ... - spheroDriver.On(sphero.Collision, func(data interface{}) { + _ = spheroDriver.On(sphero.Collision, func(data interface{}) { ... // new @@ -109,7 +109,7 @@ import( adaptor := serialport.NewAdaptor("/dev/rfcomm0") spheroDriver := serial.NewSpheroDriver(adaptor) ... - spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { + _ = spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { ... ``` diff --git a/examples/ardrone.go b/examples/ardrone.go index 74349c5be..db9a9850b 100644 --- a/examples/ardrone.go +++ b/examples/ardrone.go @@ -18,7 +18,7 @@ func main() { drone := ardrone.NewDriver(ardroneAdaptor) work := func() { - drone.On(ardrone.Flying, func(data interface{}) { + _ = drone.On(ardrone.Flying, func(data interface{}) { gobot.After(3*time.Second, func() { drone.Land() }) @@ -32,5 +32,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ardrone_face_tracking.go b/examples/ardrone_face_tracking.go index b0a70834c..92c358e85 100644 --- a/examples/ardrone_face_tracking.go +++ b/examples/ardrone_face_tracking.go @@ -41,7 +41,7 @@ func main() { window.WaitKey(1) } }) - drone.On(ardrone.Flying, func(data interface{}) { + _ = drone.On(ardrone.Flying, func(data interface{}) { gobot.After(1*time.Second, func() { drone.Up(0.2) }) gobot.After(2*time.Second, func() { drone.Hover() }) gobot.After(5*time.Second, func() { @@ -83,5 +83,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ardrone_ps3.go b/examples/ardrone_ps3.go index 37dd20131..f0067b173 100644 --- a/examples/ardrone_ps3.go +++ b/examples/ardrone_ps3.go @@ -37,34 +37,34 @@ func main() { rightY.Store(float64(0.0)) work := func() { - stick.On(joystick.SquarePress, func(data interface{}) { + _ = stick.On(joystick.SquarePress, func(data interface{}) { drone.TakeOff() }) - stick.On(joystick.TrianglePress, func(data interface{}) { + _ = stick.On(joystick.TrianglePress, func(data interface{}) { drone.Hover() }) - stick.On(joystick.XPress, func(data interface{}) { + _ = stick.On(joystick.XPress, func(data interface{}) { drone.Land() }) - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { val := float64(data.(int16)) leftX.Store(val) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { val := float64(data.(int16)) leftY.Store(val) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { val := float64(data.(int16)) rightX.Store(val) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { val := float64(data.(int16)) rightY.Store(val) }) @@ -120,7 +120,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func getLeftStick() pair { diff --git a/examples/audio.go b/examples/audio.go index dd7819560..4df44d4f8 100644 --- a/examples/audio.go +++ b/examples/audio.go @@ -29,5 +29,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/batty.go b/examples/batty.go index 7ea6aa7f4..b5237c9fe 100644 --- a/examples/batty.go +++ b/examples/batty.go @@ -42,7 +42,9 @@ func main() { }) gbot.AddRobot(r) - gbot.Start() + if err := gbot.Start(); err != nil { + fmt.Println(err) + } } var _ gobot.Adaptor = (*loopbackAdaptor)(nil) diff --git a/examples/beaglebone_basic_direct_pin.go b/examples/beaglebone_basic_direct_pin.go index 0bb2385b0..98b54d87c 100644 --- a/examples/beaglebone_basic_direct_pin.go +++ b/examples/beaglebone_basic_direct_pin.go @@ -7,6 +7,8 @@ package main import ( + "fmt" + "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/platforms/beaglebone" ) @@ -17,11 +19,15 @@ func main() { gpioPin := gpio.NewDirectPinDriver(beagleboneAdaptor, "P9_12") // Initialize the internal representation of the pinout - beagleboneAdaptor.Connect() + if err := beagleboneAdaptor.Connect(); err != nil { + fmt.Println(err) + } // Cast to byte because we are returning an int from a function // and not passing in an int literal. - gpioPin.DigitalWrite(byte(myStateFunction())) + if err := gpioPin.DigitalWrite(byte(myStateFunction())); err != nil { + fmt.Println(err) + } } // myStateFunction determines what the GPIO state should be diff --git a/examples/beaglebone_blink.go b/examples/beaglebone_blink.go index fbddafd7a..6325f5c78 100644 --- a/examples/beaglebone_blink.go +++ b/examples/beaglebone_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/beaglebone_blink_usr_led.go b/examples/beaglebone_blink_usr_led.go index ea50005c0..b9d7a3937 100644 --- a/examples/beaglebone_blink_usr_led.go +++ b/examples/beaglebone_blink_usr_led.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/beaglebone_blinkm.go b/examples/beaglebone_blinkm.go index 97c91e7f4..bdaf74dec 100644 --- a/examples/beaglebone_blinkm.go +++ b/examples/beaglebone_blinkm.go @@ -24,8 +24,13 @@ func main() { r := byte(gobot.Rand(255)) g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) - blinkm.Rgb(r, g, b) - color, _ := blinkm.Color() + if err := blinkm.Rgb(r, g, b); err != nil { + fmt.Println(err) + } + color, err := blinkm.Color() + if err != nil { + fmt.Println(err) + } fmt.Println("color", color) }) } @@ -36,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/beaglebone_button.go b/examples/beaglebone_button.go index 2aa227120..3ee3cc10e 100644 --- a/examples/beaglebone_button.go +++ b/examples/beaglebone_button.go @@ -19,11 +19,11 @@ func main() { button := gpio.NewButtonDriver(beagleboneAdaptor, "P8_09") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { + _ = button.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("button pressed") }) - button.On(gpio.ButtonRelease, func(data interface{}) { + _ = button.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("button released") }) } @@ -34,5 +34,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/beaglebone_direct_pin.go b/examples/beaglebone_direct_pin.go index 40ce35445..48ea72907 100644 --- a/examples/beaglebone_direct_pin.go +++ b/examples/beaglebone_direct_pin.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -23,9 +24,13 @@ func main() { gobot.Every(500*time.Millisecond, func() { val, _ := button.DigitalRead() if val == 1 { - led.DigitalWrite(1) + if err := led.DigitalWrite(1); err != nil { + fmt.Println(err) + } } else { - led.DigitalWrite(0) + if err := led.DigitalWrite(0); err != nil { + fmt.Println(err) + } } }) } @@ -36,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/beaglebone_grove_accelerometer.go b/examples/beaglebone_grove_accelerometer.go index f7fff980a..ffe6d1b3e 100644 --- a/examples/beaglebone_grove_accelerometer.go +++ b/examples/beaglebone_grove_accelerometer.go @@ -36,5 +36,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/beaglebone_led_brightness.go b/examples/beaglebone_led_brightness.go index 8d84b4193..f95d90768 100644 --- a/examples/beaglebone_led_brightness.go +++ b/examples/beaglebone_led_brightness.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -23,7 +24,9 @@ func main() { fadeAmount := uint8(5) gobot.Every(100*time.Millisecond, func() { - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } brightness = brightness + fadeAmount if brightness == 0 || brightness == 255 { fadeAmount = -fadeAmount @@ -37,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/beaglebone_led_brightness_with_analog_input.go b/examples/beaglebone_led_brightness_with_analog_input.go index ddd8598fb..00b36e8f0 100644 --- a/examples/beaglebone_led_brightness_with_analog_input.go +++ b/examples/beaglebone_led_brightness_with_analog_input.go @@ -22,13 +22,15 @@ func main() { led := gpio.NewLedDriver(beagleboneAdaptor, "P9_14") work := func() { - sensor.On(sensor.Event("data"), func(data interface{}) { + _ = sensor.On(sensor.Event("data"), func(data interface{}) { brightness := uint8( gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255), ) fmt.Println("sensor", data) fmt.Println("brightness", brightness) - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } }) } @@ -38,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/beaglebone_servo.go b/examples/beaglebone_servo.go index 0172eb9cd..26fd68a5a 100644 --- a/examples/beaglebone_servo.go +++ b/examples/beaglebone_servo.go @@ -23,7 +23,9 @@ func main() { gobot.Every(1*time.Second, func() { i := uint8(gobot.Rand(180)) fmt.Println("Turning", i) - servo.Move(i) + if err := servo.Move(i); err != nil { + fmt.Println(err) + } }) } @@ -33,5 +35,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/bebop.go b/examples/bebop.go index 5af654ab5..368c71706 100644 --- a/examples/bebop.go +++ b/examples/bebop.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -18,13 +19,17 @@ func main() { drone := bebop.NewDriver(bebopAdaptor) work := func() { - drone.On(bebop.Flying, func(data interface{}) { + _ = drone.On(bebop.Flying, func(data interface{}) { gobot.After(10*time.Second, func() { - drone.Land() + if err := drone.Land(); err != nil { + fmt.Println(err) + } }) }) - drone.HullProtection(true) + if err := drone.HullProtection(true); err != nil { + fmt.Println(err) + } drone.TakeOff() } @@ -34,5 +39,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/bebop_ps3.go b/examples/bebop_ps3.go index 743b7b0f2..5974b0569 100644 --- a/examples/bebop_ps3.go +++ b/examples/bebop_ps3.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "sync/atomic" "time" @@ -39,44 +40,54 @@ func main() { recording := false - stick.On(joystick.CirclePress, func(data interface{}) { + _ = stick.On(joystick.CirclePress, func(data interface{}) { if recording { - drone.StopRecording() + if err := drone.StopRecording(); err != nil { + fmt.Println(err) + } } else { - drone.StartRecording() + if err := drone.StartRecording(); err != nil { + fmt.Println(err) + } } recording = !recording }) - stick.On(joystick.SquarePress, func(data interface{}) { - drone.HullProtection(true) + _ = stick.On(joystick.SquarePress, func(data interface{}) { + if err := drone.HullProtection(true); err != nil { + fmt.Println(err) + } drone.TakeOff() }) - stick.On(joystick.TrianglePress, func(data interface{}) { - drone.Stop() + _ = stick.On(joystick.TrianglePress, func(data interface{}) { + if err := drone.Stop(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.XPress, func(data interface{}) { - drone.Land() + _ = stick.On(joystick.XPress, func(data interface{}) { + if err := drone.Land(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { val := float64(data.(int16)) leftX.Store(val) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { val := float64(data.(int16)) leftY.Store(val) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { val := float64(data.(int16)) rightX.Store(val) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { val := float64(data.(int16)) rightY.Store(val) }) @@ -86,20 +97,32 @@ func main() { switch { case leftStick.y < -10: - drone.Forward(bebop.ValidatePitch(leftStick.y, offset)) + if err := drone.Forward(bebop.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } case leftStick.y > 10: - drone.Backward(bebop.ValidatePitch(leftStick.y, offset)) + if err := drone.Backward(bebop.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Forward(0) + if err := drone.Forward(0); err != nil { + fmt.Println(err) + } } switch { case leftStick.x > 10: - drone.Right(bebop.ValidatePitch(leftStick.x, offset)) + if err := drone.Right(bebop.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } case leftStick.x < -10: - drone.Left(bebop.ValidatePitch(leftStick.x, offset)) + if err := drone.Left(bebop.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Right(0) + if err := drone.Right(0); err != nil { + fmt.Println(err) + } } }) @@ -107,20 +130,32 @@ func main() { rightStick := getRightStick() switch { case rightStick.y < -10: - drone.Up(bebop.ValidatePitch(rightStick.y, offset)) + if err := drone.Up(bebop.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } case rightStick.y > 10: - drone.Down(bebop.ValidatePitch(rightStick.y, offset)) + if err := drone.Down(bebop.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Up(0) + if err := drone.Up(0); err != nil { + fmt.Println(err) + } } switch { case rightStick.x > 20: - drone.Clockwise(bebop.ValidatePitch(rightStick.x, offset)) + if err := drone.Clockwise(bebop.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } case rightStick.x < -20: - drone.CounterClockwise(bebop.ValidatePitch(rightStick.x, offset)) + if err := drone.CounterClockwise(bebop.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Clockwise(0) + if err := drone.Clockwise(0); err != nil { + fmt.Println(err) + } } }) } @@ -131,7 +166,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func getLeftStick() pair { diff --git a/examples/bebop_ps3_video.go b/examples/bebop_ps3_video.go index 007e782e3..307b4dd55 100644 --- a/examples/bebop_ps3_video.go +++ b/examples/bebop_ps3_video.go @@ -48,23 +48,21 @@ var leftX, leftY, rightX, rightY atomic.Value const offset = 32767.0 -func ffmpeg() (stdin io.WriteCloser, stderr io.ReadCloser, err error) { +func ffmpeg() (io.WriteCloser, io.ReadCloser, error) { ffmpeg := exec.Command("ffmpeg", "-i", "pipe:0", "http://localhost:8090/bebop.ffm") - stderr, err = ffmpeg.StderrPipe() - + stderr, err := ffmpeg.StderrPipe() if err != nil { - return + return nil, stderr, err } - stdin, err = ffmpeg.StdinPipe() - + stdin, err := ffmpeg.StdinPipe() if err != nil { - return + return stdin, stderr, err } - if err = ffmpeg.Start(); err != nil { - return + if err := ffmpeg.Start(); err != nil { + return stdin, stderr, err } go func() { @@ -90,7 +88,9 @@ func main() { drone := bebop.NewDriver(bebopAdaptor) work := func() { - drone.VideoEnable(true) + if err := drone.VideoEnable(true); err != nil { + fmt.Println(err) + } video, _, _ := ffmpeg() go func() { @@ -109,41 +109,51 @@ func main() { recording := false - stick.On(joystick.CirclePress, func(data interface{}) { + _ = stick.On(joystick.CirclePress, func(data interface{}) { if recording { - drone.StopRecording() + if err := drone.StopRecording(); err != nil { + fmt.Println(err) + } } else { - drone.StartRecording() + if err := drone.StartRecording(); err != nil { + fmt.Println(err) + } } recording = !recording }) - stick.On(joystick.SquarePress, func(data interface{}) { - drone.HullProtection(true) + _ = stick.On(joystick.SquarePress, func(data interface{}) { + if err := drone.HullProtection(true); err != nil { + fmt.Println(err) + } drone.TakeOff() }) - stick.On(joystick.TrianglePress, func(data interface{}) { - drone.Stop() + _ = stick.On(joystick.TrianglePress, func(data interface{}) { + if err := drone.Stop(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.XPress, func(data interface{}) { - drone.Land() + _ = stick.On(joystick.XPress, func(data interface{}) { + if err := drone.Land(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { val := float64(data.(int16)) leftX.Store(val) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { val := float64(data.(int16)) leftY.Store(val) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { val := float64(data.(int16)) rightX.Store(val) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { val := float64(data.(int16)) rightY.Store(val) }) @@ -153,20 +163,32 @@ func main() { switch { case leftStick.y < -10: - drone.Forward(bebop.ValidatePitch(leftStick.y, offset)) + if err := drone.Forward(bebop.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } case leftStick.y > 10: - drone.Backward(bebop.ValidatePitch(leftStick.y, offset)) + if err := drone.Backward(bebop.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Forward(0) + if err := drone.Forward(0); err != nil { + fmt.Println(err) + } } switch { case leftStick.x > 10: - drone.Right(bebop.ValidatePitch(leftStick.x, offset)) + if err := drone.Right(bebop.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } case leftStick.x < -10: - drone.Left(bebop.ValidatePitch(leftStick.x, offset)) + if err := drone.Left(bebop.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Right(0) + if err := drone.Right(0); err != nil { + fmt.Println(err) + } } }) @@ -174,20 +196,32 @@ func main() { rightStick := getRightStick() switch { case rightStick.y < -10: - drone.Up(bebop.ValidatePitch(rightStick.y, offset)) + if err := drone.Up(bebop.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } case rightStick.y > 10: - drone.Down(bebop.ValidatePitch(rightStick.y, offset)) + if err := drone.Down(bebop.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Up(0) + if err := drone.Up(0); err != nil { + fmt.Println(err) + } } switch { case rightStick.x > 20: - drone.Clockwise(bebop.ValidatePitch(rightStick.x, offset)) + if err := drone.Clockwise(bebop.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } case rightStick.x < -20: - drone.CounterClockwise(bebop.ValidatePitch(rightStick.x, offset)) + if err := drone.CounterClockwise(bebop.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Clockwise(0) + if err := drone.Clockwise(0); err != nil { + fmt.Println(err) + } } }) } @@ -198,7 +232,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func getLeftStick() pair { diff --git a/examples/bebop_rtp_video.go b/examples/bebop_rtp_video.go index df3afbe9b..725f0b289 100644 --- a/examples/bebop_rtp_video.go +++ b/examples/bebop_rtp_video.go @@ -23,6 +23,8 @@ http://localhost:8090/bebop.mjpeg in a web browser. package main import ( + "fmt" + "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/platforms/parrot/bebop" ) @@ -32,7 +34,9 @@ func main() { drone := bebop.NewDriver(bebopAdaptor) work := func() { - drone.VideoEnable(true) + if err := drone.VideoEnable(true); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("drone", @@ -41,5 +45,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_battery.go b/examples/bleclient_battery.go similarity index 93% rename from examples/ble_battery.go rename to examples/bleclient_battery.go index 22276b2b6..f0a179954 100644 --- a/examples/ble_battery.go +++ b/examples/bleclient_battery.go @@ -45,5 +45,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_bb8-collision.go b/examples/bleclient_bb8-collision.go similarity index 87% rename from examples/ble_bb8-collision.go rename to examples/bleclient_bb8-collision.go index 6d00daaea..d5573a574 100644 --- a/examples/ble_bb8-collision.go +++ b/examples/bleclient_bb8-collision.go @@ -29,7 +29,7 @@ func main() { bb := sphero.NewBB8Driver(bleAdaptor) work := func() { - bb.On("collision", func(data interface{}) { + _ = bb.On("collision", func(data interface{}) { fmt.Printf("collision detected = %+v \n", data) bb.SetRGB(255, 0, 0) }) @@ -44,5 +44,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_bb8.go b/examples/bleclient_bb8.go similarity index 93% rename from examples/ble_bb8.go rename to examples/bleclient_bb8.go index 24d082d37..f22a4db1e 100644 --- a/examples/ble_bb8.go +++ b/examples/bleclient_bb8.go @@ -43,5 +43,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_device_info.go b/examples/bleclient_device_info.go similarity index 95% rename from examples/ble_device_info.go rename to examples/bleclient_device_info.go index e463a8ccb..69f8c997b 100644 --- a/examples/ble_device_info.go +++ b/examples/bleclient_device_info.go @@ -66,5 +66,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_firmata_blink.go b/examples/bleclient_firmata_blink.go similarity index 83% rename from examples/ble_firmata_blink.go rename to examples/bleclient_firmata_blink.go index b63860e1f..f74849fd4 100644 --- a/examples/ble_firmata_blink.go +++ b/examples/bleclient_firmata_blink.go @@ -16,6 +16,7 @@ package main import ( + "fmt" "os" "time" @@ -30,7 +31,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -40,5 +43,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_firmata_curie_imu.go b/examples/bleclient_firmata_curie_imu.go similarity index 66% rename from examples/ble_firmata_curie_imu.go rename to examples/bleclient_firmata_curie_imu.go index 184a9f9fc..0f6e136f6 100644 --- a/examples/ble_firmata_curie_imu.go +++ b/examples/bleclient_firmata_curie_imu.go @@ -16,6 +16,7 @@ package main import ( + "fmt" "log" "os" "time" @@ -33,26 +34,34 @@ func main() { imu := curie.NewIMUDriver(firmataAdaptor) work := func() { - imu.On("Accelerometer", func(data interface{}) { + _ = imu.On("Accelerometer", func(data interface{}) { log.Println("Accelerometer", data) }) - imu.On("Gyroscope", func(data interface{}) { + _ = imu.On("Gyroscope", func(data interface{}) { log.Println("Gyroscope", data) }) - imu.On("Temperature", func(data interface{}) { + _ = imu.On("Temperature", func(data interface{}) { log.Println("Temperature", data) }) gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(100*time.Millisecond, func() { - imu.ReadAccelerometer() - imu.ReadGyroscope() - imu.ReadTemperature() + if err := imu.ReadAccelerometer(); err != nil { + fmt.Println(err) + } + if err := imu.ReadGyroscope(); err != nil { + fmt.Println(err) + } + if err := imu.ReadTemperature(); err != nil { + fmt.Println(err) + } }) } @@ -62,5 +71,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_generic_access.go b/examples/bleclient_generic_access.go similarity index 94% rename from examples/ble_generic_access.go rename to examples/bleclient_generic_access.go index aa77064a6..47e7842fb 100644 --- a/examples/ble_generic_access.go +++ b/examples/bleclient_generic_access.go @@ -48,5 +48,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/microbit_accelerometer.go b/examples/bleclient_microbit_accelerometer.go similarity index 89% rename from examples/microbit_accelerometer.go rename to examples/bleclient_microbit_accelerometer.go index 55fbc5350..1a7b301e6 100644 --- a/examples/microbit_accelerometer.go +++ b/examples/bleclient_microbit_accelerometer.go @@ -40,7 +40,7 @@ func main() { ubit := microbit.NewAccelerometerDriver(bleAdaptor) work := func() { - ubit.On(microbit.AccelerometerEvent, func(data interface{}) { + _ = ubit.On(microbit.AccelerometerEvent, func(data interface{}) { fmt.Println("Accelerometer", data) }) } @@ -51,5 +51,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/microbit_blink.go b/examples/bleclient_microbit_blink.go similarity index 90% rename from examples/microbit_blink.go rename to examples/bleclient_microbit_blink.go index c384c68dc..6b4d92b9d 100644 --- a/examples/microbit_blink.go +++ b/examples/bleclient_microbit_blink.go @@ -30,6 +30,7 @@ package main import ( + "fmt" "os" "time" @@ -47,7 +48,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -57,5 +60,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/microbit_buttons.go b/examples/bleclient_microbit_buttons.go similarity index 85% rename from examples/microbit_buttons.go rename to examples/bleclient_microbit_buttons.go index 54123a456..c7b1d5d7a 100644 --- a/examples/microbit_buttons.go +++ b/examples/bleclient_microbit_buttons.go @@ -38,11 +38,11 @@ func main() { ubit := microbit.NewButtonDriver(bleAdaptor) work := func() { - ubit.On(microbit.ButtonAEvent, func(data interface{}) { + _ = ubit.On(microbit.ButtonAEvent, func(data interface{}) { fmt.Println("button A", data) }) - ubit.On(microbit.ButtonBEvent, func(data interface{}) { + _ = ubit.On(microbit.ButtonBEvent, func(data interface{}) { fmt.Println("button B", data) }) } @@ -53,5 +53,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/microbit_buttons_leds.go b/examples/bleclient_microbit_buttons_leds.go similarity index 71% rename from examples/microbit_buttons_leds.go rename to examples/bleclient_microbit_buttons_leds.go index 222ee9d11..b9f5ebb49 100644 --- a/examples/microbit_buttons_leds.go +++ b/examples/bleclient_microbit_buttons_leds.go @@ -27,6 +27,7 @@ package main import ( + "fmt" "os" "gobot.io/x/gobot/v2" @@ -40,22 +41,30 @@ func main() { leds := microbit.NewLEDDriver(bleAdaptor) work := func() { - buttons.On(microbit.ButtonAEvent, func(data interface{}) { + _ = buttons.On(microbit.ButtonAEvent, func(data interface{}) { if data.([]byte)[0] == 1 { - leds.UpLeftArrow() + if err := leds.UpLeftArrow(); err != nil { + fmt.Println(err) + } return } - leds.Blank() + if err := leds.Blank(); err != nil { + fmt.Println(err) + } }) - buttons.On(microbit.ButtonBEvent, func(data interface{}) { + _ = buttons.On(microbit.ButtonBEvent, func(data interface{}) { if data.([]byte)[0] == 1 { - leds.UpRightArrow() + if err := leds.UpRightArrow(); err != nil { + fmt.Println(err) + } return } - leds.Blank() + if err := leds.Blank(); err != nil { + fmt.Println(err) + } }) } @@ -65,5 +74,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/microbit_io_button.go b/examples/bleclient_microbit_io_button.go similarity index 81% rename from examples/microbit_io_button.go rename to examples/bleclient_microbit_io_button.go index c1e80be36..c203a7d65 100644 --- a/examples/microbit_io_button.go +++ b/examples/bleclient_microbit_io_button.go @@ -31,6 +31,7 @@ package main import ( + "fmt" "os" "gobot.io/x/gobot/v2" @@ -47,11 +48,15 @@ func main() { led := gpio.NewLedDriver(ubit, "1") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { - led.On() + _ = button.On(gpio.ButtonPush, func(data interface{}) { + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { - led.Off() + _ = button.On(gpio.ButtonRelease, func(data interface{}) { + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -61,5 +66,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/microbit_led.go b/examples/bleclient_microbit_led.go similarity index 79% rename from examples/microbit_led.go rename to examples/bleclient_microbit_led.go index 99586dd27..4d203750c 100644 --- a/examples/microbit_led.go +++ b/examples/bleclient_microbit_led.go @@ -27,6 +27,7 @@ package main import ( + "fmt" "os" "time" @@ -40,12 +41,18 @@ func main() { ubit := microbit.NewLEDDriver(bleAdaptor) work := func() { - ubit.Blank() + if err := ubit.Blank(); err != nil { + fmt.Println(err) + } gobot.After(1*time.Second, func() { - ubit.WriteText("Hello") + if err := ubit.WriteText("Hello"); err != nil { + fmt.Println(err) + } }) gobot.After(7*time.Second, func() { - ubit.Smile() + if err := ubit.Smile(); err != nil { + fmt.Println(err) + } }) } @@ -55,5 +62,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/microbit_magnetometer.go b/examples/bleclient_microbit_magnetometer.go similarity index 89% rename from examples/microbit_magnetometer.go rename to examples/bleclient_microbit_magnetometer.go index 8e78bbbff..90c13637e 100644 --- a/examples/microbit_magnetometer.go +++ b/examples/bleclient_microbit_magnetometer.go @@ -40,7 +40,7 @@ func main() { ubit := microbit.NewMagnetometerDriver(bleAdaptor) work := func() { - ubit.On(microbit.MagnetometerEvent, func(data interface{}) { + _ = ubit.On(microbit.MagnetometerEvent, func(data interface{}) { fmt.Println("Magnetometer", data) }) } @@ -51,5 +51,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/microbit_temperature.go b/examples/bleclient_microbit_temperature.go similarity index 89% rename from examples/microbit_temperature.go rename to examples/bleclient_microbit_temperature.go index a27109768..7b21e0443 100644 --- a/examples/microbit_temperature.go +++ b/examples/bleclient_microbit_temperature.go @@ -40,7 +40,7 @@ func main() { ubit := microbit.NewTemperatureDriver(bleAdaptor) work := func() { - ubit.On(microbit.TemperatureEvent, func(data interface{}) { + _ = ubit.On(microbit.TemperatureEvent, func(data interface{}) { fmt.Println("Temperature", data) }) } @@ -51,5 +51,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/minidrone.go b/examples/bleclient_minidrone.go similarity index 77% rename from examples/minidrone.go rename to examples/bleclient_minidrone.go index 17519d84b..4832f8e1e 100644 --- a/examples/minidrone.go +++ b/examples/bleclient_minidrone.go @@ -16,6 +16,7 @@ package main import ( + "fmt" "os" "time" @@ -29,10 +30,14 @@ func main() { drone := parrot.NewMinidroneDriver(bleAdaptor) work := func() { - drone.TakeOff() + if err := drone.TakeOff(); err != nil { + fmt.Println(err) + } gobot.After(5*time.Second, func() { - drone.Land() + if err := drone.Land(); err != nil { + fmt.Println(err) + } }) } @@ -42,5 +47,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/minidrone_events.go b/examples/bleclient_minidrone_events.go similarity index 62% rename from examples/minidrone_events.go rename to examples/bleclient_minidrone_events.go index b95eb10a6..305ed3eaa 100644 --- a/examples/minidrone_events.go +++ b/examples/bleclient_minidrone_events.go @@ -30,35 +30,39 @@ func main() { drone := parrot.NewMinidroneDriver(bleAdaptor) work := func() { - drone.On(parrot.BatteryEvent, func(data interface{}) { + _ = drone.On(parrot.BatteryEvent, func(data interface{}) { fmt.Printf("battery: %d\n", data) }) - drone.On(parrot.FlightStatusEvent, func(data interface{}) { + _ = drone.On(parrot.FlightStatusEvent, func(data interface{}) { fmt.Printf("flight status: %d\n", data) }) - drone.On(parrot.TakeoffEvent, func(data interface{}) { + _ = drone.On(parrot.TakeoffEvent, func(data interface{}) { fmt.Println("taking off...") }) - drone.On(parrot.HoveringEvent, func(data interface{}) { + _ = drone.On(parrot.HoveringEvent, func(data interface{}) { fmt.Println("hovering!") gobot.After(5*time.Second, func() { - drone.Land() + if err := drone.Land(); err != nil { + fmt.Println(err) + } }) }) - drone.On(parrot.LandingEvent, func(data interface{}) { + _ = drone.On(parrot.LandingEvent, func(data interface{}) { fmt.Println("landing...") }) - drone.On(parrot.LandedEvent, func(data interface{}) { + _ = drone.On(parrot.LandedEvent, func(data interface{}) { fmt.Println("landed.") }) time.Sleep(1000 * time.Millisecond) - drone.TakeOff() + if err := drone.TakeOff(); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("minidrone", @@ -67,5 +71,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/minidrone_mambo_ps3.go b/examples/bleclient_minidrone_mambo_ps3.go similarity index 51% rename from examples/minidrone_mambo_ps3.go rename to examples/bleclient_minidrone_mambo_ps3.go index b1b443a72..a977b89ab 100644 --- a/examples/minidrone_mambo_ps3.go +++ b/examples/bleclient_minidrone_mambo_ps3.go @@ -23,6 +23,7 @@ package main import ( + "fmt" "os" "sync/atomic" "time" @@ -59,51 +60,65 @@ func main() { clawOpen := false - stick.On(joystick.CirclePress, func(data interface{}) { + _ = stick.On(joystick.CirclePress, func(data interface{}) { if clawOpen { - drone.ClawControl(0, parrot.ClawClosed) + if err := drone.ClawControl(0, parrot.ClawClosed); err != nil { + fmt.Println(err) + } clawOpen = false } else { - drone.ClawControl(0, parrot.ClawOpen) + if err := drone.ClawControl(0, parrot.ClawOpen); err != nil { + fmt.Println(err) + } clawOpen = true } }) - stick.On(joystick.R2Press, func(data interface{}) { + _ = stick.On(joystick.R2Press, func(data interface{}) { if clawOpen { - drone.ClawControl(0, parrot.ClawClosed) + if err := drone.ClawControl(0, parrot.ClawClosed); err != nil { + fmt.Println(err) + } clawOpen = false } else { - drone.ClawControl(0, parrot.ClawOpen) + if err := drone.ClawControl(0, parrot.ClawOpen); err != nil { + fmt.Println(err) + } clawOpen = true } }) - stick.On(joystick.TrianglePress, func(data interface{}) { - drone.HullProtection(true) - drone.TakeOff() + _ = stick.On(joystick.TrianglePress, func(data interface{}) { + if err := drone.HullProtection(true); err != nil { + fmt.Println(err) + } + if err := drone.TakeOff(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.XPress, func(data interface{}) { - drone.Land() + _ = stick.On(joystick.XPress, func(data interface{}) { + if err := drone.Land(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { val := float64(data.(int16)) leftX.Store(val) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { val := float64(data.(int16)) leftY.Store(val) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { val := float64(data.(int16)) rightX.Store(val) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { val := float64(data.(int16)) rightY.Store(val) }) @@ -113,20 +128,32 @@ func main() { switch { case rightStick.y < -10: - drone.Forward(parrot.ValidatePitch(rightStick.y, offset)) + if err := drone.Forward(parrot.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } case rightStick.y > 10: - drone.Backward(parrot.ValidatePitch(rightStick.y, offset)) + if err := drone.Backward(parrot.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Forward(0) + if err := drone.Forward(0); err != nil { + fmt.Println(err) + } } switch { case rightStick.x > 10: - drone.Right(parrot.ValidatePitch(rightStick.x, offset)) + if err := drone.Right(parrot.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } case rightStick.x < -10: - drone.Left(parrot.ValidatePitch(rightStick.x, offset)) + if err := drone.Left(parrot.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Right(0) + if err := drone.Right(0); err != nil { + fmt.Println(err) + } } }) @@ -134,20 +161,32 @@ func main() { leftStick := getLeftStick() switch { case leftStick.y < -10: - drone.Up(parrot.ValidatePitch(leftStick.y, offset)) + if err := drone.Up(parrot.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } case leftStick.y > 10: - drone.Down(parrot.ValidatePitch(leftStick.y, offset)) + if err := drone.Down(parrot.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Up(0) + if err := drone.Up(0); err != nil { + fmt.Println(err) + } } switch { case leftStick.x > 20: - drone.Clockwise(parrot.ValidatePitch(leftStick.x, offset)) + if err := drone.Clockwise(parrot.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } case leftStick.x < -20: - drone.CounterClockwise(parrot.ValidatePitch(leftStick.x, offset)) + if err := drone.CounterClockwise(parrot.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Clockwise(0) + if err := drone.Clockwise(0); err != nil { + fmt.Println(err) + } } }) } @@ -158,7 +197,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func getLeftStick() pair { diff --git a/examples/minidrone_ps3.go b/examples/bleclient_minidrone_ps3.go similarity index 52% rename from examples/minidrone_ps3.go rename to examples/bleclient_minidrone_ps3.go index a316a3d52..409c24865 100644 --- a/examples/minidrone_ps3.go +++ b/examples/bleclient_minidrone_ps3.go @@ -23,6 +23,7 @@ package main import ( + "fmt" "os" "sync/atomic" "time" @@ -57,44 +58,56 @@ func main() { recording := false - stick.On(joystick.CirclePress, func(data interface{}) { + _ = stick.On(joystick.CirclePress, func(data interface{}) { if recording { - drone.StopRecording() + if err := drone.StopRecording(); err != nil { + fmt.Println(err) + } } else { - drone.StartRecording() + if err := drone.StartRecording(); err != nil { + fmt.Println(err) + } } recording = !recording }) - stick.On(joystick.SquarePress, func(data interface{}) { - drone.Stop() + _ = stick.On(joystick.SquarePress, func(data interface{}) { + if err := drone.Stop(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.TrianglePress, func(data interface{}) { - drone.HullProtection(true) - drone.TakeOff() + _ = stick.On(joystick.TrianglePress, func(data interface{}) { + if err := drone.HullProtection(true); err != nil { + fmt.Println(err) + } + if err := drone.TakeOff(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.XPress, func(data interface{}) { - drone.Land() + _ = stick.On(joystick.XPress, func(data interface{}) { + if err := drone.Land(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { val := float64(data.(int16)) leftX.Store(val) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { val := float64(data.(int16)) leftY.Store(val) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { val := float64(data.(int16)) rightX.Store(val) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { val := float64(data.(int16)) rightY.Store(val) }) @@ -104,20 +117,32 @@ func main() { switch { case rightStick.y < -10: - drone.Forward(parrot.ValidatePitch(rightStick.y, offset)) + if err := drone.Forward(parrot.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } case rightStick.y > 10: - drone.Backward(parrot.ValidatePitch(rightStick.y, offset)) + if err := drone.Backward(parrot.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Forward(0) + if err := drone.Forward(0); err != nil { + fmt.Println(err) + } } switch { case rightStick.x > 10: - drone.Right(parrot.ValidatePitch(rightStick.x, offset)) + if err := drone.Right(parrot.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } case rightStick.x < -10: - drone.Left(parrot.ValidatePitch(rightStick.x, offset)) + if err := drone.Left(parrot.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Right(0) + if err := drone.Right(0); err != nil { + fmt.Println(err) + } } }) @@ -125,20 +150,32 @@ func main() { leftStick := getLeftStick() switch { case leftStick.y < -10: - drone.Up(parrot.ValidatePitch(leftStick.y, offset)) + if err := drone.Up(parrot.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } case leftStick.y > 10: - drone.Down(parrot.ValidatePitch(leftStick.y, offset)) + if err := drone.Down(parrot.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Up(0) + if err := drone.Up(0); err != nil { + fmt.Println(err) + } } switch { case leftStick.x > 20: - drone.Clockwise(parrot.ValidatePitch(leftStick.x, offset)) + if err := drone.Clockwise(parrot.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } case leftStick.x < -20: - drone.CounterClockwise(parrot.ValidatePitch(leftStick.x, offset)) + if err := drone.CounterClockwise(parrot.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Clockwise(0) + if err := drone.Clockwise(0); err != nil { + fmt.Println(err) + } } }) } @@ -149,7 +186,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func getLeftStick() pair { diff --git a/examples/ble_multiple_generic.go b/examples/bleclient_multiple_generic.go similarity index 95% rename from examples/ble_multiple_generic.go rename to examples/bleclient_multiple_generic.go index ddc7d313f..c09b4e3ec 100644 --- a/examples/ble_multiple_generic.go +++ b/examples/bleclient_multiple_generic.go @@ -61,5 +61,7 @@ func main() { master.AddRobot(bot) } - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_multiple_info.go b/examples/bleclient_multiple_info.go similarity index 96% rename from examples/ble_multiple_info.go rename to examples/bleclient_multiple_info.go index b4960e9a5..f76f5b0ae 100644 --- a/examples/ble_multiple_info.go +++ b/examples/bleclient_multiple_info.go @@ -79,5 +79,7 @@ func main() { master.AddRobot(bot) } - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_ollie.go b/examples/bleclient_ollie.go similarity index 91% rename from examples/ble_ollie.go rename to examples/bleclient_ollie.go index a2dfe8e19..82f91762c 100644 --- a/examples/ble_ollie.go +++ b/examples/bleclient_ollie.go @@ -34,5 +34,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_ollie_boost.go b/examples/bleclient_ollie_boost.go similarity index 92% rename from examples/ble_ollie_boost.go rename to examples/bleclient_ollie_boost.go index ba1859f17..b4a10bf8c 100644 --- a/examples/ble_ollie_boost.go +++ b/examples/bleclient_ollie_boost.go @@ -37,5 +37,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_ollie_crazy.go b/examples/bleclient_ollie_crazy.go similarity index 92% rename from examples/ble_ollie_crazy.go rename to examples/bleclient_ollie_crazy.go index cef96f22d..4d2566b5a 100644 --- a/examples/ble_ollie_crazy.go +++ b/examples/bleclient_ollie_crazy.go @@ -33,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_ollie_mqtt.go b/examples/bleclient_ollie_mqtt.go similarity index 77% rename from examples/ble_ollie_mqtt.go rename to examples/bleclient_ollie_mqtt.go index 2d9c07977..cfd9a4e48 100644 --- a/examples/ble_ollie_mqtt.go +++ b/examples/bleclient_ollie_mqtt.go @@ -33,7 +33,7 @@ func main() { work := func() { ollie.SetRGB(255, 0, 255) - mqttAdaptor.On("sensores/dial", func(msg mqtt.Message) { + _ = mqttAdaptor.On("sensors/dial", func(msg mqtt.Message) { val, _ := strconv.Atoi(string(msg.Payload())) if val > 2000 { @@ -47,28 +47,28 @@ func main() { ollie.SetRGB(255, 0, 0) }) - mqttAdaptor.On("rover/frente", func(msg mqtt.Message) { + _ = mqttAdaptor.On("rover/frente", func(msg mqtt.Message) { ollie.Roll(40, FRENTE) gobot.After(1*time.Second, func() { ollie.Stop() }) }) - mqttAdaptor.On("rover/derecha", func(msg mqtt.Message) { + _ = mqttAdaptor.On("rover/derecha", func(msg mqtt.Message) { ollie.Roll(40, DERECHA) gobot.After(1*time.Second, func() { ollie.Stop() }) }) - mqttAdaptor.On("rover/atras", func(msg mqtt.Message) { + _ = mqttAdaptor.On("rover/atras", func(msg mqtt.Message) { ollie.Roll(40, ATRAS) gobot.After(1*time.Second, func() { ollie.Stop() }) }) - mqttAdaptor.On("rover/izquierda", func(msg mqtt.Message) { + _ = mqttAdaptor.On("rover/izquierda", func(msg mqtt.Message) { ollie.Roll(40, IZQUIERDA) gobot.After(1*time.Second, func() { ollie.Stop() @@ -82,5 +82,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_ollie_multiple.go b/examples/bleclient_ollie_multiple.go similarity index 94% rename from examples/ble_ollie_multiple.go rename to examples/bleclient_ollie_multiple.go index a80f1d413..90a06d714 100644 --- a/examples/ble_ollie_multiple.go +++ b/examples/bleclient_ollie_multiple.go @@ -55,5 +55,7 @@ func main() { master.AddRobot(bot) } - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_ollie_roll.go b/examples/bleclient_ollie_roll.go similarity index 91% rename from examples/ble_ollie_roll.go rename to examples/bleclient_ollie_roll.go index bf07d7e36..7bcba8401 100644 --- a/examples/ble_ollie_roll.go +++ b/examples/bleclient_ollie_roll.go @@ -32,5 +32,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_ollie_spin.go b/examples/bleclient_ollie_spin.go similarity index 92% rename from examples/ble_ollie_spin.go rename to examples/bleclient_ollie_spin.go index 027328f79..4851826c2 100644 --- a/examples/ble_ollie_spin.go +++ b/examples/bleclient_ollie_spin.go @@ -33,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_sprkplus.go b/examples/bleclient_sprkplus.go similarity index 93% rename from examples/ble_sprkplus.go rename to examples/bleclient_sprkplus.go index ad85eb50e..36c5d1914 100644 --- a/examples/ble_sprkplus.go +++ b/examples/bleclient_sprkplus.go @@ -43,5 +43,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/ble_sprkplus_collision.go b/examples/bleclient_sprkplus_collision.go similarity index 87% rename from examples/ble_sprkplus_collision.go rename to examples/bleclient_sprkplus_collision.go index c053c2893..44b09890b 100644 --- a/examples/ble_sprkplus_collision.go +++ b/examples/bleclient_sprkplus_collision.go @@ -29,7 +29,7 @@ func main() { ball := sphero.NewSPRKPlusDriver(bleAdaptor) work := func() { - ball.On("collision", func(data interface{}) { + _ = ball.On("collision", func(data interface{}) { fmt.Printf("collision detected = %+v \n", data) ball.SetRGB(255, 0, 0) }) @@ -44,5 +44,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_blink.go b/examples/chip_blink.go index 528e41f5d..cd54f2fd9 100644 --- a/examples/chip_blink.go +++ b/examples/chip_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_blinkm.go b/examples/chip_blinkm.go index 85bbc816e..ca53a29a3 100644 --- a/examples/chip_blinkm.go +++ b/examples/chip_blinkm.go @@ -24,8 +24,13 @@ func main() { r := byte(gobot.Rand(255)) g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) - blinkm.Rgb(r, g, b) - color, _ := blinkm.Color() + if err := blinkm.Rgb(r, g, b); err != nil { + fmt.Println(err) + } + color, err := blinkm.Color() + if err != nil { + fmt.Println(err) + } fmt.Println("color", color) }) } @@ -36,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_button.go b/examples/chip_button.go index bc1a6d600..06d3b1d4b 100644 --- a/examples/chip_button.go +++ b/examples/chip_button.go @@ -19,11 +19,11 @@ func main() { button := gpio.NewButtonDriver(chipAdaptor, "XIO-P0") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { + _ = button.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("button pressed") }) - button.On(gpio.ButtonRelease, func(data interface{}) { + _ = button.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("button released") }) } @@ -34,5 +34,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_button_led.go b/examples/chip_button_led.go index d011a58b9..c450550dc 100644 --- a/examples/chip_button_led.go +++ b/examples/chip_button_led.go @@ -7,6 +7,8 @@ package main import ( + "fmt" + "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/platforms/chip" @@ -18,12 +20,16 @@ func main() { led := gpio.NewLedDriver(chipAdaptor, "XIO-P7") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { - led.On() + _ = button.On(gpio.ButtonPush, func(data interface{}) { + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { - led.Off() + _ = button.On(gpio.ButtonRelease, func(data interface{}) { + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -33,5 +39,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_drv2605l.go b/examples/chip_drv2605l.go index 12fad0981..847f82441 100644 --- a/examples/chip_drv2605l.go +++ b/examples/chip_drv2605l.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -21,8 +22,12 @@ func main() { work := func() { gobot.Every(3*time.Second, func() { pause := haptic.GetPauseWaveform(50) - haptic.SetSequence([]byte{1, pause, 1, pause, 1}) - haptic.Go() + if err := haptic.SetSequence([]byte{1, pause, 1, pause, 1}); err != nil { + fmt.Println(err) + } + if err := haptic.Go(); err != nil { + fmt.Println(err) + } }) } @@ -32,5 +37,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_grove_accelerometer.go b/examples/chip_grove_accelerometer.go index 7030724a2..ba0994926 100644 --- a/examples/chip_grove_accelerometer.go +++ b/examples/chip_grove_accelerometer.go @@ -36,5 +36,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_grove_lcd.go b/examples/chip_grove_lcd.go index 513147682..401c50337 100644 --- a/examples/chip_grove_lcd.go +++ b/examples/chip_grove_lcd.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -19,26 +20,47 @@ func main() { screen := i2c.NewGroveLcdDriver(board) work := func() { - screen.Write("hello") + if err := screen.Write("hello"); err != nil { + fmt.Println(err) + } - screen.SetRGB(255, 0, 0) + if err := screen.SetRGB(255, 0, 0); err != nil { + fmt.Println(err) + } gobot.After(5*time.Second, func() { - screen.Clear() - screen.Home() - screen.SetRGB(0, 255, 0) + if err := screen.Clear(); err != nil { + fmt.Println(err) + } + if err := screen.Home(); err != nil { + fmt.Println(err) + } + if err := screen.SetRGB(0, 255, 0); err != nil { + fmt.Println(err) + } // set a custom character in the first position - screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]) + if err := screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]); err != nil { + fmt.Println(err) + } // add the custom character at the end of the string - screen.Write("goodbye\nhave a nice day " + string(byte(0))) + if err := screen.Write("goodbye\nhave a nice day " + string(byte(0))); err != nil { + fmt.Println(err) + } + gobot.Every(500*time.Millisecond, func() { - screen.Scroll(false) + if err := screen.Scroll(false); err != nil { + fmt.Println(err) + } }) }) - screen.Home() + if err := screen.Home(); err != nil { + fmt.Println(err) + } time.Sleep(1 * time.Second) - screen.SetRGB(0, 0, 255) + if err := screen.SetRGB(0, 0, 255); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("screenBot", @@ -47,5 +69,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_mpu6050.go b/examples/chip_mpu6050.go index 6238f220a..887b41d55 100644 --- a/examples/chip_mpu6050.go +++ b/examples/chip_mpu6050.go @@ -21,7 +21,9 @@ func main() { work := func() { gobot.Every(100*time.Millisecond, func() { - mpu6050.GetData() + if err := mpu6050.GetData(); err != nil { + fmt.Println(err) + } fmt.Println("Accelerometer", mpu6050.Accelerometer) fmt.Println("Gyroscope", mpu6050.Gyroscope) @@ -35,5 +37,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_tsl2561.go b/examples/chip_tsl2561.go index 9f7ba1b72..10d6fdbf3 100644 --- a/examples/chip_tsl2561.go +++ b/examples/chip_tsl2561.go @@ -38,5 +38,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/chip_wiichuck.go b/examples/chip_wiichuck.go index 120f82c85..bf546951d 100644 --- a/examples/chip_wiichuck.go +++ b/examples/chip_wiichuck.go @@ -19,18 +19,18 @@ func main() { wiichuck := i2c.NewWiichuckDriver(chipAdaptor) work := func() { - wiichuck.On(wiichuck.Event("joystick"), func(data interface{}) { + _ = wiichuck.On(wiichuck.Event("joystick"), func(data interface{}) { fmt.Println("joystick", data) }) - wiichuck.On(wiichuck.Event("c"), func(data interface{}) { + _ = wiichuck.On(wiichuck.Event("c"), func(data interface{}) { fmt.Println("c") }) - wiichuck.On(wiichuck.Event("z"), func(data interface{}) { + _ = wiichuck.On(wiichuck.Event("z"), func(data interface{}) { fmt.Println("z") }) - wiichuck.On(wiichuck.Event("error"), func(data interface{}) { + _ = wiichuck.On(wiichuck.Event("error"), func(data interface{}) { fmt.Println("Wiichuck error:", data) }) } @@ -41,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/digispark_api.go b/examples/digispark_api.go index 8614f783e..b409ba8f5 100644 --- a/examples/digispark_api.go +++ b/examples/digispark_api.go @@ -27,5 +27,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/digispark_blink.go b/examples/digispark_blink.go index dc500d2de..dc7120d62 100644 --- a/examples/digispark_blink.go +++ b/examples/digispark_blink.go @@ -21,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -31,8 +33,7 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/digispark_blinkm.go b/examples/digispark_blinkm.go index b64c693b5..d7c39a551 100644 --- a/examples/digispark_blinkm.go +++ b/examples/digispark_blinkm.go @@ -24,8 +24,13 @@ func main() { r := byte(gobot.Rand(255)) g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) - blinkm.Rgb(r, g, b) - color, _ := blinkm.Color() + if err := blinkm.Rgb(r, g, b); err != nil { + fmt.Println(err) + } + color, err := blinkm.Color() + if err != nil { + fmt.Println(err) + } fmt.Println("color", color) }) } @@ -36,8 +41,7 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/digispark_driver.go b/examples/digispark_driver.go index 369449b7e..9ccf5a51f 100644 --- a/examples/digispark_driver.go +++ b/examples/digispark_driver.go @@ -72,8 +72,7 @@ func main() { work, ) - err = robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/digispark_led_brightness.go b/examples/digispark_led_brightness.go index e52cfe17c..cc0348313 100644 --- a/examples/digispark_led_brightness.go +++ b/examples/digispark_led_brightness.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -23,7 +24,9 @@ func main() { fadeAmount := uint8(15) gobot.Every(100*time.Millisecond, func() { - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } brightness = brightness + fadeAmount if brightness == 0 || brightness == 255 { fadeAmount = -fadeAmount @@ -37,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/digispark_mpl115a2.go b/examples/digispark_mpl115a2.go index b4bd8ea68..b31134353 100644 --- a/examples/digispark_mpl115a2.go +++ b/examples/digispark_mpl115a2.go @@ -35,8 +35,7 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/digispark_pca9501.go b/examples/digispark_pca9501.go index 81ae873e4..7023d8190 100644 --- a/examples/digispark_pca9501.go +++ b/examples/digispark_pca9501.go @@ -83,8 +83,7 @@ func main() { work, ) - err = robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/digispark_servo.go b/examples/digispark_servo.go index 7968b5ed4..4a6fd4d95 100644 --- a/examples/digispark_servo.go +++ b/examples/digispark_servo.go @@ -23,7 +23,9 @@ func main() { gobot.Every(1*time.Second, func() { i := uint8(gobot.Rand(180)) fmt.Println("Turning", i) - servo.Move(i) + if err := servo.Move(i); err != nil { + fmt.Println(err) + } }) } @@ -33,5 +35,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/dragonboard_button.go b/examples/dragonboard_button.go index 1a7f01fff..520f3965c 100644 --- a/examples/dragonboard_button.go +++ b/examples/dragonboard_button.go @@ -19,11 +19,11 @@ func main() { button := gpio.NewButtonDriver(dragonAdaptor, "GPIO_A") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { + _ = button.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("button pressed") }) - button.On(gpio.ButtonRelease, func(data interface{}) { + _ = button.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("button released") }) } @@ -34,5 +34,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_blink.go b/examples/edison_blink.go index 7d3dd1d9b..b30ee3269 100644 --- a/examples/edison_blink.go +++ b/examples/edison_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -22,7 +23,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -32,5 +35,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_blink_without_all_gobot_framework.go b/examples/edison_blink_without_all_gobot_framework.go index 935e1840c..b65e0b088 100644 --- a/examples/edison_blink_without_all_gobot_framework.go +++ b/examples/edison_blink_without_all_gobot_framework.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2/drivers/gpio" @@ -19,13 +20,19 @@ import ( // golang library to interact with sensors and other devices. func main() { e := edison.NewAdaptor() - e.Connect() + if err := e.Connect(); err != nil { + fmt.Println(err) + } led := gpio.NewLedDriver(e, "13") - led.Start() + if err := led.Start(); err != nil { + fmt.Println(err) + } for { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } time.Sleep(1000 * time.Millisecond) } } diff --git a/examples/edison_blinkm.go b/examples/edison_blinkm.go index 4b75e34af..390d4c710 100644 --- a/examples/edison_blinkm.go +++ b/examples/edison_blinkm.go @@ -24,8 +24,13 @@ func main() { r := byte(gobot.Rand(255)) g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) - blinkm.Rgb(r, g, b) - color, _ := blinkm.Color() + if err := blinkm.Rgb(r, g, b); err != nil { + fmt.Println(err) + } + color, err := blinkm.Color() + if err != nil { + fmt.Println(err) + } fmt.Println("color", color) }) } @@ -36,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_bme280.go b/examples/edison_bme280.go index ec16959cc..0b0652981 100644 --- a/examples/edison_bme280.go +++ b/examples/edison_bme280.go @@ -53,8 +53,7 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/edison_button.go b/examples/edison_button.go index 022eedccb..34bc4ce85 100644 --- a/examples/edison_button.go +++ b/examples/edison_button.go @@ -7,6 +7,8 @@ package main import ( + "fmt" + "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/platforms/intel-iot/edison" @@ -19,11 +21,15 @@ func main() { led := gpio.NewLedDriver(e, "13") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { - led.On() + _ = button.On(gpio.ButtonPush, func(data interface{}) { + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { - led.Off() + _ = button.On(gpio.ButtonRelease, func(data interface{}) { + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -33,5 +39,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_button_led.go b/examples/edison_button_led.go index 74e0456db..28356ca23 100644 --- a/examples/edison_button_led.go +++ b/examples/edison_button_led.go @@ -7,6 +7,8 @@ package main import ( + "fmt" + "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/platforms/intel-iot/edison" @@ -19,11 +21,15 @@ func main() { led := gpio.NewLedDriver(e, "4") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { - led.On() + _ = button.On(gpio.ButtonPush, func(data interface{}) { + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { - led.Off() + _ = button.On(gpio.ButtonRelease, func(data interface{}) { + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -33,5 +39,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_button_led_api.go b/examples/edison_button_led_api.go index 7884d3aac..70dad36df 100644 --- a/examples/edison_button_led_api.go +++ b/examples/edison_button_led_api.go @@ -7,11 +7,12 @@ package main import ( + "fmt" + "gobot.io/x/gobot/v2" + "gobot.io/x/gobot/v2/api" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/platforms/intel-iot/edison" - - "gobot.io/x/gobot/v2/api" ) func main() { @@ -24,11 +25,15 @@ func main() { led := gpio.NewLedDriver(e, "4") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { - led.On() + _ = button.On(gpio.ButtonPush, func(data interface{}) { + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { - led.Off() + _ = button.On(gpio.ButtonRelease, func(data interface{}) { + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -40,5 +45,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_accelerometer.go b/examples/edison_grove_accelerometer.go index 845d89d19..c4b551530 100644 --- a/examples/edison_grove_accelerometer.go +++ b/examples/edison_grove_accelerometer.go @@ -36,5 +36,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_blink.go b/examples/edison_grove_blink.go index f390ef6b1..54617b10a 100644 --- a/examples/edison_grove_blink.go +++ b/examples/edison_grove_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_button.go b/examples/edison_grove_button.go index af5459400..7a86dc963 100644 --- a/examples/edison_grove_button.go +++ b/examples/edison_grove_button.go @@ -19,11 +19,11 @@ func main() { button := gpio.NewButtonDriver(e, "2") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { + _ = button.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("On!") }) - button.On(gpio.ButtonRelease, func(data interface{}) { + _ = button.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("Off!") }) } @@ -34,5 +34,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_buzzer.go b/examples/edison_grove_buzzer.go index 2721dc938..cb00294ab 100644 --- a/examples/edison_grove_buzzer.go +++ b/examples/edison_grove_buzzer.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -42,7 +43,9 @@ func main() { } for _, val := range song { - buzzer.Tone(val.tone, val.duration) + if err := buzzer.Tone(val.tone, val.duration); err != nil { + fmt.Println(err) + } time.Sleep(10 * time.Millisecond) } } @@ -53,5 +56,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_lcd.go b/examples/edison_grove_lcd.go index 040a927bb..6c4fc8cc3 100644 --- a/examples/edison_grove_lcd.go +++ b/examples/edison_grove_lcd.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -19,26 +20,46 @@ func main() { screen := i2c.NewGroveLcdDriver(board) work := func() { - screen.Write("hello") + if err := screen.Write("hello"); err != nil { + fmt.Println(err) + } - screen.SetRGB(255, 0, 0) + if err := screen.SetRGB(255, 0, 0); err != nil { + fmt.Println(err) + } gobot.After(5*time.Second, func() { - screen.Clear() - screen.Home() - screen.SetRGB(0, 255, 0) + if err := screen.Clear(); err != nil { + fmt.Println(err) + } + if err := screen.Home(); err != nil { + fmt.Println(err) + } + if err := screen.SetRGB(0, 255, 0); err != nil { + fmt.Println(err) + } // set a custom character in the first position - screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]) + if err := screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]); err != nil { + fmt.Println(err) + } // add the custom character at the end of the string - screen.Write("goodbye\nhave a nice day " + string(byte(0))) + if err := screen.Write("goodbye\nhave a nice day " + string(byte(0))); err != nil { + fmt.Println(err) + } gobot.Every(500*time.Millisecond, func() { - screen.Scroll(false) + if err := screen.Scroll(false); err != nil { + fmt.Println(err) + } }) }) - screen.Home() + if err := screen.Home(); err != nil { + fmt.Println(err) + } time.Sleep(1 * time.Second) - screen.SetRGB(0, 0, 255) + if err := screen.SetRGB(0, 0, 255); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("screenBot", @@ -47,5 +68,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_led.go b/examples/edison_grove_led.go index 440f58012..2c11fadbf 100644 --- a/examples/edison_grove_led.go +++ b/examples/edison_grove_led.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_light_sensor.go b/examples/edison_grove_light_sensor.go index 68f08784f..08a2b74ec 100644 --- a/examples/edison_grove_light_sensor.go +++ b/examples/edison_grove_light_sensor.go @@ -20,7 +20,7 @@ func main() { sensor := aio.NewGroveLightSensorDriver(board, "0", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(sensor.Event("data"), func(data interface{}) { + _ = sensor.On(sensor.Event("data"), func(data interface{}) { fmt.Println("sensor", data) }) } @@ -31,5 +31,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_piezo_vibration.go b/examples/edison_grove_piezo_vibration.go index ea30c7e5b..7a0a5739c 100644 --- a/examples/edison_grove_piezo_vibration.go +++ b/examples/edison_grove_piezo_vibration.go @@ -20,7 +20,7 @@ func main() { sensor := aio.NewGrovePiezoVibrationSensorDriver(board, "0", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(aio.Vibration, func(data interface{}) { + _ = sensor.On(aio.Vibration, func(data interface{}) { fmt.Println("got one!") }) } @@ -31,5 +31,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_rotary_sensor.go b/examples/edison_grove_rotary_sensor.go index 6fbde9e86..ac04ced35 100644 --- a/examples/edison_grove_rotary_sensor.go +++ b/examples/edison_grove_rotary_sensor.go @@ -20,7 +20,7 @@ func main() { sensor := aio.NewGroveRotaryDriver(board, "0", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { fmt.Println("sensor", data) }) } @@ -31,5 +31,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_sound_sensor.go b/examples/edison_grove_sound_sensor.go index 794355297..9cec7fe95 100644 --- a/examples/edison_grove_sound_sensor.go +++ b/examples/edison_grove_sound_sensor.go @@ -20,7 +20,7 @@ func main() { sensor := aio.NewGroveSoundSensorDriver(board, "0", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { fmt.Println("sensor", data) }) } @@ -31,5 +31,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_temperature_sensor.go b/examples/edison_grove_temperature_sensor.go index 6886f6093..0d6c2bf69 100644 --- a/examples/edison_grove_temperature_sensor.go +++ b/examples/edison_grove_temperature_sensor.go @@ -31,5 +31,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_grove_touch.go b/examples/edison_grove_touch.go index 3e9696730..c8b7f7632 100644 --- a/examples/edison_grove_touch.go +++ b/examples/edison_grove_touch.go @@ -19,11 +19,11 @@ func main() { touch := gpio.NewButtonDriver(e, "2") work := func() { - touch.On(gpio.ButtonPush, func(data interface{}) { + _ = touch.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("On!") }) - touch.On(gpio.ButtonRelease, func(data interface{}) { + _ = touch.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("Off!") }) } @@ -34,5 +34,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_led_brightness.go b/examples/edison_led_brightness.go index 11537e0c4..6fe99158f 100644 --- a/examples/edison_led_brightness.go +++ b/examples/edison_led_brightness.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -23,7 +24,9 @@ func main() { fadeAmount := uint8(15) gobot.Every(100*time.Millisecond, func() { - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } brightness = brightness + fadeAmount if brightness == 0 || brightness == 255 { fadeAmount = -fadeAmount @@ -37,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_led_brightness_with_analog_input.go b/examples/edison_led_brightness_with_analog_input.go index 9b82fefae..134e9f8d3 100644 --- a/examples/edison_led_brightness_with_analog_input.go +++ b/examples/edison_led_brightness_with_analog_input.go @@ -22,13 +22,15 @@ func main() { led := gpio.NewLedDriver(e, "3") work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { brightness := uint8( gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 4096), 0, 255), ) fmt.Println("sensor", data) fmt.Println("brightness", brightness) - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } }) } @@ -38,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_miniboard_grove_accelerometer.go b/examples/edison_miniboard_grove_accelerometer.go index b20c511d2..4b86bd4f3 100644 --- a/examples/edison_miniboard_grove_accelerometer.go +++ b/examples/edison_miniboard_grove_accelerometer.go @@ -37,5 +37,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/edison_rgb_led.go b/examples/edison_rgb_led.go index 427a26c3e..966887dc1 100644 --- a/examples/edison_rgb_led.go +++ b/examples/edison_rgb_led.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -23,7 +24,9 @@ func main() { r := uint8(gobot.Rand(255)) g := uint8(gobot.Rand(255)) b := uint8(gobot.Rand(255)) - led.SetRGB(r, g, b) + if err := led.SetRGB(r, g, b); err != nil { + fmt.Println(err) + } }) } @@ -33,5 +36,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/every_done.go b/examples/every_done.go index 607f50738..987dbe79b 100644 --- a/examples/every_done.go +++ b/examples/every_done.go @@ -28,5 +28,7 @@ func main() { }, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_adxl345.go b/examples/firmata_adxl345.go index a791c2bb9..a8a7e67a9 100644 --- a/examples/firmata_adxl345.go +++ b/examples/firmata_adxl345.go @@ -41,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_aip1640.go b/examples/firmata_aip1640.go index a2e4527f6..95f57a1eb 100644 --- a/examples/firmata_aip1640.go +++ b/examples/firmata_aip1640.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -38,7 +39,9 @@ func main() { aip1640.Clear() gobot.Every(600*time.Millisecond, func() { aip1640.DrawMatrix(smiles[s]) - aip1640.Display() + if err := aip1640.Display(); err != nil { + fmt.Println(err) + } s++ if s > 2 { s = 0 @@ -52,5 +55,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_blink.go b/examples/firmata_blink.go index ee7ab54fb..badde5f15 100644 --- a/examples/firmata_blink.go +++ b/examples/firmata_blink.go @@ -29,7 +29,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -39,8 +41,7 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/firmata_blink_api.go b/examples/firmata_blink_api.go index 35a6db397..9d8c027c1 100644 --- a/examples/firmata_blink_api.go +++ b/examples/firmata_blink_api.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -25,7 +26,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -37,5 +40,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_blink_metal.go b/examples/firmata_blink_metal.go index 72136f317..60d73ea06 100644 --- a/examples/firmata_blink_metal.go +++ b/examples/firmata_blink_metal.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2/drivers/gpio" @@ -19,13 +20,19 @@ import ( // golang library to interact with sensors and other devices. func main() { f := firmata.NewAdaptor("/dev/ttyACM0") - f.Connect() + if err := f.Connect(); err != nil { + fmt.Println(err) + } led := gpio.NewLedDriver(f, "13") - led.Start() + if err := led.Start(); err != nil { + fmt.Println(err) + } for { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } time.Sleep(1000 * time.Millisecond) } } diff --git a/examples/firmata_blink_robot.go b/examples/firmata_blink_robot.go index 76c276a84..aa83119f1 100644 --- a/examples/firmata_blink_robot.go +++ b/examples/firmata_blink_robot.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_blinkm.go b/examples/firmata_blinkm.go index e86c6e549..c1d9653e6 100644 --- a/examples/firmata_blinkm.go +++ b/examples/firmata_blinkm.go @@ -32,8 +32,13 @@ func main() { r := byte(gobot.Rand(255)) g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) - blinkm.Rgb(r, g, b) - color, _ := blinkm.Color() + if err := blinkm.Rgb(r, g, b); err != nil { + fmt.Println(err) + } + color, err := blinkm.Color() + if err != nil { + fmt.Println(err) + } fmt.Println("color", color) }) } @@ -44,5 +49,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_bme280.go b/examples/firmata_bme280.go index e9e84ed0f..1cb47ecc3 100644 --- a/examples/firmata_bme280.go +++ b/examples/firmata_bme280.go @@ -42,5 +42,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_bmp180.go b/examples/firmata_bmp180.go index 78980e630..43932dc3f 100644 --- a/examples/firmata_bmp180.go +++ b/examples/firmata_bmp180.go @@ -36,5 +36,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_bmp280.go b/examples/firmata_bmp280.go index ff649a6e5..f11327294 100644 --- a/examples/firmata_bmp280.go +++ b/examples/firmata_bmp280.go @@ -39,5 +39,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_button.go b/examples/firmata_button.go index 0844b18c6..783cd7bb8 100644 --- a/examples/firmata_button.go +++ b/examples/firmata_button.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "gobot.io/x/gobot/v2" @@ -28,11 +29,15 @@ func main() { led := gpio.NewLedDriver(firmataAdaptor, "3") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { - led.On() + _ = button.On(gpio.ButtonPush, func(data interface{}) { + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { - led.Off() + _ = button.On(gpio.ButtonRelease, func(data interface{}) { + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -42,5 +47,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_buzzer.go b/examples/firmata_buzzer.go index 2a406c95e..6089ffdc2 100644 --- a/examples/firmata_buzzer.go +++ b/examples/firmata_buzzer.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -50,7 +51,9 @@ func main() { } for _, val := range song { - buzzer.Tone(val.tone, val.duration) + if err := buzzer.Tone(val.tone, val.duration); err != nil { + fmt.Println(err) + } time.Sleep(10 * time.Millisecond) } } @@ -61,5 +64,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_cat_toy.go b/examples/firmata_cat_toy.go index e80f40c05..89f818300 100644 --- a/examples/firmata_cat_toy.go +++ b/examples/firmata_cat_toy.go @@ -35,7 +35,7 @@ func main() { work := func() { x := 90.0 z := 90.0 - leapDriver.On(leap.MessageEvent, func(data interface{}) { + _ = leapDriver.On(leap.MessageEvent, func(data interface{}) { if len(data.(leap.Frame).Hands) > 0 { hand := data.(leap.Frame).Hands[0] x = gobot.ToScale(gobot.FromScale(hand.X(), -300, 300), 30, 150) @@ -43,8 +43,12 @@ func main() { } }) gobot.Every(10*time.Millisecond, func() { - servo1.Move(uint8(x)) - servo2.Move(uint8(z)) + if err := servo1.Move(uint8(x)); err != nil { + fmt.Println(err) + } + if err := servo2.Move(uint8(z)); err != nil { + fmt.Println(err) + } fmt.Println("Current Angle: ", servo1.Angle(), ",", servo2.Angle()) }) } @@ -55,5 +59,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_curie_imu.go b/examples/firmata_curie_imu.go index f9f53e4bf..084d80d51 100644 --- a/examples/firmata_curie_imu.go +++ b/examples/firmata_curie_imu.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "log" "os" "time" @@ -30,31 +31,41 @@ func main() { imu := curie.NewIMUDriver(firmataAdaptor) work := func() { - imu.On("Accelerometer", func(data interface{}) { + _ = imu.On("Accelerometer", func(data interface{}) { log.Println("Accelerometer", data) }) - imu.On("Gyroscope", func(data interface{}) { + _ = imu.On("Gyroscope", func(data interface{}) { log.Println("Gyroscope", data) }) - imu.On("Temperature", func(data interface{}) { + _ = imu.On("Temperature", func(data interface{}) { log.Println("Temperature", data) }) - imu.On("Motion", func(data interface{}) { + _ = imu.On("Motion", func(data interface{}) { log.Println("Motion", data) }) gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(100*time.Millisecond, func() { - imu.ReadAccelerometer() - imu.ReadGyroscope() - imu.ReadTemperature() - imu.ReadMotion() + if err := imu.ReadAccelerometer(); err != nil { + fmt.Println(err) + } + if err := imu.ReadGyroscope(); err != nil { + fmt.Println(err) + } + if err := imu.ReadTemperature(); err != nil { + fmt.Println(err) + } + if err := imu.ReadMotion(); err != nil { + fmt.Println(err) + } }) } @@ -64,5 +75,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_curie_imu_shock_detect.go b/examples/firmata_curie_imu_shock_detect.go index bbc09abbf..2c212a299 100644 --- a/examples/firmata_curie_imu_shock_detect.go +++ b/examples/firmata_curie_imu_shock_detect.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "log" "os" "time" @@ -30,15 +31,19 @@ func main() { imu := curie.NewIMUDriver(firmataAdaptor) work := func() { - imu.On("Shock", func(data interface{}) { + _ = imu.On("Shock", func(data interface{}) { log.Println("Shock", data) }) gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) - imu.EnableShockDetection(true) + if err := imu.EnableShockDetection(true); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("curieBot", @@ -47,5 +52,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_curie_imu_step_counter.go b/examples/firmata_curie_imu_step_counter.go index a6797586f..8cfea03c4 100644 --- a/examples/firmata_curie_imu_step_counter.go +++ b/examples/firmata_curie_imu_step_counter.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "log" "os" "time" @@ -30,15 +31,19 @@ func main() { imu := curie.NewIMUDriver(firmataAdaptor) work := func() { - imu.On("Steps", func(data interface{}) { + _ = imu.On("Steps", func(data interface{}) { log.Println("Steps", data) }) gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) - imu.EnableStepCounter(true) + if err := imu.EnableStepCounter(true); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("curieBot", @@ -47,5 +52,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_curie_imu_tap_detect.go b/examples/firmata_curie_imu_tap_detect.go index 501711b0a..8aedc380f 100644 --- a/examples/firmata_curie_imu_tap_detect.go +++ b/examples/firmata_curie_imu_tap_detect.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "log" "os" "time" @@ -30,15 +31,19 @@ func main() { imu := curie.NewIMUDriver(firmataAdaptor) work := func() { - imu.On("Tap", func(data interface{}) { + _ = imu.On("Tap", func(data interface{}) { log.Println("Tap", data) }) gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) - imu.EnableTapDetection(true) + if err := imu.EnableTapDetection(true); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("curieBot", @@ -47,5 +52,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_direct_pin.go b/examples/firmata_direct_pin.go index 2ba80f25d..351ce2d34 100644 --- a/examples/firmata_direct_pin.go +++ b/examples/firmata_direct_pin.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -30,7 +31,9 @@ func main() { level := byte(1) gobot.Every(1*time.Second, func() { - pin.DigitalWrite(level) + if err := pin.DigitalWrite(level); err != nil { + fmt.Println(err) + } if level == 1 { level = 0 } else { @@ -45,5 +48,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_gpio_max7219.go b/examples/firmata_gpio_max7219.go index d77865c64..87f3b7682 100644 --- a/examples/firmata_gpio_max7219.go +++ b/examples/firmata_gpio_max7219.go @@ -18,6 +18,7 @@ package main import ( + "fmt" "os" "time" @@ -37,8 +38,12 @@ func main() { work := func() { gobot.Every(100*time.Millisecond, func() { - max.ClearAll() - max.One(module, digit, bits) + if err := max.ClearAll(); err != nil { + fmt.Println(err) + } + if err := max.One(module, digit, bits); err != nil { + fmt.Println(err) + } bits = bits << 1 count++ @@ -64,5 +69,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_grove_lcd.go b/examples/firmata_grove_lcd.go index 4cf6287ba..821e8fba6 100644 --- a/examples/firmata_grove_lcd.go +++ b/examples/firmata_grove_lcd.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "os" "time" @@ -20,26 +21,46 @@ func main() { screen := i2c.NewGroveLcdDriver(board) work := func() { - screen.Write("hello") + if err := screen.Write("hello"); err != nil { + fmt.Println(err) + } - screen.SetRGB(255, 0, 0) + if err := screen.SetRGB(255, 0, 0); err != nil { + fmt.Println(err) + } gobot.After(5*time.Second, func() { - screen.Clear() - screen.Home() - screen.SetRGB(0, 255, 0) + if err := screen.Clear(); err != nil { + fmt.Println(err) + } + if err := screen.Home(); err != nil { + fmt.Println(err) + } + if err := screen.SetRGB(0, 255, 0); err != nil { + fmt.Println(err) + } // set a custom character in the first position - screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]) + if err := screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]); err != nil { + fmt.Println(err) + } // add the custom character at the end of the string - screen.Write("goodbye\nhave a nice day " + string(byte(0))) + if err := screen.Write("goodbye\nhave a nice day " + string(byte(0))); err != nil { + fmt.Println(err) + } gobot.Every(500*time.Millisecond, func() { - screen.Scroll(false) + if err := screen.Scroll(false); err != nil { + fmt.Println(err) + } }) }) - screen.Home() + if err := screen.Home(); err != nil { + fmt.Println(err) + } time.Sleep(1 * time.Second) - screen.SetRGB(0, 0, 255) + if err := screen.SetRGB(0, 0, 255); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("screenBot", @@ -48,5 +69,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_grove_sound_sensor.go b/examples/firmata_grove_sound_sensor.go index d118c7a52..1038126e6 100644 --- a/examples/firmata_grove_sound_sensor.go +++ b/examples/firmata_grove_sound_sensor.go @@ -21,7 +21,7 @@ func main() { sensor := aio.NewGroveSoundSensorDriver(board, "3", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { fmt.Println("sensor", data) }) } @@ -32,5 +32,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_hmc6352.go b/examples/firmata_hmc6352.go index 74c307c26..90031127d 100644 --- a/examples/firmata_hmc6352.go +++ b/examples/firmata_hmc6352.go @@ -40,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_integration.go b/examples/firmata_integration.go index eafbddbc9..9b1917482 100644 --- a/examples/firmata_integration.go +++ b/examples/firmata_integration.go @@ -33,18 +33,26 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led1.Toggle() + if err := led1.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(2*time.Second, func() { - led2.Toggle() + if err := led2.Toggle(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonPush, func(data interface{}) { - led2.On() + _ = button.On(gpio.ButtonPush, func(data interface{}) { + if err := led2.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { - led2.Off() + _ = button.On(gpio.ButtonRelease, func(data interface{}) { + if err := led2.Off(); err != nil { + fmt.Println(err) + } }) - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { fmt.Println("sensor", data) }) } @@ -55,5 +63,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_led_brightness.go b/examples/firmata_led_brightness.go index 970093a02..08ef5cdd7 100644 --- a/examples/firmata_led_brightness.go +++ b/examples/firmata_led_brightness.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -31,7 +32,9 @@ func main() { fadeAmount := uint8(15) gobot.Every(100*time.Millisecond, func() { - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } brightness = brightness + fadeAmount if brightness == 0 || brightness == 255 { fadeAmount = -fadeAmount @@ -45,5 +48,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_led_brightness_with_analog_input.go b/examples/firmata_led_brightness_with_analog_input.go index 3c86ae375..177e66d2e 100644 --- a/examples/firmata_led_brightness_with_analog_input.go +++ b/examples/firmata_led_brightness_with_analog_input.go @@ -30,13 +30,15 @@ func main() { led := gpio.NewLedDriver(firmataAdaptor, "3") work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { brightness := uint8( gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255), ) fmt.Println("sensor", data) fmt.Println("brightness", brightness) - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } }) } @@ -46,5 +48,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_lidarlite.go b/examples/firmata_lidarlite.go index ff6a1ced9..eba2c217b 100644 --- a/examples/firmata_lidarlite.go +++ b/examples/firmata_lidarlite.go @@ -40,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_metal_button.go b/examples/firmata_metal_button.go index 003d34c7d..d5cd9d79e 100644 --- a/examples/firmata_metal_button.go +++ b/examples/firmata_metal_button.go @@ -23,20 +23,30 @@ import ( func main() { f := firmata.NewAdaptor(os.Args[1]) - f.Connect() + if err := f.Connect(); err != nil { + fmt.Println(err) + } led := gpio.NewLedDriver(f, "2") - led.Start() - led.Off() + if err := led.Start(); err != nil { + fmt.Println(err) + } + if err := led.Off(); err != nil { + fmt.Println(err) + } button := gpio.NewButtonDriver(f, "3") - button.Start() + if err := button.Start(); err != nil { + fmt.Println(err) + } buttonEvents := button.Subscribe() for event := range buttonEvents { fmt.Println("Event:", event.Name, event.Data) if event.Name == gpio.ButtonPush { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } } } } diff --git a/examples/firmata_mma7660.go b/examples/firmata_mma7660.go index 4e9c804e3..db4f19a76 100644 --- a/examples/firmata_mma7660.go +++ b/examples/firmata_mma7660.go @@ -44,5 +44,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_motor.go b/examples/firmata_motor.go index f3abbf200..590ae7322 100644 --- a/examples/firmata_motor.go +++ b/examples/firmata_motor.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -31,7 +32,9 @@ func main() { fadeAmount := byte(15) gobot.Every(100*time.Millisecond, func() { - motor.SetSpeed(speed) + if err := motor.SetSpeed(speed); err != nil { + fmt.Println(err) + } speed = speed + fadeAmount if speed == 0 || speed == 255 { fadeAmount = -fadeAmount @@ -45,5 +48,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_mpl115a2.go b/examples/firmata_mpl115a2.go index 20e943fba..ae1f8ba5d 100644 --- a/examples/firmata_mpl115a2.go +++ b/examples/firmata_mpl115a2.go @@ -43,5 +43,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_mpu6050.go b/examples/firmata_mpu6050.go index 231a6eadc..2bdf25c11 100644 --- a/examples/firmata_mpu6050.go +++ b/examples/firmata_mpu6050.go @@ -29,7 +29,9 @@ func main() { work := func() { gobot.Every(100*time.Millisecond, func() { - mpu6050.GetData() + if err := mpu6050.GetData(); err != nil { + fmt.Println(err) + } fmt.Println("Accelerometer", mpu6050.Accelerometer) fmt.Println("Gyroscope", mpu6050.Gyroscope) @@ -43,5 +45,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_pca9685.go b/examples/firmata_pca9685.go index 658b96e98..05e56c766 100644 --- a/examples/firmata_pca9685.go +++ b/examples/firmata_pca9685.go @@ -30,17 +30,23 @@ func main() { servo := gpio.NewServoDriver(pca9685, "15") work := func() { - pca9685.SetPWMFreq(60) + if err := pca9685.SetPWMFreq(60); err != nil { + fmt.Println(err) + } for i := 10; i < 150; i += 10 { fmt.Println("Turning", i) - servo.Move(uint8(i)) + if err := servo.Move(uint8(i)); err != nil { + fmt.Println(err) + } time.Sleep(1 * time.Second) } for i := 150; i > 10; i -= 10 { fmt.Println("Turning", i) - servo.Move(uint8(i)) + if err := servo.Move(uint8(i)); err != nil { + fmt.Println(err) + } time.Sleep(1 * time.Second) } } @@ -51,5 +57,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_pir_motion.go b/examples/firmata_pir_motion.go index ceb4fd0d2..d67d6a63e 100644 --- a/examples/firmata_pir_motion.go +++ b/examples/firmata_pir_motion.go @@ -29,13 +29,17 @@ func main() { led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { - sensor.On(gpio.MotionDetected, func(data interface{}) { + _ = sensor.On(gpio.MotionDetected, func(data interface{}) { fmt.Println(gpio.MotionDetected) - led.On() + if err := led.On(); err != nil { + fmt.Println(err) + } }) - sensor.On(gpio.MotionStopped, func(data interface{}) { + _ = sensor.On(gpio.MotionStopped, func(data interface{}) { fmt.Println(gpio.MotionStopped) - led.Off() + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -45,5 +49,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_rgb_led.go b/examples/firmata_rgb_led.go index e9cd613bc..8a246b66d 100644 --- a/examples/firmata_rgb_led.go +++ b/examples/firmata_rgb_led.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -31,7 +32,9 @@ func main() { r := uint8(gobot.Rand(255)) g := uint8(gobot.Rand(255)) b := uint8(gobot.Rand(255)) - led.SetRGB(r, g, b) + if err := led.SetRGB(r, g, b); err != nil { + fmt.Println(err) + } }) } @@ -41,5 +44,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_servo.go b/examples/firmata_servo.go index c55a0b35e..ed1cbb07d 100644 --- a/examples/firmata_servo.go +++ b/examples/firmata_servo.go @@ -31,7 +31,9 @@ func main() { gobot.Every(1*time.Second, func() { i := uint8(gobot.Rand(180)) fmt.Println("Turning", i) - servo.Move(i) + if err := servo.Move(i); err != nil { + fmt.Println(err) + } }) } @@ -41,5 +43,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_ssd1306.go b/examples/firmata_ssd1306.go index 14ad349db..2b50b7c1c 100644 --- a/examples/firmata_ssd1306.go +++ b/examples/firmata_ssd1306.go @@ -37,7 +37,9 @@ func main() { } } stage = !stage - oled.Display() + if err := oled.Display(); err != nil { + fmt.Println(err) + } }) } @@ -47,5 +49,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_temp36.go b/examples/firmata_temp36.go index 94fca35a4..d42494c78 100644 --- a/examples/firmata_temp36.go +++ b/examples/firmata_temp36.go @@ -48,5 +48,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_tm1638.go b/examples/firmata_tm1638.go index 0d80c9c01..b64143b50 100644 --- a/examples/firmata_tm1638.go +++ b/examples/firmata_tm1638.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -46,10 +47,18 @@ func main() { work := func() { gobot.Every(400*time.Millisecond, func() { // Enable and change the color of the LEDs - modules[0].SetLED(color, ledInt) - modules[1].SetLED(color, ledInt) - modules[2].SetLED(color, ledInt) - modules[3].SetLED(color, ledInt) + if err := modules[0].SetLED(color, ledInt); err != nil { + fmt.Println(err) + } + if err := modules[1].SetLED(color, ledInt); err != nil { + fmt.Println(err) + } + if err := modules[2].SetLED(color, ledInt); err != nil { + fmt.Println(err) + } + if err := modules[3].SetLED(color, ledInt); err != nil { + fmt.Println(err) + } ledInt++ if ledInt > 7 { @@ -62,7 +71,9 @@ func main() { // Scroll the text for i := 0; i < 4; i++ { - modules[i].SetDisplayText(text[offset+8*i : offset+8*i+8]) + if err := modules[i].SetDisplayText(text[offset+8*i : offset+8*i+8]); err != nil { + fmt.Println(err) + } } offset++ if offset >= len(showText) { @@ -77,5 +88,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_travis.go b/examples/firmata_travis.go index 51862ff9b..c8f16ff83 100644 --- a/examples/firmata_travis.go +++ b/examples/firmata_travis.go @@ -42,13 +42,21 @@ type TravisResponse struct { } func turnOn(robot *gobot.Robot, device string) { - robot.Device(device).(*gpio.LedDriver).On() + if err := robot.Device(device).(*gpio.LedDriver).On(); err != nil { + fmt.Println(err) + } } func resetLeds(robot *gobot.Robot) { - robot.Device("red").(*gpio.LedDriver).Off() - robot.Device("green").(*gpio.LedDriver).Off() - robot.Device("blue").(*gpio.LedDriver).Off() + if err := robot.Device("red").(*gpio.LedDriver).Off(); err != nil { + fmt.Println(err) + } + if err := robot.Device("green").(*gpio.LedDriver).Off(); err != nil { + fmt.Println(err) + } + if err := robot.Device("blue").(*gpio.LedDriver).Off(); err != nil { + fmt.Println(err) + } } func checkTravis(robot *gobot.Robot) { @@ -68,7 +76,9 @@ func checkTravis(robot *gobot.Robot) { panic(err) } var travis TravisResponse - json.Unmarshal(body, &travis) + if err := json.Unmarshal(body, &travis); err != nil { + fmt.Println(err) + } resetLeds(robot) if travis.LastBuildStatus == 0 { turnOn(robot, "green") @@ -98,5 +108,7 @@ func main() { ) master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/firmata_wiichuck.go b/examples/firmata_wiichuck.go index dff3c3ccd..22819ded2 100644 --- a/examples/firmata_wiichuck.go +++ b/examples/firmata_wiichuck.go @@ -27,19 +27,19 @@ func main() { wiichuck := i2c.NewWiichuckDriver(firmataAdaptor) work := func() { - wiichuck.On(wiichuck.Event("joystick"), func(data interface{}) { + _ = wiichuck.On(wiichuck.Event("joystick"), func(data interface{}) { fmt.Println("joystick", data) }) - wiichuck.On(wiichuck.Event("c"), func(data interface{}) { + _ = wiichuck.On(wiichuck.Event("c"), func(data interface{}) { fmt.Println("c") }) - wiichuck.On(wiichuck.Event("z"), func(data interface{}) { + _ = wiichuck.On(wiichuck.Event("z"), func(data interface{}) { fmt.Println("z") }) - wiichuck.On(wiichuck.Event("error"), func(data interface{}) { + _ = wiichuck.On(wiichuck.Event("error"), func(data interface{}) { fmt.Println("Wiichuck error:", data) }) } @@ -50,5 +50,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/gopigo3.go b/examples/gopigo3.go index 338cced0b..cca5ebfac 100644 --- a/examples/gopigo3.go +++ b/examples/gopigo3.go @@ -40,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/gopigo3_grove_button.go b/examples/gopigo3_grove_button.go index f1e376130..6ce4f3a20 100644 --- a/examples/gopigo3_grove_button.go +++ b/examples/gopigo3_grove_button.go @@ -22,13 +22,17 @@ func main() { button := gpio.NewButtonDriver(gpg3, "AD_2_1") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { + _ = button.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("On!") - led.On() + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { + _ = button.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("Off!") - led.Off() + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -38,5 +42,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/gopigo3_grove_lcd.go b/examples/gopigo3_grove_lcd.go index 3423400db..bc3e2be14 100644 --- a/examples/gopigo3_grove_lcd.go +++ b/examples/gopigo3_grove_lcd.go @@ -7,6 +7,8 @@ package main import ( + "fmt" + "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/i2c" "gobot.io/x/gobot/v2/platforms/dexter/gopigo3" @@ -19,17 +21,24 @@ func main() { screen := i2c.NewGroveLcdDriver(raspiAdaptor) work := func() { - manufacturerName := "" - boardName := "" - hardwareVersion := "" - manufacturerName, _ = gpg3.GetManufacturerName() - boardName, _ = gpg3.GetBoardName() - hardwareVersion, _ = gpg3.GetHardwareVersion() - screen.Write(manufacturerName[0:15]) - screen.SetPosition(16) - screen.Write(boardName + " " + hardwareVersion) - screen.SetRGB(0, 0, 255) - screen.Home() + manufacturerName, _ := gpg3.GetManufacturerName() + boardName, _ := gpg3.GetBoardName() + hardwareVersion, _ := gpg3.GetHardwareVersion() + if err := screen.Write(manufacturerName[0:15]); err != nil { + fmt.Println(err) + } + if err := screen.SetPosition(16); err != nil { + fmt.Println(err) + } + if err := screen.Write(boardName + " " + hardwareVersion); err != nil { + fmt.Println(err) + } + if err := screen.SetRGB(0, 0, 255); err != nil { + fmt.Println(err) + } + if err := screen.Home(); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("gopigo3lcd", @@ -38,5 +47,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/gopigo3_grove_light_sensor.go b/examples/gopigo3_grove_light_sensor.go index 8454f96fc..ae99fb191 100644 --- a/examples/gopigo3_grove_light_sensor.go +++ b/examples/gopigo3_grove_light_sensor.go @@ -22,7 +22,7 @@ func main() { sensor := aio.NewGroveLightSensorDriver(gpg3, "AD_1_1", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(sensor.Event("data"), func(data interface{}) { + _ = sensor.On(sensor.Event("data"), func(data interface{}) { fmt.Println("sensor", data) }) } @@ -33,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/gopigo3_led_brightness.go b/examples/gopigo3_led_brightness.go index 62a57e556..417363f35 100644 --- a/examples/gopigo3_led_brightness.go +++ b/examples/gopigo3_led_brightness.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -25,7 +26,9 @@ func main() { fadeAmount := uint8(15) gobot.Every(100*time.Millisecond, func() { - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } brightness = brightness + fadeAmount if brightness == 0 || brightness == 255 { fadeAmount = -fadeAmount @@ -39,5 +42,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/gopigo3_servo.go b/examples/gopigo3_servo.go index dbb943cb8..04e50bfdf 100644 --- a/examples/gopigo3_servo.go +++ b/examples/gopigo3_servo.go @@ -25,7 +25,9 @@ func main() { gobot.Every(1*time.Second, func() { i := uint8(gobot.Rand(180)) fmt.Println("Turning", i) - servo.Move(i) + if err := servo.Move(i); err != nil { + fmt.Println(err) + } }) } @@ -35,5 +37,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/hello.go b/examples/hello.go index 6f1503675..88ef3bd55 100644 --- a/examples/hello.go +++ b/examples/hello.go @@ -20,5 +20,7 @@ func main() { }, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/hello_api.go b/examples/hello_api.go index 5707720c3..9079343b8 100644 --- a/examples/hello_api.go +++ b/examples/hello_api.go @@ -36,5 +36,7 @@ func main() { return fmt.Sprintf("This command is attached to the robot %v", hello.Name) }) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/hello_api_auth.go b/examples/hello_api_auth.go index 04da9e86b..a4fa3249e 100644 --- a/examples/hello_api_auth.go +++ b/examples/hello_api_auth.go @@ -38,5 +38,7 @@ func main() { return fmt.Sprintf("This command is attached to the robot %v", hello.Name) }) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/hello_api_custom.go b/examples/hello_api_custom.go index 7fddff341..895165ecb 100644 --- a/examples/hello_api_custom.go +++ b/examples/hello_api_custom.go @@ -21,11 +21,15 @@ func main() { // creates routes/handlers for the custom API a.Get("/", func(res http.ResponseWriter, req *http.Request) { - res.Write([]byte("OK")) + if _, err := res.Write([]byte("OK")); err != nil { + fmt.Println(err) + } }) a.Get("/api/hello", func(res http.ResponseWriter, req *http.Request) { msg := fmt.Sprintf("This command is attached to the robot %v", master.Robot("hello").Name) - res.Write([]byte(msg)) + if _, err := res.Write([]byte(msg)); err != nil { + fmt.Println(err) + } }) // starts the API without the default C2PIO API and Robeaux web interface. @@ -33,5 +37,7 @@ func main() { master.AddRobot(gobot.NewRobot("hello")) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/hello_api_video.go b/examples/hello_api_video.go index 3d63fe046..dbcf73e1d 100644 --- a/examples/hello_api_video.go +++ b/examples/hello_api_video.go @@ -61,7 +61,9 @@ func main() { // start capturing go mjpegCapture() - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } func mjpegCapture() { diff --git a/examples/holystone_hs200.go b/examples/holystone_hs200.go index 7d9473b8d..db5ccb890 100644 --- a/examples/holystone_hs200.go +++ b/examples/holystone_hs200.go @@ -36,5 +36,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/jetson-nano_blink.go b/examples/jetson-nano_blink.go index cd5632e49..c6b29ce94 100644 --- a/examples/jetson-nano_blink.go +++ b/examples/jetson-nano_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/jetson-nano_servo.go b/examples/jetson-nano_servo.go index 064589ffc..5eaafe92b 100644 --- a/examples/jetson-nano_servo.go +++ b/examples/jetson-nano_servo.go @@ -12,6 +12,7 @@ package main // 2. if end pin configure, reboot Jetson nano. // 3. run gobot import ( + "fmt" "log" "time" @@ -29,7 +30,9 @@ func main() { work := func() { gobot.Every(100*time.Millisecond, func() { log.Println("Turning", counter) - servo.Move(uint8(counter)) + if err := servo.Move(uint8(counter)); err != nil { + fmt.Println(err) + } if counter == 140 { flg = false } else if counter == 30 { @@ -50,5 +53,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joule_blink.go b/examples/joule_blink.go index 875529205..560237827 100644 --- a/examples/joule_blink.go +++ b/examples/joule_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joule_blinkm.go b/examples/joule_blinkm.go index cc6ac5ae6..97676ebaa 100644 --- a/examples/joule_blinkm.go +++ b/examples/joule_blinkm.go @@ -24,8 +24,13 @@ func main() { r := byte(gobot.Rand(255)) g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) - blinkm.Rgb(r, g, b) - color, _ := blinkm.Color() + if err := blinkm.Rgb(r, g, b); err != nil { + fmt.Println(err) + } + color, err := blinkm.Color() + if err != nil { + fmt.Println(err) + } fmt.Println("color", color) }) } @@ -36,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joule_grove_lcd.go b/examples/joule_grove_lcd.go index ec2afd3b8..929f181a0 100644 --- a/examples/joule_grove_lcd.go +++ b/examples/joule_grove_lcd.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -19,26 +20,46 @@ func main() { screen := i2c.NewGroveLcdDriver(board) work := func() { - screen.Write("hello") + if err := screen.Write("hello"); err != nil { + fmt.Println(err) + } - screen.SetRGB(255, 0, 0) + if err := screen.SetRGB(255, 0, 0); err != nil { + fmt.Println(err) + } gobot.After(5*time.Second, func() { - screen.Clear() - screen.Home() - screen.SetRGB(0, 255, 0) + if err := screen.Clear(); err != nil { + fmt.Println(err) + } + if err := screen.Home(); err != nil { + fmt.Println(err) + } + if err := screen.SetRGB(0, 255, 0); err != nil { + fmt.Println(err) + } // set a custom character in the first position - screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]) + if err := screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]); err != nil { + fmt.Println(err) + } // add the custom character at the end of the string - screen.Write("goodbye\nhave a nice day " + string(byte(0))) + if err := screen.Write("goodbye\nhave a nice day " + string(byte(0))); err != nil { + fmt.Println(err) + } gobot.Every(500*time.Millisecond, func() { - screen.Scroll(false) + if err := screen.Scroll(false); err != nil { + fmt.Println(err) + } }) }) - screen.Home() + if err := screen.Home(); err != nil { + fmt.Println(err) + } time.Sleep(1 * time.Second) - screen.SetRGB(0, 0, 255) + if err := screen.SetRGB(0, 0, 255); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("screenBot", @@ -47,5 +68,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joule_grove_rotary_sensor.go b/examples/joule_grove_rotary_sensor.go index bd1e7cbc6..afe9a78ef 100644 --- a/examples/joule_grove_rotary_sensor.go +++ b/examples/joule_grove_rotary_sensor.go @@ -22,7 +22,7 @@ func main() { sensor := aio.NewGroveRotaryDriver(ads1015, "0", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { fmt.Println("sensor", data) }) } @@ -33,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joule_led_brightness.go b/examples/joule_led_brightness.go index 0fec54b7d..46a7793e3 100644 --- a/examples/joule_led_brightness.go +++ b/examples/joule_led_brightness.go @@ -24,8 +24,7 @@ func main() { fadeAmount := uint8(15) gobot.Every(100*time.Millisecond, func() { - err := led.Brightness(brightness) - if err != nil { + if err := led.Brightness(brightness); err != nil { fmt.Println(err) } brightness = brightness + fadeAmount @@ -41,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joule_led_brightness_with_analog_input.go b/examples/joule_led_brightness_with_analog_input.go index 167e3210a..277c3a242 100644 --- a/examples/joule_led_brightness_with_analog_input.go +++ b/examples/joule_led_brightness_with_analog_input.go @@ -24,11 +24,13 @@ func main() { led := gpio.NewLedDriver(e, "J12_26") work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { brightness := uint8(gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1023), 0, 255)) fmt.Println("sensor", data) fmt.Println("brightness", brightness) - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } }) } @@ -38,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joule_leds.go b/examples/joule_leds.go index ec34e2159..4f68cd6f9 100644 --- a/examples/joule_leds.go +++ b/examples/joule_leds.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -22,22 +23,38 @@ func main() { led3 := gpio.NewLedDriver(e, "GP103") work := func() { - led0.Off() - led1.Off() - led2.Off() - led3.Off() + if err := led0.Off(); err != nil { + fmt.Println(err) + } + if err := led1.Off(); err != nil { + fmt.Println(err) + } + if err := led2.Off(); err != nil { + fmt.Println(err) + } + if err := led3.Off(); err != nil { + fmt.Println(err) + } gobot.Every(1*time.Second, func() { - led0.Toggle() + if err := led0.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(2*time.Second, func() { - led1.Toggle() + if err := led1.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(4*time.Second, func() { - led2.Toggle() + if err := led2.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(8*time.Second, func() { - led3.Toggle() + if err := led3.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -47,5 +64,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joule_rgb_led.go b/examples/joule_rgb_led.go index b94e9fc28..6f008969a 100644 --- a/examples/joule_rgb_led.go +++ b/examples/joule_rgb_led.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -23,7 +24,9 @@ func main() { r := uint8(gobot.Rand(255)) g := uint8(gobot.Rand(255)) b := uint8(gobot.Rand(255)) - led.SetRGB(r, g, b) + if err := led.SetRGB(r, g, b); err != nil { + fmt.Println(err) + } }) } @@ -33,5 +36,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joystick_ps3.go b/examples/joystick_ps3.go index 1d2f3a2ce..422f5c06a 100644 --- a/examples/joystick_ps3.go +++ b/examples/joystick_ps3.go @@ -19,110 +19,110 @@ func main() { work := func() { // buttons - stick.On(joystick.SquarePress, func(data interface{}) { + _ = stick.On(joystick.SquarePress, func(data interface{}) { fmt.Println("square_press") }) - stick.On(joystick.SquareRelease, func(data interface{}) { + _ = stick.On(joystick.SquareRelease, func(data interface{}) { fmt.Println("square_release") }) - stick.On(joystick.TrianglePress, func(data interface{}) { + _ = stick.On(joystick.TrianglePress, func(data interface{}) { fmt.Println("triangle_press") }) - stick.On(joystick.TriangleRelease, func(data interface{}) { + _ = stick.On(joystick.TriangleRelease, func(data interface{}) { fmt.Println("triangle_release") }) - stick.On(joystick.CirclePress, func(data interface{}) { + _ = stick.On(joystick.CirclePress, func(data interface{}) { fmt.Println("circle_press") }) - stick.On(joystick.CircleRelease, func(data interface{}) { + _ = stick.On(joystick.CircleRelease, func(data interface{}) { fmt.Println("circle_release") }) - stick.On(joystick.XPress, func(data interface{}) { + _ = stick.On(joystick.XPress, func(data interface{}) { fmt.Println("x_press") }) - stick.On(joystick.XRelease, func(data interface{}) { + _ = stick.On(joystick.XRelease, func(data interface{}) { fmt.Println("x_release") }) - stick.On(joystick.StartPress, func(data interface{}) { + _ = stick.On(joystick.StartPress, func(data interface{}) { fmt.Println("start_press") }) - stick.On(joystick.StartRelease, func(data interface{}) { + _ = stick.On(joystick.StartRelease, func(data interface{}) { fmt.Println("start_release") }) - stick.On(joystick.SelectPress, func(data interface{}) { + _ = stick.On(joystick.SelectPress, func(data interface{}) { fmt.Println("select_press") }) - stick.On(joystick.SelectRelease, func(data interface{}) { + _ = stick.On(joystick.SelectRelease, func(data interface{}) { fmt.Println("select_release") }) - stick.On(joystick.HomePress, func(data interface{}) { + _ = stick.On(joystick.HomePress, func(data interface{}) { fmt.Println("home_press") }) - stick.On(joystick.HomeRelease, func(data interface{}) { + _ = stick.On(joystick.HomeRelease, func(data interface{}) { fmt.Println("home_release") }) - stick.On(joystick.RightPress, func(data interface{}) { + _ = stick.On(joystick.RightPress, func(data interface{}) { fmt.Println("right_press") }) - stick.On(joystick.RightRelease, func(data interface{}) { + _ = stick.On(joystick.RightRelease, func(data interface{}) { fmt.Println("right_release") }) - stick.On(joystick.LeftPress, func(data interface{}) { + _ = stick.On(joystick.LeftPress, func(data interface{}) { fmt.Println("left_press") }) - stick.On(joystick.LeftRelease, func(data interface{}) { + _ = stick.On(joystick.LeftRelease, func(data interface{}) { fmt.Println("left_release") }) - stick.On(joystick.UpPress, func(data interface{}) { + _ = stick.On(joystick.UpPress, func(data interface{}) { fmt.Println("up_press") }) - stick.On(joystick.UpRelease, func(data interface{}) { + _ = stick.On(joystick.UpRelease, func(data interface{}) { fmt.Println("up_release") }) - stick.On(joystick.DownPress, func(data interface{}) { + _ = stick.On(joystick.DownPress, func(data interface{}) { fmt.Println("down_press") }) - stick.On(joystick.DownRelease, func(data interface{}) { + _ = stick.On(joystick.DownRelease, func(data interface{}) { fmt.Println("down_release") }) // joysticks - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { fmt.Println("left_x", data) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { fmt.Println("left_y", data) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { fmt.Println("right_x", data) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { fmt.Println("right_y", data) }) // triggers - stick.On(joystick.R1Press, func(data interface{}) { + _ = stick.On(joystick.R1Press, func(data interface{}) { fmt.Println("R1Press", data) }) - stick.On(joystick.R1Release, func(data interface{}) { + _ = stick.On(joystick.R1Release, func(data interface{}) { fmt.Println("R1Release", data) }) - stick.On(joystick.R2Press, func(data interface{}) { + _ = stick.On(joystick.R2Press, func(data interface{}) { fmt.Println("R2Press", data) }) - stick.On(joystick.R2Release, func(data interface{}) { + _ = stick.On(joystick.R2Release, func(data interface{}) { fmt.Println("R2Release", data) }) - stick.On(joystick.L1Press, func(data interface{}) { + _ = stick.On(joystick.L1Press, func(data interface{}) { fmt.Println("L1Press", data) }) - stick.On(joystick.L1Release, func(data interface{}) { + _ = stick.On(joystick.L1Release, func(data interface{}) { fmt.Println("L1Release", data) }) - stick.On(joystick.L2Press, func(data interface{}) { + _ = stick.On(joystick.L2Press, func(data interface{}) { fmt.Println("L2Press", data) }) - stick.On(joystick.L2Release, func(data interface{}) { + _ = stick.On(joystick.L2Release, func(data interface{}) { fmt.Println("L2Release", data) }) } @@ -133,5 +133,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joystick_ps4.go b/examples/joystick_ps4.go index c824090d4..de950ab76 100644 --- a/examples/joystick_ps4.go +++ b/examples/joystick_ps4.go @@ -18,114 +18,114 @@ func main() { stick := joystick.NewDriver(joystickAdaptor, joystick.Dualshock4) work := func() { - stick.On(joystick.SquarePress, func(data interface{}) { + _ = stick.On(joystick.SquarePress, func(data interface{}) { fmt.Println("square_press") }) - stick.On(joystick.SquareRelease, func(data interface{}) { + _ = stick.On(joystick.SquareRelease, func(data interface{}) { fmt.Println("square_release") }) - stick.On(joystick.TrianglePress, func(data interface{}) { + _ = stick.On(joystick.TrianglePress, func(data interface{}) { fmt.Println("triangle_press") }) - stick.On(joystick.TriangleRelease, func(data interface{}) { + _ = stick.On(joystick.TriangleRelease, func(data interface{}) { fmt.Println("triangle_release") }) - stick.On(joystick.CirclePress, func(data interface{}) { + _ = stick.On(joystick.CirclePress, func(data interface{}) { fmt.Println("circle_press") }) - stick.On(joystick.CircleRelease, func(data interface{}) { + _ = stick.On(joystick.CircleRelease, func(data interface{}) { fmt.Println("circle_release") }) - stick.On(joystick.XPress, func(data interface{}) { + _ = stick.On(joystick.XPress, func(data interface{}) { fmt.Println("x_press") }) - stick.On(joystick.XRelease, func(data interface{}) { + _ = stick.On(joystick.XRelease, func(data interface{}) { fmt.Println("x_release") }) - stick.On(joystick.HomePress, func(data interface{}) { + _ = stick.On(joystick.HomePress, func(data interface{}) { fmt.Println("home_press") }) - stick.On(joystick.HomeRelease, func(data interface{}) { + _ = stick.On(joystick.HomeRelease, func(data interface{}) { fmt.Println("home_release") }) - stick.On(joystick.SharePress, func(data interface{}) { + _ = stick.On(joystick.SharePress, func(data interface{}) { fmt.Println("share_press") }) - stick.On(joystick.ShareRelease, func(data interface{}) { + _ = stick.On(joystick.ShareRelease, func(data interface{}) { fmt.Println("share_release") }) - stick.On(joystick.OptionsPress, func(data interface{}) { + _ = stick.On(joystick.OptionsPress, func(data interface{}) { fmt.Println("options_press") }) - stick.On(joystick.OptionsRelease, func(data interface{}) { + _ = stick.On(joystick.OptionsRelease, func(data interface{}) { fmt.Println("options_release") }) - stick.On(joystick.L1Press, func(data interface{}) { + _ = stick.On(joystick.L1Press, func(data interface{}) { fmt.Println("l1_press") }) - stick.On(joystick.L1Release, func(data interface{}) { + _ = stick.On(joystick.L1Release, func(data interface{}) { fmt.Println("l1_release") }) - stick.On(joystick.L2Press, func(data interface{}) { + _ = stick.On(joystick.L2Press, func(data interface{}) { fmt.Println("l2_press") }) - stick.On(joystick.L2Release, func(data interface{}) { + _ = stick.On(joystick.L2Release, func(data interface{}) { fmt.Println("l2_release") }) - stick.On(joystick.R1Press, func(data interface{}) { + _ = stick.On(joystick.R1Press, func(data interface{}) { fmt.Println("r1_press") }) - stick.On(joystick.R1Release, func(data interface{}) { + _ = stick.On(joystick.R1Release, func(data interface{}) { fmt.Println("r1_release") }) - stick.On(joystick.R2Press, func(data interface{}) { + _ = stick.On(joystick.R2Press, func(data interface{}) { fmt.Println("r2_press") }) - stick.On(joystick.R2Release, func(data interface{}) { + _ = stick.On(joystick.R2Release, func(data interface{}) { fmt.Println("r2_release") }) - stick.On(joystick.UpPress, func(data interface{}) { + _ = stick.On(joystick.UpPress, func(data interface{}) { fmt.Println("up_press") }) - stick.On(joystick.UpRelease, func(data interface{}) { + _ = stick.On(joystick.UpRelease, func(data interface{}) { fmt.Println("up_release") }) - stick.On(joystick.DownPress, func(data interface{}) { + _ = stick.On(joystick.DownPress, func(data interface{}) { fmt.Println("down_press") }) - stick.On(joystick.DownRelease, func(data interface{}) { + _ = stick.On(joystick.DownRelease, func(data interface{}) { fmt.Println("down_release") }) - stick.On(joystick.RightPress, func(data interface{}) { + _ = stick.On(joystick.RightPress, func(data interface{}) { fmt.Println("right_press") }) - stick.On(joystick.RightRelease, func(data interface{}) { + _ = stick.On(joystick.RightRelease, func(data interface{}) { fmt.Println("right_release") }) - stick.On(joystick.LeftPress, func(data interface{}) { + _ = stick.On(joystick.LeftPress, func(data interface{}) { fmt.Println("left_press") }) - stick.On(joystick.LeftRelease, func(data interface{}) { + _ = stick.On(joystick.LeftRelease, func(data interface{}) { fmt.Println("left_release") }) - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { fmt.Println("left_x", data) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { fmt.Println("left_y", data) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { fmt.Println("right_x", data) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { fmt.Println("right_y", data) }) - stick.On(joystick.L2, func(data interface{}) { + _ = stick.On(joystick.L2, func(data interface{}) { fmt.Println("L2", data) }) - stick.On(joystick.R2, func(data interface{}) { + _ = stick.On(joystick.R2, func(data interface{}) { fmt.Println("R2", data) }) } @@ -136,5 +136,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joystick_ps5.go b/examples/joystick_ps5.go index d5cbf631b..0057a5a78 100644 --- a/examples/joystick_ps5.go +++ b/examples/joystick_ps5.go @@ -18,114 +18,114 @@ func main() { stick := joystick.NewDriver(joystickAdaptor, joystick.Dualsense) work := func() { - stick.On(joystick.SquarePress, func(data interface{}) { + _ = stick.On(joystick.SquarePress, func(data interface{}) { fmt.Println("square_press") }) - stick.On(joystick.SquareRelease, func(data interface{}) { + _ = stick.On(joystick.SquareRelease, func(data interface{}) { fmt.Println("square_release") }) - stick.On(joystick.TrianglePress, func(data interface{}) { + _ = stick.On(joystick.TrianglePress, func(data interface{}) { fmt.Println("triangle_press") }) - stick.On(joystick.TriangleRelease, func(data interface{}) { + _ = stick.On(joystick.TriangleRelease, func(data interface{}) { fmt.Println("triangle_release") }) - stick.On(joystick.CirclePress, func(data interface{}) { + _ = stick.On(joystick.CirclePress, func(data interface{}) { fmt.Println("circle_press") }) - stick.On(joystick.CircleRelease, func(data interface{}) { + _ = stick.On(joystick.CircleRelease, func(data interface{}) { fmt.Println("circle_release") }) - stick.On(joystick.XPress, func(data interface{}) { + _ = stick.On(joystick.XPress, func(data interface{}) { fmt.Println("x_press") }) - stick.On(joystick.XRelease, func(data interface{}) { + _ = stick.On(joystick.XRelease, func(data interface{}) { fmt.Println("x_release") }) - stick.On(joystick.HomePress, func(data interface{}) { + _ = stick.On(joystick.HomePress, func(data interface{}) { fmt.Println("home_press") }) - stick.On(joystick.HomeRelease, func(data interface{}) { + _ = stick.On(joystick.HomeRelease, func(data interface{}) { fmt.Println("home_release") }) - stick.On(joystick.CreatePress, func(data interface{}) { + _ = stick.On(joystick.CreatePress, func(data interface{}) { fmt.Println("create_press") }) - stick.On(joystick.CreateRelease, func(data interface{}) { + _ = stick.On(joystick.CreateRelease, func(data interface{}) { fmt.Println("create_release") }) - stick.On(joystick.OptionsPress, func(data interface{}) { + _ = stick.On(joystick.OptionsPress, func(data interface{}) { fmt.Println("options_press") }) - stick.On(joystick.OptionsRelease, func(data interface{}) { + _ = stick.On(joystick.OptionsRelease, func(data interface{}) { fmt.Println("options_release") }) - stick.On(joystick.L1Press, func(data interface{}) { + _ = stick.On(joystick.L1Press, func(data interface{}) { fmt.Println("l1_press") }) - stick.On(joystick.L1Release, func(data interface{}) { + _ = stick.On(joystick.L1Release, func(data interface{}) { fmt.Println("l1_release") }) - stick.On(joystick.R1Press, func(data interface{}) { + _ = stick.On(joystick.R1Press, func(data interface{}) { fmt.Println("r1_press") }) - stick.On(joystick.R1Release, func(data interface{}) { + _ = stick.On(joystick.R1Release, func(data interface{}) { fmt.Println("r1_release") }) - stick.On(joystick.PSPress, func(data interface{}) { + _ = stick.On(joystick.PSPress, func(data interface{}) { fmt.Println("ps_press") }) - stick.On(joystick.PSRelease, func(data interface{}) { + _ = stick.On(joystick.PSRelease, func(data interface{}) { fmt.Println("ps_release") }) - stick.On(joystick.TrackpadPress, func(data interface{}) { + _ = stick.On(joystick.TrackpadPress, func(data interface{}) { fmt.Println("trackpad_press") }) - stick.On(joystick.TrackpadRelease, func(data interface{}) { + _ = stick.On(joystick.TrackpadRelease, func(data interface{}) { fmt.Println("trackpad_release") }) - stick.On(joystick.UpPress, func(data interface{}) { + _ = stick.On(joystick.UpPress, func(data interface{}) { fmt.Println("up_press") }) - stick.On(joystick.UpRelease, func(data interface{}) { + _ = stick.On(joystick.UpRelease, func(data interface{}) { fmt.Println("up_release") }) - stick.On(joystick.DownPress, func(data interface{}) { + _ = stick.On(joystick.DownPress, func(data interface{}) { fmt.Println("down_press") }) - stick.On(joystick.DownRelease, func(data interface{}) { + _ = stick.On(joystick.DownRelease, func(data interface{}) { fmt.Println("down_release") }) - stick.On(joystick.RightPress, func(data interface{}) { + _ = stick.On(joystick.RightPress, func(data interface{}) { fmt.Println("right_press") }) - stick.On(joystick.RightRelease, func(data interface{}) { + _ = stick.On(joystick.RightRelease, func(data interface{}) { fmt.Println("right_release") }) - stick.On(joystick.LeftPress, func(data interface{}) { + _ = stick.On(joystick.LeftPress, func(data interface{}) { fmt.Println("left_press") }) - stick.On(joystick.LeftRelease, func(data interface{}) { + _ = stick.On(joystick.LeftRelease, func(data interface{}) { fmt.Println("left_release") }) - // stick.On(joystick.LeftX, func(data interface{}) { + // _ = stick.On(joystick.LeftX, func(data interface{}) { // fmt.Println("left_x", data) // }) - // stick.On(joystick.LeftY, func(data interface{}) { + // _ = stick.On(joystick.LeftY, func(data interface{}) { // fmt.Println("left_y", data) // }) - // stick.On(joystick.RightX, func(data interface{}) { + // _ = stick.On(joystick.RightX, func(data interface{}) { // fmt.Println("right_x", data) // }) - // stick.On(joystick.RightY, func(data interface{}) { + // _ = stick.On(joystick.RightY, func(data interface{}) { // fmt.Println("right_y", data) // }) - // stick.On(joystick.L2, func(data interface{}) { + // _ = stick.On(joystick.L2, func(data interface{}) { // fmt.Println("L2", data) // }) - // stick.On(joystick.R2, func(data interface{}) { + // _ = stick.On(joystick.R2, func(data interface{}) { // fmt.Println("R2", data) // }) } @@ -136,5 +136,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joystick_xbox360.go b/examples/joystick_xbox360.go index dff41efb3..ad7e111d5 100644 --- a/examples/joystick_xbox360.go +++ b/examples/joystick_xbox360.go @@ -18,40 +18,40 @@ func main() { stick := joystick.NewDriver(joystickAdaptor, joystick.Xbox360) work := func() { - stick.On(joystick.APress, func(data interface{}) { + _ = stick.On(joystick.APress, func(data interface{}) { fmt.Println("a_press") }) - stick.On(joystick.ARelease, func(data interface{}) { + _ = stick.On(joystick.ARelease, func(data interface{}) { fmt.Println("a_release") }) - stick.On(joystick.BPress, func(data interface{}) { + _ = stick.On(joystick.BPress, func(data interface{}) { fmt.Println("b_press") }) - stick.On(joystick.BRelease, func(data interface{}) { + _ = stick.On(joystick.BRelease, func(data interface{}) { fmt.Println("b_release") }) - stick.On(joystick.UpPress, func(data interface{}) { + _ = stick.On(joystick.UpPress, func(data interface{}) { fmt.Println("up", data) }) - stick.On(joystick.DownPress, func(data interface{}) { + _ = stick.On(joystick.DownPress, func(data interface{}) { fmt.Println("down", data) }) - stick.On(joystick.LeftPress, func(data interface{}) { + _ = stick.On(joystick.LeftPress, func(data interface{}) { fmt.Println("left", data) }) - stick.On(joystick.RightPress, func(data interface{}) { + _ = stick.On(joystick.RightPress, func(data interface{}) { fmt.Println("right", data) }) - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { fmt.Println("left_x", data) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { fmt.Println("left_y", data) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { fmt.Println("right_x", data) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { fmt.Println("right_y", data) }) } @@ -62,5 +62,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joystick_xbox360_rock_band_drums.go b/examples/joystick_xbox360_rock_band_drums.go index 05c6bf0a2..6e01a9da6 100644 --- a/examples/joystick_xbox360_rock_band_drums.go +++ b/examples/joystick_xbox360_rock_band_drums.go @@ -18,46 +18,46 @@ func main() { stick := joystick.NewDriver(joystickAdaptor, joystick.Xbox360RockBandDrums) work := func() { - stick.On(joystick.RedPress, func(data interface{}) { + _ = stick.On(joystick.RedPress, func(data interface{}) { fmt.Println("red_press") }) - stick.On(joystick.RedRelease, func(data interface{}) { + _ = stick.On(joystick.RedRelease, func(data interface{}) { fmt.Println("red_release") }) - stick.On(joystick.YellowPress, func(data interface{}) { + _ = stick.On(joystick.YellowPress, func(data interface{}) { fmt.Println("yellow_press") }) - stick.On(joystick.YellowRelease, func(data interface{}) { + _ = stick.On(joystick.YellowRelease, func(data interface{}) { fmt.Println("yellow_release") }) - stick.On(joystick.BluePress, func(data interface{}) { + _ = stick.On(joystick.BluePress, func(data interface{}) { fmt.Println("blue_press") }) - stick.On(joystick.BlueRelease, func(data interface{}) { + _ = stick.On(joystick.BlueRelease, func(data interface{}) { fmt.Println("blue_release") }) - stick.On(joystick.GreenPress, func(data interface{}) { + _ = stick.On(joystick.GreenPress, func(data interface{}) { fmt.Println("green_press") }) - stick.On(joystick.GreenRelease, func(data interface{}) { + _ = stick.On(joystick.GreenRelease, func(data interface{}) { fmt.Println("blue_release") }) - stick.On(joystick.PedalPress, func(data interface{}) { + _ = stick.On(joystick.PedalPress, func(data interface{}) { fmt.Println("pedal_press") }) - stick.On(joystick.PedalRelease, func(data interface{}) { + _ = stick.On(joystick.PedalRelease, func(data interface{}) { fmt.Println("pedal_release") }) - stick.On(joystick.UpPress, func(data interface{}) { + _ = stick.On(joystick.UpPress, func(data interface{}) { fmt.Println("up", data) }) - stick.On(joystick.DownPress, func(data interface{}) { + _ = stick.On(joystick.DownPress, func(data interface{}) { fmt.Println("down", data) }) - stick.On(joystick.LeftPress, func(data interface{}) { + _ = stick.On(joystick.LeftPress, func(data interface{}) { fmt.Println("left", data) }) - stick.On(joystick.RightPress, func(data interface{}) { + _ = stick.On(joystick.RightPress, func(data interface{}) { fmt.Println("right", data) }) } @@ -68,5 +68,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/joystick_xboxone.go b/examples/joystick_xboxone.go index 883a4d5f9..0732df69d 100644 --- a/examples/joystick_xboxone.go +++ b/examples/joystick_xboxone.go @@ -19,144 +19,144 @@ func main() { work := func() { // start button - joystick.On(joystick.Event("start_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("start_press"), func(data interface{}) { fmt.Println("start_press") }) - joystick.On(joystick.Event("start_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("start_release"), func(data interface{}) { fmt.Println("start_release") }) // back button - joystick.On(joystick.Event("back_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("back_press"), func(data interface{}) { fmt.Println("back_press") }) - joystick.On(joystick.Event("back_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("back_release"), func(data interface{}) { fmt.Println("back_release") }) // a button - joystick.On(joystick.Event("a_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("a_press"), func(data interface{}) { fmt.Println("a_press") }) - joystick.On(joystick.Event("a_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("a_release"), func(data interface{}) { fmt.Println("a_release") }) // b button - joystick.On(joystick.Event("b_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("b_press"), func(data interface{}) { fmt.Println("b_press") }) - joystick.On(joystick.Event("b_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("b_release"), func(data interface{}) { fmt.Println("b_release") }) // x button - joystick.On(joystick.Event("x_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("x_press"), func(data interface{}) { fmt.Println("x_press") }) - joystick.On(joystick.Event("x_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("x_release"), func(data interface{}) { fmt.Println("x_release") }) // y button - joystick.On(joystick.Event("y_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("y_press"), func(data interface{}) { fmt.Println("y_press") }) - joystick.On(joystick.Event("y_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("y_release"), func(data interface{}) { fmt.Println("y_release") }) // up dpad - joystick.On(joystick.Event("up_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("up_press"), func(data interface{}) { fmt.Println("up_press", data) }) - joystick.On(joystick.Event("up_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("up_release"), func(data interface{}) { fmt.Println("up_release", data) }) // down dpad - joystick.On(joystick.Event("down_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("down_press"), func(data interface{}) { fmt.Println("down_press") }) - joystick.On(joystick.Event("down_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("down_release"), func(data interface{}) { fmt.Println("down_release") }) // left dpad - joystick.On(joystick.Event("left_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("left_press"), func(data interface{}) { fmt.Println("left_press") }) - joystick.On(joystick.Event("left_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("left_release"), func(data interface{}) { fmt.Println("left_release") }) // right dpad - joystick.On(joystick.Event("right_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("right_press"), func(data interface{}) { fmt.Println("right_press") }) - joystick.On(joystick.Event("right_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("right_release"), func(data interface{}) { fmt.Println("right_release") }) // rt trigger - joystick.On(joystick.Event("rt"), func(data interface{}) { + _ = joystick.On(joystick.Event("rt"), func(data interface{}) { fmt.Println("rt", data) }) // lt trigger - joystick.On(joystick.Event("lt"), func(data interface{}) { + _ = joystick.On(joystick.Event("lt"), func(data interface{}) { fmt.Println("lt", data) }) // lb button - joystick.On(joystick.Event("lb_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("lb_press"), func(data interface{}) { fmt.Println("lb_press") }) - joystick.On(joystick.Event("lb_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("lb_release"), func(data interface{}) { fmt.Println("lb_release") }) // rb button - joystick.On(joystick.Event("rb_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("rb_press"), func(data interface{}) { fmt.Println("rb_press") }) - joystick.On(joystick.Event("rb_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("rb_release"), func(data interface{}) { fmt.Println("rb_release") }) // rx stick - joystick.On(joystick.Event("right_x"), func(data interface{}) { + _ = joystick.On(joystick.Event("right_x"), func(data interface{}) { fmt.Println("right_x", data) }) // ry stick - joystick.On(joystick.Event("right_y"), func(data interface{}) { + _ = joystick.On(joystick.Event("right_y"), func(data interface{}) { fmt.Println("right_y", data) }) // right_stick button - joystick.On(joystick.Event("right_stick_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("right_stick_press"), func(data interface{}) { fmt.Println("right_stick_press") }) - joystick.On(joystick.Event("right_stick_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("right_stick_release"), func(data interface{}) { fmt.Println("right_stick_release") }) // lx stick - joystick.On(joystick.Event("left_x"), func(data interface{}) { + _ = joystick.On(joystick.Event("left_x"), func(data interface{}) { fmt.Println("left_x", data) }) // ly stick - joystick.On(joystick.Event("left_y"), func(data interface{}) { + _ = joystick.On(joystick.Event("left_y"), func(data interface{}) { fmt.Println("left_y", data) }) // left_stick button - joystick.On(joystick.Event("left_stick_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("left_stick_press"), func(data interface{}) { fmt.Println("left_stick_press") }) - joystick.On(joystick.Event("left_stick_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("left_stick_release"), func(data interface{}) { fmt.Println("left_stick_release") }) } @@ -167,5 +167,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/keyboard.go b/examples/keyboard.go index b26b81661..30eb40135 100644 --- a/examples/keyboard.go +++ b/examples/keyboard.go @@ -17,7 +17,7 @@ func main() { keys := keyboard.NewDriver() work := func() { - keys.On(keyboard.Key, func(data interface{}) { + _ = keys.On(keyboard.Key, func(data interface{}) { key := data.(keyboard.KeyEvent) if key.Key == keyboard.A { @@ -34,5 +34,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/keyboard_mqtt.go b/examples/keyboard_mqtt.go index b56f8155d..5fc54c8c1 100644 --- a/examples/keyboard_mqtt.go +++ b/examples/keyboard_mqtt.go @@ -17,7 +17,7 @@ func main() { mqttAdaptor := mqtt.NewAdaptor("tcp://iot.eclipse.org:1883", "conductor") work := func() { - keys.On(keyboard.Key, func(data interface{}) { + _ = keys.On(keyboard.Key, func(data interface{}) { key := data.(keyboard.KeyEvent) switch key.Key { @@ -39,5 +39,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/leap_motion.go b/examples/leap_motion.go index 25ae1e9f6..eb6375ac6 100644 --- a/examples/leap_motion.go +++ b/examples/leap_motion.go @@ -18,7 +18,7 @@ func main() { l := leap.NewDriver(leapMotionAdaptor) work := func() { - l.On(leap.MessageEvent, func(data interface{}) { + _ = l.On(leap.MessageEvent, func(data interface{}) { fmt.Println(data.(leap.Frame)) }) } @@ -29,5 +29,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/leap_motion_gestures.go b/examples/leap_motion_gestures.go index 152826a33..f607e05e2 100644 --- a/examples/leap_motion_gestures.go +++ b/examples/leap_motion_gestures.go @@ -18,7 +18,7 @@ func main() { l := leap.NewDriver(leapMotionAdaptor) work := func() { - l.On(leap.GestureEvent, func(data interface{}) { + _ = l.On(leap.GestureEvent, func(data interface{}) { printGesture(data.(leap.Gesture)) }) } @@ -29,7 +29,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func printGesture(gesture leap.Gesture) { diff --git a/examples/leap_motion_hands.go b/examples/leap_motion_hands.go index ecf2fbd32..95be506b7 100644 --- a/examples/leap_motion_hands.go +++ b/examples/leap_motion_hands.go @@ -18,7 +18,7 @@ func main() { l := leap.NewDriver(leapMotionAdaptor) work := func() { - l.On(leap.HandEvent, func(data interface{}) { + _ = l.On(leap.HandEvent, func(data interface{}) { printHand(data.(leap.Hand)) }) } @@ -29,7 +29,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func printHand(hand leap.Hand) { diff --git a/examples/leap_servos.go b/examples/leap_servos.go index f3d715447..5d9e068eb 100644 --- a/examples/leap_servos.go +++ b/examples/leap_servos.go @@ -7,6 +7,8 @@ package main import ( + "fmt" + "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/gpio" "gobot.io/x/gobot/v2/platforms/firmata" @@ -27,21 +29,41 @@ func main() { work := func() { fist := false - l.On(leap.MessageEvent, func(data interface{}) { + _ = l.On(leap.MessageEvent, func(data interface{}) { handIsOpen := len(data.(leap.Frame).Pointables) > 0 if handIsOpen && fist { - servo1.Move(0) - servo2.Move(0) - servo3.Move(0) - servo4.Move(0) - servo5.Move(0) + if err := servo1.Move(0); err != nil { + fmt.Println(err) + } + if err := servo2.Move(0); err != nil { + fmt.Println(err) + } + if err := servo3.Move(0); err != nil { + fmt.Println(err) + } + if err := servo4.Move(0); err != nil { + fmt.Println(err) + } + if err := servo5.Move(0); err != nil { + fmt.Println(err) + } fist = false } else if !handIsOpen && !fist { - servo1.Move(120) - servo2.Move(120) - servo3.Move(120) - servo4.Move(120) - servo5.Move(120) + if err := servo1.Move(120); err != nil { + fmt.Println(err) + } + if err := servo2.Move(120); err != nil { + fmt.Println(err) + } + if err := servo3.Move(120); err != nil { + fmt.Println(err) + } + if err := servo4.Move(120); err != nil { + fmt.Println(err) + } + if err := servo5.Move(120); err != nil { + fmt.Println(err) + } fist = true } }) @@ -53,5 +75,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/leap_sphero.go b/examples/leap_sphero.go index 91e6c179d..b4aae6170 100644 --- a/examples/leap_sphero.go +++ b/examples/leap_sphero.go @@ -23,7 +23,7 @@ func main() { spheroDriver := serial.NewSpheroDriver(spheroAdaptor) work := func() { - leapDriver.On(leap.MessageEvent, func(data interface{}) { + _ = leapDriver.On(leap.MessageEvent, func(data interface{}) { hands := data.(leap.Frame).Hands if len(hands) > 0 { @@ -41,7 +41,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func scale(position float64) uint8 { diff --git a/examples/mavlink.go b/examples/mavlink.go index 6f21624f5..b7d355562 100644 --- a/examples/mavlink.go +++ b/examples/mavlink.go @@ -19,7 +19,7 @@ func main() { iris := mavlink.NewDriver(adaptor) work := func() { - iris.Once(mavlink.PacketEvent, func(data interface{}) { + _ = iris.Once(mavlink.PacketEvent, func(data interface{}) { packet := data.(*common.MAVLinkPacket) dataStream := common.NewRequestDataStream(100, @@ -28,13 +28,13 @@ func main() { 4, 1, ) - iris.SendPacket(common.CraftMAVLinkPacket(packet.SystemID, - packet.ComponentID, - dataStream, - )) + if err := iris.SendPacket( + common.CraftMAVLinkPacket(packet.SystemID, packet.ComponentID, dataStream)); err != nil { + fmt.Println(err) + } }) - iris.On(mavlink.MessageEvent, func(data interface{}) { + _ = iris.On(mavlink.MessageEvent, func(data interface{}) { if data.(common.MAVLinkMessage).Id() == 30 { message := data.(*common.Attitude) fmt.Println("Attitude") @@ -56,5 +56,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/megapi_motor.go b/examples/megapi_motor.go index ca61c3db3..fba251446 100644 --- a/examples/megapi_motor.go +++ b/examples/megapi_motor.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -24,7 +25,9 @@ func main() { fadeAmount := int16(30) gobot.Every(100*time.Millisecond, func() { - motor.Speed(speed) + if err := motor.Speed(speed); err != nil { + fmt.Println(err) + } speed = speed + fadeAmount if speed == 0 || speed == 300 { fadeAmount = -fadeAmount @@ -38,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/metal_button.go b/examples/metal_button.go index 3516e6416..bfc8d68de 100644 --- a/examples/metal_button.go +++ b/examples/metal_button.go @@ -15,22 +15,29 @@ import ( func main() { e := edison.NewAdaptor() - e.Connect() + if err := e.Connect(); err != nil { + fmt.Println(err) + } led := gpio.NewLedDriver(e, "13") - led.Start() - led.Off() + if err := led.Start(); err != nil { + fmt.Println(err) + } + if err := led.Off(); err != nil { + fmt.Println(err) + } button := gpio.NewButtonDriver(e, "5") - button.Start() + if err := button.Start(); err != nil { + fmt.Println(err) + } buttonEvents := button.Subscribe() - for { - select { - case event := <-buttonEvents: - fmt.Println("Event:", event.Name, event.Data) - if event.Name == gpio.ButtonPush { - led.Toggle() + for event := range buttonEvents { + fmt.Println("Event:", event.Name, event.Data) + if event.Name == gpio.ButtonPush { + if err := led.Toggle(); err != nil { + fmt.Println(err) } } } diff --git a/examples/mqtt_driver_ping.go b/examples/mqtt_driver_ping.go index 1236d80c4..27cf9d380 100644 --- a/examples/mqtt_driver_ping.go +++ b/examples/mqtt_driver_ping.go @@ -30,11 +30,11 @@ func main() { helloDriver := mqtt.NewDriver(mqttAdaptor, "hello") work := func() { - helloDriver.On(mqtt.Data, func(data interface{}) { + _ = helloDriver.On(mqtt.Data, func(data interface{}) { fmt.Println("hello") }) - holaDriver.On(mqtt.Data, func(data interface{}) { + _ = holaDriver.On(mqtt.Data, func(data interface{}) { fmt.Println("hola") }) @@ -54,5 +54,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/mqtt_firmata_blink.go b/examples/mqtt_firmata_blink.go index 23fb97016..49d1af067 100644 --- a/examples/mqtt_firmata_blink.go +++ b/examples/mqtt_firmata_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -21,11 +22,15 @@ func main() { led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { - mqttAdaptor.On("lights/on", func(msg mqtt.Message) { - led.On() + _ = mqttAdaptor.On("lights/on", func(msg mqtt.Message) { + if err := led.On(); err != nil { + fmt.Println(err) + } }) - mqttAdaptor.On("lights/off", func(msg mqtt.Message) { - led.Off() + _ = mqttAdaptor.On("lights/off", func(msg mqtt.Message) { + if err := led.Off(); err != nil { + fmt.Println(err) + } }) data := []byte("") gobot.Every(1*time.Second, func() { @@ -42,5 +47,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/mqtt_ping.go b/examples/mqtt_ping.go index ba3b1ccd9..bc5fd1b2b 100644 --- a/examples/mqtt_ping.go +++ b/examples/mqtt_ping.go @@ -18,10 +18,10 @@ func main() { mqttAdaptor := mqtt.NewAdaptor("tcp://test.mosquitto.org:1883", "pinger") work := func() { - mqttAdaptor.On("hello", func(msg mqtt.Message) { + _ = mqttAdaptor.On("hello", func(msg mqtt.Message) { fmt.Println("hello") }) - mqttAdaptor.On("hola", func(msg mqtt.Message) { + _ = mqttAdaptor.On("hola", func(msg mqtt.Message) { fmt.Println("hola") }) data := []byte("o") @@ -38,5 +38,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/nanopi_direct_pin.go b/examples/nanopi_direct_pin.go index 616b2ef79..afbb130b6 100644 --- a/examples/nanopi_direct_pin.go +++ b/examples/nanopi_direct_pin.go @@ -20,8 +20,10 @@ import ( // PWR NanoPi: 1, 17 (+3.3V, VCC); 2, 4 (+5V, VDD); 6, 9, 14, 20 (GND) // GPIO NanoPi: header pin 22 is input, pin 23 is normal output, pin 24 is inverted output // Button: the input pin is wired with a button to GND, the internal pull up resistor is used -// LED's: the output pins are wired to the cathode of a LED, the anode is wired with a resistor (70-130Ohm for 20mA) to VCC -// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state changes +// LED's: the output pins are wired to the cathode of the LED, the anode is wired with a resistor (70-130Ohm for 20mA) +// to VCC +// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state +// changes func main() { const ( inPinNum = "22" // 7, 8, 10, 11, 12, 13, 15, 16, 18, 22 @@ -77,5 +79,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/nanopi_direct_pin_event.go b/examples/nanopi_direct_pin_event.go index f29f4dd8d..8a898a4b2 100644 --- a/examples/nanopi_direct_pin_event.go +++ b/examples/nanopi_direct_pin_event.go @@ -31,8 +31,10 @@ var ( // PWR NanoPi: 1, 17 (+3.3V, VCC); 2, 4 (+5V, VDD); 6, 9, 14, 20 (GND) // GPIO NanoPi: header pin 22 is input, pin 23 is normal output, pin 24 is inverted output // Button: the input pin is wired with a button to GND, the internal pull up resistor is used -// LED's: the output pins are wired to the cathode of a LED, the anode is wired with a resistor (70-130Ohm for 20mA) to VCC -// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state changes +// LED's: the output pins are wired to the cathode of a LED, the anode is wired with a resistor (70-130Ohm for 20mA) +// to VCC +// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state +// changes func main() { board := nanopi.NewNeoAdaptor() @@ -73,7 +75,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func buttonEventHandler(offset int, t time.Duration, et string, sn uint32, lsn uint32) { diff --git a/examples/nanopi_led_brightness.go b/examples/nanopi_led_brightness.go index 72af91a01..d9ad9ac77 100644 --- a/examples/nanopi_led_brightness.go +++ b/examples/nanopi_led_brightness.go @@ -18,7 +18,7 @@ import ( // Wiring // PWR NanoPi: 1, 17 (+3.3V, VCC); 2, 4 (+5V, VDD); 6, 9, 14, 20 (GND) // GPIO NanoPi: the fourth header pin at inner USB side, count from USB side, is the PWM output -// LED: the PWM output is NOT able to drive a 20mA LED with full brightness, so a custom driver or low current LED is needed +// LED: the PWM output is NOT able to drive a 20mA LED with full brightness (custom driver or low current LED is needed) // Expected behavior: the LED fades in and out func main() { r := nanopi.NewNeoAdaptor() @@ -45,5 +45,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/nanopi_pca9533.go b/examples/nanopi_pca9533.go index 73a5d614a..844f75cea 100644 --- a/examples/nanopi_pca9533.go +++ b/examples/nanopi_pca9533.go @@ -69,9 +69,8 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/nats.go b/examples/nats.go index fdefc5085..2213fabac 100644 --- a/examples/nats.go +++ b/examples/nats.go @@ -38,5 +38,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/nats_driver_ping.go b/examples/nats_driver_ping.go index b813b9fb7..d372ee678 100644 --- a/examples/nats_driver_ping.go +++ b/examples/nats_driver_ping.go @@ -29,11 +29,11 @@ func main() { helloDriver := nats.NewDriver(natsAdaptor, "hello") work := func() { - helloDriver.On(nats.Data, func(msg nats.Message) { + _ = helloDriver.On(nats.Data, func(msg nats.Message) { fmt.Println("hello") }) - holaDriver.On(nats.Data, func(msg nats.Message) { + _ = holaDriver.On(nats.Data, func(msg nats.Message) { fmt.Println("hola") }) @@ -53,5 +53,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/neurosky.go b/examples/neurosky.go index 37cb12a94..4c492230f 100644 --- a/examples/neurosky.go +++ b/examples/neurosky.go @@ -18,25 +18,25 @@ func main() { neuro := neurosky.NewDriver(adaptor) work := func() { - neuro.On(neuro.Event("extended"), func(data interface{}) { + _ = neuro.On(neuro.Event("extended"), func(data interface{}) { fmt.Println("Extended", data) }) - neuro.On(neuro.Event("signal"), func(data interface{}) { + _ = neuro.On(neuro.Event("signal"), func(data interface{}) { fmt.Println("Signal", data) }) - neuro.On(neuro.Event("attention"), func(data interface{}) { + _ = neuro.On(neuro.Event("attention"), func(data interface{}) { fmt.Println("Attention", data) }) - neuro.On(neuro.Event("meditation"), func(data interface{}) { + _ = neuro.On(neuro.Event("meditation"), func(data interface{}) { fmt.Println("Meditation", data) }) - neuro.On(neuro.Event("blink"), func(data interface{}) { + _ = neuro.On(neuro.Event("blink"), func(data interface{}) { fmt.Println("Blink", data) }) - neuro.On(neuro.Event("wave"), func(data interface{}) { + _ = neuro.On(neuro.Event("wave"), func(data interface{}) { fmt.Println("Wave", data) }) - neuro.On(neuro.Event("eeg"), func(data interface{}) { + _ = neuro.On(neuro.Event("eeg"), func(data interface{}) { eeg := data.(neurosky.EEGData) fmt.Println("Delta", eeg.Delta) fmt.Println("Theta", eeg.Theta) @@ -56,5 +56,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/opencv_face_detect.go b/examples/opencv_face_detect.go index 54774e8e4..88aec5e02 100644 --- a/examples/opencv_face_detect.go +++ b/examples/opencv_face_detect.go @@ -53,5 +53,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/opencv_window.go b/examples/opencv_window.go index ece48d187..51286bf4e 100644 --- a/examples/opencv_window.go +++ b/examples/opencv_window.go @@ -29,5 +29,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/particle_api.go b/examples/particle_api.go index d39f390a7..ee267d073 100644 --- a/examples/particle_api.go +++ b/examples/particle_api.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -32,7 +33,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -44,5 +47,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/particle_blink.go b/examples/particle_blink.go index 53212927b..0f4eb4382 100644 --- a/examples/particle_blink.go +++ b/examples/particle_blink.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -28,7 +29,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -38,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/particle_button.go b/examples/particle_button.go index abe5d7f94..bb9580e99 100644 --- a/examples/particle_button.go +++ b/examples/particle_button.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "gobot.io/x/gobot/v2" @@ -27,12 +28,16 @@ func main() { button := gpio.NewButtonDriver(core, "D5") work := func() { - button.On(button.Event("push"), func(data interface{}) { - led.On() + _ = button.On(button.Event("push"), func(data interface{}) { + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(button.Event("release"), func(data interface{}) { - led.Off() + _ = button.On(button.Event("release"), func(data interface{}) { + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -42,5 +47,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/particle_events.go b/examples/particle_events.go index 77d39b43f..3106ab22d 100644 --- a/examples/particle_events.go +++ b/examples/particle_events.go @@ -38,5 +38,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/particle_function.go b/examples/particle_function.go index 5135519c3..3c45ec3fe 100644 --- a/examples/particle_function.go +++ b/examples/particle_function.go @@ -37,5 +37,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/particle_led_brightness.go b/examples/particle_led_brightness.go index 40e7672c8..89907e120 100644 --- a/examples/particle_led_brightness.go +++ b/examples/particle_led_brightness.go @@ -14,6 +14,7 @@ package main import ( + "fmt" "os" "time" @@ -31,7 +32,9 @@ func main() { fadeAmount := uint8(25) gobot.Every(500*time.Millisecond, func() { - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } brightness = brightness + fadeAmount if brightness == 0 || brightness == 255 { fadeAmount = -fadeAmount @@ -45,5 +48,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/particle_variable.go b/examples/particle_variable.go index 1f2023902..54fddba49 100644 --- a/examples/particle_variable.go +++ b/examples/particle_variable.go @@ -40,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/pebble.go b/examples/pebble.go index d585e5654..3bbe1bedd 100644 --- a/examples/pebble.go +++ b/examples/pebble.go @@ -25,11 +25,11 @@ func main() { work := func() { pebbleDriver.SendNotification("Hello Pebble!") - pebbleDriver.On(pebbleDriver.Event("button"), func(data interface{}) { + _ = pebbleDriver.On(pebbleDriver.Event("button"), func(data interface{}) { fmt.Println("Button pushed: " + data.(string)) }) - pebbleDriver.On(pebbleDriver.Event("tap"), func(data interface{}) { + _ = pebbleDriver.On(pebbleDriver.Event("tap"), func(data interface{}) { fmt.Println("Tap event detected") }) } @@ -42,5 +42,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/pebble_accelerometer.go b/examples/pebble_accelerometer.go index 5444312b3..632989ed3 100644 --- a/examples/pebble_accelerometer.go +++ b/examples/pebble_accelerometer.go @@ -24,7 +24,7 @@ func main() { pebbleDriver := pebble.NewDriver(pebbleAdaptor) work := func() { - pebbleDriver.On(pebbleDriver.Event("accel"), func(data interface{}) { + _ = pebbleDriver.On(pebbleDriver.Event("accel"), func(data interface{}) { fmt.Println(data.(string)) }) } @@ -37,5 +37,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_adafruit2327_servo.go b/examples/raspi_adafruit2327_servo.go index 9a93aa985..d87d78103 100644 --- a/examples/raspi_adafruit2327_servo.go +++ b/examples/raspi_adafruit2327_servo.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "log" "time" @@ -38,7 +39,9 @@ func main() { work := func() { gobot.Every(5*time.Second, func() { - adafruitServoMotorRunner(adaFruit) + if err := adafruitServoMotorRunner(adaFruit); err != nil { + fmt.Println(err) + } }) } @@ -48,7 +51,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func adafruitServoMotorRunner(a *i2c.Adafruit2327Driver) error { @@ -60,26 +65,22 @@ func adafruitServoMotorRunner(a *i2c.Adafruit2327Driver) error { // Do not need to set this every run loop freq := 60.0 if err := a.SetServoMotorFreq(freq); err != nil { - log.Printf("%s", err.Error()) return err } // start in the middle of the 180-deg range pulse := degree2pulse(deg) if err := a.SetServoMotorPulse(channel, 0, pulse); err != nil { - log.Printf(err.Error()) return err } // INCR pulse = degree2pulse(deg + degIncrease) if err := a.SetServoMotorPulse(channel, 0, pulse); err != nil { - log.Printf(err.Error()) return err } time.Sleep(2000 * time.Millisecond) // DECR pulse = degree2pulse(deg - degIncrease) if err := a.SetServoMotorPulse(channel, 0, pulse); err != nil { - log.Printf(err.Error()) return err } return nil diff --git a/examples/raspi_adafruit2348_dcmotor.go b/examples/raspi_adafruit2348_dcmotor.go index b15967109..0df538cc5 100644 --- a/examples/raspi_adafruit2348_dcmotor.go +++ b/examples/raspi_adafruit2348_dcmotor.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "log" "time" @@ -24,7 +25,9 @@ func main() { work := func() { gobot.Every(5*time.Second, func() { dcMotor := 2 // 0-based - adafruitDCMotorRunner(adaFruit, dcMotor) + if err := adafruitDCMotorRunner(adaFruit, dcMotor); err != nil { + fmt.Println(err) + } }) } @@ -34,7 +37,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func adafruitDCMotorRunner(a *i2c.Adafruit2348Driver, dcMotor int) error { diff --git a/examples/raspi_adafruit2348_stepper.go b/examples/raspi_adafruit2348_stepper.go index c1eb80f38..0cac6546a 100644 --- a/examples/raspi_adafruit2348_stepper.go +++ b/examples/raspi_adafruit2348_stepper.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "log" "time" @@ -24,7 +25,9 @@ func main() { work := func() { gobot.Every(5*time.Second, func() { motor := 0 // 0-based - adafruitStepperMotorRunner(adaFruit, motor) + if err := adafruitStepperMotorRunner(adaFruit, motor); err != nil { + fmt.Println(err) + } }) } @@ -34,7 +37,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func adafruitStepperMotorRunner(a *i2c.Adafruit2348Driver, motor int) error { @@ -44,15 +49,17 @@ func adafruitStepperMotorRunner(a *i2c.Adafruit2348Driver, motor int) error { style := i2c.Adafruit2348Double steps := 20 - a.SetStepperMotorSpeed(motor, speed) + if err := a.SetStepperMotorSpeed(motor, speed); err != nil { + return err + } if err := a.Step(motor, steps, i2c.Adafruit2348Forward, style); err != nil { - log.Printf(err.Error()) return err } + if err := a.Step(motor, steps, i2c.Adafruit2348Backward, style); err != nil { - log.Printf(err.Error()) return err } + return nil } diff --git a/examples/raspi_ads1015.go b/examples/raspi_ads1015.go index 8ac0b29a2..3255d3d7d 100644 --- a/examples/raspi_ads1015.go +++ b/examples/raspi_ads1015.go @@ -33,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_blink.go b/examples/raspi_blink.go index fb3623955..f519f006e 100644 --- a/examples/raspi_blink.go +++ b/examples/raspi_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_blinkm.go b/examples/raspi_blinkm.go index bf7a3d066..80afb59b2 100644 --- a/examples/raspi_blinkm.go +++ b/examples/raspi_blinkm.go @@ -24,8 +24,13 @@ func main() { r := byte(gobot.Rand(255)) g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) - blinkm.Rgb(r, g, b) - color, _ := blinkm.Color() + if err := blinkm.Rgb(r, g, b); err != nil { + fmt.Println(err) + } + color, err := blinkm.Color() + if err != nil { + fmt.Println(err) + } fmt.Println("color", color) }) } @@ -36,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_button.go b/examples/raspi_button.go index b1e620df4..f491b401b 100644 --- a/examples/raspi_button.go +++ b/examples/raspi_button.go @@ -20,14 +20,18 @@ func main() { led := gpio.NewLedDriver(r, "7") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { + _ = button.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("button pressed") - led.On() + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { + _ = button.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("button released") - led.Off() + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -37,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_ccs811.go b/examples/raspi_ccs811.go index 275fe915b..312223519 100644 --- a/examples/raspi_ccs811.go +++ b/examples/raspi_ccs811.go @@ -18,21 +18,21 @@ import ( func CCS811BootData(a *i2c.CCS811Driver) { v, err := a.GetHardwareVersion() if err != nil { - fmt.Printf(err.Error()) + fmt.Println(err.Error()) } fmt.Printf("Hardare Version %#x\n", v) d, err := a.GetFirmwareBootVersion() if err != nil { - fmt.Printf(err.Error()) + fmt.Println(err.Error()) } fmt.Printf("Boot Version %#x\n", d) d, err = a.GetFirmwareAppVersion() if err != nil { - fmt.Printf(err.Error()) + fmt.Println(err.Error()) } fmt.Printf("App Version %#x\n\n", d) @@ -74,5 +74,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_direct_pin.go b/examples/raspi_direct_pin.go index 24f31e47d..e41b826c3 100644 --- a/examples/raspi_direct_pin.go +++ b/examples/raspi_direct_pin.go @@ -20,8 +20,10 @@ import ( // PWR Raspi: 1 (+3.3V, VCC), 2(+5V), 6, 9, 14, 20 (GND) // GPIO Raspi: header pin 21 (GPIO9) is input, pin 24 (GPIO8) is normal output, pin 26 (GPIO7) is inverted output // Button: the input pin is wired with a button to GND, the internal pull up resistor is used -// LED's: the output pins are wired to the cathode of a LED, the anode is wired with a resistor (70-130Ohm for 20mA) to VCC -// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state changes +// LED's: the output pins are wired to the cathode of a LED, the anode is wired with a resistor (70-130Ohm for 20mA) +// to VCC +// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state +// changes func main() { const ( inPinNum = "21" @@ -76,5 +78,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_direct_pin_event.go b/examples/raspi_direct_pin_event.go index 0f50f3122..87f022c45 100644 --- a/examples/raspi_direct_pin_event.go +++ b/examples/raspi_direct_pin_event.go @@ -31,8 +31,10 @@ var ( // PWR Raspi: 1 (+3.3V, VCC), 2(+5V), 6, 9, 14, 20 (GND) // GPIO Raspi: header pin 21 (GPIO9) is input, pin 24 (GPIO8) is normal output, pin 26 (GPIO7) is inverted output // Button: the input pin is wired with a button to GND, the internal pull up resistor is used -// LED's: the output pins are wired to the cathode of a LED, the anode is wired with a resistor (70-130Ohm for 20mA) to VCC -// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state changes +// LED's: the output pins are wired to the cathode of a LED, the anode is wired with a resistor (70-130Ohm for 20mA) +// to VCC +// Expected behavior: always one LED is on, the other in opposite state, if button is pressed for >2 seconds the state +// changes func main() { board := raspi.NewAdaptor() @@ -73,7 +75,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func buttonEventHandler(offset int, t time.Duration, et string, sn uint32, lsn uint32) { diff --git a/examples/raspi_generic.go b/examples/raspi_generic.go index 319986cdc..da2b90ab1 100644 --- a/examples/raspi_generic.go +++ b/examples/raspi_generic.go @@ -87,8 +87,7 @@ func main() { work, ) - err = robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/raspi_grove_pi_blink.go b/examples/raspi_grove_pi_blink.go index 96d0678cf..384bed35f 100644 --- a/examples/raspi_grove_pi_blink.go +++ b/examples/raspi_grove_pi_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -22,7 +23,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -32,5 +35,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_grove_pi_button.go b/examples/raspi_grove_pi_button.go index 88cfd6059..07519da52 100644 --- a/examples/raspi_grove_pi_button.go +++ b/examples/raspi_grove_pi_button.go @@ -23,14 +23,18 @@ func main() { led := gpio.NewLedDriver(gp, "D2") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { + _ = button.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("button pressed") - led.On() + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { + _ = button.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("button released") - led.Off() + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -40,5 +44,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_grove_pi_dht.go b/examples/raspi_grove_pi_dht.go index 6aee0f996..015c7d025 100644 --- a/examples/raspi_grove_pi_dht.go +++ b/examples/raspi_grove_pi_dht.go @@ -42,5 +42,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_grove_pi_rotary.go b/examples/raspi_grove_pi_rotary.go index afecd5eff..9f97f1822 100644 --- a/examples/raspi_grove_pi_rotary.go +++ b/examples/raspi_grove_pi_rotary.go @@ -22,7 +22,7 @@ func main() { sensor := aio.NewGroveRotaryDriver(gp, "A1", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { fmt.Println("sensor", data) }) } @@ -33,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_grove_pi_ultrasonic.go b/examples/raspi_grove_pi_ultrasonic.go index 4d213b901..2391cd0f4 100644 --- a/examples/raspi_grove_pi_ultrasonic.go +++ b/examples/raspi_grove_pi_ultrasonic.go @@ -40,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_grove_rotary_sensor.go b/examples/raspi_grove_rotary_sensor.go index f9960ce7f..b6c5ee3d7 100644 --- a/examples/raspi_grove_rotary_sensor.go +++ b/examples/raspi_grove_rotary_sensor.go @@ -22,7 +22,7 @@ func main() { sensor := aio.NewGroveRotaryDriver(ads1015, "0", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { fmt.Println("sensor", data) }) } @@ -33,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_hcsr04.go b/examples/raspi_hcsr04.go index a16bf01b0..7ff54ea3f 100644 --- a/examples/raspi_hcsr04.go +++ b/examples/raspi_hcsr04.go @@ -88,6 +88,6 @@ func main() { ) if err := robot.Start(); err != nil { - log.Fatal(err) + panic(err) } } diff --git a/examples/raspi_hmc5883l.go b/examples/raspi_hmc5883l.go index 1a6e46dc1..a02cb004e 100644 --- a/examples/raspi_hmc5883l.go +++ b/examples/raspi_hmc5883l.go @@ -43,5 +43,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_ina3221.go b/examples/raspi_ina3221.go index 13f4786bd..c4cca7f43 100644 --- a/examples/raspi_ina3221.go +++ b/examples/raspi_ina3221.go @@ -55,5 +55,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_led_brightness.go b/examples/raspi_led_brightness.go index 1ae9a6dc9..2348cd593 100644 --- a/examples/raspi_led_brightness.go +++ b/examples/raspi_led_brightness.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -23,7 +24,9 @@ func main() { fadeAmount := uint8(15) gobot.Every(100*time.Millisecond, func() { - led.Brightness(brightness) + if err := led.Brightness(brightness); err != nil { + fmt.Println(err) + } brightness = brightness + fadeAmount if brightness == 0 || brightness == 255 { fadeAmount = -fadeAmount @@ -37,5 +40,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_mcp3008.go b/examples/raspi_mcp3008.go index 1ecebd751..df393f928 100644 --- a/examples/raspi_mcp3008.go +++ b/examples/raspi_mcp3008.go @@ -32,5 +32,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_pca9533.go b/examples/raspi_pca9533.go index f71959f2f..da9454e6c 100644 --- a/examples/raspi_pca9533.go +++ b/examples/raspi_pca9533.go @@ -69,9 +69,8 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/raspi_sht2x.go b/examples/raspi_sht2x.go index 92cca3234..b37144372 100644 --- a/examples/raspi_sht2x.go +++ b/examples/raspi_sht2x.go @@ -35,5 +35,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_sht3x.go b/examples/raspi_sht3x.go index 2f3411ba0..8efd07801 100644 --- a/examples/raspi_sht3x.go +++ b/examples/raspi_sht3x.go @@ -21,7 +21,9 @@ func main() { work := func() { sht3x.Units = "F" - sht3x.Start() + if err := sht3x.Start(); err != nil { + fmt.Println(err) + } sn, err := sht3x.SerialNumber() fmt.Printf("Serial Number: 0x%08x, err: %v\n", sn, err) @@ -37,5 +39,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_ssd1306.go b/examples/raspi_ssd1306.go index c43f58175..276a74971 100644 --- a/examples/raspi_ssd1306.go +++ b/examples/raspi_ssd1306.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -33,7 +34,9 @@ func main() { } } stage = !stage - oled.Display() + if err := oled.Display(); err != nil { + fmt.Println(err) + } }) } @@ -43,5 +46,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_ssd1306spi.go b/examples/raspi_ssd1306spi.go index 4df424e77..2bf5bc5a6 100644 --- a/examples/raspi_ssd1306spi.go +++ b/examples/raspi_ssd1306spi.go @@ -7,25 +7,33 @@ package main import ( + "fmt" + "gobot.io/x/gobot/v2" "gobot.io/x/gobot/v2/drivers/spi" "gobot.io/x/gobot/v2/platforms/raspi" ) // this example only works for a 128x64 display +// +//nolint:lll // ok for example var gobotLogo = []byte{0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xe0, 0xb0, 0x90, 0xc8, 0x6e, 0x9a, 0xb6, 0xd, 0x3a, 0x15, 0xf7, 0xd, 0x59, 0x98, 0x94, 0xf4, 0xf4, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xdf, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x8f, 0x8f, 0xff, 0x97, 0xcf, 0x4f, 0xc3, 0x51, 0xc0, 0x41, 0xd1, 0x40, 0xa4, 0xc4, 0x50, 0xc0, 0x40, 0xd1, 0x87, 0xdf, 0x97, 0x77, 0x3f, 0x8f, 0x4f, 0xff, 0x9f, 0xbf, 0x9f, 0x9f, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x3f, 0x37, 0x37, 0xef, 0xda, 0xbf, 0xef, 0x8e, 0x8d, 0xe7, 0xad, 0xfb, 0xaf, 0x1b, 0xdb, 0x29, 0x1f, 0x56, 0xcf, 0x1b, 0xcf, 0x9b, 0x55, 0x8f, 0xdd, 0x1a, 0xd7, 0x1e, 0xb5, 0x9b, 0xad, 0x17, 0xbd, 0xab, 0x15, 0xbf, 0x2d, 0x9a, 0xb7, 0x1d, 0xb7, 0x2d, 0x9a, 0xb7, 0x9e, 0x95, 0x9f, 0x55, 0x9b, 0x5d, 0x97, 0x5a, 0x8f, 0xda, 0xf, 0xda, 0x4f, 0x9a, 0x2e, 0x5a, 0xae, 0x14, 0xff, 0x67, 0xcf, 0x8b, 0x56, 0xdd, 0x74, 0xdd, 0x77, 0x57, 0x5f, 0x5f, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xfc, 0xfe, 0xff, 0xf2, 0xff, 0xfc, 0xef, 0xba, 0xef, 0xba, 0xed, 0xbf, 0xea, 0x5f, 0xfa, 0x56, 0xfe, 0xb4, 0xde, 0x74, 0xbe, 0xec, 0x5a, 0xfc, 0x55, 0xfc, 0xd5, 0xbc, 0x74, 0xad, 0x7c, 0xa9, 0xfc, 0xa5, 0xec, 0x9d, 0xc8, 0xcd, 0xac, 0x79, 0xd5, 0x7c, 0xb4, 0xdc, 0xb4, 0xdd, 0x74, 0xdd, 0xf4, 0xac, 0xfd, 0xaa, 0xfc, 0x56, 0xfc, 0xae, 0xfa, 0xad, 0xfe, 0xaa, 0x7f, 0xed, 0x5b, 0xfe, 0x55, 0xff, 0xff, 0xab, 0xaf, 0xf9, 0xf8, 0xfc, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x1f, 0x1f, 0x6e, 0xfb, 0x6e, 0xdb, 0x7e, 0xd5, 0x7f, 0xd5, 0x7f, 0xd5, 0xff, 0xaa, 0xff, 0x55, 0xff, 0x55, 0xff, 0x55, 0xff, 0xd6, 0xfd, 0xd7, 0x7d, 0xeb, 0xff, 0xaa, 0xff, 0xdb, 0x7f, 0xf5, 0xdf, 0x7b, 0xef, 0xfb, 0xed, 0xbf, 0xea, 0x7f, 0xea, 0xbf, 0xeb, 0xbe, 0xeb, 0x5e, 0xfb, 0x56, 0xff, 0x55, 0xff, 0xaa, 0xff, 0x56, 0xfd, 0x57, 0xfd, 0x57, 0xfd, 0x57, 0xfd, 0xb7, 0xb7, 0xda, 0x1a, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0xff, 0xff, 0xf, 0xf, 0xf, 0x1, 0x20, 0x8, 0x40, 0x10, 0x84, 0x0, 0xa8, 0x0, 0x2, 0xa8, 0x0, 0x2, 0xa8, 0x0, 0x42, 0xfd, 0x9f, 0x75, 0xdf, 0xb5, 0xdf, 0xb5, 0xff, 0xaa, 0x7f, 0x2a, 0x5f, 0x75, 0x3f, 0x6d, 0x7f, 0x5b, 0x7f, 0xf6, 0x3f, 0xed, 0x7f, 0xfb, 0xaf, 0x7e, 0xfb, 0x6f, 0xbd, 0xf7, 0x5f, 0xfd, 0x77, 0xde, 0x7f, 0xf5, 0x5f, 0x7f, 0xf5, 0x5f, 0xff, 0x35, 0xff, 0x57, 0x7d, 0x6f, 0x3d, 0x6b, 0x3f, 0x2a, 0xff, 0x55, 0xff, 0x95, 0x7f, 0x55, 0xff, 0x95, 0x6f, 0xa8, 0x40, 0x0, 0x2a, 0x0, 0x44, 0x10, 0x4, 0x40, 0x10, 0x84, 0x0, 0x28, 0x0, 0x20, 0x1, 0xf, 0x2f, 0x2f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0xff, 0x7, 0x7, 0x7, 0xa1, 0x0, 0x48, 0xa0, 0xd4, 0x30, 0xe8, 0x1a, 0x4, 0x18, 0x44, 0xc, 0x80, 0xe, 0x20, 0x84, 0x8c, 0x0, 0xcd, 0x8, 0x88, 0x92, 0x8, 0xa0, 0x2, 0x8, 0x42, 0xb0, 0x60, 0x9a, 0xf0, 0xc, 0x10, 0x4d, 0x8, 0x85, 0x24, 0x5, 0x48, 0x4, 0x84, 0x2c, 0x0, 0x8c, 0x19, 0x68, 0xb2, 0x48, 0xf1, 0x0, 0x44, 0x10, 0x0, 0x6c, 0xd8, 0x24, 0xfc, 0x80, 0x4c, 0x84, 0x48, 0x84, 0x4c, 0x80, 0x4c, 0x84, 0x48, 0xd4, 0x38, 0xe4, 0x18, 0x60, 0x4, 0x90, 0x2, 0x20, 0xc4, 0x31, 0xe8, 0x92, 0x78, 0x4, 0x19, 0x44, 0x9, 0x85, 0x25, 0x8, 0x85, 0x24, 0x4, 0x48, 0x5, 0x18, 0xb4, 0x49, 0xb0, 0xd4, 0x21, 0xcc, 0x0, 0x4c, 0x1, 0x8c, 0x24, 0x4, 0x88, 0x76, 0xa8, 0xdc, 0x30, 0x4e, 0x0, 0xc, 0x44, 0xc, 0x0, 0xc, 0x8, 0x62, 0x0, 0xa, 0x0, 0x10, 0x10, 0x80, 0xc0, 0xe0, 0xe2, 0x8, 0x0, 0x13, 0x6, 0x9, 0x27, 0xc, 0xc9, 0x18, 0x2, 0x58, 0x0, 0x9a, 0x10, 0x44, 0x18, 0x81, 0x18, 0x47, 0x18, 0x7, 0x4d, 0x2, 0x10, 0x4, 0x1, 0x13, 0x4, 0xb, 0x26, 0xd, 0xc8, 0x18, 0x82, 0x18, 0x10, 0x54, 0x1, 0x18, 0x40, 0x1a, 0x88, 0x98, 0xc6, 0x9, 0x27, 0xa, 0x85, 0x11, 0x40, 0xa, 0x20, 0x8b, 0x16, 0x49, 0x8e, 0x19, 0x80, 0x58, 0x82, 0x18, 0x81, 0x58, 0x8, 0x90, 0x89, 0xd8, 0x5, 0xe, 0x29, 0x7, 0x12, 0x4, 0x0, 0x68, 0x1, 0x87, 0xa0, 0xf, 0xa, 0xd4, 0x9, 0x18, 0x40, 0x1a, 0x0, 0x58, 0x2, 0x18, 0x40, 0x99, 0x4, 0x58, 0x6, 0x2b, 0x4, 0x13, 0x5, 0x80, 0x8, 0x2, 0x0, 0x28, 0x2, 0x40, 0x8, 0x97, 0xa, 0x9d, 0x53, 0x4, 0x0, 0x51, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80} func main() { raspiAdaptor := raspi.NewAdaptor() oled := spi.NewSSD1306Driver(raspiAdaptor) work := func() { - oled.Clear() - oled.SetBufferAndDisplay(gobotLogo) + _ = oled.Clear() + if err := oled.SetBufferAndDisplay(gobotLogo); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("ssd1360", []gobot.Connection{raspiAdaptor}, []gobot.Device{oled}, work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/raspi_stepper_move.go b/examples/raspi_stepper_move.go index 2dd62cd60..d214d5438 100644 --- a/examples/raspi_stepper_move.go +++ b/examples/raspi_stepper_move.go @@ -69,7 +69,6 @@ func main() { if err := stepper.MoveDeg(-360 * countRot); err != nil { log.Println("move backward", err) } - return } robot := gobot.NewRobot("stepperBot", @@ -78,5 +77,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/serial_sphero.go b/examples/serial_sphero.go index a6d942811..d44143497 100644 --- a/examples/serial_sphero.go +++ b/examples/serial_sphero.go @@ -23,11 +23,11 @@ func main() { work := func() { spheroDriver.SetDataStreaming(sphero.DefaultDataStreamingConfig()) - spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { + _ = spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { fmt.Printf("Collision! %+v\n", data) }) - spheroDriver.On(sphero.SensorDataEvent, func(data interface{}) { + _ = spheroDriver.On(sphero.SensorDataEvent, func(data interface{}) { fmt.Printf("Streaming Data! %+v\n", data) }) @@ -49,5 +49,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/serial_sphero_api.go b/examples/serial_sphero_api.go index 33607ae13..558ae86d3 100644 --- a/examples/serial_sphero_api.go +++ b/examples/serial_sphero_api.go @@ -42,5 +42,7 @@ func main() { master.AddRobot(robot) } - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/serial_sphero_calibration.go b/examples/serial_sphero_calibration.go index b0f2ae353..d81830b27 100644 --- a/examples/serial_sphero_calibration.go +++ b/examples/serial_sphero_calibration.go @@ -27,7 +27,7 @@ func main() { calibrating := false work := func() { - keys.On(keyboard.Key, func(data interface{}) { + _ = keys.On(keyboard.Key, func(data interface{}) { key := data.(keyboard.KeyEvent) switch key.Key { @@ -64,5 +64,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/serial_sphero_conways.go b/examples/serial_sphero_conways.go index c03a0b2df..d7acbf908 100644 --- a/examples/serial_sphero_conways.go +++ b/examples/serial_sphero_conways.go @@ -43,7 +43,7 @@ func main() { conway.birth() - cell.On(sphero.CollisionEvent, func(data interface{}) { + _ = cell.On(sphero.CollisionEvent, func(data interface{}) { conway.contact() }) @@ -69,7 +69,9 @@ func main() { master.AddRobot(robot) } - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } func (c *conway) resetContacts() { diff --git a/examples/serial_sphero_dpad.go b/examples/serial_sphero_dpad.go index 45d34293c..d24673d81 100644 --- a/examples/serial_sphero_dpad.go +++ b/examples/serial_sphero_dpad.go @@ -49,5 +49,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/serial_sphero_master.go b/examples/serial_sphero_master.go index 0c7e16f0c..d57be5d82 100644 --- a/examples/serial_sphero_master.go +++ b/examples/serial_sphero_master.go @@ -52,5 +52,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/serial_sphero_multiple.go b/examples/serial_sphero_multiple.go index a5ab95b02..04cd68339 100644 --- a/examples/serial_sphero_multiple.go +++ b/examples/serial_sphero_multiple.go @@ -24,7 +24,7 @@ func NewSwarmBot(port string) *gobot.Robot { work := func() { spheroDriver.Stop() - spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { + _ = spheroDriver.On(sphero.CollisionEvent, func(data interface{}) { fmt.Println("Collision Detected!") }) @@ -63,5 +63,7 @@ func main() { master.AddRobot(NewSwarmBot(port)) } - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/square.go b/examples/square.go index bd0921b89..7a6c3fc30 100644 --- a/examples/square.go +++ b/examples/square.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -29,9 +30,15 @@ func main() { enabled := true work := func() { - red.Brightness(0xff) - green.Brightness(0x00) - blue.Brightness(0x00) + if err := red.Brightness(0xff); err != nil { + fmt.Println(err) + } + if err := green.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := blue.Brightness(0x00); err != nil { + fmt.Println(err) + } flash := false on := true @@ -40,29 +47,47 @@ func main() { if enabled { if flash { if on { - red.Brightness(0x00) - green.Brightness(0xff) - blue.Brightness(0x00) + if err := red.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := green.Brightness(0xff); err != nil { + fmt.Println(err) + } + if err := blue.Brightness(0x00); err != nil { + fmt.Println(err) + } on = false } else { - red.Brightness(0xff) - green.Brightness(0x00) - blue.Brightness(0x00) + if err := red.Brightness(0xff); err != nil { + fmt.Println(err) + } + if err := green.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := blue.Brightness(0x00); err != nil { + fmt.Println(err) + } on = true } } } }) - button.On(gpio.ButtonPush, func(data interface{}) { + _ = button.On(gpio.ButtonPush, func(data interface{}) { flash = true }) - button.On(gpio.ButtonRelease, func(data interface{}) { + _ = button.On(gpio.ButtonRelease, func(data interface{}) { flash = false - red.Brightness(0x00) - green.Brightness(0x00) - blue.Brightness(0xff) + if err := red.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := green.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := blue.Brightness(0xff); err != nil { + fmt.Println(err) + } }) } @@ -80,5 +105,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/square_fire.go b/examples/square_fire.go index 69c9c0121..76980069d 100644 --- a/examples/square_fire.go +++ b/examples/square_fire.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -29,9 +30,15 @@ func main() { enabled := true work := func() { - red.Brightness(0xff) - green.Brightness(0x00) - blue.Brightness(0x00) + if err := red.Brightness(0xff); err != nil { + fmt.Println(err) + } + if err := green.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := blue.Brightness(0x00); err != nil { + fmt.Println(err) + } flash := false on := true @@ -40,29 +47,47 @@ func main() { if enabled { if flash { if on { - red.Brightness(0x00) - green.Brightness(0xff) - blue.Brightness(0x00) + if err := red.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := green.Brightness(0xff); err != nil { + fmt.Println(err) + } + if err := blue.Brightness(0x00); err != nil { + fmt.Println(err) + } on = false } else { - red.Brightness(0x00) - green.Brightness(0x00) - blue.Brightness(0xff) + if err := red.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := green.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := blue.Brightness(0xff); err != nil { + fmt.Println(err) + } on = true } } } }) - button.On(gpio.ButtonPush, func(data interface{}) { + _ = button.On(gpio.ButtonPush, func(data interface{}) { flash = true }) - button.On(gpio.ButtonRelease, func(data interface{}) { + _ = button.On(gpio.ButtonRelease, func(data interface{}) { flash = false - red.Brightness(0x00) - green.Brightness(0x00) - blue.Brightness(0xff) + if err := red.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := green.Brightness(0x00); err != nil { + fmt.Println(err) + } + if err := blue.Brightness(0xff); err != nil { + fmt.Println(err) + } }) } @@ -80,5 +105,7 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } diff --git a/examples/tello.go b/examples/tello.go index 2d7b442f6..cba99b307 100644 --- a/examples/tello.go +++ b/examples/tello.go @@ -16,6 +16,7 @@ Once you are connected you can run the Gobot code on your computer to control th package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -26,10 +27,14 @@ func main() { drone := tello.NewDriver("8888") work := func() { - drone.TakeOff() + if err := drone.TakeOff(); err != nil { + fmt.Println(err) + } gobot.After(5*time.Second, func() { - drone.Land() + if err := drone.Land(); err != nil { + fmt.Println(err) + } }) } @@ -39,5 +44,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tello_facetracker.go b/examples/tello_facetracker.go index 38cc2bcc6..e576f7413 100644 --- a/examples/tello_facetracker.go +++ b/examples/tello_facetracker.go @@ -94,22 +94,30 @@ func init() { return } - drone.On(tello.FlightDataEvent, func(data interface{}) { + _ = drone.On(tello.FlightDataEvent, func(data interface{}) { // TODO: protect flight data from race condition flightData = data.(*tello.FlightData) }) - drone.On(tello.ConnectedEvent, func(data interface{}) { + _ = drone.On(tello.ConnectedEvent, func(data interface{}) { fmt.Println("Connected") - drone.StartVideo() - drone.SetVideoEncoderRate(tello.VideoBitRateAuto) - drone.SetExposure(0) + if err := drone.StartVideo(); err != nil { + fmt.Println(err) + } + if err := drone.SetVideoEncoderRate(tello.VideoBitRateAuto); err != nil { + fmt.Println(err) + } + if err := drone.SetExposure(0); err != nil { + fmt.Println(err) + } gobot.Every(100*time.Millisecond, func() { - drone.StartVideo() + if err := drone.StartVideo(); err != nil { + fmt.Println(err) + } }) }) - drone.On(tello.VideoFrameEvent, func(data interface{}) { + _ = drone.On(tello.VideoFrameEvent, func(data interface{}) { pkt := data.([]byte) if _, err := ffmpegIn.Write(pkt); err != nil { fmt.Println(err) @@ -121,7 +129,10 @@ func init() { []gobot.Device{drone, stick}, ) - robot.Start() + err := robot.Start() + if err != nil { + fmt.Println(err) + } }() } @@ -257,7 +268,7 @@ func dist(x1, y1, x2, y2 float64) float64 { } func handleJoystick() { - stick.On(joystick.CirclePress, func(data interface{}) { + _ = stick.On(joystick.CirclePress, func(data interface{}) { drone.Forward(0) drone.Up(0) drone.Clockwise(0) @@ -270,33 +281,33 @@ func handleJoystick() { println("not tracking") } }) - stick.On(joystick.SquarePress, func(data interface{}) { + _ = stick.On(joystick.SquarePress, func(data interface{}) { fmt.Println("battery:", flightData.BatteryPercentage) }) - stick.On(joystick.TrianglePress, func(data interface{}) { + _ = stick.On(joystick.TrianglePress, func(data interface{}) { drone.TakeOff() println("Takeoff") }) - stick.On(joystick.XPress, func(data interface{}) { + _ = stick.On(joystick.XPress, func(data interface{}) { drone.Land() println("Land") }) - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { val := float64(data.(int16)) leftX.Store(val) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { val := float64(data.(int16)) leftY.Store(val) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { val := float64(data.(int16)) rightX.Store(val) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { val := float64(data.(int16)) rightY.Store(val) }) @@ -305,20 +316,32 @@ func handleJoystick() { switch { case rightStick.y < -10: - drone.Forward(tello.ValidatePitch(rightStick.y, offset)) + if err := drone.Forward(tello.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } case rightStick.y > 10: - drone.Backward(tello.ValidatePitch(rightStick.y, offset)) + if err := drone.Backward(tello.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Forward(0) + if err := drone.Forward(0); err != nil { + fmt.Println(err) + } } switch { case rightStick.x > 10: - drone.Right(tello.ValidatePitch(rightStick.x, offset)) + if err := drone.Right(tello.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } case rightStick.x < -10: - drone.Left(tello.ValidatePitch(rightStick.x, offset)) + if err := drone.Left(tello.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Right(0) + if err := drone.Right(0); err != nil { + fmt.Println(err) + } } }) @@ -326,20 +349,32 @@ func handleJoystick() { leftStick := getLeftStick() switch { case leftStick.y < -10: - drone.Up(tello.ValidatePitch(leftStick.y, offset)) + if err := drone.Up(tello.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } case leftStick.y > 10: - drone.Down(tello.ValidatePitch(leftStick.y, offset)) + if err := drone.Down(tello.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Up(0) + if err := drone.Up(0); err != nil { + fmt.Println(err) + } } switch { case leftStick.x > 20: - drone.Clockwise(tello.ValidatePitch(leftStick.x, offset)) + if err := drone.Clockwise(tello.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } case leftStick.x < -20: - drone.CounterClockwise(tello.ValidatePitch(leftStick.x, offset)) + if err := drone.CounterClockwise(tello.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Clockwise(0) + if err := drone.Clockwise(0); err != nil { + fmt.Println(err) + } } }) } diff --git a/examples/tello_keyboard.go b/examples/tello_keyboard.go index 82ee7c9bf..7d143e9b9 100644 --- a/examples/tello_keyboard.go +++ b/examples/tello_keyboard.go @@ -24,58 +24,96 @@ import ( ) func resetDronePostion(drone *tello.Driver) { - drone.Forward(0) - drone.Backward(0) - drone.Up(0) - drone.Down(0) - drone.Left(0) - drone.Right(0) - drone.Clockwise(0) + if err := drone.Forward(0); err != nil { + fmt.Println(err) + } + if err := drone.Backward(0); err != nil { + fmt.Println(err) + } + if err := drone.Up(0); err != nil { + fmt.Println(err) + } + if err := drone.Down(0); err != nil { + fmt.Println(err) + } + if err := drone.Left(0); err != nil { + fmt.Println(err) + } + if err := drone.Right(0); err != nil { + fmt.Println(err) + } + if err := drone.Clockwise(0); err != nil { + fmt.Println(err) + } } func main() { drone := tello.NewDriver("8888") keys := keyboard.NewDriver() - keys.On(keyboard.Key, func(data interface{}) { + _ = keys.On(keyboard.Key, func(data interface{}) { key := data.(keyboard.KeyEvent) switch key.Key { case keyboard.A: fmt.Println(key.Char) - drone.Clockwise(-25) + if err := drone.Clockwise(-25); err != nil { + fmt.Println(err) + } case keyboard.D: fmt.Println(key.Char) - drone.Clockwise(25) + if err := drone.Clockwise(25); err != nil { + fmt.Println(err) + } case keyboard.W: fmt.Println(key.Char) - drone.Forward(20) + if err := drone.Forward(20); err != nil { + fmt.Println(err) + } case keyboard.S: fmt.Println(key.Char) - drone.Backward(20) + if err := drone.Backward(20); err != nil { + fmt.Println(err) + } case keyboard.K: fmt.Println(key.Char) - drone.Down(20) + if err := drone.Down(20); err != nil { + fmt.Println(err) + } case keyboard.J: fmt.Println(key.Char) - drone.Up(20) + if err := drone.Up(20); err != nil { + fmt.Println(err) + } case keyboard.Q: fmt.Println(key.Char) - drone.Land() + if err := drone.Land(); err != nil { + fmt.Println(err) + } case keyboard.P: fmt.Println(key.Char) - drone.TakeOff() + if err := drone.TakeOff(); err != nil { + fmt.Println(err) + } case keyboard.ArrowUp: fmt.Println(key.Char) - drone.FrontFlip() + if err := drone.FrontFlip(); err != nil { + fmt.Println(err) + } case keyboard.ArrowDown: fmt.Println(key.Char) - drone.BackFlip() + if err := drone.BackFlip(); err != nil { + fmt.Println(err) + } case keyboard.ArrowLeft: fmt.Println(key.Char) - drone.LeftFlip() + if err := drone.LeftFlip(); err != nil { + fmt.Println(err) + } case keyboard.ArrowRight: fmt.Println(key.Char) - drone.RightFlip() + if err := drone.RightFlip(); err != nil { + fmt.Println(err) + } case keyboard.Escape: resetDronePostion(drone) } @@ -83,7 +121,7 @@ func main() { var flightData *tello.FlightData work := func() { - drone.On(tello.FlightDataEvent, func(data interface{}) { + _ = drone.On(tello.FlightDataEvent, func(data interface{}) { flightData = data.(*tello.FlightData) fmt.Println("Height:", flightData.Height) }) @@ -95,5 +133,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tello_opencv.go b/examples/tello_opencv.go index 165c5d85f..9b135c188 100644 --- a/examples/tello_opencv.go +++ b/examples/tello_opencv.go @@ -48,18 +48,26 @@ func main() { return } - drone.On(tello.ConnectedEvent, func(data interface{}) { + _ = drone.On(tello.ConnectedEvent, func(data interface{}) { fmt.Println("Connected") - drone.StartVideo() - drone.SetVideoEncoderRate(tello.VideoBitRateAuto) - drone.SetExposure(0) + if err := drone.StartVideo(); err != nil { + fmt.Println(err) + } + if err := drone.SetVideoEncoderRate(tello.VideoBitRateAuto); err != nil { + fmt.Println(err) + } + if err := drone.SetExposure(0); err != nil { + fmt.Println(err) + } gobot.Every(100*time.Millisecond, func() { - drone.StartVideo() + if err := drone.StartVideo(); err != nil { + fmt.Println(err) + } }) }) - drone.On(tello.VideoFrameEvent, func(data interface{}) { + _ = drone.On(tello.VideoFrameEvent, func(data interface{}) { pkt := data.([]byte) if _, err := ffmpegIn.Write(pkt); err != nil { fmt.Println(err) diff --git a/examples/tello_ps3.go b/examples/tello_ps3.go index fb0e2a7f1..267d5be91 100644 --- a/examples/tello_ps3.go +++ b/examples/tello_ps3.go @@ -48,50 +48,62 @@ func main() { rightX.Store(float64(0.0)) rightY.Store(float64(0.0)) - stick.On(joystick.TrianglePress, func(data interface{}) { - drone.TakeOff() + _ = stick.On(joystick.TrianglePress, func(data interface{}) { + if err := drone.TakeOff(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.XPress, func(data interface{}) { - drone.Land() + _ = stick.On(joystick.XPress, func(data interface{}) { + if err := drone.Land(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.UpPress, func(data interface{}) { + _ = stick.On(joystick.UpPress, func(data interface{}) { fmt.Println("FrontFlip") - drone.FrontFlip() + if err := drone.FrontFlip(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.DownPress, func(data interface{}) { + _ = stick.On(joystick.DownPress, func(data interface{}) { fmt.Println("BackFlip") - drone.BackFlip() + if err := drone.BackFlip(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.RightPress, func(data interface{}) { + _ = stick.On(joystick.RightPress, func(data interface{}) { fmt.Println("RightFlip") - drone.RightFlip() + if err := drone.RightFlip(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.LeftPress, func(data interface{}) { + _ = stick.On(joystick.LeftPress, func(data interface{}) { fmt.Println("LeftFlip") - drone.LeftFlip() + if err := drone.LeftFlip(); err != nil { + fmt.Println(err) + } }) - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { val := float64(data.(int16)) leftX.Store(val) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { val := float64(data.(int16)) leftY.Store(val) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { val := float64(data.(int16)) rightX.Store(val) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { val := float64(data.(int16)) rightY.Store(val) }) @@ -101,20 +113,32 @@ func main() { switch { case rightStick.y < -10: - drone.Forward(tello.ValidatePitch(rightStick.y, offset)) + if err := drone.Forward(tello.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } case rightStick.y > 10: - drone.Backward(tello.ValidatePitch(rightStick.y, offset)) + if err := drone.Backward(tello.ValidatePitch(rightStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Forward(0) + if err := drone.Forward(0); err != nil { + fmt.Println(err) + } } switch { case rightStick.x > 10: - drone.Right(tello.ValidatePitch(rightStick.x, offset)) + if err := drone.Right(tello.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } case rightStick.x < -10: - drone.Left(tello.ValidatePitch(rightStick.x, offset)) + if err := drone.Left(tello.ValidatePitch(rightStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Right(0) + if err := drone.Right(0); err != nil { + fmt.Println(err) + } } }) @@ -122,20 +146,32 @@ func main() { leftStick := getLeftStick() switch { case leftStick.y < -10: - drone.Up(tello.ValidatePitch(leftStick.y, offset)) + if err := drone.Up(tello.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } case leftStick.y > 10: - drone.Down(tello.ValidatePitch(leftStick.y, offset)) + if err := drone.Down(tello.ValidatePitch(leftStick.y, offset)); err != nil { + fmt.Println(err) + } default: - drone.Up(0) + if err := drone.Up(0); err != nil { + fmt.Println(err) + } } switch { case leftStick.x > 20: - drone.Clockwise(tello.ValidatePitch(leftStick.x, offset)) + if err := drone.Clockwise(tello.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } case leftStick.x < -20: - drone.CounterClockwise(tello.ValidatePitch(leftStick.x, offset)) + if err := drone.CounterClockwise(tello.ValidatePitch(leftStick.x, offset)); err != nil { + fmt.Println(err) + } default: - drone.Clockwise(0) + if err := drone.Clockwise(0); err != nil { + fmt.Println(err) + } } }) } @@ -146,7 +182,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } func getLeftStick() pair { diff --git a/examples/tello_video.go b/examples/tello_video.go index 55b649b4e..63728c5e1 100644 --- a/examples/tello_video.go +++ b/examples/tello_video.go @@ -35,16 +35,22 @@ func main() { } work := func() { - drone.On(tello.ConnectedEvent, func(data interface{}) { + _ = drone.On(tello.ConnectedEvent, func(data interface{}) { fmt.Println("Connected") - drone.StartVideo() - drone.SetVideoEncoderRate(tello.VideoBitRateAuto) + if err := drone.StartVideo(); err != nil { + fmt.Println(err) + } + if err := drone.SetVideoEncoderRate(tello.VideoBitRateAuto); err != nil { + fmt.Println(err) + } gobot.Every(100*time.Millisecond, func() { - drone.StartVideo() + if err := drone.StartVideo(); err != nil { + fmt.Println(err) + } }) }) - drone.On(tello.VideoFrameEvent, func(data interface{}) { + _ = drone.On(tello.VideoFrameEvent, func(data interface{}) { pkt := data.([]byte) if _, err := mplayerIn.Write(pkt); err != nil { fmt.Println(err) @@ -58,5 +64,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_adafruit1109_lcd_keys.go b/examples/tinkerboard_adafruit1109_lcd_keys.go index 305c09484..acdef3cdd 100644 --- a/examples/tinkerboard_adafruit1109_lcd_keys.go +++ b/examples/tinkerboard_adafruit1109_lcd_keys.go @@ -26,24 +26,40 @@ func main() { work := func() { // set a custom character smiley := [8]byte{0, 0, 10, 0, 0, 17, 14, 0} - ada.CreateChar(0, smiley) + if err := ada.CreateChar(0, smiley); err != nil { + fmt.Println(err) + } - ada.Clear() - ada.SetRGB(true, false, false) - ada.Write(" Hello from \n Tinker Board ") + if err := ada.Clear(); err != nil { + fmt.Println(err) + } + if err := ada.SetRGB(true, false, false); err != nil { + fmt.Println(err) + } + if err := ada.Write(" Hello from \n Tinker Board "); err != nil { + fmt.Println(err) + } // add the custom character at the end of the string - ada.Write(string(byte(0))) + if err := ada.Write(string(byte(0))); err != nil { + fmt.Println(err) + } // after 1 sec. activate rotation direction := 1 gobot.After(1*time.Second, func() { - ada.SetRGB(false, true, false) + if err := ada.SetRGB(false, true, false); err != nil { + fmt.Println(err) + } gobot.Every(400*time.Millisecond, func() { if direction == 1 { - ada.ScrollLeft() + if err := ada.ScrollLeft(); err != nil { + fmt.Println(err) + } } if direction == 2 { - ada.ScrollRight() + if err := ada.ScrollRight(); err != nil { + fmt.Println(err) + } } }) }) @@ -52,62 +68,92 @@ func main() { gobot.After(7*time.Second, func() { direction = 0 time.Sleep(1 * time.Second) - ada.LeftToRight() - ada.Clear() - ada.SetRGB(false, false, true) - ada.Write("Try the buttons!") + if err := ada.LeftToRight(); err != nil { + fmt.Println(err) + } + if err := ada.Clear(); err != nil { + fmt.Println(err) + } + if err := ada.SetRGB(false, false, true); err != nil { + fmt.Println(err) + } + if err := ada.Write("Try the buttons!"); err != nil { + fmt.Println(err) + } gobot.Every(500*time.Millisecond, func() { if val, err := ada.SelectButton(); err != nil { fmt.Println(err) - } else { - if val != 0 { - ada.Clear() - ada.Write("-Select Button-\nclear the screen") - ada.Blink(false) - direction = 0 + } else if val != 0 { + if err := ada.Clear(); err != nil { + fmt.Println(err) + } + if err := ada.Write("-Select Button-\nclear the screen"); err != nil { + fmt.Println(err) + } + if err := ada.Blink(false); err != nil { + fmt.Println(err) } + direction = 0 } if val, err := ada.UpButton(); err != nil { fmt.Println(err) - } else { - if val != 0 { - ada.Clear() - ada.Write(" -Up Button- \nset RGB to white") - ada.Blink(false) - ada.SetRGB(true, true, true) - direction = 0 + } else if val != 0 { + if err := ada.Clear(); err != nil { + fmt.Println(err) + } + if err := ada.Write(" -Up Button- \nset RGB to white"); err != nil { + fmt.Println(err) + } + if err := ada.Blink(false); err != nil { + fmt.Println(err) + } + if err := ada.SetRGB(true, true, true); err != nil { + fmt.Println(err) } + direction = 0 } if val, err := ada.DownButton(); err != nil { fmt.Println(err) - } else { - if val != 0 { - ada.Clear() - ada.Write(" -Down Button- \nset blink on") - ada.Blink(true) - direction = 0 + } else if val != 0 { + if err := ada.Clear(); err != nil { + fmt.Println(err) } + if err := ada.Write(" -Down Button- \nset blink on"); err != nil { + fmt.Println(err) + } + if err := ada.Blink(true); err != nil { + fmt.Println(err) + } + direction = 0 } if val, err := ada.LeftButton(); err != nil { fmt.Println(err) - } else { - if val != 0 { - ada.Clear() - ada.Write(" -Left Button- \nrotate left") - ada.Blink(false) - direction = 1 + } else if val != 0 { + if err := ada.Clear(); err != nil { + fmt.Println(err) + } + if err := ada.Write(" -Left Button- \nrotate left"); err != nil { + fmt.Println(err) + } + if err := ada.Blink(false); err != nil { + fmt.Println(err) } + direction = 1 } if val, err := ada.RightButton(); err != nil { fmt.Println(err) - } else { - if val != 0 { - ada.Clear() - ada.Write(" -Right Button- \nrotate right") - ada.Blink(false) - direction = 2 + } else if val != 0 { + if err := ada.Clear(); err != nil { + fmt.Println(err) } + if err := ada.Write(" -Right Button- \nrotate right"); err != nil { + fmt.Println(err) + } + if err := ada.Blink(false); err != nil { + fmt.Println(err) + } + direction = 2 } }) }) @@ -119,5 +165,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_ads1115.go b/examples/tinkerboard_ads1115.go index 883048635..625e01fba 100644 --- a/examples/tinkerboard_ads1115.go +++ b/examples/tinkerboard_ads1115.go @@ -84,6 +84,6 @@ func main() { ) if err := robot.Start(); err != nil { - fmt.Println(err) + panic(err) } } diff --git a/examples/tinkerboard_adxl345.go b/examples/tinkerboard_adxl345.go index 4dd6b65c6..1ddb1c4d7 100644 --- a/examples/tinkerboard_adxl345.go +++ b/examples/tinkerboard_adxl345.go @@ -39,5 +39,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_blink.go b/examples/tinkerboard_blink.go index c90faefe0..9a63d61d7 100644 --- a/examples/tinkerboard_blink.go +++ b/examples/tinkerboard_blink.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -20,7 +21,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -30,5 +33,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_bme280.go b/examples/tinkerboard_bme280.go index 4a78ff95e..eca32cc79 100644 --- a/examples/tinkerboard_bme280.go +++ b/examples/tinkerboard_bme280.go @@ -62,8 +62,7 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/tinkerboard_bmp280.go b/examples/tinkerboard_bmp280.go index 8146ca7e0..721d8e499 100644 --- a/examples/tinkerboard_bmp280.go +++ b/examples/tinkerboard_bmp280.go @@ -55,8 +55,7 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/tinkerboard_direct_pin.go b/examples/tinkerboard_direct_pin.go index 222425f60..564a17cd8 100644 --- a/examples/tinkerboard_direct_pin.go +++ b/examples/tinkerboard_direct_pin.go @@ -20,7 +20,8 @@ import ( // PWR Tinkerboard: 1 (+3.3V, VCC), 2(+5V), 6, 9, 14, 20 (GND) // GPIO Tinkerboard: header pin 21 is input, pin 24 used as normal output, pin 26 used as inverted output // Button: the input pin is wired with a button to GND, an external pull up resistor is needed (e.g. 1K) -// LED's: the output pins are wired to the cathode of a LED, the anode is wired with a resistor (70-130Ohm for 20mA) to VCC +// LED's: the output pins are wired to the cathode of a LED, the anode is wired with a resistor (70-130Ohm for 20mA) +// to VCC // Expected behavior: always one LED is on, the other in opposite state, on button press the state changes func main() { const ( @@ -71,5 +72,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_generic.go b/examples/tinkerboard_generic.go index c76e9e16e..9410163b5 100644 --- a/examples/tinkerboard_generic.go +++ b/examples/tinkerboard_generic.go @@ -97,13 +97,13 @@ func main() { work, ) - err = robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } -// workaround for some boards (e.g. tinkerboard), because Read*Data not working together with PCA9501 caused by bad timing +// workaround for some boards (e.g. tinkerboard), because Read*Data not working together with PCA9501, +// caused by bad timing func readBlockDataBadTiming(drv *i2c.GenericDriver, reg uint8, data []byte) error { // set a value to the dummy address if err := drv.WriteByteData(reg-1, 0x00); err != nil { diff --git a/examples/tinkerboard_grove_lcd.go b/examples/tinkerboard_grove_lcd.go index b0ff7ed7f..d7414d136 100644 --- a/examples/tinkerboard_grove_lcd.go +++ b/examples/tinkerboard_grove_lcd.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -19,26 +20,46 @@ func main() { screen := i2c.NewGroveLcdDriver(board) work := func() { - screen.Write("Hello from") + if err := screen.Write("Hello from"); err != nil { + fmt.Println(err) + } - screen.SetRGB(255, 0, 0) + if err := screen.SetRGB(255, 0, 0); err != nil { + fmt.Println(err) + } gobot.After(5*time.Second, func() { - screen.Clear() - screen.Home() - screen.SetRGB(0, 255, 0) + if err := screen.Clear(); err != nil { + fmt.Println(err) + } + if err := screen.Home(); err != nil { + fmt.Println(err) + } + if err := screen.SetRGB(0, 255, 0); err != nil { + fmt.Println(err) + } // set a custom character in the first position - screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]) + if err := screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]); err != nil { + fmt.Println(err) + } // add the custom character at the end of the string - screen.Write("\nTinker Board " + string(byte(0))) + if err := screen.Write("\nTinker Board " + string(byte(0))); err != nil { + fmt.Println(err) + } gobot.Every(500*time.Millisecond, func() { - screen.Scroll(false) + if err := screen.Scroll(false); err != nil { + fmt.Println(err) + } }) }) - screen.Home() + if err := screen.Home(); err != nil { + fmt.Println(err) + } time.Sleep(1 * time.Second) - screen.SetRGB(0, 0, 255) + if err := screen.SetRGB(0, 0, 255); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("screenBot", @@ -47,5 +68,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_hcsr04.go b/examples/tinkerboard_hcsr04.go index f7a89f941..333f54168 100644 --- a/examples/tinkerboard_hcsr04.go +++ b/examples/tinkerboard_hcsr04.go @@ -92,6 +92,6 @@ func main() { ) if err := robot.Start(); err != nil { - log.Fatal(err) + panic(err) } } diff --git a/examples/tinkerboard_hmc5883l.go b/examples/tinkerboard_hmc5883l.go index 32b9c3c37..86467ff8e 100644 --- a/examples/tinkerboard_hmc5883l.go +++ b/examples/tinkerboard_hmc5883l.go @@ -48,5 +48,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_mfcrc522gpio.go b/examples/tinkerboard_mfcrc522gpio.go index fa126e2df..484743bd2 100644 --- a/examples/tinkerboard_mfcrc522gpio.go +++ b/examples/tinkerboard_mfcrc522gpio.go @@ -72,5 +72,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_mfcrc522spi.go b/examples/tinkerboard_mfcrc522spi.go index ccb0c8496..161567e9c 100644 --- a/examples/tinkerboard_mfcrc522spi.go +++ b/examples/tinkerboard_mfcrc522spi.go @@ -64,5 +64,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_mpl115a2.go b/examples/tinkerboard_mpl115a2.go index fbab149e8..b8b967312 100644 --- a/examples/tinkerboard_mpl115a2.go +++ b/examples/tinkerboard_mpl115a2.go @@ -47,8 +47,7 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/tinkerboard_mpu6050.go b/examples/tinkerboard_mpu6050.go index dbac9d20a..d7ecbdca9 100644 --- a/examples/tinkerboard_mpu6050.go +++ b/examples/tinkerboard_mpu6050.go @@ -41,5 +41,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_pca9533.go b/examples/tinkerboard_pca9533.go index cf9b03085..fe084c7b4 100644 --- a/examples/tinkerboard_pca9533.go +++ b/examples/tinkerboard_pca9533.go @@ -69,9 +69,8 @@ func main() { work, ) - err := robot.Start() - if err != nil { - fmt.Println(err) + if err := robot.Start(); err != nil { + panic(err) } } diff --git a/examples/tinkerboard_pcf8583_clock.go b/examples/tinkerboard_pcf8583_clock.go index ddd3209be..6392a088c 100644 --- a/examples/tinkerboard_pcf8583_clock.go +++ b/examples/tinkerboard_pcf8583_clock.go @@ -17,9 +17,9 @@ import ( ) // Wiring -// PWR Tinkerboard: 1 (+3.3V, VCC), 6, 9, 14, 20 (GND) -// I2C1 Tinkerboard: 3 (SDA), 5 (SCL) -// PCF8583 DIP package: 1 (OSCI, 50Hz), 2 (OSCO, nc), 3 (A0 - GND), 4 (VSS, GND), 5 (SDA), 6 (SCL), 7 (/INT, nc), 8 (VDD, +3.3V) +// PWR Tinkerboard: 1(+3.3V, VCC), 6,9,14,20(GND) +// I2C1 Tinkerboard: 3(SDA), 5(SCL) +// PCF8583 DIP package: 1(OSCI,50Hz), 2(OSCO,nc), 3(A0-GND), 4(VSS,GND), 5(SDA), 6(SCL), 7(/INT,nc), 8(VDD,+3.3V) func main() { board := tinkerboard.NewAdaptor() pcf := i2c.NewPCF8583Driver(board, i2c.WithBus(1), i2c.WithPCF8583Mode(i2c.PCF8583CtrlModeClock50)) @@ -58,5 +58,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_pcf8583_counter.go b/examples/tinkerboard_pcf8583_counter.go index 63fda9679..89e292792 100644 --- a/examples/tinkerboard_pcf8583_counter.go +++ b/examples/tinkerboard_pcf8583_counter.go @@ -17,9 +17,9 @@ import ( ) // Wiring -// PWR Tinkerboard: 1 (+3.3V, VCC), 6, 9, 14, 20 (GND) -// I2C1 Tinkerboard: 3 (SDA), 5 (SCL) -// PCF8583 DIP package: 1 (OSCI, event), 2 (OSCO, nc), 3 (A0 - GND), 4 (VSS, GND), 5 (SDA), 6 (SCL), 7 (/INT, nc), 8 (VDD, +3.3V) +// PWR Tinkerboard: 1(+3.3V,VCC), 6,9,14,20(GND) +// I2C1 Tinkerboard: 3(SDA), 5(SCL) +// PCF8583 DIP package: 1(OSCI,event), 2(OSCO,nc), 3(A0-GND), 4(VSS,GND), 5(SDA), 6(SCL), 7(/INT,nc), 8(VDD,+3.3V) // Note: event can be created by e.g. an debounced button func main() { board := tinkerboard.NewAdaptor() @@ -59,5 +59,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_pcf8591.go b/examples/tinkerboard_pcf8591.go index c25cc664a..b422ee87a 100644 --- a/examples/tinkerboard_pcf8591.go +++ b/examples/tinkerboard_pcf8591.go @@ -89,5 +89,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/tinkerboard_yl40.go b/examples/tinkerboard_yl40.go index 222d9562b..7d2201443 100644 --- a/examples/tinkerboard_yl40.go +++ b/examples/tinkerboard_yl40.go @@ -74,5 +74,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/up2_lcd.go b/examples/up2_lcd.go index 94cf3b860..0fd97c0d8 100644 --- a/examples/up2_lcd.go +++ b/examples/up2_lcd.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -19,26 +20,46 @@ func main() { screen := i2c.NewGroveLcdDriver(board) work := func() { - screen.Write("hello") + if err := screen.Write("hello"); err != nil { + fmt.Println(err) + } - screen.SetRGB(255, 0, 0) + if err := screen.SetRGB(255, 0, 0); err != nil { + fmt.Println(err) + } gobot.After(5*time.Second, func() { - screen.Clear() - screen.Home() - screen.SetRGB(0, 255, 0) + if err := screen.Clear(); err != nil { + fmt.Println(err) + } + if err := screen.Home(); err != nil { + fmt.Println(err) + } + if err := screen.SetRGB(0, 255, 0); err != nil { + fmt.Println(err) + } // set a custom character in the first position - screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]) + if err := screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]); err != nil { + fmt.Println(err) + } // add the custom character at the end of the string - screen.Write("goodbye\nhave a nice day " + string(byte(0))) + if err := screen.Write("goodbye\nhave a nice day " + string(byte(0))); err != nil { + fmt.Println(err) + } gobot.Every(500*time.Millisecond, func() { - screen.Scroll(false) + if err := screen.Scroll(false); err != nil { + fmt.Println(err) + } }) }) - screen.Home() + if err := screen.Home(); err != nil { + fmt.Println(err) + } time.Sleep(1 * time.Second) - screen.SetRGB(0, 0, 255) + if err := screen.SetRGB(0, 0, 255); err != nil { + fmt.Println(err) + } } robot := gobot.NewRobot("screenBot", @@ -47,5 +68,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/up2_leds.go b/examples/up2_leds.go index 9c7ff0916..cefae8410 100644 --- a/examples/up2_leds.go +++ b/examples/up2_leds.go @@ -7,6 +7,7 @@ package main import ( + "fmt" "time" "gobot.io/x/gobot/v2" @@ -22,22 +23,38 @@ func main() { yellow := gpio.NewLedDriver(b, up2.LEDYellow) work := func() { - red.Off() - blue.Off() - green.Off() - yellow.Off() + if err := red.Off(); err != nil { + fmt.Println(err) + } + if err := blue.Off(); err != nil { + fmt.Println(err) + } + if err := green.Off(); err != nil { + fmt.Println(err) + } + if err := yellow.Off(); err != nil { + fmt.Println(err) + } gobot.Every(1*time.Second, func() { - red.Toggle() + if err := red.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(2*time.Second, func() { - green.Toggle() + if err := green.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(4*time.Second, func() { - yellow.Toggle() + if err := yellow.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(8*time.Second, func() { - blue.Toggle() + if err := blue.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -47,5 +64,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/wifi_firmata_analog_input.go b/examples/wifi_firmata_analog_input.go index 924d81e35..9b5275690 100644 --- a/examples/wifi_firmata_analog_input.go +++ b/examples/wifi_firmata_analog_input.go @@ -21,7 +21,7 @@ func main() { sensor := aio.NewAnalogSensorDriver(firmataAdaptor, "A0", aio.WithSensorCyclicRead(500*time.Millisecond)) work := func() { - sensor.On(aio.Data, func(data interface{}) { + _ = sensor.On(aio.Data, func(data interface{}) { brightness := uint8( gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255), ) @@ -36,5 +36,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/examples/wifi_firmata_blink.go b/examples/wifi_firmata_blink.go index b996db114..d1d06b148 100644 --- a/examples/wifi_firmata_blink.go +++ b/examples/wifi_firmata_blink.go @@ -20,6 +20,7 @@ package main import ( + "fmt" "os" "time" @@ -34,7 +35,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -44,5 +47,7 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } diff --git a/platforms/beaglebone/README.md b/platforms/beaglebone/README.md index ea871af24..b3a116e98 100644 --- a/platforms/beaglebone/README.md +++ b/platforms/beaglebone/README.md @@ -45,7 +45,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -55,7 +57,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` @@ -78,7 +82,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -88,7 +94,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/beaglebone/doc.go b/platforms/beaglebone/doc.go index d868ed3f7..48f9716dd 100644 --- a/platforms/beaglebone/doc.go +++ b/platforms/beaglebone/doc.go @@ -24,7 +24,9 @@ Example: work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -34,7 +36,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For more information refer to the beaglebone README: diff --git a/platforms/bleclient/README.md b/platforms/bleclient/README.md index 271c93880..8655f7526 100644 --- a/platforms/bleclient/README.md +++ b/platforms/bleclient/README.md @@ -85,6 +85,8 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/dexter/gopigo3/README.md b/platforms/dexter/gopigo3/README.md index cadbc9df4..061c555a2 100644 --- a/platforms/dexter/gopigo3/README.md +++ b/platforms/dexter/gopigo3/README.md @@ -47,6 +47,8 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/digispark/README.md b/platforms/digispark/README.md index 95813e2bc..80a953aff 100644 --- a/platforms/digispark/README.md +++ b/platforms/digispark/README.md @@ -48,7 +48,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -58,7 +60,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/digispark/doc.go b/platforms/digispark/doc.go index 4a6477dfa..dd335f32c 100644 --- a/platforms/digispark/doc.go +++ b/platforms/digispark/doc.go @@ -26,7 +26,9 @@ Example: work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -36,7 +38,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For further information refer to digispark README: diff --git a/platforms/dji/tello/README.md b/platforms/dji/tello/README.md index 9b0f9cf61..29326ee3e 100644 --- a/platforms/dji/tello/README.md +++ b/platforms/dji/tello/README.md @@ -44,7 +44,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/firmata/README.md b/platforms/firmata/README.md index 6d7dedb6e..94b5230a9 100644 --- a/platforms/firmata/README.md +++ b/platforms/firmata/README.md @@ -42,7 +42,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -52,7 +54,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` @@ -75,7 +79,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -85,7 +91,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/firmata/client/examples/blink.go b/platforms/firmata/client/examples/blink.go index eebee49ac..6e76ca3e9 100644 --- a/platforms/firmata/client/examples/blink.go +++ b/platforms/firmata/client/examples/blink.go @@ -11,6 +11,7 @@ import ( "time" "go.bug.st/serial" + "gobot.io/x/gobot/v2/platforms/firmata/client" ) @@ -24,7 +25,11 @@ func main() { fmt.Println("connecting.....") err = board.Connect(sp) - defer board.Disconnect() + defer func() { + if err := board.Disconnect(); err != nil { + fmt.Println(err) + } + }() if err != nil { panic(err) diff --git a/platforms/firmata/doc.go b/platforms/firmata/doc.go index adf227c12..66c5c5a3d 100644 --- a/platforms/firmata/doc.go +++ b/platforms/firmata/doc.go @@ -23,7 +23,9 @@ Example: work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -33,7 +35,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For further information refer to firmata readme: diff --git a/platforms/holystone/hs200/README.md b/platforms/holystone/hs200/README.md index 7357f3a9d..39e87ef4d 100644 --- a/platforms/holystone/hs200/README.md +++ b/platforms/holystone/hs200/README.md @@ -45,7 +45,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/intel-iot/curie/README.md b/platforms/intel-iot/curie/README.md index 45b5eee11..7fd8616af 100644 --- a/platforms/intel-iot/curie/README.md +++ b/platforms/intel-iot/curie/README.md @@ -37,20 +37,22 @@ func main() { imu := curie.NewIMUDriver(firmataAdaptor) work := func() { - imu.On("Accelerometer", func(data interface{}) { + _ = imu.On("Accelerometer", func(data interface{}) { log.Println("Accelerometer", data) }) - imu.On("Gyroscope", func(data interface{}) { + _ = imu.On("Gyroscope", func(data interface{}) { log.Println("Gyroscope", data) }) - imu.On("Temperature", func(data interface{}) { + _ = imu.On("Temperature", func(data interface{}) { log.Println("Temperature", data) }) gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) gobot.Every(100*time.Millisecond, func() { @@ -66,7 +68,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/intel-iot/edison/README.md b/platforms/intel-iot/edison/README.md index 8334b34ce..2819009e9 100644 --- a/platforms/intel-iot/edison/README.md +++ b/platforms/intel-iot/edison/README.md @@ -61,7 +61,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -71,7 +73,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/intel-iot/joule/README.md b/platforms/intel-iot/joule/README.md index 7800e61eb..d07b10b48 100644 --- a/platforms/intel-iot/joule/README.md +++ b/platforms/intel-iot/joule/README.md @@ -38,7 +38,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -48,7 +50,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/jetson/README.md b/platforms/jetson/README.md index 18fde6556..178c7cfe8 100644 --- a/platforms/jetson/README.md +++ b/platforms/jetson/README.md @@ -34,7 +34,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -44,7 +46,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/joystick/README.md b/platforms/joystick/README.md index 9f8f06740..555bd61d2 100644 --- a/platforms/joystick/README.md +++ b/platforms/joystick/README.md @@ -56,68 +56,68 @@ func main() { work := func() { // buttons - stick.On(joystick.SquarePress, func(data interface{}) { + _ = stick.On(joystick.SquarePress, func(data interface{}) { fmt.Println("square_press") }) - stick.On(joystick.SquareRelease, func(data interface{}) { + _ = stick.On(joystick.SquareRelease, func(data interface{}) { fmt.Println("square_release") }) - stick.On(joystick.TrianglePress, func(data interface{}) { + _ = stick.On(joystick.TrianglePress, func(data interface{}) { fmt.Println("triangle_press") }) - stick.On(joystick.TriangleRelease, func(data interface{}) { + _ = stick.On(joystick.TriangleRelease, func(data interface{}) { fmt.Println("triangle_release") }) - stick.On(joystick.CirclePress, func(data interface{}) { + _ = stick.On(joystick.CirclePress, func(data interface{}) { fmt.Println("circle_press") }) - stick.On(joystick.CircleRelease, func(data interface{}) { + _ = stick.On(joystick.CircleRelease, func(data interface{}) { fmt.Println("circle_release") }) - stick.On(joystick.XPress, func(data interface{}) { + _ = stick.On(joystick.XPress, func(data interface{}) { fmt.Println("x_press") }) - stick.On(joystick.XRelease, func(data interface{}) { + _ = stick.On(joystick.XRelease, func(data interface{}) { fmt.Println("x_release") }) - stick.On(joystick.StartPress, func(data interface{}) { + _ = stick.On(joystick.StartPress, func(data interface{}) { fmt.Println("start_press") }) - stick.On(joystick.StartRelease, func(data interface{}) { + _ = stick.On(joystick.StartRelease, func(data interface{}) { fmt.Println("start_release") }) - stick.On(joystick.SelectPress, func(data interface{}) { + _ = stick.On(joystick.SelectPress, func(data interface{}) { fmt.Println("select_press") }) - stick.On(joystick.SelectRelease, func(data interface{}) { + _ = stick.On(joystick.SelectRelease, func(data interface{}) { fmt.Println("select_release") }) // joysticks - stick.On(joystick.LeftX, func(data interface{}) { + _ = stick.On(joystick.LeftX, func(data interface{}) { fmt.Println("left_x", data) }) - stick.On(joystick.LeftY, func(data interface{}) { + _ = stick.On(joystick.LeftY, func(data interface{}) { fmt.Println("left_y", data) }) - stick.On(joystick.RightX, func(data interface{}) { + _ = stick.On(joystick.RightX, func(data interface{}) { fmt.Println("right_x", data) }) - stick.On(joystick.RightY, func(data interface{}) { + _ = stick.On(joystick.RightY, func(data interface{}) { fmt.Println("right_y", data) }) // triggers - stick.On(joystick.R1Press, func(data interface{}) { + _ = stick.On(joystick.R1Press, func(data interface{}) { fmt.Println("R1Press", data) }) - stick.On(joystick.R2Press, func(data interface{}) { + _ = stick.On(joystick.R2Press, func(data interface{}) { fmt.Println("R2Press", data) }) - stick.On(joystick.L1Press, func(data interface{}) { + _ = stick.On(joystick.L1Press, func(data interface{}) { fmt.Println("L1Press", data) }) - stick.On(joystick.L2Press, func(data interface{}) { + _ = stick.On(joystick.L2Press, func(data interface{}) { fmt.Println("L2Press", data) }) } @@ -128,7 +128,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/joystick/doc.go b/platforms/joystick/doc.go index 3b5fcd64e..640429d6c 100644 --- a/platforms/joystick/doc.go +++ b/platforms/joystick/doc.go @@ -21,28 +21,28 @@ Example: joystick := joystick.NewDriver(joystickAdaptor, "dualshock3") work := func() { - joystick.On(joystick.Event("square_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("square_press"), func(data interface{}) { fmt.Println("square_press") }) - joystick.On(joystick.Event("square_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("square_release"), func(data interface{}) { fmt.Println("square_release") }) - joystick.On(joystick.Event("triangle_press"), func(data interface{}) { + _ = joystick.On(joystick.Event("triangle_press"), func(data interface{}) { fmt.Println("triangle_press") }) - joystick.On(joystick.Event("triangle_release"), func(data interface{}) { + _ = joystick.On(joystick.Event("triangle_release"), func(data interface{}) { fmt.Println("triangle_release") }) - joystick.On(joystick.Event("left_x"), func(data interface{}) { + _ = joystick.On(joystick.Event("left_x"), func(data interface{}) { fmt.Println("left_x", data) }) - joystick.On(joystick.Event("left_y"), func(data interface{}) { + _ = joystick.On(joystick.Event("left_y"), func(data interface{}) { fmt.Println("left_y", data) }) - joystick.On(joystick.Event("right_x"), func(data interface{}) { + _ = joystick.On(joystick.Event("right_x"), func(data interface{}) { fmt.Println("right_x", data) }) - joystick.On(joystick.Event("right_y"), func(data interface{}) { + _ = joystick.On(joystick.Event("right_y"), func(data interface{}) { fmt.Println("right_y", data) }) } @@ -53,7 +53,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For further information refer to joystick README: diff --git a/platforms/keyboard/README.md b/platforms/keyboard/README.md index 2044a1624..8c0d79b01 100644 --- a/platforms/keyboard/README.md +++ b/platforms/keyboard/README.md @@ -24,7 +24,7 @@ func main() { keys := keyboard.NewDriver() work := func() { - keys.On(keyboard.Key, func(data interface{}) { + _ = keys.On(keyboard.Key, func(data interface{}) { key := data.(keyboard.KeyEvent) if key.Key == keyboard.A { @@ -41,6 +41,8 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/keyboard/doc.go b/platforms/keyboard/doc.go index e7e364c69..f5c6620e6 100644 --- a/platforms/keyboard/doc.go +++ b/platforms/keyboard/doc.go @@ -22,7 +22,7 @@ Example: keys := keyboard.NewDriver() work := func() { - keys.On(keyboard.Key, func(data interface{}) { + _ = keys.On(keyboard.Key, func(data interface{}) { key := data.(keyboard.KeyEvent) if key.Key == keyboard.A { @@ -39,7 +39,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For further information refer to keyboard README: diff --git a/platforms/leap/README.md b/platforms/leap/README.md index c6132061b..a77220103 100644 --- a/platforms/leap/README.md +++ b/platforms/leap/README.md @@ -39,7 +39,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/leap/doc.go b/platforms/leap/doc.go index 226445d60..fbb030810 100644 --- a/platforms/leap/doc.go +++ b/platforms/leap/doc.go @@ -34,7 +34,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For more information refer to the leap README: diff --git a/platforms/mavlink/README.md b/platforms/mavlink/README.md index b8b7412bd..45ab173d8 100644 --- a/platforms/mavlink/README.md +++ b/platforms/mavlink/README.md @@ -75,7 +75,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/mavlink/doc.go b/platforms/mavlink/doc.go index b88fcf757..630c180de 100644 --- a/platforms/mavlink/doc.go +++ b/platforms/mavlink/doc.go @@ -59,7 +59,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For further information refer to mavlink README: diff --git a/platforms/megapi/README.md b/platforms/megapi/README.md index f4200b919..29db58c1b 100644 --- a/platforms/megapi/README.md +++ b/platforms/megapi/README.md @@ -45,6 +45,8 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/microbit/README.md b/platforms/microbit/README.md index b95e086a2..ba0f30423 100644 --- a/platforms/microbit/README.md +++ b/platforms/microbit/README.md @@ -51,7 +51,9 @@ func main() { ubit := microbit.NewLEDDriver(bleAdaptor) work := func() { - ubit.Blank() + if err := ubit.Blank(); err != nil { + fmt.Println(err) + } gobot.After(1*time.Second, func() { ubit.WriteText("Hello") }) @@ -66,7 +68,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` @@ -96,11 +100,15 @@ func main() { led := gpio.NewLedDriver(ubit, "1") work := func() { - button.On(gpio.ButtonPush, func(data interface{}) { - led.On() + _ = button.On(gpio.ButtonPush, func(data interface{}) { + if err := led.On(); err != nil { + fmt.Println(err) + } }) - button.On(gpio.ButtonRelease, func(data interface{}) { - led.Off() + _ = button.On(gpio.ButtonRelease, func(data interface{}) { + if err := led.Off(); err != nil { + fmt.Println(err) + } }) } @@ -110,7 +118,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/mqtt/README.md b/platforms/mqtt/README.md index 5b7555db3..62d85c04f 100644 --- a/platforms/mqtt/README.md +++ b/platforms/mqtt/README.md @@ -30,10 +30,10 @@ func main() { mqttAdaptor := mqtt.NewAdaptor("tcp://0.0.0.0:1883", "pinger") work := func() { - mqttAdaptor.On("hello", func(msg mqtt.Message) { + _ = mqttAdaptor.On("hello", func(msg mqtt.Message) { fmt.Println(msg) }) - mqttAdaptor.On("hola", func(msg mqtt.Message) { + _ = mqttAdaptor.On("hola", func(msg mqtt.Message) { fmt.Println(msg) }) data := []byte("o") @@ -50,7 +50,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/nats/README.md b/platforms/nats/README.md index a079fb659..1594c94b7 100644 --- a/platforms/nats/README.md +++ b/platforms/nats/README.md @@ -60,7 +60,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` @@ -105,7 +107,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/neurosky/README.md b/platforms/neurosky/README.md index 68ec33cc4..b0cc9f33a 100644 --- a/platforms/neurosky/README.md +++ b/platforms/neurosky/README.md @@ -67,25 +67,25 @@ func main() { neuro := neurosky.NewDriver(adaptor) work := func() { - neuro.On(neuro.Event("extended"), func(data interface{}) { + _ = neuro.On(neuro.Event("extended"), func(data interface{}) { fmt.Println("Extended", data) }) - neuro.On(neuro.Event("signal"), func(data interface{}) { + _ = neuro.On(neuro.Event("signal"), func(data interface{}) { fmt.Println("Signal", data) }) - neuro.On(neuro.Event("attention"), func(data interface{}) { + _ = neuro.On(neuro.Event("attention"), func(data interface{}) { fmt.Println("Attention", data) }) - neuro.On(neuro.Event("meditation"), func(data interface{}) { + _ = neuro.On(neuro.Event("meditation"), func(data interface{}) { fmt.Println("Meditation", data) }) - neuro.On(neuro.Event("blink"), func(data interface{}) { + _ = neuro.On(neuro.Event("blink"), func(data interface{}) { fmt.Println("Blink", data) }) - neuro.On(neuro.Event("wave"), func(data interface{}) { + _ = neuro.On(neuro.Event("wave"), func(data interface{}) { fmt.Println("Wave", data) }) - neuro.On(neuro.Event("eeg"), func(data interface{}) { + _ = neuro.On(neuro.Event("eeg"), func(data interface{}) { eeg := data.(neurosky.EEGData) fmt.Println("Delta", eeg.Delta) fmt.Println("Theta", eeg.Theta) @@ -105,6 +105,8 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/neurosky/doc.go b/platforms/neurosky/doc.go index d4afbff6a..bee9e928a 100644 --- a/platforms/neurosky/doc.go +++ b/platforms/neurosky/doc.go @@ -21,25 +21,25 @@ Example: neuro := neurosky.NewDriver(adaptor) work := func() { - neuro.On(neuro.Event("extended"), func(data interface{}) { + _ = neuro.On(neuro.Event("extended"), func(data interface{}) { fmt.Println("Extended", data) }) - neuro.On(neuro.Event("signal"), func(data interface{}) { + _ = neuro.On(neuro.Event("signal"), func(data interface{}) { fmt.Println("Signal", data) }) - neuro.On(neuro.Event("attention"), func(data interface{}) { + _ = neuro.On(neuro.Event("attention"), func(data interface{}) { fmt.Println("Attention", data) }) - neuro.On(neuro.Event("meditation"), func(data interface{}) { + _ = neuro.On(neuro.Event("meditation"), func(data interface{}) { fmt.Println("Meditation", data) }) - neuro.On(neuro.Event("blink"), func(data interface{}) { + _ = neuro.On(neuro.Event("blink"), func(data interface{}) { fmt.Println("Blink", data) }) - neuro.On(neuro.Event("wave"), func(data interface{}) { + _ = neuro.On(neuro.Event("wave"), func(data interface{}) { fmt.Println("Wave", data) }) - neuro.On(neuro.Event("eeg"), func(data interface{}) { + _ = neuro.On(neuro.Event("eeg"), func(data interface{}) { eeg := data.(neurosky.EEGData) fmt.Println("Delta", eeg.Delta) fmt.Println("Theta", eeg.Theta) @@ -59,7 +59,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For further information refer to neuroky README: diff --git a/platforms/opencv/README.md b/platforms/opencv/README.md index f45dad612..c89e25b92 100644 --- a/platforms/opencv/README.md +++ b/platforms/opencv/README.md @@ -64,6 +64,8 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/opencv/doc.go b/platforms/opencv/doc.go index ecd83ce15..da047368f 100644 --- a/platforms/opencv/doc.go +++ b/platforms/opencv/doc.go @@ -34,7 +34,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For further information refer to opencv README: diff --git a/platforms/parrot/ardrone/README.md b/platforms/parrot/ardrone/README.md index 893e103f4..5a57a2e2f 100644 --- a/platforms/parrot/ardrone/README.md +++ b/platforms/parrot/ardrone/README.md @@ -40,7 +40,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/parrot/ardrone/doc.go b/platforms/parrot/ardrone/doc.go index 3ea5b032f..bb1f8b896 100644 --- a/platforms/parrot/ardrone/doc.go +++ b/platforms/parrot/ardrone/doc.go @@ -35,7 +35,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For more information refer to the ardrone README: diff --git a/platforms/parrot/bebop/README.md b/platforms/parrot/bebop/README.md index 112c86276..746af9756 100644 --- a/platforms/parrot/bebop/README.md +++ b/platforms/parrot/bebop/README.md @@ -40,7 +40,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/parrot/bebop/client/examples/takeoff.go b/platforms/parrot/bebop/client/examples/takeoff.go index 605b2ca38..60b4d1358 100644 --- a/platforms/parrot/bebop/client/examples/takeoff.go +++ b/platforms/parrot/bebop/client/examples/takeoff.go @@ -21,7 +21,10 @@ func main() { return } - bebop.HullProtection(true) + if err := bebop.HullProtection(true); err != nil { + fmt.Println(err) + return + } fmt.Println("takeoff") if err := bebop.TakeOff(); err != nil { diff --git a/platforms/parrot/minidrone/README.md b/platforms/parrot/minidrone/README.md index dc03a75b7..b52c5c2e5 100644 --- a/platforms/parrot/minidrone/README.md +++ b/platforms/parrot/minidrone/README.md @@ -82,7 +82,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/particle/README.md b/platforms/particle/README.md index 50f8d2786..364f9f2b5 100644 --- a/platforms/particle/README.md +++ b/platforms/particle/README.md @@ -31,7 +31,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -41,6 +43,8 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/particle/doc.go b/platforms/particle/doc.go index 467b65dec..8151b6335 100644 --- a/platforms/particle/doc.go +++ b/platforms/particle/doc.go @@ -23,7 +23,9 @@ Example: work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -33,7 +35,9 @@ Example: work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } For further information refer to Particle readme: diff --git a/platforms/pebble/README.md b/platforms/pebble/README.md index 0fa25a4a5..c12e35005 100644 --- a/platforms/pebble/README.md +++ b/platforms/pebble/README.md @@ -54,7 +54,9 @@ func main() { master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/pebble/doc.go b/platforms/pebble/doc.go index 686eb837a..5e723cf76 100644 --- a/platforms/pebble/doc.go +++ b/platforms/pebble/doc.go @@ -49,7 +49,9 @@ your computer IP, robot name is 'pebble' and robot api port is 8080 master.AddRobot(robot) - master.Start() + if err := master.Start(); err != nil { + panic(err) + } } For more information refer to the pebble README: diff --git a/platforms/raspi/README.md b/platforms/raspi/README.md index 8db99b238..718c523e3 100644 --- a/platforms/raspi/README.md +++ b/platforms/raspi/README.md @@ -37,7 +37,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -47,7 +49,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/rockpi/README.md b/platforms/rockpi/README.md index 42af42108..ba6fc76d4 100644 --- a/platforms/rockpi/README.md +++ b/platforms/rockpi/README.md @@ -42,7 +42,9 @@ func main() { work := func() { gobot.Every(1*time.Second, func() { - led.Toggle() + if err := led.Toggle(); err != nil { + fmt.Println(err) + } }) } @@ -52,7 +54,9 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/sphero/bb8/README.md b/platforms/sphero/bb8/README.md index e9b2f85b7..fa1d77ea8 100644 --- a/platforms/sphero/bb8/README.md +++ b/platforms/sphero/bb8/README.md @@ -39,7 +39,10 @@ func main() { work, ) - robot.Start() + err := robot.Start() + if err != nil { + fmt.Println(err) + } } ``` diff --git a/platforms/sphero/ollie/README.md b/platforms/sphero/ollie/README.md index 803016f5d..48cc3bb1d 100644 --- a/platforms/sphero/ollie/README.md +++ b/platforms/sphero/ollie/README.md @@ -39,7 +39,10 @@ func main() { work, ) - robot.Start() + err := robot.Start() + if err != nil { + fmt.Println(err) + } } ``` diff --git a/platforms/sphero/sphero/README.md b/platforms/sphero/sphero/README.md index e2cdb0087..d156bce53 100644 --- a/platforms/sphero/sphero/README.md +++ b/platforms/sphero/sphero/README.md @@ -84,6 +84,8 @@ func main() { work, ) - robot.Start() + if err := robot.Start(); err != nil { + panic(err) + } } ``` diff --git a/platforms/sphero/sprkplus/README.md b/platforms/sphero/sprkplus/README.md index 87fcdb3c4..c6ab58a7c 100644 --- a/platforms/sphero/sprkplus/README.md +++ b/platforms/sphero/sprkplus/README.md @@ -39,7 +39,10 @@ func main() { work, ) - robot.Start() + err := robot.Start() + if err != nil { + fmt.Println(err) + } } ```