fix: fix BLE level when the value in cache is 1 (#551)

feat: change UUID to address in the BLE device toolTip
This commit is contained in:
Serhiy Mytrovtsiy
2021-07-30 16:54:51 +02:00
parent 62f253ec3a
commit 4831777b19
3 changed files with 8 additions and 2 deletions

View File

@@ -15,6 +15,7 @@ import CoreBluetooth
public struct BLEDevice {
let uuid: UUID
let address: String
let name: String
var RSSI: Int?

View File

@@ -38,6 +38,7 @@ internal class Popup: NSStackView, Popup_p {
self.addArrangedSubview(BLEView(
width: self.frame.width,
uuid: ble.uuid,
address: ble.address,
name: ble.name,
batteryLevel: ble.batteryLevel
))
@@ -59,7 +60,7 @@ internal class BLEView: NSStackView {
return CGSize(width: self.bounds.width, height: self.bounds.height)
}
public init(width: CGFloat, uuid: UUID, name: String, batteryLevel: [KeyValue_t]) {
public init(width: CGFloat, uuid: UUID, address: String, name: String, batteryLevel: [KeyValue_t]) {
self.uuid = uuid
super.init(frame: NSRect(x: 0, y: 0, width: width, height: 30))
@@ -73,7 +74,7 @@ internal class BLEView: NSStackView {
let nameView: NSTextField = TextView(frame: NSRect(x: 0, y: 0, width: 0, height: 16))
nameView.font = NSFont.systemFont(ofSize: 13, weight: .light)
nameView.stringValue = name
nameView.toolTip = uuid.uuidString
nameView.toolTip = address
self.addArrangedSubview(nameView)
self.addArrangedSubview(NSView())

View File

@@ -72,6 +72,7 @@ class BluetoothDelegate: NSObject, CBCentralManagerDelegate, CBPeripheralDelegat
} else {
self.devices.append(BLEDevice(
uuid: cache.uuid,
address: device.addressString,
name: device.nameOrAddress,
RSSI: rssi,
batteryLevel: cache.batteryLevel,
@@ -108,6 +109,9 @@ class BluetoothDelegate: NSObject, CBCentralManagerDelegate, CBPeripheralDelegat
switch pair.value {
case let value as Int:
percentage = value
if "\(pair.value)" == "1.00" {
percentage *= 100
}
case let value as Double:
percentage = Int(value*100)
default: continue