Last active
December 16, 2018 16:30
-
-
Save pablovv72/6729110087250891a97c7a2d63761067 to your computer and use it in GitHub Desktop.
gps.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ui | |
import location | |
import time | |
import motion | |
from math import * | |
cardinales = ( | |
'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', | |
'S', 'SSO', 'SO', 'OSO', 'O', 'ONO', 'NO', 'NNO' | |
) | |
v = ui.load_view() | |
v.present('sheet', hide_title_bar = True) | |
motion.start_updates() | |
while True: | |
location.start_updates() | |
gps = location.get_location() | |
location.stop_updates() | |
v['latitud'].text = f"{gps['latitude']:12.7f}N" | |
v['longitud'].text = f"{gps['longitude']:12.7f}E" | |
v['altura'].text = f"{round(gps['altitude']):4d} m." | |
v['speed'].text = f"{round(gps['speed'] * 3.6):^4d}" if gps['speed'] != -1 \ | |
else "N/D" | |
rumbo = gps['course'] | |
i = round(rumbo / 22.5) | |
v['course'].text = f"{round(rumbo):3d}° {cardinales[i % 16]}" \ | |
if rumbo != -1 else "N/D" | |
direcciones = '' | |
for direccion in location.reverse_geocode(gps): | |
direcciones += f"{direccion.get('Street')}\n" | |
v['direccion'].text = direcciones[:-1] | |
mag_vec = motion.get_magnetic_field() | |
if mag_vec[0] < 0: | |
compas = pi / 2 + atan(mag_vec[1] / min(mag_vec[0], -1e-14)) | |
else: | |
compas = pi + pi / 2 + atan(mag_vec[1] / max(mag_vec[0], 1e-14)) | |
compas = compas / (2 * pi) * 359 | |
i = round(compas / 22.5) | |
v['compas'].text = f"{round(compas):3d}° {cardinales[i % 16]}" | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment