Skip to content

Commit

Permalink
ble: introduce in drivers folder (#1057)
Browse files Browse the repository at this point in the history
  • Loading branch information
gen2thomas authored Feb 4, 2024
1 parent 474d553 commit 3ac63bf
Show file tree
Hide file tree
Showing 158 changed files with 3,966 additions and 4,154 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ including_except := $(shell go list ./... | grep -v platforms/opencv)

# Run tests on nearly all directories without test cache, with race detection
test_race:
go test -failfast -count=1 -v -race $(including_except)
go test -failfast -count=1 -race $(including_except)

# Run tests on nearly all directories without test cache
test:
Expand Down
83 changes: 54 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ import (
"time"

"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/platforms/sphero"
"gobot.io/x/gobot/v2/drivers/serial"
"gobot.io/x/gobot/v2/platforms/serialport"
)

func main() {
adaptor := sphero.NewAdaptor("/dev/rfcomm0")
driver := sphero.NewSpheroDriver(adaptor)
adaptor := serialport.NewAdaptor("/dev/rfcomm0")
driver := serial.NewSpheroDriver(adaptor)

work := func() {
gobot.Every(3*time.Second, func() {
Expand Down Expand Up @@ -166,18 +167,20 @@ import (

"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/api"
"gobot.io/x/gobot/v2/platforms/sphero"
"gobot.io/x/gobot/v2/drivers/common/sphero"
"gobot.io/x/gobot/v2/drivers/serial"
"gobot.io/x/gobot/v2/platforms/serialport"
)

func NewSwarmBot(port string) *gobot.Robot {
spheroAdaptor := sphero.NewAdaptor(port)
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
spheroAdaptor := serialport.NewAdaptor(port)
spheroDriver := serial.NewSpheroDriver(spheroAdaptor)
spheroDriver.SetName("Sphero" + port)

work := func() {
spheroDriver.Stop()

spheroDriver.On(sphero.Collision, func(data interface{}) {
spheroDriver.On(sphero.CollisionEvent, func(data interface{}) {
fmt.Println("Collision Detected!")
})

Expand Down Expand Up @@ -229,7 +232,7 @@ platforms are currently supported:
- Audio <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/audio)
- [Beaglebone Black](http://beagleboard.org/boards) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/beaglebone)
- [Beaglebone PocketBeagle](http://beagleboard.org/pocket/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/beaglebone)
- [Bluetooth LE](https://www.bluetooth.com/what-is-bluetooth-technology/bluetooth-technology-basics/low-energy) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/ble)
- [Bluetooth LE](https://www.bluetooth.com/what-is-bluetooth-technology/bluetooth-technology-basics/low-energy) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/bleclient)
- [C.H.I.P](http://www.nextthing.co/pages/chip) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/chip)
- [C.H.I.P Pro](https://docs.getchip.com/chip_pro.html) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/chip)
- [Digispark](http://digistump.com/products/1) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/digispark)
Expand Down Expand Up @@ -259,15 +262,47 @@ platforms are currently supported:
- [Pebble](https://www.getpebble.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/pebble)
- [Radxa Rock Pi 4](https://wiki.radxa.com/Rock4/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/rockpi)
- [Raspberry Pi](http://www.raspberrypi.org/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/raspi)
- [Sphero](http://www.sphero.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero)
- [Serial Port](https://en.wikipedia.org/wiki/Serial_port) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/serialport)
- [Sphero](http://www.sphero.com/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero/sphero)
- [Sphero BB-8](http://www.sphero.com/bb8) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero/bb8)
- [Sphero Ollie](http://www.sphero.com/ollie) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero/ollie)
- [Sphero SPRK+](http://www.sphero.com/sprk-plus) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/sphero/sprkplus)
- [Tinker Board](https://www.asus.com/us/Single-Board-Computer/Tinker-Board/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/tinkerboard)
- [UP2](http://www.up-board.org/upsquared/) <=> [Package](https://github.com/hybridgroup/gobot/tree/master/platforms/upboard/up2)

Support for many devices that use General Purpose Input/Output (GPIO) have
a shared set of drivers provided using the `gobot/drivers/gpio` package:
Support for many devices that use Analog Input/Output (AIO) have a shared set of drivers provided using
the `gobot/drivers/aio` package:

- [AIO](https://en.wikipedia.org/wiki/Analog-to-digital_converter) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/aio)
- Analog Actuator
- Analog Sensor
- Grove Light Sensor
- Grove Piezo Vibration Sensor
- Grove Rotary Dial
- Grove Sound Sensor
- Grove Temperature Sensor
- Temperature Sensor (supports linear and NTC thermistor in normal and inverse mode)
- Thermal Zone Temperature Sensor

Support for many devices that use Bluetooth LE (BLE) have a shared set of drivers provided using
the `gobot/drivers/ble` package:

- [BLE](http://en.wikipedia.org/wiki/Bluetooth_low_energy) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/ble)
- Battery Service
- Device Information Service
- Generic Access Service
- Microbit: AccelerometerDriver
- Microbit: ButtonDriver
- Microbit: IOPinDriver
- Microbit: LEDDriver
- Microbit: MagnetometerDriver
- Microbit: TemperatureDriver
- Sphero: BB8
- Sphero: Ollie
- Sphero: SPRK+

Support for many devices that use General Purpose Input/Output (GPIO) have a shared set of drivers provided using
the `gobot/drivers/gpio` package:

- [GPIO](https://en.wikipedia.org/wiki/General_Purpose_Input/Output) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/gpio)
- AIP1640 LED Dot Matrix/7 Segment Controller
Expand All @@ -294,22 +329,8 @@ a shared set of drivers provided using the `gobot/drivers/gpio` package:
- Stepper Motor
- TM1638 LED Controller

Support for many devices that use Analog Input/Output (AIO) have
a shared set of drivers provided using the `gobot/drivers/aio` package:

- [AIO](https://en.wikipedia.org/wiki/Analog-to-digital_converter) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/aio)
- Analog Actuator
- Analog Sensor
- Grove Light Sensor
- Grove Piezo Vibration Sensor
- Grove Rotary Dial
- Grove Sound Sensor
- Grove Temperature Sensor
- Temperature Sensor (supports linear and NTC thermistor in normal and inverse mode)
- Thermal Zone Temperature Sensor

Support for devices that use Inter-Integrated Circuit (I2C) have a shared set of
drivers provided using the `gobot/drivers/i2c` package:
Support for devices that use Inter-Integrated Circuit (I2C) have a shared set of drivers provided using
the `gobot/drivers/i2c` package:

- [I2C](https://en.wikipedia.org/wiki/I%C2%B2C) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/i2c)
- Adafruit 1109 2x16 RGB-LCD with 5 keys
Expand Down Expand Up @@ -351,6 +372,12 @@ drivers provided using the `gobot/drivers/i2c` package:
- Wii Nunchuck Controller
- YL-40 Brightness/Temperature sensor, Potentiometer, analog input, analog output Driver

Support for many devices that use Serial communication (UART) have a shared set of drivers provided using
the `gobot/drivers/serial` package:

- [UART](https://en.wikipedia.org/wiki/Serial_port) <=> [Drivers](https://github.com/hybridgroup/gobot/tree/master/drivers/serial)
- Sphero: Sphero

Support for devices that use Serial Peripheral Interface (SPI) have
a shared set of drivers provided using the `gobot/drivers/spi` package:

Expand All @@ -366,8 +393,6 @@ a shared set of drivers provided using the `gobot/drivers/spi` package:
- MFRC522 RFID Card Reader
- SSD1306 OLED Display Controller

More platforms and drivers are coming soon...

## API

Gobot includes a RESTful API to query the status of any robot running within a group, including the connection and
Expand Down
14 changes: 14 additions & 0 deletions adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,20 @@ type Adaptor interface {
Finalize() error
}

// BLEConnector is the interface that a BLE ClientAdaptor must implement
type BLEConnector interface {
Adaptor

Reconnect() error
Disconnect() error
Address() string

ReadCharacteristic(cUUID string) ([]byte, error)
WriteCharacteristic(cUUID string, data []byte) error
Subscribe(cUUID string, f func([]byte, error)) error
WithoutResponses(use bool)
}

// Porter is the interface that describes an adaptor's port
type Porter interface {
Port() string
Expand Down
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ before_test:
build_script:
- go test -v -cpu=2 .
- go test -v -cpu=2 ./drivers/aio/...
- go test -v -cpu=2 ./platforms/ble/...
- go test -v -cpu=2 ./drivers/ble/.
- go test -v -cpu=2 ./drivers/ble/parrot/.
- go test -v -cpu=2 ./drivers/ble/sphero/.
- go test -v -cpu=2 ./drivers/serial/...
- go test -v -cpu=2 ./platforms/bleclient/...
- go test -v -cpu=2 ./platforms/dji/...
- go test -v -cpu=2 ./platforms/firmata/...
- go test -v -cpu=2 ./platforms/joystick/...
- go test -v -cpu=2 ./platforms/parrot/...
- go test -v -cpu=2 ./platforms/sphero/...
- go test -v -cpu=2 ./platforms/serialport/...
- cd ..
122 changes: 62 additions & 60 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,66 +70,68 @@ pure idiomatic Golang code. For example:
Finally, you can use Master Gobot to add the complete Gobot API or control swarms of Robots:
package main
import (
"fmt"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/api"
"gobot.io/x/gobot/v2/platforms/sphero"
)
func NewSwarmBot(port string) *gobot.Robot {
spheroAdaptor := sphero.NewAdaptor(port)
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
spheroDriver.SetName("Sphero" + port)
work := func() {
spheroDriver.Stop()
spheroDriver.On(sphero.Collision, func(data interface{}) {
fmt.Println("Collision Detected!")
})
gobot.Every(1*time.Second, func() {
spheroDriver.Roll(100, uint16(gobot.Rand(360)))
})
gobot.Every(3*time.Second, func() {
spheroDriver.SetRGB(uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
)
})
}
robot := gobot.NewRobot("sphero",
[]gobot.Connection{spheroAdaptor},
[]gobot.Device{spheroDriver},
work,
)
return robot
}
func main() {
master := gobot.NewMaster()
api.NewAPI(master).Start()
spheros := []string{
"/dev/rfcomm0",
"/dev/rfcomm1",
"/dev/rfcomm2",
"/dev/rfcomm3",
}
for _, port := range spheros {
master.AddRobot(NewSwarmBot(port))
}
master.Start()
}
package main
import (
"fmt"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/api"
"gobot.io/x/gobot/v2/drivers/common/sphero"
"gobot.io/x/gobot/v2/drivers/serial"
"gobot.io/x/gobot/v2/platforms/serialport"
)
func NewSwarmBot(port string) *gobot.Robot {
spheroAdaptor := serialport.NewAdaptor(port)
spheroDriver := serial.NewSpheroDriver(spheroAdaptor)
spheroDriver.SetName("Sphero" + port)
work := func() {
spheroDriver.Stop()
spheroDriver.On(sphero.CollisionEvent, func(data interface{}) {
fmt.Println("Collision Detected!")
})
gobot.Every(1*time.Second, func() {
spheroDriver.Roll(100, uint16(gobot.Rand(360)))
})
gobot.Every(3*time.Second, func() {
spheroDriver.SetRGB(uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
)
})
}
robot := gobot.NewRobot("sphero",
[]gobot.Connection{spheroAdaptor},
[]gobot.Device{spheroDriver},
work,
)
return robot
}
func main() {
master := gobot.NewMaster()
api.NewAPI(master).Start()
spheros := []string{
"/dev/rfcomm0",
"/dev/rfcomm1",
"/dev/rfcomm2",
"/dev/rfcomm3",
}
for _, port := range spheros {
master.AddRobot(NewSwarmBot(port))
}
master.Start()
}
Copyright (c) 2013-2018 The Hybrid Group. Licensed under the Apache 2.0 license.
*/
Expand Down
Loading

0 comments on commit 3ac63bf

Please sign in to comment.