feat: Merge SaltyTag BLE — GPS/IMU streaming to UWB tag, anchor display, UWB position authority #5
@ -42,6 +42,10 @@ final class BLEManager: NSObject, ObservableObject {
|
|||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
|
// autoReconnect=true before creating the central so that
|
||||||
|
// centralManagerDidUpdateState(.poweredOn) immediately starts scanning
|
||||||
|
// without any user action. The user can still tap Disconnect to stop.
|
||||||
|
autoReconnect = true
|
||||||
central = CBCentralManager(delegate: self,
|
central = CBCentralManager(delegate: self,
|
||||||
queue: DispatchQueue(label: "ble.queue", qos: .utility))
|
queue: DispatchQueue(label: "ble.queue", qos: .utility))
|
||||||
}
|
}
|
||||||
@ -95,12 +99,13 @@ final class BLEManager: NSObject, ObservableObject {
|
|||||||
// We filter by device name prefix in didDiscover instead.
|
// We filter by device name prefix in didDiscover instead.
|
||||||
central.scanForPeripherals(withServices: nil,
|
central.scanForPeripherals(withServices: nil,
|
||||||
options: [CBCentralManagerScanOptionAllowDuplicatesKey: false])
|
options: [CBCentralManagerScanOptionAllowDuplicatesKey: false])
|
||||||
// Auto-stop after 15 s if nothing found
|
// Stop after 15 s if nothing found, then retry after 5 s (TAG may be booting)
|
||||||
scanTimer?.invalidate()
|
scanTimer?.invalidate()
|
||||||
scanTimer = Timer.scheduledTimer(withTimeInterval: 15, repeats: false) { [weak self] _ in
|
scanTimer = Timer.scheduledTimer(withTimeInterval: 15, repeats: false) { [weak self] _ in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
self.stopScan()
|
self.stopScan()
|
||||||
DispatchQueue.main.async { self.connectionState = .idle }
|
DispatchQueue.main.async { self.connectionState = .idle }
|
||||||
|
self.reconnectAfterDelay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user