-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgpspoller.py
34 lines (29 loc) · 922 Bytes
/
gpspoller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages')
import gps
import threading
class GpsPoller(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.gps = gps
self.gpsd = None
self.last_fix = None
def run(self):
self.running = True
while self.running:
try:
if self.gpsd:
if self.gpsd.waiting(timeout=1):
self.gpsd.next()
self.last_fix = self.gpsd.fix
else:
self.gpsd = self.gps.gps(mode=self.gps.WATCH_ENABLE)
except (StopIteration, ConnectionResetError, OSError):
self.gpsd = None
self.last_fix = None
sleep(1)
def fix(self):
return self.last_fix
def stop(self):
self.running = False
self.join()