forked from aaronpk/Overland-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
209 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// PebbleManager.h | ||
// GPSLogger | ||
// | ||
// Created by Aaron Parecki on 10/27/15. | ||
// Copyright © 2015 Aaron Parecki. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
@import PebbleKit; | ||
|
||
@interface PebbleManager : NSObject <PBPebbleCentralDelegate> | ||
|
||
+ (PebbleManager *)sharedManager; | ||
|
||
- (void)startWatchSession; | ||
- (void)stopWatchSession; | ||
|
||
- (void)refreshWatchface; | ||
- (void)updateTripInfoWithTime:(NSTimeInterval)time distance:(double)distance speed:(double)speed; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// | ||
// PebbleManager.m | ||
// GPSLogger | ||
// | ||
// Created by Aaron Parecki on 10/27/15. | ||
// Copyright © 2015 Aaron Parecki. All rights reserved. | ||
// | ||
|
||
#import "PebbleManager.h" | ||
#import "GLManager.h" | ||
|
||
@implementation PebbleManager { | ||
PBWatch *_targetWatch; | ||
bool sportsEnabled; | ||
} | ||
|
||
+ (PebbleManager *)sharedManager { | ||
static PebbleManager *_instance = nil; | ||
|
||
@synchronized (self) { | ||
if (_instance == nil) { | ||
_instance = [[self alloc] init]; | ||
|
||
[[PBPebbleCentral defaultCentral] setDelegate:_instance]; | ||
// Configure our communications channel to target the sports app: | ||
[[PBPebbleCentral defaultCentral] setAppUUID:PBSportsUUID]; | ||
[[PBPebbleCentral defaultCentral] run]; | ||
NSLog(@"Registered watches: %@", [[PBPebbleCentral defaultCentral] registeredWatches]); | ||
} | ||
} | ||
|
||
return _instance; | ||
} | ||
|
||
- (void)startWatchSession { | ||
NSLog(@"Pebble: Starting watch session with last connected watch: %@", [[PBPebbleCentral defaultCentral] lastConnectedWatch]); | ||
|
||
[self setTargetWatch:[[PBPebbleCentral defaultCentral] lastConnectedWatch]]; | ||
|
||
// if(!sportsEnabled) return; | ||
[self configureWatchSession]; | ||
} | ||
|
||
- (void)configureWatchSession { | ||
[_targetWatch sportsAppSetLabel:NO onSent:^(PBWatch *watch, NSError *error) { | ||
if(error) { | ||
NSLog(@"Pebble: Failed setting label to 'speed'"); | ||
} else { | ||
NSLog(@"Pebble: Set label to 'speed'"); | ||
} | ||
}]; | ||
[_targetWatch sportsAppSetMetric:NO onSent:^(PBWatch *watch, NSError *error) { | ||
if(error) { | ||
NSLog(@"Pebble: Failed to set units to imperial"); | ||
} else { | ||
NSLog(@"Pebble: Set units to imperial"); | ||
} | ||
}]; | ||
[_targetWatch sportsAppLaunch:^(PBWatch *watch, NSError *error) { | ||
if(error) { | ||
NSLog(@"Pebble: Failed sending launch command"); | ||
} else { | ||
NSLog(@"Pebble: launch command sent"); | ||
} | ||
}]; | ||
} | ||
|
||
- (void)stopWatchSession { | ||
if(!sportsEnabled) return; | ||
|
||
[_targetWatch sportsAppKill:^(PBWatch *watch, NSError *error) { | ||
if(error) { | ||
NSLog(@"Pebble: Failed to kill session"); | ||
} else { | ||
NSLog(@"Pebble: Successfully killed session"); | ||
} | ||
}]; | ||
[_targetWatch releaseSharedSession]; | ||
} | ||
|
||
- (void)refreshWatchface { | ||
GLManager *m = [GLManager sharedManager]; | ||
[self updateTripInfoWithTime:m.currentTripDuration distance:m.currentTripDistance*MetersToMiles speed:m.currentTripSpeed]; | ||
} | ||
|
||
- (void)updateTripInfoWithTime:(NSTimeInterval)time distance:(double)distance speed:(double)speed { | ||
NSDictionary *pebbleDict = @{ | ||
PBSportsTimeKey: [PBSportsUpdate timeStringFromFloat:time], | ||
PBSportsDistanceKey: [NSString stringWithFormat:@"%2.02f", distance], | ||
PBSportsDataKey: [NSString stringWithFormat:@"%2.02f", speed] | ||
}; | ||
[_targetWatch sportsAppUpdate:pebbleDict onSent:^(PBWatch *watch, NSError *error) { | ||
if(error) { | ||
NSLog(@"Pebble: Failed to send update"); | ||
} else { | ||
} | ||
}]; | ||
} | ||
|
||
|
||
#pragma mark - | ||
|
||
- (void)setTargetWatch:(PBWatch*)watch { | ||
_targetWatch = watch; | ||
|
||
// Test if the Pebble's firmware supports AppMessages / Sports: | ||
[watch appMessagesGetIsSupported:^(PBWatch *watch, BOOL isAppMessagesSupported) { | ||
if (isAppMessagesSupported) { | ||
[[PBPebbleCentral defaultCentral] setAppUUID:PBSportsUUID]; | ||
|
||
NSLog(@"Pebble: %@ supports AppMessages :D", [watch name]); | ||
sportsEnabled = YES; | ||
|
||
[self configureWatchSession]; | ||
} else { | ||
|
||
NSLog(@"Pebble: %@ does NOT support AppMessages :'(", [watch name]); | ||
sportsEnabled = NO; | ||
} | ||
}]; | ||
} | ||
|
||
#pragma mark - Pebble delegate | ||
|
||
- (void)pebbleCentral:(PBPebbleCentral*)central watchDidConnect:(PBWatch*)watch isNew:(BOOL)isNew { | ||
NSLog(@"Pebble: watch %@ connected", watch.name); | ||
[self setTargetWatch:watch]; | ||
} | ||
|
||
- (void)pebbleCentral:(PBPebbleCentral*)central watchDidDisconnect:(PBWatch*)watch { | ||
NSLog(@"Pebble: Watch %@ disconnected", watch.name); | ||
if (_targetWatch == watch || [watch isEqual:_targetWatch]) { | ||
[self setTargetWatch:nil]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ | |
target 'GPSLogger' do | ||
pod 'AFNetworking' | ||
pod 'FMDB' | ||
pod 'PebbleKit' | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters