Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Apps/MetaWear/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>10.0</string>
<key>CFBundleVersion</key>
<string>2</string>
<string>3</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
Expand Down
12 changes: 6 additions & 6 deletions Apps/MetaWear/MetaWearApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = MetaWear.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = S2273LZ6GL;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = NO;
Expand Down Expand Up @@ -449,7 +449,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = MetaWear.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = S2273LZ6GL;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = NO;
Expand Down Expand Up @@ -484,7 +484,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = S2273LZ6GL;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
Expand All @@ -506,7 +506,7 @@
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = S2273LZ6GL;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
Expand All @@ -527,7 +527,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = S2273LZ6GL;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
Expand All @@ -547,7 +547,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = S2273LZ6GL;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
Expand Down
27 changes: 23 additions & 4 deletions Sources/MetaWear/MetaWearScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,34 @@ public final class MetaWearScanner {
for await result in stream {
let id = result.identifier
let name = result.name ?? ""
// The scan runs with allow-duplicates (presence and RSSI must
// keep updating), so advertisements arrive several times per
// second per board. Guard every write on actual change —
// @Observable treats same-value dictionary writes as
// mutations, and unguarded writes would invalidate observers
// at advertising rate.
//
// Record every advertisement's name so renamed devices remain
// observable even when they no longer match the MetaWear prefix.
self.advertisedNames[id] = name
self.advertisementRSSI[id] = result.rssi
self.advertisementLastSeen[id] = .now
if self.advertisedNames[id] != name {
self.advertisedNames[id] = name
}
if self.advertisementRSSI[id] != result.rssi {
self.advertisementRSSI[id] = result.rssi
}
// 1 s granularity is plenty for the UI's freshness window.
if let seen = self.advertisementLastSeen[id] {
if Date.now.timeIntervalSince(seen) >= 1 {
self.advertisementLastSeen[id] = .now
}
} else {
self.advertisementLastSeen[id] = .now
}
// Record manufacturer data when present — lets tests verify a
// board has flipped into iBeacon mode by inspecting the Apple
// company-ID payload broadcast on air.
if let mfg = result.manufacturerData {
if let mfg = result.manufacturerData,
self.advertisementManufacturerData[id] != mfg {
self.advertisementManufacturerData[id] = mfg
// Boards configured to broadcast their MAC (company
// 0x626D) identify themselves here without a connection.
Expand Down
18 changes: 16 additions & 2 deletions Sources/MetaWear/Transport/MWCentralManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ actor MWCentralManager: NSObject {
return
}
mwLog("[BLE] beginScan: starting scan")
central.scanForPeripherals(withServices: services, options: nil)
central.scanForPeripherals(
withServices: services,
// Without allow-duplicates, iOS delivers each peripheral ONCE per
// scan session - advertisementLastSeen would freeze at discovery
// and presence/RSSI could never update. Scans here are foreground
// + user-visible, the sanctioned use for this energy-costly flag.
options: [CBCentralManagerScanOptionAllowDuplicatesKey: true]
)
}

private func endScan() {
Expand Down Expand Up @@ -185,7 +192,14 @@ extension MWCentralManager: CBCentralManagerDelegate {
if state == .poweredOn, scanContinuation != nil {
// A scan was requested before BT was ready — start it now.
mwLog("[BLE] handleStateUpdate: BT now poweredOn, starting deferred scan")
central.scanForPeripherals(withServices: pendingScanServices, options: nil)
central.scanForPeripherals(
withServices: pendingScanServices,
// Without allow-duplicates, iOS delivers each peripheral ONCE per
// scan session - advertisementLastSeen would freeze at discovery
// and presence/RSSI could never update. Scans here are foreground
// + user-visible, the sanctioned use for this energy-costly flag.
options: [CBCentralManagerScanOptionAllowDuplicatesKey: true]
)
}
}

Expand Down
Loading