Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2015 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/748f0c95eb5fe4bafbb6 to your computer and use it in GitHub Desktop.
Save anonymous/748f0c95eb5fe4bafbb6 to your computer and use it in GitHub Desktop.
import Foundation
class MetawearConfig:NSObject, MBLRestorable {
var pulseWidthEvent:MBLEvent!
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(self.pulseWidthEvent, forKey: "pulseWidthEvent")
}
required init(coder: NSCoder) {
super.init()
self.pulseWidthEvent = coder.decodeObjectForKey("pulseWidthEvent") as? MBLEvent
}
override init () {
super.init()
}
func runOnDeviceBoot(device: MBLMetaWear) {
// Log some Accelerometer data
device.accelerometer.fullScaleRange = MBLAccelerometerRange.Range2G
device.accelerometer.filterCutoffFreq = 0
device.accelerometer.highPassFilter = true;
var periodicEvent = device.accelerometer.rmsDataReadyEvent.periodicSampleOfEvent(1000)
self.pulseWidthEvent = periodicEvent.pulseDetectorOfEventWithThreshold(30, width: 3, output: MBLPulseOutput.Width)
self.pulseWidthEvent.startLogging()
println("Logging Started")
}
}
// Config code
self.device.setConfiguration(MetawearConfig()) { error in
self.downloadLogButton.enabled = true
println("set Configuration successful")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment