Skip to content

Commit eb8cbb0

Browse files
committed
- Added user-configurable graph style toggle (line graph or filled graph)
- Added some DFU view updates to make it more clear when the transfer is complete. - Default status view graph is now based on the last viewed graph, rather than always defaulting to the heart rate graph - Added onboarding screen, which lays the groundwork for a "what's new" screen after updates. I hate hunting for new features...
1 parent c6ff2c0 commit eb8cbb0

19 files changed

Lines changed: 382 additions & 186 deletions

Infini-iOS.xcodeproj/project.pbxproj

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
263B20C526CEB46800676BF0 /* SwiftUICharts in Frameworks */ = {isa = PBXBuildFile; productRef = 263B20C426CEB46800676BF0 /* SwiftUICharts */; };
1515
263B20C726CF07BB00676BF0 /* DFUProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 263B20C626CF07BB00676BF0 /* DFUProgressBar.swift */; };
1616
2644261226DC093D009BD54A /* SetTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2644261126DC093D009BD54A /* SetTime.swift */; };
17+
2644261626DC1D8E009BD54A /* Onboarding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2644261526DC1D8E009BD54A /* Onboarding.swift */; };
1718
264BFE4226BC51CE0050A223 /* Infini_iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 264BFE4126BC51CE0050A223 /* Infini_iOSApp.swift */; };
1819
264BFE4426BC51CE0050A223 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 264BFE4326BC51CE0050A223 /* ContentView.swift */; };
1920
264BFE4626BC51CF0050A223 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 264BFE4526BC51CF0050A223 /* Assets.xcassets */; };
@@ -26,6 +27,8 @@
2627
264BFE7826BCAAC00050A223 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 264BFE7726BCAAC00050A223 /* README.md */; };
2728
264DB80B26C62ED600E812C3 /* SideMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 264DB80A26C62ED600E812C3 /* SideMenu.swift */; };
2829
264DB80D26C633CF00E812C3 /* PageSwitcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 264DB80C26C633CF00E812C3 /* PageSwitcher.swift */; };
30+
2675CA5726DC447500967E4D /* SheetManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2675CA5626DC447500967E4D /* SheetManager.swift */; };
31+
2675CA5A26DC81AA00967E4D /* DFUComplete.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2675CA5926DC81AA00967E4D /* DFUComplete.swift */; };
2932
26A6314D26BEFD2C005AE404 /* MusicController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6314C26BEFD2C005AE404 /* MusicController.swift */; };
3033
26A6315226BF45E0005AE404 /* BLEMusic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6315126BF45E0005AE404 /* BLEMusic.swift */; };
3134
26A6315526C0297A005AE404 /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6315426C0297A005AE404 /* Notifications.swift */; };
@@ -67,6 +70,7 @@
6770
263B20BB26CDF20400676BF0 /* BatteryChart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryChart.swift; sourceTree = "<group>"; };
6871
263B20C626CF07BB00676BF0 /* DFUProgressBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFUProgressBar.swift; sourceTree = "<group>"; };
6972
2644261126DC093D009BD54A /* SetTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetTime.swift; sourceTree = "<group>"; };
73+
2644261526DC1D8E009BD54A /* Onboarding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Onboarding.swift; sourceTree = "<group>"; };
7074
264BFE3E26BC51CE0050A223 /* Infini-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Infini-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
7175
264BFE4126BC51CE0050A223 /* Infini_iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Infini_iOSApp.swift; sourceTree = "<group>"; };
7276
264BFE4326BC51CE0050A223 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -86,6 +90,8 @@
8690
264DB80A26C62ED600E812C3 /* SideMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenu.swift; sourceTree = "<group>"; };
8791
264DB80C26C633CF00E812C3 /* PageSwitcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageSwitcher.swift; sourceTree = "<group>"; };
8892
2656FD9A26D1B30C001EF20C /* PrivacyPolicy.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = PrivacyPolicy.md; sourceTree = "<group>"; };
93+
2675CA5626DC447500967E4D /* SheetManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SheetManager.swift; sourceTree = "<group>"; };
94+
2675CA5926DC81AA00967E4D /* DFUComplete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFUComplete.swift; sourceTree = "<group>"; };
8995
26A6314C26BEFD2C005AE404 /* MusicController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicController.swift; sourceTree = "<group>"; };
9096
26A6315126BF45E0005AE404 /* BLEMusic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLEMusic.swift; sourceTree = "<group>"; };
9197
26A6315426C0297A005AE404 /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
@@ -139,13 +145,14 @@
139145
path = "Status View Components";
140146
sourceTree = "<group>";
141147
};
142-
263B20C826CF07BE00676BF0 /* DFU */ = {
148+
263B20C826CF07BE00676BF0 /* DFU View */ = {
143149
isa = PBXGroup;
144150
children = (
145151
26A6315F26C4BC25005AE404 /* DFUView.swift */,
152+
2675CA5926DC81AA00967E4D /* DFUComplete.swift */,
146153
263B20C626CF07BB00676BF0 /* DFUProgressBar.swift */,
147154
);
148-
path = DFU;
155+
path = "DFU View";
149156
sourceTree = "<group>";
150157
};
151158
264BFE3526BC51CE0050A223 = {
@@ -221,16 +228,26 @@
221228
isa = PBXGroup;
222229
children = (
223230
264DB80A26C62ED600E812C3 /* SideMenu.swift */,
231+
2644261526DC1D8E009BD54A /* Onboarding.swift */,
224232
26A6316226C4C6D6005AE404 /* BLEConnectView.swift */,
225233
26F426EE26C72D7D00D0866B /* BLEStatusView.swift */,
226-
263B20C826CF07BE00676BF0 /* DFU */,
227234
26D7816F26CA004B00BBF555 /* SettingsView.swift */,
228-
264DB80C26C633CF00E812C3 /* PageSwitcher.swift */,
235+
263B20C826CF07BE00676BF0 /* DFU View */,
236+
2675CA5826DC5C9400967E4D /* View Utilities */,
229237
263B20B626CD673D00676BF0 /* Status View Components */,
230238
);
231239
path = "View Components";
232240
sourceTree = "<group>";
233241
};
242+
2675CA5826DC5C9400967E4D /* View Utilities */ = {
243+
isa = PBXGroup;
244+
children = (
245+
2675CA5626DC447500967E4D /* SheetManager.swift */,
246+
264DB80C26C633CF00E812C3 /* PageSwitcher.swift */,
247+
);
248+
path = "View Utilities";
249+
sourceTree = "<group>";
250+
};
234251
26A6314E26BF0FA2005AE404 /* Music */ = {
235252
isa = PBXGroup;
236253
children = (
@@ -442,14 +459,17 @@
442459
26A6315226BF45E0005AE404 /* BLEMusic.swift in Sources */,
443460
26F426EF26C72D7D00D0866B /* BLEStatusView.swift in Sources */,
444461
264BFE7426BC526C0050A223 /* BLEManager.swift in Sources */,
462+
2644261626DC1D8E009BD54A /* Onboarding.swift in Sources */,
445463
263B20C726CF07BB00676BF0 /* DFUProgressBar.swift in Sources */,
446464
26A6314D26BEFD2C005AE404 /* MusicController.swift in Sources */,
447465
264DB80B26C62ED600E812C3 /* SideMenu.swift in Sources */,
448466
264DB80D26C633CF00E812C3 /* PageSwitcher.swift in Sources */,
449467
264BFE4226BC51CE0050A223 /* Infini_iOSApp.swift in Sources */,
468+
2675CA5726DC447500967E4D /* SheetManager.swift in Sources */,
450469
26318B1626CB27E70036051E /* Infini_iOS.xcdatamodeld in Sources */,
451470
264BFE7626BC52720050A223 /* HexStringToData.swift in Sources */,
452471
26D7817326CAB27800BBF555 /* WatchNotificationsView.swift in Sources */,
472+
2675CA5A26DC81AA00967E4D /* DFUComplete.swift in Sources */,
453473
26D7817526CAB79200BBF555 /* PhoneNotificationsView.swift in Sources */,
454474
263B20BC26CDF20400676BF0 /* BatteryChart.swift in Sources */,
455475
2644261226DC093D009BD54A /* SetTime.swift in Sources */,

Infini-iOS/BLE/BLEDelegates.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ extension BLEManager: CBPeripheralDelegate {
8686

8787
case timeCBUUID:
8888
// convert string with hex value of time to actual hex data, then write to PineTime
89-
peripheral.writeValue(SetTime().currentTime().hexData /*currentTime().hexData*/, for: characteristic, type: .withResponse)
89+
do {
90+
try peripheral.writeValue(SetTime().currentTime().hexData, for: characteristic, type: .withResponse)
91+
} catch SetTime.SetTimeError.nilValue {
92+
setTimeError = true
93+
} catch {
94+
print("Unexpected error: \(error).")
95+
}
9096

9197
case firmwareCBUUID:
9298
firmwareVersion = String(decoding: characteristic.value!, as: UTF8.self)

Infini-iOS/BLE/BLEManager.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
4242
@Published var hrmChartDataPoints: [LineChartDataPoint] = []
4343
@Published var batChartDataPoints: [LineChartDataPoint] = []
4444
@Published var firmwareVersion: String = "Disconnected"
45+
@Published var setTimeError = false
46+
@Published var blePermissions: Bool!
4547

4648
// Selecting and connecting variables
4749
@Published var peripherals = [Peripheral]() // used to print human-readable device names to UI in selection process
@@ -70,7 +72,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
7072

7173
myCentral = CBCentralManager(delegate: self, queue: nil)
7274
myCentral.delegate = self
73-
75+
if myCentral.state == .unauthorized {
76+
blePermissions = false
77+
} else {
78+
blePermissions = true
79+
}
7480
}
7581

7682
func startScanning() {
@@ -109,14 +115,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
109115
}
110116
}
111117

118+
119+
112120
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
113121

114122
var peripheralName: String!
115-
116-
//for item in advertisementData { // DEBUG
117-
// print(item)
118-
//}
119-
120123
// TODO: Recreate the process below.
121124
/*
122125
- the hash I'm using is only unique between PineTimes because the peripheral struct includes an incrementing ID number that's part of the hash.
@@ -128,11 +131,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
128131
if let name = advertisementData[CBAdvertisementDataLocalNameKey] as? String {
129132
peripheralName = name
130133
let devUUIDString: String = peripheral.identifier.uuidString
131-
//setAutoconnectUUID = devUUIDString
132134
let devUUID: CBUUID = CBUUID(string: devUUIDString)
133135
let newPeripheral = Peripheral(id: peripheralDictionary.count, name: peripheralName, rssi: RSSI.intValue, peripheralHash: peripheral.hash, deviceUUID: devUUID)
134-
135-
//print(peripheralName + ": " + String(peripheral.identifier.uuidString))
136+
136137

137138
// handle autoconnect defaults
138139
let settings = UserDefaults.standard
@@ -147,8 +148,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
147148
if !peripherals.contains(where: {$0.deviceUUID == newPeripheral.deviceUUID}) {
148149
peripherals.append(newPeripheral)
149150
peripheralDictionary[newPeripheral.peripheralHash] = peripheral
150-
151-
//print(newPeripheral, "added to list")
152151
}
153152
}
154153
}

Infini-iOS/ContentView.swift

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ struct ContentView: View {
1414
@EnvironmentObject var pageSwitcher: PageSwitcher
1515
@EnvironmentObject var bleManager: BLEManager
1616
@ObservedObject var batteryNotifications = BatteryNotifications()
17+
@ObservedObject var sheetManager = SheetManager()
1718

1819
@AppStorage("autoconnect") var autoconnect: Bool = false
1920
@AppStorage("autoconnectUUID") var autoconnectUUID: String = ""
2021
@AppStorage("batteryNotification") var batteryNotification: Bool = false
22+
@AppStorage("onboarding") var onboarding: Bool = true
2123

2224

2325
init() {
@@ -47,9 +49,14 @@ struct ContentView: View {
4749
GeometryReader { geometry in
4850
ZStack(alignment: .leading) {
4951
MainView()
50-
.sheet(isPresented: $pageSwitcher.connectViewLoad, content: {
51-
// pop-up menu to connect to a device
52-
Connect().environmentObject(self.bleManager)
52+
.sheet(isPresented: $sheetManager.showSheet, content: {
53+
sheetManager.setView(isOnboarding: onboarding, bleManager: bleManager)
54+
.onDisappear {
55+
if onboarding {
56+
onboarding = false
57+
sheetManager.showSheet = true
58+
}
59+
}
5360
})
5461
.onChange(of: bleManager.batteryLevel) { bat in
5562
batteryNotifications.notify(bat: Int(bat), bleManager: bleManager)
@@ -69,24 +76,27 @@ struct ContentView: View {
6976
}
7077
}
7178
})
72-
79+
// alert to handle errors thrown by SetTime
80+
.alert(isPresented: $bleManager.setTimeError, content: {
81+
Alert(title: Text("Failed to Set Time"), message: Text("There was an issue setting the time on your watch. Please disconnect from the watch, and then reconnect."), dismissButton: .default(Text("Dismiss")))
82+
})
83+
7384
.onAppear(){
7485
// if autoconnect is set, start scan ASAP, but give bleManager half a second to start up
7586
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
7687
if autoconnect && bleManager.isSwitchedOn {
7788
self.bleManager.startScanning()
7889
}
90+
91+
if (autoconnect && autoconnectUUID == "") || (!autoconnect && !bleManager.isConnectedToPinetime) {
92+
sheetManager.sheetSelection = .connect
93+
sheetManager.showSheet = true
94+
}
7995
})
80-
if (autoconnect && autoconnectUUID == "") || (!autoconnect && !bleManager.isConnectedToPinetime) {
81-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
82-
withAnimation {
83-
pageSwitcher.connectViewLoad = true
84-
}
85-
})
86-
}
8796
}
8897
if self.pageSwitcher.showMenu {
8998
SideMenu(isOpen: self.$pageSwitcher.showMenu)
99+
.environmentObject(sheetManager)
90100
.frame(width: geometry.size.width/2)
91101
.transition(.move(edge: .leading))
92102
.ignoresSafeArea()
@@ -137,5 +147,6 @@ struct ContentView_Previews: PreviewProvider {
137147
ContentView()
138148
.environmentObject(PageSwitcher())
139149
.environmentObject(BLEManager())
150+
.environmentObject(DFU_Updater())
140151
}
141152
}

Infini-iOS/DFU/DFU.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class DFU_Updater: ObservableObject, DFUServiceDelegate, DFUProgressDelegate, Lo
1717

1818
@Published var dfuState: String = ""
1919
@Published var transferFailed = false
20+
@Published var transferCompleted = false
2021
@Published var percentComplete: Double = 0
2122

2223

@@ -51,6 +52,12 @@ class DFU_Updater: ObservableObject, DFUServiceDelegate, DFUProgressDelegate, Lo
5152
// stubs added automatically.
5253
func dfuStateDidChange(to state: DFUState) {
5354
dfuState = state.description()
55+
print(dfuState)
56+
if state.rawValue == 6 {
57+
print("hooray")
58+
transferCompleted = true
59+
print(transferCompleted)
60+
}
5461
}
5562

5663
func dfuError(_ error: DFUError, didOccurWithMessage message: String) {

Infini-iOS/Infini_iOSApp.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct Infini_iOSApp: App {
1717
.environment(\.managedObjectContext, persistenceController.container.viewContext)
1818
.environmentObject(PageSwitcher())
1919
.environmentObject(BLEManager())
20+
.environmentObject(DFU_Updater())
2021
}
2122
}
2223
}

Infini-iOS/View Components/BLEStatusView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct StatusView: View {
3131
.padding()
3232
.padding(.vertical, 7)
3333
.frame(maxWidth: .infinity, alignment: .center)
34-
.background(colorScheme == .dark ? Color.darkGray : Color.gray)
34+
.background(colorScheme == .dark ? Color.darkGray : Color.lightGray)
3535
.foregroundColor(Color.white)
3636
.cornerRadius(10)
3737
.padding(.horizontal, 20)
@@ -42,7 +42,7 @@ struct StatusView: View {
4242
.padding()
4343
.padding(.vertical, 7)
4444
.frame(maxWidth: .infinity, alignment: .center)
45-
.background(colorScheme == .dark ? Color.gray : Color.lightGray)
45+
.background(colorScheme == .dark ? Color.darkGray : Color.gray)
4646
.foregroundColor(Color.white)
4747
.cornerRadius(10)
4848
.padding(.horizontal, 20)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// DFUComplete.swift
3+
// Infini-iOS
4+
//
5+
// Created by Alex Emry on 8/29/21.
6+
//
7+
//
8+
9+
10+
import SwiftUI
11+
12+
struct DFUComplete: View {
13+
14+
var body: some View {
15+
Text("Transfer Completed!")
16+
.font(.largeTitle)
17+
.padding()
18+
.foregroundColor(Color.white)
19+
.background(Color.green)
20+
}
21+
}

Infini-iOS/View Components/DFU/DFUProgressBar.swift renamed to Infini-iOS/View Components/DFU View/DFUProgressBar.swift

File renamed without changes.

0 commit comments

Comments
 (0)