Skip to content

Commit

Permalink
Revised lazy GPS loading
Browse files Browse the repository at this point in the history
  • Loading branch information
connervieira committed Jun 7, 2024
1 parent 2e683b9 commit 70a429c
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,32 +675,24 @@ def get_gps_location():

return position[0], position[1], speed, altitude, heading, satellites, gps_time
except Exception as exception:
gps_connection_active = False
display_message("A GPS error occurred: " + str(exception), 2)
return 0.0000, 0.0000, 0.0, 0.0, 0.0, 0, 0 # Return a default placeholder location.
else: # If GPS is disabled, then this function should never be called, but return a placeholder position regardless.
display_message("The `get_gps_location` function was called, even though GPS is disabled. This is a bug, and should never occur.", 2)
return 0.0000, 0.0000, 0.0, 0.0, 0.0, 0, 0 # Return a default placeholder location.

most_recent_gps_location = [0.0, 0.0, 0.0, 0.0, 0.0, 0, 0]
gps_daemon_running = False
def gps_daemon():
debug_message("Starting lazy GPS daemon")
global gps_daemon_running
global most_recent_gps_location
try:
while True:
debug_message("Fetching lazy GPS location")
most_recent_gps_location = get_gps_location()
time.sleep(float(config["general"]["gps"]["lazy_polling_interval"])) # Wait before polling the GPS again.
finally:
gps_daemon_running = False
while True:
debug_message("Fetching lazy GPS location")
most_recent_gps_location = get_gps_location()
time.sleep(float(config["general"]["gps"]["lazy_polling_interval"])) # Wait before polling the GPS again.
def get_gps_location_lazy(): # This function gets the most recent GPS location from the lazy GPS monitor.
global gps_daemon_running
if (gps_daemon_running == False): # Check to see if the GPS daemon is not running.
gps_daemon_thread = threading.Thread(target=gps_daemon, name="LazyGPSDaemon") # Create the lazy GPS manager thread.
gps_daemon_thread.start() # Start the GPS daemon thread.
return most_recent_gps_location
gps_daemon_thread = threading.Thread(target=gps_daemon, name="LazyGPSDaemon") # Create the lazy GPS manager thread.
gps_daemon_thread.start() # Start the GPS daemon thread.



Expand Down

0 comments on commit 70a429c

Please sign in to comment.