Expose precise BLE scan timestamps - #289
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
timestampMicrosecondstoBleDeviceand the PigeonUniversalBleScanResultmodel (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.
rohitsangwan01
approved these changes
Aug 25, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
timestampMicrosecondstoBleDeviceand the Pigeon scan-result model while retaining the existing millisecond field for compatibility.ScanResult.timestampNanosfrom the Bluetooth event's monotonic clock to epoch microseconds before dispatching to Flutter.