Skip to content

Commit

Permalink
Adds watcher support. Refs #37.
Browse files Browse the repository at this point in the history
  • Loading branch information
gradha committed Jun 2, 2015
1 parent ed8371e commit 6bc893f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/GPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ typedef enum ACCURACY_ENUM ACCURACY;

+ (GPS*)get;
+ (NSString*)degrees_to_dms:(CLLocationDegrees)value latitude:(BOOL)latitude;
+ (NSString*)key_path;
- (id)init;
- (bool)start;
- (void)stop;
Expand Down
7 changes: 0 additions & 7 deletions src/GPS.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,6 @@ - (void)stop
[manager_ stopUpdatingLocation];
}

/** Returns the string used by add_watcher: and removeObserver:.
*/
+ (NSString*)key_path
{
return _KEY_PATH;
}

/** Registers an observer for changes to last_pos.
* Observers will monitor the key_path value.
*/
Expand Down
35 changes: 31 additions & 4 deletions src/SGPS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum Accuracy
@objc class SGPS : NSObject, CLLocationManagerDelegate
{
private let _GPS_IS_ON_KEY = "gps_is_on"
private let _KEY_PATH = "last_pos"
private let _KEY_SAVE_SINGLE_POSITION = "save_single_positions"

static private let cInstance: SGPS = SGPS()
Expand Down Expand Up @@ -70,14 +71,14 @@ enum Accuracy
}
}

func stop()
func pingWatchdog()
{
println("Stopping, not implemented!")
println("Pinging watchdog, not implemented!");
}

func pingWatchdog()
func stopWatchdog()
{
println("Pinging watchdog, not implemented!");
println("Stopping watchdog, not implemented!");
}

/** Converts a coordinate from degrees to decimal minute second format.
Expand Down Expand Up @@ -132,4 +133,30 @@ enum Accuracy
return false
}
}
/** Stops the GPS tracking.
* You can call this function anytime, doesn't really fail.
*/
func stop() {
if gpsIsOn && !mNoLog {
DB.get().log("Stopping location updates");
}
stopWatchdog()
gpsIsOn = false
mManager.stopUpdatingLocation()
}

/** Registers an observer for changes to last_pos.
* Observers will monitor the key_path value.
*/
func addWatcher(watcher: NSObject) {
addObserver(watcher, forKeyPath:_KEY_PATH,
options: .New, context: nil)
}

/** Removes an observer for changes to last_pos.
*/
func removeWatcher(watcher: NSObject) {
removeObserver(watcher, forKeyPath: _KEY_PATH)
}

}

0 comments on commit 6bc893f

Please sign in to comment.