Add smoke tests that run in CI
This commit is contained in:
parent
6f9f11dbac
commit
f87fda3204
5 changed files with 122 additions and 0 deletions
13
.circleci/config.yml
Normal file
13
.circleci/config.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
version: 2
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
docker:
|
||||||
|
- image: tinygo/tinygo-dev
|
||||||
|
working_directory: /usr/local/go/src/github.com/aykevl/go-bluetooth
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: tinygo version
|
||||||
|
- run:
|
||||||
|
name: "Run smoke tests"
|
||||||
|
command: make smoketest
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
test.hex
|
17
Makefile
Normal file
17
Makefile
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
TINYGO=tinygo
|
||||||
|
|
||||||
|
smoketest:
|
||||||
|
# Test all examples (and some boards)
|
||||||
|
$(TINYGO) build -o test.hex -size=short -target=pca10040-s132v6 ./examples/advertisement
|
||||||
|
@md5sum test.hex
|
||||||
|
$(TINYGO) build -o test.hex -size=short -target=pca10040-s132v6 ./examples/heartrate
|
||||||
|
@md5sum test.hex
|
||||||
|
$(TINYGO) build -o test.hex -size=short -target=reelboard-s140v7 ./examples/ledcolor
|
||||||
|
@md5sum test.hex
|
||||||
|
# Test some more boards that are not tested above.
|
||||||
|
$(TINYGO) build -o test.hex -size=short -target=pca10056-s140v7 ./examples/advertisement
|
||||||
|
@md5sum test.hex
|
||||||
|
# Test on the host
|
||||||
|
go build -o /tmp/go-build-discard ./examples/advertisement
|
||||||
|
go build -o /tmp/go-build-discard ./examples/heartrate
|
|
@ -1,5 +1,7 @@
|
||||||
# Go Bluetooth
|
# Go Bluetooth
|
||||||
|
|
||||||
|
[![CircleCI](https://circleci.com/gh/aykevl/go-bluetooth/tree/master.svg?style=svg)](https://circleci.com/gh/aykevl/go-bluetooth/tree/master)
|
||||||
|
|
||||||
Bluetooth API for embedded devices.
|
Bluetooth API for embedded devices.
|
||||||
|
|
||||||
This package attempts to build a cross-system Bluetooth API written in Go. It
|
This package attempts to build a cross-system Bluetooth API written in Go. It
|
||||||
|
|
89
examples/ledcolor/main.go
Normal file
89
examples/ledcolor/main.go
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"machine"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/aykevl/go-bluetooth"
|
||||||
|
)
|
||||||
|
|
||||||
|
// flags + local name
|
||||||
|
var advPayload = []byte("\x02\x01\x06" + "\x0b\x09LED colors")
|
||||||
|
|
||||||
|
// TODO: use atomics to access this value.
|
||||||
|
var ledColor = [3]byte{0xff, 0x00, 0x00} // start out with red
|
||||||
|
var leds = [3]machine.Pin{machine.LED_RED, machine.LED_GREEN, machine.LED_BLUE}
|
||||||
|
var hasColorChange = true
|
||||||
|
|
||||||
|
var (
|
||||||
|
serviceUUID = [16]byte{0xa0, 0xb4, 0x00, 0x01, 0x92, 0x6d, 0x4d, 0x61, 0x98, 0xdf, 0x8c, 0x5c, 0x62, 0xee, 0x53, 0xb3}
|
||||||
|
charUUID = [16]byte{0xa0, 0xb4, 0x00, 0x02, 0x92, 0x6d, 0x4d, 0x61, 0x98, 0xdf, 0x8c, 0x5c, 0x62, 0xee, 0x53, 0xb3}
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
println("starting")
|
||||||
|
adapter, err := bluetooth.DefaultAdapter()
|
||||||
|
must("get default adapter", err)
|
||||||
|
adapter.SetEventHandler(handleBluetoothEvents)
|
||||||
|
must("enable SD", adapter.Enable())
|
||||||
|
adv := adapter.NewAdvertisement()
|
||||||
|
options := &bluetooth.AdvertiseOptions{
|
||||||
|
Interval: bluetooth.NewAdvertiseInterval(100),
|
||||||
|
}
|
||||||
|
must("config adv", adv.Configure(advPayload, nil, options))
|
||||||
|
must("start adv", adv.Start())
|
||||||
|
|
||||||
|
var ledColorCharacteristic bluetooth.Characteristic
|
||||||
|
must("add service", adapter.AddService(&bluetooth.Service{
|
||||||
|
UUID: bluetooth.NewUUID(serviceUUID),
|
||||||
|
Characteristics: []bluetooth.CharacteristicConfig{
|
||||||
|
{
|
||||||
|
Handle: &ledColorCharacteristic,
|
||||||
|
UUID: bluetooth.NewUUID(charUUID),
|
||||||
|
Value: ledColor[:],
|
||||||
|
Flags: bluetooth.CharacteristicReadPermission | bluetooth.CharacteristicWritePermission,
|
||||||
|
WriteEvent: func(client bluetooth.Connection, offset int, value []byte) {
|
||||||
|
if offset != 0 || len(value) != 3 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ledColor[0] = value[0]
|
||||||
|
ledColor[1] = value[1]
|
||||||
|
ledColor[2] = value[2]
|
||||||
|
hasColorChange = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
for _, led := range leds {
|
||||||
|
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
for !hasColorChange {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
hasColorChange = false
|
||||||
|
for i, led := range leds {
|
||||||
|
led.Set(ledColor[i] == 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func must(action string, err error) {
|
||||||
|
if err != nil {
|
||||||
|
panic("failed to " + action + ": " + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// handleBluetoothEvents prints BLE events as they happen.
|
||||||
|
func handleBluetoothEvents(evt bluetooth.Event) {
|
||||||
|
switch evt := evt.(type) {
|
||||||
|
case *bluetooth.ConnectEvent:
|
||||||
|
println("evt: connected", evt.Connection)
|
||||||
|
case *bluetooth.DisconnectEvent:
|
||||||
|
println("evt: disconnected", evt.Connection)
|
||||||
|
default:
|
||||||
|
println("evt: unknown")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue