def __init__(self): self.device_name = "GPS" self.interval = 0 self.verbose = False # GPS Stuff self.the_connection = gps3.GPSDSocket() self.the_fix = gps3.Fix()
def runGPS(self): sense = SenseHat() sense.clear() sense.set_rotation(90) the_connection = gps3.GPSDSocket() the_fix = gps3.Fix() finalLat = 0 finalLong = 0 #Get the Latitude and Longitude if self.run == True: try: for new_data in the_connection: if new_data: the_fix.refresh(new_data) if not isinstance(the_fix.TPV['lat'], str): # check for valid data latitude = the_fix.TPV['lat'] longitude = the_fix.TPV['lon'] finalLat = latitude finalLong = longitude time.sleep(1) self.gentle_close() break if self.run == False: break self.gentle_close() except KeyboardInterrupt: self.gentle_close() the_connection.close() print("\nTerminated by user\nGood Bye.\n") latString = "" longString = "" if finalLat < 0: latString = "Latitude: " + str(abs(finalLat)) + " South" else: latString = "Latitude: " + str(finalLat) + " North" if finalLong < 0: longString = "Longitude: " + str(abs(finalLong)) + " West" else: longString = "Longitude: " + str(finalLong) + " East" self.say(latString) sense.show_message(latString, scroll_speed=.045) time.sleep(.5) self.say(longString) sense.show_message(longString, scroll_speed=.045)
def read(): the_connection = gps3.GPSDSocket() the_fix = gps3.Fix() try: for new_data in the_connection: if new_data: the_fix.refresh(new_data) if not isinstance(the_fix.TPV['lat'], str): # check for valid data speed = the_fix.TPV['speed'] latitude = the_fix.TPV['lat'] longitude = the_fix.TPV['lon'] altitude = the_fix.TPV['alt'] #sleep(2) the_connection.close() except: return latitude, longitude, altitude return latitude, longitude, altitude
def runGPS(): sense = SenseHat() sense.clear() sense.set_rotation(90) the_connection = gps3.GPSDSocket() the_fix = gps3.Fix() finalLat = 0 finalLong = 0 #Get the Latitude and Longitude try: for new_data in the_connection: if new_data: the_fix.refresh(new_data) if not isinstance(the_fix.TPV['lat'], str): # check for valid data latitude = the_fix.TPV['lat'] longitude = the_fix.TPV['lon'] finalLat = latitude finalLong = longitude sleep(1) break except KeyboardInterrupt: the_connection.close() print("\nTerminated by user\nGood Bye.\n") latString = "" longString = "" if finalLat < 0: latString = "Lat: " + str(abs(finalLat)) + " S" else: latString = "Lat: " + str(finalLat) + " N" if finalLong < 0: longString = "Long: " + str(abs(finalLong)) + " W" else: longString = "Long: " + str(finalLong) + " E" sense.show_message(latString + " " + longString, scroll_speed=.04)
#! /usr/bin/python3 # coding=utf-8 """banana""" import xml.dom.minidom import gps3 import time from datetime import datetime, timezone, timedelta import os import sys gps_connection = gps3.GPSDSocket() gps_fix = gps3.Fix() the_log = '/tmp/gpx3.gpx' def start_time(): """time in the beginning""" timestart = str(datetime.utcnow().replace(tzinfo=(timezone(timedelta(0))))) return timestart def close(doc): """write file to disk and close""" log_write = open(the_log, "w") doc.writexml(log_write) log_write.close() if os.path.isfile(the_log): doc = xml.dom.minidom.parse(the_log) # opens the pre-existing
from time import sleep import gps3 the_connection = gps3.GPSDSocket() the_fix = gps3.Fix() try: for new_data in the_connection: if new_data: the_fix.refresh(new_data) if not isinstance(the_fix.TPV['lat'], str): # check for valid data speed = the_fix.TPV['speed'] latitude = the_fix.TPV['lat'] longitude = the_fix.TPV['lon'] altitude = the_fix.TPV['alt'] with open('Lon_Lat_Alt_logs', 'a') as f: print('Latitude:', latitude, 'Longitude:', longitude) f.write('Latittude: %f, Longitude: %f, Altitude: %f\n' % (latitude, longitude, altitude)) sleep(2) except KeyboardInterrupt: the_connection.close() print("\nTerminated by user\nGood Bye.\n")