mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Fix potential timer crash on BLEManager
Format temperature using the users setting from Settings > Language & Region > Temperature
This commit is contained in:
parent
d9243f5a00
commit
a55b0b68d7
4 changed files with 26 additions and 7 deletions
|
|
@ -32,7 +32,7 @@ func TelemetryToCsvFile(telemetry: [TelemetryEntity], metricsType: Int) -> Strin
|
|||
for dm in telemetry{
|
||||
if dm.metricsType == 1 {
|
||||
csvString += "\n"
|
||||
csvString += String(dm.temperature)
|
||||
csvString += String(dm.temperature.localeTemperature())
|
||||
csvString += ", "
|
||||
csvString += String(dm.relativeHumidity)
|
||||
csvString += ", "
|
||||
|
|
|
|||
|
|
@ -531,11 +531,12 @@ class BLEManager: NSObject, CBPeripheralDelegate, ObservableObject {
|
|||
// Use a RunLoop to prevent the timer from running on the main UI thread
|
||||
if userSettings?.provideLocation ?? false {
|
||||
if positionTimer != nil {
|
||||
|
||||
positionTimer!.invalidate()
|
||||
}
|
||||
positionTimer = Timer.scheduledTimer(timeInterval: TimeInterval((userSettings?.provideLocationInterval ?? 900)), target: self, selector: #selector(positionTimerFired), userInfo: context, repeats: true)
|
||||
RunLoop.current.add(positionTimer!, forMode: .common)
|
||||
if positionTimer != nil {
|
||||
RunLoop.current.add(positionTimer!, forMode: .common)
|
||||
}
|
||||
}
|
||||
|
||||
if decodedInfo.configCompleteID != 0 && decodedInfo.configCompleteID == configNonce {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,25 @@ extension Date {
|
|||
}
|
||||
}
|
||||
|
||||
extension Float {
|
||||
|
||||
func formattedTemperature() -> String {
|
||||
let temperature = Measurement<UnitTemperature>(value: Double(self), unit: .celsius)
|
||||
return temperature.formatted(.measurement(width: .abbreviated, usage: .weather))
|
||||
}
|
||||
func localeTemperature() -> Double {
|
||||
let temperature = Measurement<UnitTemperature>(value: Double(self), unit: .celsius)
|
||||
let locale = NSLocale.current as NSLocale
|
||||
let localeUnit = locale.object(forKey: NSLocale.Key(rawValue: "kCFLocaleTemperatureUnitKey"))
|
||||
var format: UnitTemperature = .celsius
|
||||
|
||||
if localeUnit! as! String == "Fahrenheit" {
|
||||
format = .fahrenheit
|
||||
}
|
||||
return temperature.converted(to: format).value
|
||||
}
|
||||
}
|
||||
|
||||
extension Int {
|
||||
|
||||
func numberOfDigits() -> Int {
|
||||
|
|
|
|||
|
|
@ -17,18 +17,17 @@ struct EnvironmentMetricsLog: View {
|
|||
@State var exportString = ""
|
||||
|
||||
var node: NodeInfoEntity
|
||||
|
||||
|
||||
var body: some View {
|
||||
|
||||
NavigationStack {
|
||||
|
||||
let tempReadingType = (!(node.telemetryConfig?.environmentDisplayFahrenheit ?? false)) ? "°C" : "°F"
|
||||
if UIDevice.current.userInterfaceIdiom == .pad || UIDevice.current.userInterfaceIdiom == .mac {
|
||||
//Add a table for mac and ipad
|
||||
Table(node.telemetries!.reversed() as! [TelemetryEntity]) {
|
||||
TableColumn("Temperature") { em in
|
||||
if em.metricsType == 1 {
|
||||
Text("\(String(format: "%.2f", em.temperature))\(tempReadingType)")
|
||||
Text(em.temperature.formattedTemperature())
|
||||
}
|
||||
}
|
||||
TableColumn("Humidity") { em in
|
||||
|
|
@ -98,7 +97,7 @@ struct EnvironmentMetricsLog: View {
|
|||
|
||||
GridRow {
|
||||
|
||||
Text("\(String(format: "%.2f", em.temperature))\(tempReadingType)")
|
||||
Text(em.temperature.formattedTemperature())
|
||||
.font(.caption)
|
||||
Text("\(String(format: "%.2f", em.relativeHumidity))")
|
||||
.font(.caption)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue