Skip to content

Commit

Permalink
all: variety of needed updates
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Jun 22, 2024
1 parent 77b34ec commit 3384394
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 13 deletions.
Empty file modified README.md
100644 → 100755
Empty file.
10 changes: 3 additions & 7 deletions examples/hello/main.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import (
"tinygo.org/x/bluetooth"
)

// replace this with the MAC address of the Bluetooth peripheral you want to connect to.
const deviceAddress = "78:A5:04:60:86:EF"

var (
adapter = bluetooth.DefaultAdapter
device bluetooth.Device
Expand All @@ -19,13 +16,12 @@ var (
)

func main() {
time.Sleep(5 * time.Second)
println("enabling...")
wait()

println("enabling...")
must("enable BLE interface", adapter.Enable())

println("start scan...")

must("start scan", adapter.Scan(scanHandler))

var err error
Expand Down Expand Up @@ -125,7 +121,7 @@ func main() {

func scanHandler(a *bluetooth.Adapter, d bluetooth.ScanResult) {
println("device:", d.Address.String(), d.RSSI, d.LocalName())
if d.Address.String() == deviceAddress {
if d.Address.String() == connectAddress() {
a.StopScan()
ch <- d
}
Expand Down
37 changes: 37 additions & 0 deletions examples/hello/mcu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//go:build baremetal

package main

import (
"time"
)

// DeviceAddress is the MAC address of the Bluetooth peripheral you want to connect to.
// Replace this by using -ldflags="-X main.DeviceAddress=[MAC ADDRESS]"
// where [MAC ADDRESS] is the actual MAC address of the peripheral.
// For example:
// tinygo flash -target circuitplay-bluefruit -ldflags="-X main.DeviceAddress=7B:36:98:8C:41:1C" ./examples/hello/
var DeviceAddress string

func connectAddress() string {
return DeviceAddress
}

// wait on baremetal, proceed immediately on desktop OS.
func wait() {
time.Sleep(3 * time.Second)
}

// done just blocks forever, allows USB CDC reset for flashing new software.
func done() {
println("Done.")

time.Sleep(1 * time.Hour)
}

func failMessage(msg string) {
for {
println(msg)
time.Sleep(time.Second)
}
}
30 changes: 30 additions & 0 deletions examples/hello/os.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build !baremetal

package main

import "os"

func connectAddress() string {
if len(os.Args) < 2 {
println("usage: hello [address]")
os.Exit(1)
}

address := os.Args[1]

return address
}

// wait on baremetal, proceed immediately on desktop OS.
func wait() {
}

// done just prints a message and allows program to exit.
func done() {
println("Done.")
}

func failMessage(msg string) {
println(msg)
os.Exit(1)
}
7 changes: 6 additions & 1 deletion go.mod
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ module github.com/hybridgroup/tinygo-powerup

go 1.22.2

require tinygo.org/x/bluetooth v0.10.0

require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/saltosystems/winrt-go v0.0.0-20240509164145-4f7860a3bd2b // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/soypat/cyw43439 v0.0.0-20240609122733-da9153086796 // indirect
github.com/soypat/seqs v0.0.0-20240527012110-1201bab640ef // indirect
github.com/tinygo-org/cbgo v0.0.4 // indirect
github.com/tinygo-org/pio v0.0.0-20231216154340-cd888eb58899 // indirect
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 // indirect
golang.org/x/sys v0.11.0 // indirect
tinygo.org/x/bluetooth v0.9.1-0.20240529200147-d46f2cc2067a // indirect
)
18 changes: 16 additions & 2 deletions go.sum
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/saltosystems/winrt-go v0.0.0-20240509164145-4f7860a3bd2b h1:du3zG5fd8snsFN6RBoLA7fpaYV9ZQIsyH9snlk2Zvik=
github.com/saltosystems/winrt-go v0.0.0-20240509164145-4f7860a3bd2b/go.mod h1:CIltaIm7qaANUIvzr0Vmz71lmQMAIbGJ7cvgzX7FMfA=
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/soypat/cyw43439 v0.0.0-20240609122733-da9153086796 h1:1/r2URInjjFtWqT61gU7YGVCq3BRyXt/C7z4oLRF9Lo=
github.com/soypat/cyw43439 v0.0.0-20240609122733-da9153086796/go.mod h1:1Otjk6PRhfzfcVHeWMEeku/VntFqWghUwuSQyivb2vE=
github.com/soypat/seqs v0.0.0-20240527012110-1201bab640ef h1:phH95I9wANjTYw6bSYLZDQfNvao+HqYDom8owbNa0P4=
github.com/soypat/seqs v0.0.0-20240527012110-1201bab640ef/go.mod h1:oCVCNGCHMKoBj97Zp9znLbQ1nHxpkmOY9X+UAGzOxc8=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.5 h1:s5PTfem8p8EbKQOctVV53k6jCJt3UX4IEJzwh+C324Q=
github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/tinygo-org/cbgo v0.0.4 h1:3D76CRYbH03Rudi8sEgs/YO0x3JIMdyq8jlQtk/44fU=
github.com/tinygo-org/cbgo v0.0.4/go.mod h1:7+HgWIHd4nbAz0ESjGlJ1/v9LDU1Ox8MGzP9mah/fLk=
github.com/tinygo-org/pio v0.0.0-20231216154340-cd888eb58899 h1:/DyaXDEWMqoVUVEJVJIlNk1bXTbFs8s3Q4GdPInSKTQ=
github.com/tinygo-org/pio v0.0.0-20231216154340-cd888eb58899/go.mod h1:LU7Dw00NJ+N86QkeTGjMLNkYcEYMor6wTDpTCu0EaH8=
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 h1:/yRP+0AN7mf5DkD3BAI6TOFnd51gEoDEb8o35jIFtgw=
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
tinygo.org/x/bluetooth v0.9.1-0.20240529200147-d46f2cc2067a h1:nkgiMDTgaiEay8uwDNsjzS5DC3ZdQ4sxPAPT5/KUFVU=
tinygo.org/x/bluetooth v0.9.1-0.20240529200147-d46f2cc2067a/go.mod h1:CH7kXNLmcX7KUow7ReNcKGfb9wfBk84t4p9Tt/L7jZo=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
tinygo.org/x/bluetooth v0.10.0 h1:42n8qj2tuF5AfdbAUR2Nv45EhtVmbDFH6UoWnt6lzZQ=
tinygo.org/x/bluetooth v0.10.0/go.mod h1:t/Vm2a/rslsBoqFQKCBsWQw/cmRicQq+8Tl3tj5RCRI=
6 changes: 3 additions & 3 deletions powerup.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ func (a *Airplane) Stop() (err error) {
}

// Throttle sets the throttle of the Airplane.
func (a *Airplane) Throttle(thrust uint8) (err error) {
buf := []byte{thrust}
func (a *Airplane) Throttle(thrust int) (err error) {
buf := []byte{uint8(thrust)}
_, err = a.motor.WriteWithoutResponse(buf)

return err
}

// Rudder sets the rudder of the Airplane.
// angle goes from -45 to 45.
func (a *Airplane) Rudder(angle int8) (err error) {
func (a *Airplane) Rudder(angle int) (err error) {
buf := []byte{byte(angle)}
_, err = a.rudder.WriteWithoutResponse(buf)

Expand Down

0 comments on commit 3384394

Please sign in to comment.