Skip to content

Commit 651ab90

Browse files
committed
Converted all of my print statements to debug log entries. Few last minute bug fixes before 0.9.1 release.
1 parent c765372 commit 651ab90

25 files changed

Lines changed: 134 additions & 103 deletions

Infini-iOS.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
26A40E932707D119007966F6 /* BLEUpdateHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A40E922707D119007966F6 /* BLEUpdateHandler.swift */; };
5454
26A40E952708C7F8007966F6 /* ScanningPopover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A40E942708C7F8007966F6 /* ScanningPopover.swift */; };
5555
26A40EE8270A1F97007966F6 /* RenameDeviceHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A40EE7270A1F97007966F6 /* RenameDeviceHeader.swift */; };
56+
26A40EEA270A5F39007966F6 /* DFUStartButtonColorSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A40EE9270A5F39007966F6 /* DFUStartButtonColorSelector.swift */; };
5657
26A6314D26BEFD2C005AE404 /* MusicController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6314C26BEFD2C005AE404 /* MusicController.swift */; };
5758
26A6315526C0297A005AE404 /* BLEWriteManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6315426C0297A005AE404 /* BLEWriteManager.swift */; };
5859
26A6315B26C49841005AE404 /* DFU.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6315A26C49841005AE404 /* DFU.swift */; };
@@ -143,6 +144,7 @@
143144
26A40E922707D119007966F6 /* BLEUpdateHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLEUpdateHandler.swift; sourceTree = "<group>"; };
144145
26A40E942708C7F8007966F6 /* ScanningPopover.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanningPopover.swift; sourceTree = "<group>"; };
145146
26A40EE7270A1F97007966F6 /* RenameDeviceHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RenameDeviceHeader.swift; sourceTree = "<group>"; };
147+
26A40EE9270A5F39007966F6 /* DFUStartButtonColorSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFUStartButtonColorSelector.swift; sourceTree = "<group>"; };
146148
26A6314C26BEFD2C005AE404 /* MusicController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicController.swift; sourceTree = "<group>"; };
147149
26A6315426C0297A005AE404 /* BLEWriteManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLEWriteManager.swift; sourceTree = "<group>"; };
148150
26A6315A26C49841005AE404 /* DFU.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFU.swift; sourceTree = "<group>"; };
@@ -229,6 +231,7 @@
229231
2632388526F2548600D72B43 /* DFUWithoutBLE.swift */,
230232
2632388726F2576D00D72B43 /* DFUFileSelectButton.swift */,
231233
2632388926F2591900D72B43 /* DFUStartTransferButton.swift */,
234+
26A40EE9270A5F39007966F6 /* DFUStartButtonColorSelector.swift */,
232235
2675CA5926DC81AA00967E4D /* DFUComplete.swift */,
233236
263B20C626CF07BB00676BF0 /* DFUProgressBar.swift */,
234237
);
@@ -617,6 +620,7 @@
617620
26C5FAD526FBB76100921207 /* DeviceNameManager.swift in Sources */,
618621
26A6315B26C49841005AE404 /* DFU.swift in Sources */,
619622
26D7817A26CAD19F00BBF555 /* ColorPalette.swift in Sources */,
623+
26A40EEA270A5F39007966F6 /* DFUStartButtonColorSelector.swift in Sources */,
620624
26A40EE8270A1F97007966F6 /* RenameDeviceHeader.swift in Sources */,
621625
266F53EA26FA91F3007481A6 /* DeviceInfo.swift in Sources */,
622626
);

Infini-iOS/BLE/BLEDelegates.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ extension BLEManager: CBPeripheralDelegate {
2929
}
3030
}
3131

32-
func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {
33-
if (error == nil) {
34-
print("notification state updated for \(characteristic.uuid)")
35-
} else {
36-
print(error!.localizedDescription)
37-
}
38-
}
39-
4032
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
4133
DeviceInfoManager().updateInfo(characteristic: characteristic)
4234
BLEUpdatedCharacteristicHandler().handleUpdates(characteristic: characteristic, peripheral: peripheral)

Infini-iOS/BLE/BLEDiscoveredCharacteristics.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ struct BLEDiscoveredCharacteristics {
3737
try peripheral.writeValue(SetTime().currentTime().hexData, for: characteristic, type: .withResponse)
3838
} catch {
3939
bleManager.setTimeError = true
40-
print("Error setting time: \(error)")
4140
}
4241
default:
4342
break

Infini-iOS/BLE/BLEManager.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
112112
firstConnect = true
113113
isConnectedToPinetime = false
114114
heartChartReconnect = false
115+
infiniTime = nil
115116
}
116117
}
117118

@@ -155,7 +156,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
155156
}
156157

157158
func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
158-
bleLogger.debug(error: error, log: .ble, date: Date()) // MARK: logging
159+
if error != nil {
160+
bleLogger.debug(error: "Failed to connect: \(error!)", log: .ble, date: Date()) // MARK: logging
161+
}
159162
}
160163

161164
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
@@ -169,10 +172,10 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
169172
heartChartReconnect = true
170173
//connect(peripheral: peripheral)
171174
central.connect(peripheral)
172-
bleLogger.debug(error: error, log: .ble, date: Date()) // MARK: logging
175+
bleLogger.debug(error: "Peripheral disconnected. Reason: \(error!)", log: .ble, date: Date()) // MARK: logging
173176
} else {
174177
DeviceInfoManager.init().clearDeviceInfo()
175-
bleLogger.debug(error: nil, log: .ble, additionalInfo: "User initiated disconnect", date: Date()) // MARK: logging
178+
bleLogger.debug(error: "User initiated disconnect", log: .ble, date: Date()) // MARK: logging
176179
}
177180
UptimeManager.shared.lastDisconnect = Date()
178181
UptimeManager.shared.connectTime = nil

Infini-iOS/BLE/BLEUpdateHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct BLEUpdatedCharacteristicHandler {
4141
}
4242
case bleManager.cbuuidList.bat:
4343
let batData = [UInt8](characteristic.value!)
44-
DebugLogManager.shared.debug(error: nil, log: .ble, additionalInfo: "battery level report: \(String(batData[0]))", date: Date())
44+
DebugLogManager.shared.debug(error: "battery level report: \(String(batData[0]))", log: .ble, date: Date())
4545
ChartManager.shared.addItem(dataPoint: DataPoint(date: Date(), value: Double(batData[0]), chart: ChartsAsInts.battery.rawValue))
4646
bleManager.batteryLevel = Double(batData[0])
4747
default:

Infini-iOS/BLE/BLEWriteManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ struct BLEWriteManager {
2222

2323
func sendNotification(title: String, body: String) {
2424
guard let titleData = (" " + title + "\0").data(using: .ascii) else {
25-
DebugLogManager.shared.debug(error: nil, log: .app, additionalInfo: "Failed to convert notification title to ASCII", date: Date())
25+
DebugLogManager.shared.debug(error: "Failed to convert notification title to ASCII. Title: '\(title)'", log: .app, date: Date())
2626
return }
2727
guard let bodyData = (body + "\0").data(using: .ascii) else {
28-
DebugLogManager.shared.debug(error: nil, log: .app, additionalInfo: "Failed to convert notification body to ASCII", date: Date())
28+
DebugLogManager.shared.debug(error: "Failed to convert notification body to ASCII. Body: '\(body)'", log: .app, date: Date())
2929
return }
3030
var notification = titleData
3131
notification.append(bodyData)

Infini-iOS/BLE/SetTime.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,14 @@ class SetTime {
5656
for part in dateString.components(separatedBy: " ") {
5757
debugString.append(String("\(part), "))
5858
guard let intPart = Int(part) else {
59-
logManager.debug(error: nil, log: .app, additionalInfo: "Failed to set date!", date: Date())
60-
logManager.debug(error: nil, log: .app, additionalInfo: "Full date string: \(dateString)")
61-
logManager.debug(error: nil, log: .app, additionalInfo: debugString)
62-
if part.isEmpty {
63-
logManager.debug(error: nil, log: .app, additionalInfo: "Tried to convert a nil value")
64-
} else {
65-
logManager.debug(error: nil, log: .app, additionalInfo: "'\(part)' was unable to be converted to an Integer")
66-
}
59+
logManager.debug(error: "Failed to set date!", log: .app, date: Date())
60+
logManager.debug(error: "Full date string: \(dateString)", log: .app)
61+
logManager.debug(error: "'\(part)' was unable to be converted to an Integer", log: .app)
6762
throw SetTimeError.nilValue
6863
}
6964
let hex = String(format: "%02X", intPart)
7065
fullDateString.append(hex)
71-
7266
}
73-
74-
// print(fullDateString) // debug
7567
return fullDateString
7668
}
7769
}

Infini-iOS/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct ContentView: View {
6868
.onChange(of: bleManager.batteryLevel) { bat in
6969
batteryNotifications.notify(bat: Int(bat), bleManager: bleManager)
7070
}
71-
//.offset(x: pageSwitcher.showMenu ? geometry.size.width * 0.6 : 0)
71+
.offset(x: pageSwitcher.showMenu ? geometry.size.width * 0.6 : 0)
7272
.disabled(pageSwitcher.showMenu ? true : false)
7373
.overlay(Group {
7474
// this overlay lets you tap on the main screen to close the side menu. swiftUI requires a view that is not Color.clear and has any opacity level > 0 for tap interactions

Infini-iOS/DFU/DFU.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class DFU_Updater: ObservableObject, DFUServiceDelegate, DFUProgressDelegate, Lo
3434
func transfer() {
3535
guard let url = firmwareURL else {return}
3636
guard url.startAccessingSecurityScopedResource() else { return }
37-
guard let selectedFirmware = DFUFirmware(urlToZipFile:url) else { return }
37+
guard let selectedFirmware = DFUFirmware(urlToZipFile:url) else {
38+
DebugLogManager.shared.debug(error: "Error loading firmware file. Is the file a DFU zip?", log: .dfu, date: Date())
39+
return
40+
}
3841
let initiator = DFUServiceInitiator().with(firmware: selectedFirmware)
3942

4043
// Optional:
@@ -51,10 +54,10 @@ class DFU_Updater: ObservableObject, DFUServiceDelegate, DFUProgressDelegate, Lo
5154
}
5255

5356
func downloadTransfer() {
54-
print("transfer function:")
55-
56-
57-
guard let selectedFirmware = DFUFirmware(urlToZipFile: firmwareURL) else { print("failed to load file"); return }
57+
guard let selectedFirmware = DFUFirmware(urlToZipFile: firmwareURL) else {
58+
DebugLogManager.shared.debug(error: "Error loading firmware file. Is the file a DFU zip?", log: .dfu, date: Date())
59+
return
60+
}
5861

5962
let initiator = DFUServiceInitiator().with(firmware: selectedFirmware)
6063

@@ -83,19 +86,15 @@ class DFU_Updater: ObservableObject, DFUServiceDelegate, DFUProgressDelegate, Lo
8386
// stubs added automatically.
8487
func dfuStateDidChange(to state: DFUState) {
8588
dfuState = state.description()
86-
print(dfuState)
8789
if state.rawValue == 6 {
8890
transferCompleted = true
89-
print(transferCompleted)
9091
dfuController = nil
9192
percentComplete = 0
9293
}
9394
}
9495

9596
func dfuError(_ error: DFUError, didOccurWithMessage message: String) {
96-
// print("DFU Error:", message)
97-
98-
DebugLogManager.shared.debug(error: nil, log: .dfu, additionalInfo: "DFU Error: \(message)", date: Date())
97+
DebugLogManager.shared.debug(error: "DFU Error: \(message)", log: .dfu, date: Date())
9998

10099
dfuController = nil
101100
transferCompleted = false
@@ -108,8 +107,7 @@ class DFU_Updater: ObservableObject, DFUServiceDelegate, DFUProgressDelegate, Lo
108107

109108
func logWith(_ level: LogLevel, message: String) {
110109
let logManager = DebugLogManager.shared
111-
logManager.debug(error: nil, log: .dfu, additionalInfo: "DFU \(level.name()): \(message)", date: nil)
112-
// print("DFU \(level.name()): \(message)")
110+
logManager.debug(error: "DFU \(level.name()): \(message)", log: .dfu, date: nil)
113111
}
114112

115113

Infini-iOS/DFU/DownloadManager.swift

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class DownloadManager: NSObject, ObservableObject {
5555

5656
func getDownloadUrls() {
5757
results = []
58-
print("start of json fetch. results array count: \(results.count)")
5958
guard let url = URL(string: "https://api.github.com/repos/InfiniTimeOrg/InfiniTime/releases") else {
6059
return
6160
}
@@ -65,7 +64,6 @@ class DownloadManager: NSObject, ObservableObject {
6564
let res = try JSONDecoder().decode([Result].self, from: data)
6665
DispatchQueue.main.async {
6766
for i in res {
68-
print(i.tag_name)
6967
if i.tag_name.first != "v" {
7068
if UserDefaults.standard.value(forKey: "showNewDownloadsOnly") as? Bool ?? true {
7169
let comparison = BLEDeviceInfo.shared.firmware.compare(i.tag_name, options: .numeric)
@@ -80,13 +78,10 @@ class DownloadManager: NSObject, ObservableObject {
8078
self.updateAvailable = self.checkForUpdates()
8179
}
8280
} catch {
83-
print("urlsession catch")
84-
print(error)
85-
81+
DebugLogManager.shared.debug(error: "JSON Decoding Error: \(error)", log: .app, date: Date())
8682
}
8783
}
8884
}.resume()
89-
print("end of json fetch")
9085
}
9186

9287
func chooseAsset(response: Result) -> Asset {
@@ -117,8 +112,6 @@ class DownloadManager: NSObject, ObservableObject {
117112

118113
extension DownloadManager: URLSessionDelegate, URLSessionDownloadDelegate {
119114
func urlSession(_: URLSession, downloadTask: URLSessionDownloadTask, didWriteData _: Int64, totalBytesWritten _: Int64, totalBytesExpectedToWrite _: Int64) {
120-
// uncomment for progress updates in console
121-
//print("Progress " + String(downloadTask.progress.fractionCompleted))
122115
}
123116

124117
func urlSession(_: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
@@ -131,15 +124,14 @@ extension DownloadManager: URLSessionDelegate, URLSessionDownloadDelegate {
131124
// check for existing file and delete it if there is anything.
132125
if FileManager.default.fileExists(atPath: savedURL.path) {
133126
try? FileManager.default.removeItem(at: savedURL)
134-
print("old file deleted")
135127
}
136128

137129
// move downloaded file out of ephemeral storage and tell DFU where to look
138130
try FileManager.default.moveItem(at: location, to: savedURL)
139131
DFU_Updater.shared.firmwareURL = savedURL
140132

141133
} catch let fmerror {
142-
print("filesystem error: \(fmerror)")
134+
DebugLogManager.shared.debug(error: "Error saving downloaded firmware file: \(fmerror)", log: .app, date: Date())
143135
// handle filesystem error
144136
}
145137
DispatchQueue.main.async {
@@ -149,10 +141,7 @@ extension DownloadManager: URLSessionDelegate, URLSessionDownloadDelegate {
149141

150142
func urlSession(_: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
151143
if let error = error {
152-
print("Download error: %@" + String(describing: error))
153-
// uncomment to print that it finished
154-
// } else {
155-
// print("Task finished: %@" )//+ task)
144+
DebugLogManager.shared.debug(error: "Download error: \(String(describing: error))", log: .app, date: Date())
156145
}
157146
}
158147
}

0 commit comments

Comments
 (0)