Protocol

MWStreamable

Sensors that can stream data at about 100 to 120 Hz adhere to this protocol to configure, start, and stop a data signal.

Declaration

protocol MWStreamable : MWDataConvertible

Overview

To start a stream, use the .stream() operators. They are available on a Publisher whose output is a MetaWear, including:

A .stream() operator accepts an MWStreamable instance. You can use presets that autocomplete within the operator, such as magnetometer(freq:), or construct them directly, such as init(freq:).

Some .stream() operators produce a timestamped typed output. You can collect these into an array and convert that into a String-only CSV table with aptly labeled columns by using MWDataTable, such as in the example below.


let cancel = PassthroughSubject<Void,Never>()
let config: MWStreamable = .magnetometer(freq: .hz25)
metawear
    .publishIfConnected()
    .stream(config)
    .prefix(untilOutputFrom: cancel)
    .collect()
    .map { MWDataTable(streamed: $0, config) }
    .eraseToAnyPublisher()

Multiple .stream pipelines can run independently. You can also merge the output of an arbitrary array of streams using standard operators like MergeMany, .prefix(untilOutputFrom:), and .collect() . Our open-source MetaBase 5 app provides an example in ActionVM.swift. It uses user-selected (and persisted) sensor parameters to inform the construction a container of MWStreamable configurations. Only non-nil configs are streamed. Upon cancellation, outputs merge into a single CSV file. The hyperlinked function is called as part of a loop across an arbitrary number of devices.

Unless you construct your own sensor wrappers, this protocol’s details and default methods are unlikely to be important to you.

Topics

Instance Properties

Instance Methods

Type Properties

Type Methods

See Also

Interact