Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update screenshots to include BP7000 #11

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Sources/SpeziDevices/PairedDevices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import SwiftUI
/// - ``isConnected(device:)``
/// - ``updateName(for:name:)``
@Observable
public final class PairedDevices: @unchecked Sendable {
public final class PairedDevices {
/// Determines if the device discovery sheet should be presented.
@MainActor public var shouldPresentDevicePairing = false

Expand Down Expand Up @@ -120,7 +120,7 @@ public final class PairedDevices: @unchecked Sendable {
@Dependency(Bluetooth.self) @ObservationIgnored private var bluetooth: Bluetooth?
@Dependency(ConfigureTipKit.self) @ObservationIgnored private var tipKit

private var modelContainer: ModelContainer?
@MainActor private var modelContainer: ModelContainer?

/// Determine if Bluetooth is scanning to discovery nearby devices.
///
Expand All @@ -142,6 +142,7 @@ public final class PairedDevices: @unchecked Sendable {

/// Configures the Module.
@_documentation(visibility: internal)
@MainActor
public func configure() {
if bluetooth == nil {
self.logger.warning("PairedDevices Module initialized without Bluetooth dependency!")
Expand Down Expand Up @@ -363,7 +364,7 @@ public final class PairedDevices: @unchecked Sendable {
}


extension PairedDevices: Module, EnvironmentAccessible, DefaultInitializable {}
extension PairedDevices: Module, EnvironmentAccessible, DefaultInitializable, @unchecked Sendable {}

// MARK: - Device Pairing

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This source file is part of the Stanford Spezi open-source project

SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md)

SPDX-License-Identifier: MIT
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This source file is part of the Stanford Spezi open-source project

SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md)

SPDX-License-Identifier: MIT
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion Sources/SpeziOmron/Devices/OmronBloodPressureCuff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ extension OmronBloodPressureCuff {
systolic: MedFloat16 = 103,
diastolic: MedFloat16 = 64,
pulseRate: MedFloat16 = 62,
name: String = "BP5250",
state: PeripheralState = .disconnected,
nearby: Bool = true,
manufacturerData: OmronManufacturerData = OmronManufacturerData(pairingMode: .pairingMode, users: [
Expand All @@ -145,7 +146,7 @@ extension OmronBloodPressureCuff {
let device = OmronBloodPressureCuff()

device.$id.inject(UUID())
device.$name.inject("BP5250")
device.$name.inject(name)
device.$state.inject(state)
device.$nearby.inject(nearby)

Expand Down
109 changes: 70 additions & 39 deletions Tests/UITests/TestApp/DevicesTestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,71 @@ struct DevicesTestView: View {
@State private var didRegister = false
@State private var device = MockDevice.createMockDevice()
@State private var weightScale = OmronWeightScale.createMockDevice(manufacturerData: .omronManufacturerData(mode: .transferMode))
@State private var bloodPressureCuff = OmronBloodPressureCuff.createMockDevice(manufacturerData: .omronManufacturerData(mode: .transferMode))
@State private var bloodPressureCuffBP5250 = OmronBloodPressureCuff.createMockDevice(
manufacturerData: .omronManufacturerData(mode: .transferMode)
)
@State private var bloodPressureCuffBP7000 = OmronBloodPressureCuff.createMockDevice(
name: "BP7000",
manufacturerData: .omronManufacturerData(mode: .transferMode)
)

@State private var viewState: ViewState = .idle

@ToolbarContentBuilder @MainActor private var toolbarContent: some ToolbarContent {
ToolbarItemGroup(placement: .secondaryAction) {
Button("Discover Device", systemImage: "plus.rectangle.fill.on.rectangle.fill") {
device.isInPairingMode = true
device.$advertisementData.inject(AdvertisementData()) // trigger onChange advertisement
}
AsyncButton(state: $viewState) {
try await device.connect()
try await weightScale.connect()
try await bloodPressureCuffBP5250.connect()
try await bloodPressureCuffBP7000.connect()
} label: {
Label("Connect", systemImage: "cable.connector")
}
AsyncButton {
await device.disconnect()
await weightScale.disconnect()
await bloodPressureCuffBP5250.disconnect()
await bloodPressureCuffBP7000.disconnect()
} label: {
Label("Disconnect", systemImage: "cable.connector.slash")
}

omronDevicesMenu
}
}

@MainActor private var omronDevicesMenu: some View {
Menu("Omron Devices", systemImage: "heart.text.square") {
Button("Discover Weight Scale", systemImage: "scalemass.fill") {
weightScale.$advertisementData.inject(AdvertisementData(
manufacturerData: OmronManufacturerData.omronManufacturerData(mode: .pairingMode).encode()
))
}
Menu("Discover Blood Pressure Cuff", systemImage: "heart.fill") {
Button("BP 5250") {
bloodPressureCuffBP5250.$advertisementData.inject(AdvertisementData(
manufacturerData: OmronManufacturerData.omronManufacturerData(mode: .pairingMode).encode()
))
}

Button("BP 7000") {
bloodPressureCuffBP7000.$advertisementData.inject(AdvertisementData(
manufacturerData: OmronManufacturerData.omronManufacturerData(mode: .pairingMode).encode()
))
}
}
}
}

var body: some View {
NavigationStack {
DevicesView(appName: "Example", pairingHint: "Enable pairing mode on the device.")
.toolbar {
ToolbarItemGroup(placement: .secondaryAction) {
Button("Discover Device", systemImage: "plus.rectangle.fill.on.rectangle.fill") {
device.isInPairingMode = true
device.$advertisementData.inject(AdvertisementData()) // trigger onChange advertisement
}
AsyncButton(state: $viewState) {
try await device.connect()
try await weightScale.connect()
try await bloodPressureCuff.connect()
} label: {
Label("Connect", systemImage: "cable.connector")
}
AsyncButton {
await device.disconnect()
await weightScale.disconnect()
await bloodPressureCuff.disconnect()
} label: {
Label("Disconnect", systemImage: "cable.connector.slash")
}

Menu("Omron Devices", systemImage: "heart.text.square") {
Button("Discover Weight Scale", systemImage: "scalemass.fill") {
weightScale.$advertisementData.inject(AdvertisementData(
manufacturerData: OmronManufacturerData.omronManufacturerData(mode: .pairingMode).encode()
))
}
Button("Discovery Blood Pressure Cuff", systemImage: "heart.fill") {
bloodPressureCuff.$advertisementData.inject(AdvertisementData(
manufacturerData: OmronManufacturerData.omronManufacturerData(mode: .pairingMode).encode()
))
}
}
}
toolbarContent
}
}
.viewStateAlert(state: $viewState)
Expand All @@ -87,16 +111,23 @@ struct DevicesTestView: View {

moduleLoading.loadMockDevice(device)
moduleLoading.loadMockDevice(weightScale)
moduleLoading.loadMockDevice(bloodPressureCuff)
moduleLoading.loadMockDevice(bloodPressureCuffBP5250)
moduleLoading.loadMockDevice(bloodPressureCuffBP7000)

// simulator this being called in the configure method of the device
pairedDevices.configure(device: device, accessing: device.$state, device.$advertisementData, device.$nearby)
pairedDevices.configure(device: weightScale, accessing: weightScale.$state, weightScale.$advertisementData, weightScale.$nearby)
pairedDevices.configure(
device: bloodPressureCuff,
accessing: bloodPressureCuff.$state,
bloodPressureCuff.$advertisementData,
bloodPressureCuff.$nearby
device: bloodPressureCuffBP5250,
accessing: bloodPressureCuffBP5250.$state,
bloodPressureCuffBP5250.$advertisementData,
bloodPressureCuffBP5250.$nearby
)
pairedDevices.configure(
device: bloodPressureCuffBP7000,
accessing: bloodPressureCuffBP7000.$state,
bloodPressureCuffBP7000.$advertisementData,
bloodPressureCuffBP7000.$nearby
)
didRegister = true
}
Expand Down
Loading