Skip to content

Expose precise BLE scan timestamps - #289

Merged
fotiDim merged 2 commits into
mainfrom
codex/precise-scan-timestamps
Aug 25, 2026
Merged

Expose precise BLE scan timestamps#289
fotiDim merged 2 commits into
mainfrom
codex/precise-scan-timestamps

Conversation

@fotiDim

@fotiDim fotiDim commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Why

High-accuracy synchronization needs the BLE advertisement's receive instant. Universal BLE exposed only a millisecond timestamp, and Android derived it after the packet reached the plugin callback. That discarded sub-millisecond phase and allowed Flutter/main-thread dispatch delay to move the timecode anchor.

What changed

  • Add optional timestampMicroseconds to BleDevice and the Pigeon scan-result model while retaining the existing millisecond field for compatibility.
  • On Android, convert ScanResult.timestampNanos from the Bluetooth event's monotonic clock to epoch microseconds before dispatching to Flutter.
  • Capture microsecond timestamps before Flutter dispatch on Apple and Windows.
  • Populate the same field on Linux and web.
  • Regenerate all platform bindings and add a timestamp precision test.

@navidecklabs
navidecklabs requested a lite review from Copilot August 25, 2026 05:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the scan-result model to expose microsecond-resolution timestamps across all supported platforms, enabling more precise timecode synchronization while keeping the existing millisecond timestamp for compatibility.

Changes:

  • Added timestampMicroseconds to BleDevice and the Pigeon UniversalBleScanResult model (plus regenerated bindings across platforms).
  • Populated microsecond timestamps on Android (converted from ScanResult.timestampNanos) and captured microsecond timestamps on Apple/Windows/Linux/Web.
  • Added a Dart unit test to verify microsecond timestamps are exposed without rounding.

Reviewed changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
windows/src/universal_ble_plugin.h Adds a microsecond timestamp helper for Windows.
windows/src/universal_ble_plugin.cpp Populates both millisecond and microsecond timestamps on scan results before Flutter dispatch.
windows/src/generated/universal_ble.g.h Regenerated Pigeon header with timestamp_microseconds field support.
windows/src/generated/universal_ble.g.cpp Regenerated Pigeon implementation to serialize/deserialize timestamp_microseconds.
android/src/main/kotlin/com/navideck/universal_ble/UniversalBlePlugin.kt Computes epoch microseconds for scan events (including conversion from monotonic scan timestamps).
android/src/main/kotlin/com/navideck/universal_ble/UniversalBle.g.kt Regenerated Pigeon Kotlin model to carry timestampMicroseconds.
darwin/universal_ble/Sources/universal_ble/UniversalBlePlugin.swift Captures a single microsecond timestamp and derives millisecond value from it before dispatch.
darwin/universal_ble/Sources/universal_ble/UniversalBle.g.swift Regenerated Pigeon Swift model to carry timestampMicroseconds.
lib/src/models/ble_device.dart Adds timestampMicroseconds and a DateTime conversion getter.
lib/src/universal_ble_pigeon/universal_ble_pigeon_channel.dart Maps Pigeon timestampMicroseconds into BleDevice.
lib/src/universal_ble_web/universal_ble_web.dart Sets scan timestamps on web scan results (needs single-capture fix for consistency).
lib/src/universal_ble_linux/universal_ble_linux.dart Sets scan timestamps on Linux scan results (needs single-capture fix for consistency).
pigeon/universal_ble.dart Updates the Pigeon definition to include timestampMicroseconds.
lib/src/universal_ble.g.dart Regenerated Dart bindings + formatting changes + new scan-result field.
test/ble_device_timestamp_test.dart Adds unit test verifying microsecond timestamps are preserved and ms timestamps are rounded to ms precision.
CHANGELOG.md Documents the new microsecond scan timestamp exposure.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/src/universal_ble_linux/universal_ble_linux.dart Outdated
Comment thread lib/src/universal_ble_web/universal_ble_web.dart Outdated
@fotiDim
fotiDim merged commit bdd316b into main Aug 25, 2026
2 checks passed
@fotiDim
fotiDim deleted the codex/precise-scan-timestamps branch August 25, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants