Commits

Jason Scheirer committed faf640e

Reconnect to gpsd if you hang

Comments (0)

Files changed (1)

bikesniff/gpsfix.py

 class GpsD(GpsCoordinates):
     def __init__(self, reactor):
         self.reactor = reactor
-        import gps
+        import gps, time
         self._gps = gps.gps()
+        self._lastfix = (0., 0., time.time())
         self.reactor.callLater(1, self._update)
     def _update(self):
+        # Query
         self._gps.query('admosy\n')
+        # See if we need to time out
+        x, y = self.coordinates if self.coordinates else (0., 0.)
+        oldx, oldy, oldtime = self._lastfix
+        age = time.time() - oldtime
+        if age > 15.:
+            self._gps = gps.gps()
+            self._lastfix = (0., 0., time.time())
+        elif (x, y) != (oldx, oldy):
+            self._lastfix = (x, y, time.time())
         self.reactor.callLater(1, self._update)
     @property
     def coordinates(self):