Skip to content

Commit

Permalink
filters out duplicated data from pebble
Browse files Browse the repository at this point in the history
quick patch
  • Loading branch information
Mark Petruska committed Feb 18, 2015
1 parent 10a50b2 commit 4912a59
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ios/Lift/Device/Pebble/PebbleDeviceSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PebbleDeviceSession : DeviceSession {
private var updateHandler: AnyObject?
private var watch: PBWatch!
private var deviceId: NSUUID!
private var lastData: NSData?

required init(deviceId: NSUUID, watch: PBWatch!, deviceSessionDelegate: DeviceSessionDelegate) {
super.init()
Expand All @@ -38,14 +39,25 @@ class PebbleDeviceSession : DeviceSession {

private func appMessagesReceiveUpdateHandler(watch: PBWatch!, data: [NSObject : AnyObject]!) -> Bool {
let adKey = NSNumber(uint32: 0xface0fb0)
let deadKey = NSNumber(uint32: 0x0000dead)
if let x = data[adKey] as? NSData {
accelerometerDataReceived(x)
let duplicatedData = (lastData != nil) && (lastData! == x)
if !duplicatedData {
accelerometerDataReceived(x)
lastData = x
} else {
NSLog("INFO: Received duplicated data from Pebble.")
}
}
if let x: AnyObject = data[deadKey] {
stopIfDeadKeyReceived(data)
return true
}

private func stopIfDeadKeyReceived(data: [NSObject: AnyObject]) {
let deadKey = NSNumber(uint32: 0x0000dead)
let hasDeadKey = (data[deadKey] != nil)
if hasDeadKey {
stop()
}
return true
}

private func accelerometerDataReceived(data: NSData) {
Expand Down

0 comments on commit 4912a59

Please sign in to comment.