Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display battery usage on bluetooth radio screen #848

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions Meshtastic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
6DA39D8E2A92DC52007E311C /* MeshtasticAppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DA39D8D2A92DC52007E311C /* MeshtasticAppDelegate.swift */; };
6DEDA55A2A957B8E00321D2E /* DetectionSensorLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DEDA5592A957B8E00321D2E /* DetectionSensorLog.swift */; };
6DEDA55C2A9592F900321D2E /* MessageEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DEDA55B2A9592F900321D2E /* MessageEntityExtension.swift */; };
A0B2EC462C62EEEC00140B07 /* BatteryHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0B2EC452C62EEEC00140B07 /* BatteryHelper.swift */; };
B399E8A42B6F486400E4488E /* RetryButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B399E8A32B6F486400E4488E /* RetryButton.swift */; };
B3E905B12B71F7F300654D07 /* TextMessageField.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3E905B02B71F7F300654D07 /* TextMessageField.swift */; };
C9697FA527933B8C00250207 /* SQLite in Frameworks */ = {isa = PBXBuildFile; productRef = C9697FA427933B8C00250207 /* SQLite */; };
Expand Down Expand Up @@ -258,6 +259,7 @@
6DA39D8D2A92DC52007E311C /* MeshtasticAppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshtasticAppDelegate.swift; sourceTree = "<group>"; };
6DEDA5592A957B8E00321D2E /* DetectionSensorLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetectionSensorLog.swift; sourceTree = "<group>"; };
6DEDA55B2A9592F900321D2E /* MessageEntityExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageEntityExtension.swift; sourceTree = "<group>"; };
A0B2EC452C62EEEC00140B07 /* BatteryHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatteryHelper.swift; sourceTree = "<group>"; };
B399E8A32B6F486400E4488E /* RetryButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetryButton.swift; sourceTree = "<group>"; };
B3E905B02B71F7F300654D07 /* TextMessageField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextMessageField.swift; sourceTree = "<group>"; };
D93068D22B8129510066FBC8 /* MessageContextMenuItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageContextMenuItems.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -912,6 +914,7 @@
DD964FBC296E6B01007C176F /* EmojiOnlyTextField.swift */,
DD3619142B1EF9F900C41C8C /* LocationsHandler.swift */,
6D825E612C34786C008DBEE4 /* CommonRegex.swift */,
A0B2EC452C62EEEC00140B07 /* BatteryHelper.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -1365,6 +1368,7 @@
DDC4C9FF2A8D982900CE201C /* DetectionSensorConfig.swift in Sources */,
D9C983A22B79D1A600BDBE6A /* RequestPositionButton.swift in Sources */,
DDDB26442AAC0206003AFCB7 /* NodeDetail.swift in Sources */,
A0B2EC462C62EEEC00140B07 /* BatteryHelper.swift in Sources */,
DD77093F2AA1B146007A8BF0 /* UIColor.swift in Sources */,
DDF6B2482A9AEBF500BA6931 /* StoreForwardConfig.swift in Sources */,
DD8169F9271F1A6100F4AB02 /* MeshLogger.swift in Sources */,
Expand Down
21 changes: 21 additions & 0 deletions Meshtastic/Helpers/BatteryHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// BatteryHelper.swift
// Meshtastic
//
// Created by Gabe Kangas on 8/6/24.
//

import Foundation
import MeshtasticProtobufs

enum BatteryHelper {
static func getBatteryFromTelemetries(_ telemetries: NSOrderedSet?) -> Double? {
let deviceMetrics = telemetries?.filtered(using: NSPredicate(format: "metricsType == 0"))
guard let mostRecent = deviceMetrics?.lastObject as? TelemetryEntity else {
return nil
}

let batteryLevel = Double(mostRecent.batteryLevel)
return batteryLevel
}
}
6 changes: 6 additions & 0 deletions Meshtastic/Views/Bluetooth/Connect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ struct Connect: View {
}
Text("ble.name").font(.callout)+Text(": \(bleManager.connectedPeripheral?.peripheral.name ?? "unknown".localized)")
.font(.callout).foregroundColor(Color.gray)

if node != nil {
if let batteryLevel = BatteryHelper.getBatteryFromTelemetries(node?.telemetries) {
Text("battery.level".localized).font(.callout)+Text(": \(Int(batteryLevel))%")
.font(.callout).foregroundColor(Color.gray)
}

Text("firmware.version").font(.callout)+Text(": \(node?.metadata?.firmwareVersion ?? "unknown".localized)")
.font(.callout).foregroundColor(Color.gray)
}
Expand Down