Skip to content

Commit

Permalink
Merge pull request #512 from korzonkiee/chore/update-ios-example-app
Browse files Browse the repository at this point in the history
Update iOS example app to work with Polar SDK 5.9.0
  • Loading branch information
pth-pe-gh authored Dec 16, 2024
2 parents e54c415 + 2f3f23f commit 5df8dee
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/example-ios/iosBleSdkTestApp/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ platform :ios, '15.0'
use_frameworks!

target 'iosBleSdkTestApp' do
pod 'PolarBleSdk', '5.5.0'
pod 'PolarBleSdk', '5.9.0'
end
22 changes: 15 additions & 7 deletions examples/example-ios/iosBleSdkTestApp/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
PODS:
- PolarBleSdk (5.5.0):
- Alamofire (5.8.1)
- PolarBleSdk (5.9.0):
- Alamofire (~> 5.8.1)
- RxSwift (~> 6.5.0)
- SwiftProtobuf (~> 1.0)
- Zip (~> 2.1.2)
- RxSwift (6.5.0)
- SwiftProtobuf (1.23.0)
- SwiftProtobuf (1.28.2)
- Zip (2.1.2)

DEPENDENCIES:
- PolarBleSdk (= 5.5.0)
- PolarBleSdk (= 5.9.0)

SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- Alamofire
- PolarBleSdk
- RxSwift
- SwiftProtobuf
- Zip

SPEC CHECKSUMS:
PolarBleSdk: 2551160f3dcba0207723fc466a275e2d3aeda01f
Alamofire: 3ca42e259043ee0dc5c0cdd76c4bc568b8e42af7
PolarBleSdk: 2a5eec733ea2203e22a97e127a3ab55c70c74b49
RxSwift: 5710a9e6b17f3c3d6e40d6e559b9fa1e813b2ef8
SwiftProtobuf: b70d65f419fbfe61a2d58003456ca5da58e337d6
SwiftProtobuf: 4dbaffec76a39a8dc5da23b40af1a5dc01a4c02d
Zip: b3fef584b147b6e582b2256a9815c897d60ddc67

PODFILE CHECKSUM: aa65d965a6f6e7d086dc200b60385c49e57e8f2e
PODFILE CHECKSUM: 95719617f41d543374d1e1a785f4fc8c4acadce5

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ class PolarBleSdkManager : ObservableObject {
ppiStreamStart()
case .hr:
hrStreamStart()
case .temperature:
temperatureStreamStart(settings: PolarSensorSetting(polarSensorSettings))
case .pressure:
pressureStreamStart(settings: PolarSensorSetting(polarSensorSettings))
}
}

Expand Down Expand Up @@ -392,6 +396,15 @@ class PolarBleSdkManager : ObservableObject {
self.offlineRecordingData.dataSize = offlineRecordingEntry.size
self.offlineRecordingData.downLoadTime = elapsedTime
}
case .temperatureOfflineRecordingData(let data, startTime: let startTime):
NSLog("TEMP data received")
Task { @MainActor in
self.offlineRecordingData.startTime = startTime
self.offlineRecordingData.usedSettings = nil
self.offlineRecordingData.data = dataHeaderString(.temperature) + dataToString(data)
self.offlineRecordingData.dataSize = offlineRecordingEntry.size
self.offlineRecordingData.downLoadTime = elapsedTime
}
}
Task { @MainActor in
self.offlineRecordingData.loadState = OfflineRecordingDataLoadingState.success
Expand Down Expand Up @@ -751,6 +764,91 @@ class PolarBleSdkManager : ObservableObject {
}
}

func temperatureStreamStart(settings: PolarBleSdk.PolarSensorSetting) {
if case .connected(let deviceId) = deviceConnectionState {

Task { @MainActor in
self.onlineStreamingFeature.isStreaming[.temperature] = OnlineStreamingState.inProgress
}

let logFile: (url: URL, fileHandle: FileHandle)? = openOnlineStreamLogFile(type: .temperature)

onlineStreamingDisposables[.temperature] = api.startTemperatureStreaming(deviceId, settings: settings)
.do(onDispose: {
if let fileHandle = logFile?.fileHandle {
self.closeOnlineStreamLogFile(fileHandle)
}
Task { @MainActor in
self.onlineStreamingFeature.isStreaming[.temperature] = OnlineStreamingState.success(url: logFile?.url)
}
})
.subscribe{ e in
switch e {
case .next(let data):
if let fileHandle = logFile?.fileHandle {
self.writeOnlineStreamLogFile(fileHandle, data)
}

for item in data.samples {
NSLog("Temperature °C: \(item.temperature) timeStamp: \(item.timeStamp)")
}
case .error(let err):
NSLog("Temperature stream failed: \(err)")
if let fileHandle = logFile?.fileHandle {
self.writeErrorOnlineStreamLogFile(fileHandle, err)
}
case .completed:
NSLog("Temperature stream completed")
}
}
} else {
NSLog("Device is not connected \(deviceConnectionState)")
}
}

func pressureStreamStart(settings: PolarBleSdk.PolarSensorSetting) {
if case .connected(let deviceId) = deviceConnectionState {

Task { @MainActor in
self.onlineStreamingFeature.isStreaming[.pressure] = OnlineStreamingState.inProgress
}

let logFile: (url: URL, fileHandle: FileHandle)? = openOnlineStreamLogFile(type: .pressure)

onlineStreamingDisposables[.pressure] = api.startPressureStreaming(deviceId, settings: settings)
.do(onDispose: {
if let fileHandle = logFile?.fileHandle {
self.closeOnlineStreamLogFile(fileHandle)
}
Task { @MainActor in
self.onlineStreamingFeature.isStreaming[.pressure] = OnlineStreamingState.success(url: logFile?.url)
}
})
.subscribe{ e in
switch e {
case .next(let data):
if let fileHandle = logFile?.fileHandle {
self.writeOnlineStreamLogFile(fileHandle, data)
}

for item in data.samples {
NSLog("Pressure hPa: \(item.pressure) timeStamp: \(item.timeStamp)")
}
case .error(let err):
NSLog("Pressure stream failed: \(err)")
if let fileHandle = logFile?.fileHandle {
self.writeErrorOnlineStreamLogFile(fileHandle, err)
}
case .completed:
NSLog("Pressure stream completed")
}
}
} else {
NSLog("Device is not connected \(deviceConnectionState)")
}
}


func sdkModeToggle() {
if case .connected(let deviceId) = deviceConnectionState {
if self.sdkModeFeature.isEnabled {
Expand Down Expand Up @@ -1067,6 +1165,10 @@ class PolarBleSdkManager : ObservableObject {
result = "TIMESTAMP X(Gauss) Y(Gauss) Z(Gauss)\n"
case .hr:
result = "HR CONTACT_SUPPORTED CONTACT_STATUS RR_AVAILABLE RR(ms)\n"
case .temperature:
result = "TIMESTAMP TEMPERATURE(Celcius)\n"
case .pressure:
result = "TIMESTAMP PRESSURE(mBar)\n"
}
return result
}
Expand All @@ -1091,6 +1193,12 @@ class PolarBleSdkManager : ObservableObject {

case let polarHrData as PolarHrData:
result += polarHrData.map{ "\($0.hr) \($0.contactStatusSupported) \($0.contactStatus) \($0.rrAvailable) \($0.rrsMs.map { String($0) }.joined(separator: " "))" }.joined(separator: "\n")

case let polarTemperatureData as PolarTemperatureData:
result += polarTemperatureData.samples.map{ "\($0.timeStamp) \($0.temperature)" }.joined(separator: "\n")

case let polarPressureData as PolarPressureData:
result += polarPressureData.samples.map{ "\($0.timeStamp) \($0.pressure)" }.joined(separator: "\n")

default:
result = "Data type not supported"
Expand Down Expand Up @@ -1182,6 +1290,10 @@ fileprivate extension PolarDeviceDataType {
return "MAG"
case .hr:
return "HR"
case .temperature:
return "TEMP"
case .pressure:
return "PRE"
}
}
}
Expand Down Expand Up @@ -1238,6 +1350,10 @@ extension PolarBleSdkManager : PolarBleApiObserver {

// MARK: - PolarBleApiDeviceInfoObserver
extension PolarBleSdkManager : PolarBleApiDeviceInfoObserver {
func disInformationReceivedWithKeysAsStrings(_ identifier: String, key: String, value: String) {
// Not implemented
}

func batteryLevelReceived(_ identifier: String, batteryLevel: UInt) {
NSLog("battery level updated: \(batteryLevel)")
Task { @MainActor in
Expand Down Expand Up @@ -1286,6 +1402,40 @@ extension PolarBleSdkManager : PolarBleApiDeviceFeaturesObserver {
case .feature_polar_device_time_setup:
Task { @MainActor in
self.deviceTimeSetupFeature.isSupported = true

let dateFormatter = ISO8601DateFormatter()
dateFormatter.formatOptions = [.withInternetDateTime]
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)

let ftuConfig = PolarFirstTimeUseConfig(
gender: PolarFirstTimeUseConfig.Gender.female,
birthDate: Date(),
height: 180,
weight: 80,
maxHeartRate: 180,
vo2Max: 80,
restingHeartRate: 100,
trainingBackground: PolarFirstTimeUseConfig.TrainingBackground.frequent,
deviceTime: dateFormatter.string(from: Date()),
typicalDay: PolarFirstTimeUseConfig.TypicalDay.mostlyMoving,
sleepGoalMinutes: 480
)

/// TODO: calling doFirstTimeUse deserves a better place in the
/// application flow
api
.doFirstTimeUse(identifier, ftuConfig: ftuConfig)
.subscribe(
onCompleted: {
NSLog("FTU Completed")
},
onError: { err in
NSLog("FTU Error: \(err)")
},
onDisposed: {
NSLog("FTU Disposed")
}
).disposed(by: disposeBag)
}

Task {
Expand Down Expand Up @@ -1339,6 +1489,10 @@ extension PolarBleSdkManager : PolarBleApiDeviceFeaturesObserver {
await getSdkModeStatus()
}
break
case .feature_polar_firmware_update:
break
case .feature_polar_activity_data:
break
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ struct OfflineRecordingEntriesRow: View {
return .orange
case .hr:
return .pink
case .temperature:
return .purple
case .pressure:
return .gray
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ extension PolarDeviceDataType: Identifiable {
return 6
case .hr:
return 7
case .temperature:
return 8
case .pressure:
return 9
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func getShortNameForDataType(_ feature: PolarDeviceDataType) -> String {
return "MAG"
case .hr:
return "HR"
case .temperature:
return "TEMP"
case .pressure:
return "PRE"
}
}

Expand All @@ -38,5 +42,9 @@ func getLongNameForDataType(_ feature: PolarDeviceDataType) -> String {
return "Magnetometer"
case .hr:
return "Heart rate"
case .temperature:
return "Temperature"
case .pressure:
return "Pressure"
}
}

0 comments on commit 5df8dee

Please sign in to comment.