Skip to content

Commit c25faa8

Browse files
authored
Merge pull request #6 from xan-m/dfuUpdates
Dfu updates
2 parents de06d90 + 391d961 commit c25faa8

10 files changed

Lines changed: 554 additions & 97 deletions

File tree

Infini-iOS.xcodeproj/project.pbxproj

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 52;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -18,9 +18,17 @@
1818
264BFE7626BC52720050A223 /* HexStringToData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 264BFE7526BC52720050A223 /* HexStringToData.swift */; };
1919
264BFE7826BCAAC00050A223 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 264BFE7726BCAAC00050A223 /* README.md */; };
2020
264BFE7B26BCB9510050A223 /* Infini_iOS.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 264BFE7926BCB9510050A223 /* Infini_iOS.xcdatamodeld */; };
21+
264DB80B26C62ED600E812C3 /* SideMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 264DB80A26C62ED600E812C3 /* SideMenu.swift */; };
22+
264DB80D26C633CF00E812C3 /* PageSwitcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 264DB80C26C633CF00E812C3 /* PageSwitcher.swift */; };
2123
26A6314D26BEFD2C005AE404 /* MusicController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6314C26BEFD2C005AE404 /* MusicController.swift */; };
2224
26A6315226BF45E0005AE404 /* BLEMusic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6315126BF45E0005AE404 /* BLEMusic.swift */; };
2325
26A6315526C0297A005AE404 /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6315426C0297A005AE404 /* Notifications.swift */; };
26+
26A6315B26C49841005AE404 /* DFU.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6315A26C49841005AE404 /* DFU.swift */; };
27+
26A6315E26C498B7005AE404 /* NordicDFU in Frameworks */ = {isa = PBXBuildFile; productRef = 26A6315D26C498B7005AE404 /* NordicDFU */; };
28+
26A6316026C4BC25005AE404 /* DFUView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6315F26C4BC25005AE404 /* DFUView.swift */; };
29+
26A6316326C4C6D6005AE404 /* BLEConnectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A6316226C4C6D6005AE404 /* BLEConnectView.swift */; };
30+
26F426EF26C72D7D00D0866B /* BLEStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26F426EE26C72D7D00D0866B /* BLEStatusView.swift */; };
31+
26F426F226C8468300D0866B /* SwiftUTI in Frameworks */ = {isa = PBXBuildFile; productRef = 26F426F126C8468300D0866B /* SwiftUTI */; };
2432
/* End PBXBuildFile section */
2533

2634
/* Begin PBXContainerItemProxy section */
@@ -58,16 +66,24 @@
5866
264BFE7526BC52720050A223 /* HexStringToData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HexStringToData.swift; sourceTree = "<group>"; };
5967
264BFE7726BCAAC00050A223 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; };
6068
264BFE7A26BCB9510050A223 /* Infini_iOS.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Infini_iOS.xcdatamodel; sourceTree = "<group>"; };
69+
264DB80A26C62ED600E812C3 /* SideMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenu.swift; sourceTree = "<group>"; };
70+
264DB80C26C633CF00E812C3 /* PageSwitcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageSwitcher.swift; sourceTree = "<group>"; };
6171
26A6314C26BEFD2C005AE404 /* MusicController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MusicController.swift; sourceTree = "<group>"; };
6272
26A6315126BF45E0005AE404 /* BLEMusic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLEMusic.swift; sourceTree = "<group>"; };
6373
26A6315426C0297A005AE404 /* Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = "<group>"; };
74+
26A6315A26C49841005AE404 /* DFU.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFU.swift; sourceTree = "<group>"; };
75+
26A6315F26C4BC25005AE404 /* DFUView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DFUView.swift; sourceTree = "<group>"; };
76+
26A6316226C4C6D6005AE404 /* BLEConnectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLEConnectView.swift; sourceTree = "<group>"; };
77+
26F426EE26C72D7D00D0866B /* BLEStatusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BLEStatusView.swift; sourceTree = "<group>"; };
6478
/* End PBXFileReference section */
6579

6680
/* Begin PBXFrameworksBuildPhase section */
6781
264BFE3B26BC51CE0050A223 /* Frameworks */ = {
6882
isa = PBXFrameworksBuildPhase;
6983
buildActionMask = 2147483647;
7084
files = (
85+
26A6315E26C498B7005AE404 /* NordicDFU in Frameworks */,
86+
26F426F226C8468300D0866B /* SwiftUTI in Frameworks */,
7187
);
7288
runOnlyForDeploymentPostprocessing = 0;
7389
};
@@ -114,8 +130,10 @@
114130
children = (
115131
264BFE4126BC51CE0050A223 /* Infini_iOSApp.swift */,
116132
264BFE4326BC51CE0050A223 /* ContentView.swift */,
133+
264DB80926C62EAC00E812C3 /* View Components */,
117134
264BFE4526BC51CF0050A223 /* Assets.xcassets */,
118-
264BFE7326BC526C0050A223 /* BLEManager.swift */,
135+
26A6316126C4C6BB005AE404 /* BLE */,
136+
26A6315926C49839005AE404 /* DFU */,
119137
26A6315326BF5FD6005AE404 /* Notifications */,
120138
26A6314E26BF0FA2005AE404 /* Music */,
121139
264BFE7526BC52720050A223 /* HexStringToData.swift */,
@@ -153,6 +171,15 @@
153171
path = "Infini-iOSUITests";
154172
sourceTree = "<group>";
155173
};
174+
264DB80926C62EAC00E812C3 /* View Components */ = {
175+
isa = PBXGroup;
176+
children = (
177+
264DB80A26C62ED600E812C3 /* SideMenu.swift */,
178+
264DB80C26C633CF00E812C3 /* PageSwitcher.swift */,
179+
);
180+
path = "View Components";
181+
sourceTree = "<group>";
182+
};
156183
26A6314E26BF0FA2005AE404 /* Music */ = {
157184
isa = PBXGroup;
158185
children = (
@@ -170,6 +197,25 @@
170197
path = Notifications;
171198
sourceTree = "<group>";
172199
};
200+
26A6315926C49839005AE404 /* DFU */ = {
201+
isa = PBXGroup;
202+
children = (
203+
26A6315F26C4BC25005AE404 /* DFUView.swift */,
204+
26A6315A26C49841005AE404 /* DFU.swift */,
205+
);
206+
path = DFU;
207+
sourceTree = "<group>";
208+
};
209+
26A6316126C4C6BB005AE404 /* BLE */ = {
210+
isa = PBXGroup;
211+
children = (
212+
26A6316226C4C6D6005AE404 /* BLEConnectView.swift */,
213+
26F426EE26C72D7D00D0866B /* BLEStatusView.swift */,
214+
264BFE7326BC526C0050A223 /* BLEManager.swift */,
215+
);
216+
path = BLE;
217+
sourceTree = "<group>";
218+
};
173219
/* End PBXGroup section */
174220

175221
/* Begin PBXNativeTarget section */
@@ -186,6 +232,10 @@
186232
dependencies = (
187233
);
188234
name = "Infini-iOS";
235+
packageProductDependencies = (
236+
26A6315D26C498B7005AE404 /* NordicDFU */,
237+
26F426F126C8468300D0866B /* SwiftUTI */,
238+
);
189239
productName = "Infini-iOS";
190240
productReference = 264BFE3E26BC51CE0050A223 /* Infini-iOS.app */;
191241
productType = "com.apple.product-type.application";
@@ -257,6 +307,10 @@
257307
Base,
258308
);
259309
mainGroup = 264BFE3526BC51CE0050A223;
310+
packageReferences = (
311+
26A6315C26C498B7005AE404 /* XCRemoteSwiftPackageReference "IOS-DFU-Library" */,
312+
26F426F026C8468300D0866B /* XCRemoteSwiftPackageReference "SwiftUTI" */,
313+
);
260314
productRefGroup = 264BFE3F26BC51CE0050A223 /* Products */;
261315
projectDirPath = "";
262316
projectRoot = "";
@@ -304,11 +358,17 @@
304358
264BFE4B26BC51CF0050A223 /* Persistence.swift in Sources */,
305359
264BFE4426BC51CE0050A223 /* ContentView.swift in Sources */,
306360
26A6315526C0297A005AE404 /* Notifications.swift in Sources */,
361+
26A6316026C4BC25005AE404 /* DFUView.swift in Sources */,
307362
26A6315226BF45E0005AE404 /* BLEMusic.swift in Sources */,
363+
26F426EF26C72D7D00D0866B /* BLEStatusView.swift in Sources */,
308364
264BFE7426BC526C0050A223 /* BLEManager.swift in Sources */,
309365
26A6314D26BEFD2C005AE404 /* MusicController.swift in Sources */,
366+
264DB80B26C62ED600E812C3 /* SideMenu.swift in Sources */,
367+
264DB80D26C633CF00E812C3 /* PageSwitcher.swift in Sources */,
310368
264BFE4226BC51CE0050A223 /* Infini_iOSApp.swift in Sources */,
311369
264BFE7626BC52720050A223 /* HexStringToData.swift in Sources */,
370+
26A6316326C4C6D6005AE404 /* BLEConnectView.swift in Sources */,
371+
26A6315B26C49841005AE404 /* DFU.swift in Sources */,
312372
);
313373
runOnlyForDeploymentPostprocessing = 0;
314374
};
@@ -631,6 +691,38 @@
631691
};
632692
/* End XCConfigurationList section */
633693

694+
/* Begin XCRemoteSwiftPackageReference section */
695+
26A6315C26C498B7005AE404 /* XCRemoteSwiftPackageReference "IOS-DFU-Library" */ = {
696+
isa = XCRemoteSwiftPackageReference;
697+
repositoryURL = "https://github.com/NordicSemiconductor/IOS-DFU-Library.git";
698+
requirement = {
699+
branch = master;
700+
kind = branch;
701+
};
702+
};
703+
26F426F026C8468300D0866B /* XCRemoteSwiftPackageReference "SwiftUTI" */ = {
704+
isa = XCRemoteSwiftPackageReference;
705+
repositoryURL = "git@github.com:mkeiser/SwiftUTI.git";
706+
requirement = {
707+
branch = master;
708+
kind = branch;
709+
};
710+
};
711+
/* End XCRemoteSwiftPackageReference section */
712+
713+
/* Begin XCSwiftPackageProductDependency section */
714+
26A6315D26C498B7005AE404 /* NordicDFU */ = {
715+
isa = XCSwiftPackageProductDependency;
716+
package = 26A6315C26C498B7005AE404 /* XCRemoteSwiftPackageReference "IOS-DFU-Library" */;
717+
productName = NordicDFU;
718+
};
719+
26F426F126C8468300D0866B /* SwiftUTI */ = {
720+
isa = XCSwiftPackageProductDependency;
721+
package = 26F426F026C8468300D0866B /* XCRemoteSwiftPackageReference "SwiftUTI" */;
722+
productName = SwiftUTI;
723+
};
724+
/* End XCSwiftPackageProductDependency section */
725+
634726
/* Begin XCVersionGroup section */
635727
264BFE7926BCB9510050A223 /* Infini_iOS.xcdatamodeld */ = {
636728
isa = XCVersionGroup;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// BLEView.swift
3+
// Infini-iOS
4+
//
5+
// Created by xan-m on 8/11/21.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
struct Connect: View {
12+
13+
//@ObservedObject var bleManager = BLEManager()
14+
@EnvironmentObject var bleManager: BLEManager
15+
16+
var body: some View {
17+
18+
VStack (spacing: 10){
19+
Text("Available Devices")
20+
.font(.largeTitle)
21+
.frame(maxWidth: .infinity, alignment: .center)
22+
.padding(30)
23+
List(bleManager.peripherals) { peripheral in
24+
HStack {
25+
Button(action: {
26+
self.bleManager.deviceToConnect = peripheral.peripheralHash
27+
self.bleManager.connect(peripheral: self.bleManager.peripheralDictionary[peripheral.peripheralHash]!)
28+
}) {
29+
Text(peripheral.name)
30+
}
31+
}
32+
}
33+
34+
Spacer()
35+
36+
37+
Button(action: {
38+
self.bleManager.startScanning()
39+
}) {
40+
Text("Scan and Connect")
41+
.padding(10)
42+
}
43+
.background(Color.gray)
44+
.foregroundColor(Color.white)
45+
.cornerRadius(5)
46+
Button(action: {
47+
self.bleManager.stopScanning()
48+
}) {
49+
Text("Stop Scanning")
50+
.padding(10)
51+
}
52+
.background(Color.gray)
53+
.foregroundColor(Color.white)
54+
.cornerRadius(5)
55+
Button(action: {
56+
self.bleManager.disconnect()
57+
}) {
58+
Text("Disconnect")
59+
.padding(10)
60+
}
61+
.background(Color.gray)
62+
.foregroundColor(Color.white)
63+
.cornerRadius(5)
64+
}.padding()
65+
}
66+
}
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
2626
@Published var isSwitchedOn = false // for now this is used to display if bluetooth is on in the main app screen. maybe an alert in the future?
2727
@Published var isScanning = false // another UI flag. Probably not necessary for anything but debugging. I dunno maybe a little swirly animation or something could be triggered by this
2828
@Published var isConnectedToPinetime = false // another flag published to update UI stuff. Can probably be implemented better in the future
29-
@Published var heartBPM: String! // published var to communicate the HRM data to the UI. I don't know enough about Swift to know if this is a bad idea.
30-
@Published var batteryLevel: String! // Same as heartBPM but for battery data
29+
@Published var heartBPM: String = "Disconnected" // published var to communicate the HRM data to the UI.
30+
@Published var batteryLevel: String = "Disconnected" // Same as heartBPM but for battery data
31+
@Published var firmwareVersion: String = "Disconnected"
3132

3233
// Selecting and connecting variables
3334
@Published var peripherals = [Peripheral]() // used to print human-readable device names to UI in selection process
@@ -40,6 +41,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
4041
let batCBUUID = CBUUID(string: "2A19")
4142
let timeCBUUID = CBUUID(string: "2A2B")
4243
let notifyCBUUID = CBUUID(string: "2A46")
44+
let firmwareCBUUID = CBUUID(string: "2A26")
4345
let musicControlCBUUID = CBUUID(string: "00000001-78FC-48FE-8E23-433B3A1942D0")
4446
let musicTrackCBUUID = CBUUID(string: "00000004-78FC-48FE-8E23-433B3A1942D0")
4547
let musicArtistCBUUID = CBUUID(string: "00000003-78FC-48FE-8E23-433B3A1942D0")
@@ -58,6 +60,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
5860
myCentral.delegate = self
5961
heartBPM = "Reading"
6062
batteryLevel = "Reading"
63+
firmwareVersion = "Reading"
64+
6165
}
6266

6367
func startScanning() {
@@ -211,7 +215,9 @@ extension BLEManager: CBPeripheralDelegate {
211215
case timeCBUUID:
212216
// convert string with hex value of time to actual hex data, then write to PineTime
213217
peripheral.writeValue(currentTime().hexData, for: characteristic, type: .withResponse)
214-
218+
219+
case firmwareCBUUID:
220+
firmwareVersion = String(decoding: characteristic.value!, as: UTF8.self)
215221
default:
216222
break
217223
}

Infini-iOS/BLE/BLEStatusView.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// BLEStatusView.swift
3+
// Infini-iOS
4+
//
5+
// Created by xan-m on 8/13/21.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
struct DeviceView: View {
12+
13+
@EnvironmentObject var bleManager: BLEManager
14+
15+
var body: some View {
16+
VStack (spacing: 10){
17+
Text("InfiniTime Status")
18+
.font(.largeTitle)
19+
.frame(maxWidth: .infinity, alignment: .center)
20+
.padding(30)
21+
22+
HStack (spacing: 10){
23+
Text("Heart Rate: ")
24+
.font(.title)
25+
Text(bleManager.heartBPM)
26+
.font(.title)
27+
.foregroundColor(.red)
28+
}
29+
30+
HStack (spacing: 10){
31+
Text("Battery Level: ")
32+
.font(.title)
33+
Text(bleManager.batteryLevel)
34+
.font(.title)
35+
.foregroundColor(.red)
36+
}
37+
38+
Spacer()
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)