Protocol

MWLoggable

Sensors that can log data to onboard storage adhere to this protocol to configure, start, stop, and download the logger.

Declaration

protocol MWLoggable : MWDataConvertible

Overview

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

These operators accept MWLoggable instances construct by autocompletion, such as sensorFusionQuaternion(mode:), or by direct construction, such as MWSensorFusion init(mode:).


metawear
   .publishWhenConnected()
   .first()
   .mapToMWError() // Changes Failure from Never to MWError
   .log(.sensorFusionQuaternion(mode: .ndof)
   .log(.gyroscope(range: .dps2000, frequency: .hz400)
   .sink { _ in }
   .store(in: &subs)

Direct construction may be useful when you persist user selected settings or organize arbitrarily large logging sessions. The SDK includes the operators .macro(executeOnBoot:) and .optionallyLog to help with this.


let pressure = MWBarometer.MWPressure(standby: .ms125, iir: .off, oversampling: .standard)
let gyro = MWGyroscope(range: .dps1000, frequency: .hz400)
let euler: MWSensorFusion.EulerAngles? = nil


metawear
    .publishIfConnected()
    .macro(executeOnBoot: true) { metawear in
         metawear
            .optionallyLog(euler)
            .optionallyLog(gyro)
            .optionallyLog(pressure)
    }
    .sink { _ in }
    .store(in: &subs)

Our open-source MetaBase 5 app provides a similar example in ActionVM.swift and MetaWear+WriteSensorMacro.swift by creating a macro of multiple MWLoggable and MWPollable signals from arbitrary user-selected sensors and sensor parameters.

Downloading logs in CSV format is simple with the .downloadLogs operator, also demonstrated in the aforementioned MetaBase app.

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