Skip to content

Commit

Permalink
Visualize Biopot measurements (#46)
Browse files Browse the repository at this point in the history
# Visualize Biopot measurements

## ♻️ Current situation & Problem
The biopot device integration is currently relatively limited. With #41
we introduced initial pairing functionality based on SpeziBluetooth and
#45 introduced parsing the BLE layer. This PR does first steps to
integrate the Biopot device into the existing device search
infrastructure and aims to display live data from the device.


## ⚙️ Release Notes 
* Integrate Biopot devices into the nearby devices list.
* Visualize live measurements from the currently connected Biopot.


## 📚 Documentation
--


## ✅ Testing
_TBA_


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
Supereg authored Dec 5, 2023
1 parent ff0752a commit c448c04
Show file tree
Hide file tree
Showing 61 changed files with 758 additions and 302 deletions.
80 changes: 67 additions & 13 deletions NAMS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

110 changes: 0 additions & 110 deletions NAMS/BioPot/BiopotDevice.swift

This file was deleted.

File renamed without changes.
82 changes: 36 additions & 46 deletions NAMS/BioPot/Biopot.swift → NAMS/Devices/BioPot/Biopot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// SPDX-License-Identifier: MIT
//

import Spezi
import SpeziBluetooth
import SpeziViews
import SwiftUI
Expand All @@ -18,47 +19,45 @@ struct Biopot: View {
@State private var viewState: ViewState = .idle

var body: some View {
List {
ListRow("Device") {
Text(biopot.bluetoothState.localizedStringResource)
ListRow("Device") {
Text(biopot.bluetoothState.localizedStringResource)
}
.viewStateAlert(state: $viewState)
.onChange(of: biopot.bluetoothState) {
if biopot.bluetoothState != .connected {
biopot.deviceInfo = nil
}
}
testingSupport

testingSupport

if let info = biopot.deviceInfo {
Section("Status") {
ListRow("BATTERY") {
BatteryIcon(percentage: Int(info.batteryLevel))
}
ListRow("Charging") {
if info.batteryCharging {
Text("Yes")
} else {
Text("No")
}
}
ListRow("Temperature") {
Text("\(info.temperatureValue) °C")

if let info = biopot.deviceInfo {
Section("Status") {
ListRow("BATTERY") {
BatteryIcon(percentage: Int(info.batteryLevel))
}
ListRow("Charging") {
if info.batteryCharging {
Text("Yes")
} else {
Text("No")
}
}

actionButtons
} else if biopot.bluetoothState == .scanning {
Section {
ProgressView()
.listRowBackground(Color.clear)
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
.frame(maxWidth: .infinity)
ListRow("Temperature") {
Text("\(info.temperatureValue) °C")
}
}
}
.viewStateAlert(state: $viewState)
.navigationTitle("BioPot 3")
.onChange(of: biopot.bluetoothState) {
if biopot.bluetoothState != .connected {
biopot.deviceInfo = nil
}

actionButtons
} else if biopot.bluetoothState == .scanning {
Section {
ProgressView()
.listRowBackground(Color.clear)
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
.frame(maxWidth: .infinity)
}
}
}

@MainActor @ViewBuilder private var testingSupport: some View {
Expand Down Expand Up @@ -104,7 +103,7 @@ extension BluetoothState: CustomLocalizedStringResourceConvertible {
case .disconnected:
return "Disconnected"
case .scanning:
return "Scanning"
return "Scanning ..."
case .poweredOff:
return "Bluetooth Off"
case .unauthorized:
Expand All @@ -115,19 +114,10 @@ extension BluetoothState: CustomLocalizedStringResourceConvertible {


#if DEBUG
import Spezi

#Preview {
class PreviewDelegate: SpeziAppDelegate {
override var configuration: Configuration {
Configuration {
Bluetooth()
BiopotDevice()
}
}
List {
Biopot()
}

return Biopot()
.spezi(PreviewDelegate())
.biopotPreviewSetup()
}
#endif
Loading

0 comments on commit c448c04

Please sign in to comment.