Walk Wright

The ability to walk can be impaired after a cerebral infraction. To improving walking the use of Continuous Sensory Rehabilitation through Real-Time Feedworward can help. It tracks the feet movement by attaching a sensor to both feet.

This application reads and stores realtime sensor data to improve walking. The sensors used are the MetaMotionNR from MBientlab. To communicate with these sensors MBientlab provides the MetaWear SDK. The data is stored using CoreData and realtime sensor data is displayed with the use of SwiftUI.

Idea

Theo Theunissen of Moving Reality approached us during our mobile application development course and asked if we could help out developing a iOS app that reads the sensor data. He had some trouble using the MetaWear SDK and asked us to write a wrapper around the SDK

This SDK is a minimal wrapper around their C++ library posing some challenge with integrating it within Swift. Because the sensors provide a continuous stream of data we decided to write this wrapper with RxSwift.

Challenge

The Challenge we faced was the implementation of callbacks within the MetaWear SDK. The SDK implemented a bridge function to retrieve the sensor within the callback. But by the time the callback was called, Automatic Reference Counting already cleaned the memory and the reference to this sensor was gone.

mbl_mw_datasignal_subscribe(la, bridge(obj: self)) { (context, data) in
  guard let context = context else { return }
  let accSensor: AccelerometerSensor = bridge(ptr: context)
//...
}

To combat the issue we added a static Dictionary to add all the sensors too. In the callback the sensor could then be retrieved by sensor MAC address and sensor type.

mbl_mw_datasignal_subscribe(la, bridge(obj: self)) { (context, data) in
//...
  let sensor: AccelerometerSensor? = MetaWearDevice.getSensor(mac: accSensor.device.mac!, type: .accelerometer)
  sensor?.subject?.onNext(cartesianFloat)
}

Repository

collaborators

  • Sven van der Vlist

Technologies

  • Swift
  • CoreData
  • SwiftUI
  • RxSwift
  • MetaWear