mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Remove old BLE devices from scan
This commit is contained in:
parent
0b375a4ba2
commit
809dad5e76
2 changed files with 10 additions and 4 deletions
|
|
@ -98,7 +98,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
|
||||
self.centralManager.stopScan()
|
||||
self.isScanning = self.centralManager.isScanning
|
||||
|
||||
peripherals.removeAll(where: { $0.peripheral.state == CBPeripheralState.disconnected })
|
||||
print("🛑 Stopped Scanning")
|
||||
}
|
||||
}
|
||||
|
|
@ -177,7 +177,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
peripheralName = name
|
||||
}
|
||||
|
||||
let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, num: 0, name: peripheralName, shortName: String(peripheralName.suffix(3)), longName: peripheralName, firmwareVersion: "Unknown", rssi: RSSI.intValue, channelUtilization: nil, airTime: nil, subscribed: false, peripheral: peripheral)
|
||||
let newPeripheral = Peripheral(id: peripheral.identifier.uuidString, num: 0, name: peripheralName, shortName: String(peripheralName.suffix(3)), longName: peripheralName, firmwareVersion: "Unknown", rssi: RSSI.intValue, channelUtilization: nil, airTime: nil, lastUpdate: Date(), subscribed: false, peripheral: peripheral)
|
||||
let peripheralIndex = peripherals.firstIndex(where: { $0.id == newPeripheral.id })
|
||||
|
||||
if peripheralIndex != nil && newPeripheral.peripheral.state != CBPeripheralState.connected {
|
||||
|
|
@ -187,13 +187,17 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
|
|||
peripherals.append(newPeripheral)
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if newPeripheral.peripheral.state != CBPeripheralState.connected {
|
||||
|
||||
peripherals.append(newPeripheral)
|
||||
print("ℹ️ Adding peripheral: \(peripheralName)")
|
||||
}
|
||||
}
|
||||
|
||||
let today = Date()
|
||||
let fiveMinutesAgo = Calendar.current.date(byAdding: .minute, value: -5, to: today)!
|
||||
peripherals.removeAll(where: { $0.lastUpdate <= fiveMinutesAgo})
|
||||
}
|
||||
|
||||
// Called when a peripheral is connected
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ struct Peripheral: Identifiable {
|
|||
var rssi: Int
|
||||
var channelUtilization: Float?
|
||||
var airTime: Float?
|
||||
var lastUpdate: Date
|
||||
var subscribed: Bool
|
||||
var peripheral: CBPeripheral
|
||||
|
||||
init(id: String, num: Int64, name: String, shortName: String, longName: String, firmwareVersion: String, rssi: Int, channelUtilization: Float?, airTime: Float?, subscribed: Bool, peripheral: CBPeripheral) {
|
||||
init(id: String, num: Int64, name: String, shortName: String, longName: String, firmwareVersion: String, rssi: Int, channelUtilization: Float?, airTime: Float?, lastUpdate: Date, subscribed: Bool, peripheral: CBPeripheral) {
|
||||
self.id = id
|
||||
self.num = num
|
||||
self.name = name
|
||||
|
|
@ -24,6 +25,7 @@ struct Peripheral: Identifiable {
|
|||
self.rssi = rssi
|
||||
self.channelUtilization = channelUtilization
|
||||
self.airTime = airTime
|
||||
self.lastUpdate = lastUpdate
|
||||
self.subscribed = subscribed
|
||||
self.peripheral = peripheral
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue