Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give BLE scan more options. #2643

Merged
merged 17 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions examples/ble/advertise.toit
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ main:

data := ble.AdvertisementData
--name="Toit device"
--service-classes=[BATTERY-SERVICE]
--manufacturer-data=#[0xFF, 0xFF, 't', 'o', 'i', 't']
--services=[BATTERY-SERVICE]
--manufacturer-specific=#[0xFF, 0xFF, 't', 'o', 'i', 't']
if false:
// An equivalent way to create the data would use data blocks.
data = ble.AdvertisementData [
ble.DataBlock.name "Toit device",
ble.DataBlock.services-16 [BATTERY-SERVICE],
// The company-id is not included here, as its default is #[0xFF, 0xFF].
ble.DataBlock.manufacturer-specific "toit",
]

peripheral.start-advertise data
sleep --ms=1000000
Expand Down
2 changes: 1 addition & 1 deletion examples/ble/connect.toit
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SCAN-DURATION ::= Duration --s=3

find-with-service central/ble.Central service/ble.BleUuid:
central.scan --duration=SCAN-DURATION: | device/ble.RemoteScannedDevice |
if device.data.service-classes.contains service:
if device.data.contains-service service:
return device.address
throw "no device found"

Expand Down
2 changes: 1 addition & 1 deletion examples/ble/heart_rate.toit
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ main:
? BLE-CONNECT-MODE-NONE
: BLE-CONNECT-MODE-UNDIRECTIONAL
peripheral.start-advertise
AdvertisementData --name="Toit heart rate demo"
--connection-mode=connection-mode
AdvertisementData --name="Toit heart rate demo"

task::
simulated-heart-rate := 60
Expand Down
2 changes: 1 addition & 1 deletion examples/ble/scan.toit
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ main:
addresses := []

central.scan --duration=SCAN-DURATION: | device/ble.RemoteScannedDevice |
if device.data.service-classes.contains BATTERY-SERVICE:
if device.data.contains-service BATTERY-SERVICE:
addresses.add device.address

print addresses
Loading
Loading