spezidevices

Support interactions with Bluetooth Devices.

https://github.com/stanfordspezi/spezidevices

Science Score: 49.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.7%) to scientific vocabulary
Last synced: 6 months ago · JSON representation

Repository

Support interactions with Bluetooth Devices.

Basic Info
Statistics
  • Stars: 4
  • Watchers: 12
  • Forks: 1
  • Open Issues: 3
  • Releases: 12
Created over 1 year ago · Last pushed 6 months ago
Metadata Files
Readme License Citation

README.md

SpeziDevices

Build and Test codecov DOI

Support interactions with Bluetooth Devices.

Overview

SpeziDevices provides three different targets: SpeziDevices, SpeziDevicesUI and SpeziOmron.

|Screenshot showing paired devices in a grid layout. A sheet is presented in the foreground showing a nearby devices able to pair. Screenshot showing paired devices in a grid layout. A sheet is presented in the foreground showing a nearby devices able to pair.|Displaying the device details of a paired device with information like Model number and battery percentage. Displaying the device details of a paired device with information like Model number and battery percentage.| Showing a newly recorded blood pressure measurement. Showing a newly recorded blood pressure measurement. | |:--:|:--:|:--:| |Display paired in a grid-layout devices using DevicesView.|Display device details using DeviceDetailsView.|Display recorded measurements using MeasurementsRecordedSheet.|

SpeziDevices

SpeziDevices abstracts common interactions with Bluetooth devices that are implemented using SpeziBluetooth. It supports pairing with devices and process health measurements.

Pairing Devices

Pairing devices is a good way of making sure that your application only connects to fixed set of devices and doesn't accept data from non-authorized devices. Further, it might be necessary to ensure certain operations stay secure.

Use the PairedDevices module to discover and pair PairableDevices and automatically manage connection establishment of connected devices.

To support PairedDevices, you need to adopt the PairableDevice protocol for your device. Optionally you can adopt the BatteryPoweredDevice protocol, if your device supports the BatteryService. Once your device is loaded, register it with the PairedDevices module by calling the PairedDevices/configure(device:accessing:_:_:) method.

[!IMPORTANT] Don't forget to configure the PairedDevices module in your SpeziAppDelegate.

```swift import SpeziDevices

class MyDevice: PairableDevice { @DeviceState(.id) var id @DeviceState(.name) var name @DeviceState(.state) var state @DeviceState(.advertisementData) var advertisementData @DeviceState(.nearby) var nearby

@Service var deviceInformation = DeviceInformationService()

@DeviceAction(\.connect) var connect
@DeviceAction(\.disconnect) var disconnect

var isInPairingMode: Bool {
    // determine if a nearby device is in pairing mode
}

@Dependency private var pairedDevices: PairedDevices?

required init() {}

func configure() {
    pairedDevices?.configure(device: self, accessing: $state, $advertisementData, $nearby)
}

func handleSuccessfulPairing() { // called on events where a device can be considered paired (e.g., incoming notifications)
    pairedDevices?.signalDevicePaired(self)
}

} ```

[!TIP] To display and manage paired devices and support adding new paired devices, you can use the full-featured DevicesView.

Health Measurements

Use the HealthMeasurements module to collect health measurements from nearby Bluetooth devices like connected weight scales or blood pressure cuffs.

To support HealthMeasurements, you need to adopt the HealthDevice protocol for your device. One your device is loaded, register its measurement service with the HealthMeasurements module by calling a suitable variant of configureReceivingMeasurements(for:on:).

```swift import SpeziDevices

class MyDevice: HealthDevice { @Service var deviceInformation = DeviceInformationService() @Service var weightScale = WeightScaleService()

@Dependency private var measurements: HealthMeasurements?

required init() {}

func configure() {
    measurements?.configureReceivingMeasurements(for: self, on: weightScale)
}

} ```

To display new measurements to the user and save them to your external data store, you can use MeasurementsRecordedSheet. Below is a short code example.

```swift import SpeziDevices import SpeziDevicesUI

struct MyHomeView: View { @Environment(HealthMeasurements.self) private var measurements

var body: some View {
    @Bindable var measurements = measurements
    ContentView()
        .sheet(isPresented: $measurements.shouldPresentMeasurements) {
            MeasurementsRecordedSheet { measurement in
                // handle saving the measurement
            }
        }
}

} ```

[!IMPORTANT] Don't forget to configure the HealthMeasurements module in your SpeziAppDelegate.

SpeziDevicesUI

SpeziDevicesUI helps you to visualize Bluetooth device state and communicate interactions to the user.

Displaying paired devices

When managing paired devices using PairedDevices, SpeziDevicesUI provides reusable View components to display paired devices.

The DevicesView provides everything you need to pair and manage paired devices. It shows already paired devices in a grid layout using the DevicesGrid. Additionally, it places an add button in the toolbar to discover new devices using the AccessorySetupSheet view.

swift struct MyHomeView: View { var body: some View { TabView { NavigationStack { DevicesView(appName: "Example") { Text("Provide helpful pairing instructions to the user.") } } .tabItem { Label("Devices", systemImage: "sensor.fill") } } } }

Displaying Measurements

When managing measurements using HealthMeasurements, you can use the MeasurementsRecordedSheet to display pending measurements. Below is a short code example on how you would configure this view.

```swift struct MyHomeView: View { @Environment(HealthMeasurements.self) private var measurements

var body: some View {
    @Bindable var measurements = measurements
    ContentView()
        .sheet(isPresented: $measurements.shouldPresentMeasurements) {
            MeasurementsRecordedSheet { samples in
                // save the array of HKSamples
            }
        }
}

} ```

[!IMPORTANT] Don't forget to configure the HealthMeasurements module in your SpeziAppDelegate.

SpeziOmron

SpeziOmron extends SpeziDevices with support for Omron devices. This includes Omron-specific models, characteristics, services and fully reusable device support.

Omron Devices

The OmronBloodPressureCuff and OmronWeightScale devices provide reusable device implementations for Omron blood pressure cuffs and the Omron weight scales respectively. Both devices automatically integrate with the HealthMeasurements and PairedDevices modules of SpeziDevices. You just need to configure them for use with the Bluetooth module.

```swift import SpeziBluetooth import SpeziBluetoothServices import SpeziDevices import SpeziOmron

class ExampleAppDelegate: SpeziAppDelegate { override var configuration: Configuration { Configuration { Bluetooth { Discover(OmronBloodPressureCuff.self, by: .advertisedService(BloodPressureService.self)) Discover(OmronWeightScale.self, by: .advertisedService(WeightScaleService.self)) }

        // If required, configure the PairedDevices and HealthMeasurements modules
        PairedDevices()
        HealthMeasurements()
    }
}

} ```

Setup

You need to add the SpeziDevices Swift package to your app in Xcode or Swift package.

License

This project is licensed under the MIT License. See Licenses for more information.

Contributors

This project is developed as part of the Stanford Mussallem Center for Biodesign at Stanford University. See CONTRIBUTORS.md for a full list of all TemplatePackage contributors.

Stanford Mussallem Center for Biodesign Logo Stanford Mussallem Center for Biodesign Logo

Owner

  • Name: Stanford Spezi
  • Login: StanfordSpezi
  • Kind: organization

GitHub Events

Total
  • Create event: 6
  • Issues event: 1
  • Release event: 3
  • Watch event: 1
  • Delete event: 3
  • Issue comment event: 6
  • Push event: 27
  • Pull request review event: 6
  • Pull request review comment event: 9
  • Pull request event: 6
  • Fork event: 1
Last Year
  • Create event: 6
  • Issues event: 1
  • Release event: 3
  • Watch event: 1
  • Delete event: 3
  • Issue comment event: 6
  • Push event: 27
  • Pull request review event: 6
  • Pull request review comment event: 9
  • Pull request event: 6
  • Fork event: 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 3
  • Total pull requests: 13
  • Average time to close issues: 25 days
  • Average time to close pull requests: 5 days
  • Total issue authors: 1
  • Total pull request authors: 2
  • Average comments per issue: 0.0
  • Average comments per pull request: 1.0
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 6
  • Average time to close issues: N/A
  • Average time to close pull requests: about 14 hours
  • Issue authors: 0
  • Pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 0.33
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Supereg (4)
  • pauljohanneskraft (1)
Pull Request Authors
  • Supereg (25)
  • phnagy (1)
Top Labels
Issue Labels
enhancement (5)
Pull Request Labels
enhancement (11) documentation (2)

Packages

  • Total packages: 1
  • Total downloads: unknown
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 11
swiftpackageindex.com: github.com/StanfordSpezi/SpeziDevices

Support interactions with Bluetooth Devices.

  • Versions: 11
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 19.0%
Dependent repos count: 27.3%
Average: 42.0%
Forks count: 53.6%
Stargazers count: 67.9%
Last synced: 6 months ago

Dependencies

.github/workflows/build-and-test.yml actions
.github/workflows/pull_request.yml actions
Package.swift swiftpm