Logging and manipulating accelerometer (and gyro) data simultaneously

edited July 2017 in iOS
I am trying to log accelerometer data and also manipulate it in real time.

I call this function:
@IBAction func accelerometerBMI160StartLogPressed(_ sender: Any) {
accelerometerBMI160StartLog.isEnabled = false
accelerometerBMI160StopLog.isEnabled = true
accelerometerBMI160StartStream.isEnabled = false
accelerometerBMI160StopStream.isEnabled = false
updateAccelerometerBMI160Settings()
device.accelerometer!.dataReadyEvent.startLoggingAsync()
manipulate_data()

Under: manipulate_data(), I have added:
================================

var array = [MBLAccelerometerData]() /* capacity: 1000 */
accelerometerBMI160Data = array
device.accelerometer!.dataReadyEvent.startNotificationsAsync { (obj, error) in
if let obj = obj {
//Manipulate data
}
}

================================

Then when Stop log is pressed, I call the stop log function and have added:

device.accelerometer!.dataReadyEvent.stopNotificationsAsync()

================================


Is that ok? Any causes of concern here?

Comments

  • Offhand it looks fine.  Have you tried running the code yet?
  • Yes - code works. Last time you mentioned concerns around adding step counting event - so wanted to be sure. 

    Thanks!
This discussion has been closed.