forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ble: more WIP on multiple ble devices
Signed-off-by: deadprogram <[email protected]>
- Loading branch information
1 parent
3344273
commit 5f93b1e
Showing
2 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
To run this example, pass the BLE address or BLE name as first param: | ||
go run examples/ollie_multiple.go 2B-1234 2B-5678 | ||
NOTE: sudo is required to use BLE in Linux | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"gobot.io/x/gobot" | ||
"gobot.io/x/gobot/api" | ||
"gobot.io/x/gobot/platforms/ble" | ||
"gobot.io/x/gobot/platforms/sphero/ollie" | ||
) | ||
|
||
func NewSwarmBot(port string) *gobot.Robot { | ||
bleAdaptor := ble.NewClientAdaptor(port) | ||
ollieDriver := ollie.NewDriver(bleAdaptor) | ||
|
||
work := func() { | ||
gobot.Every(1*time.Second, func() { | ||
ollieDriver.SetRGB(uint8(gobot.Rand(255)), | ||
uint8(gobot.Rand(255)), | ||
uint8(gobot.Rand(255)), | ||
) | ||
}) | ||
} | ||
|
||
robot := gobot.NewRobot("ollie "+port, | ||
[]gobot.Connection{bleAdaptor}, | ||
[]gobot.Device{ollieDriver}, | ||
work, | ||
) | ||
|
||
return robot | ||
} | ||
|
||
func main() { | ||
master := gobot.NewMaster() | ||
api.NewAPI(master).Start() | ||
|
||
for _, port := range os.Args[1:] { | ||
bot := NewSwarmBot(port) | ||
master.AddRobot(bot) | ||
} | ||
|
||
master.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters