Merge pull request #13 from peterhinch/portable

Replace dependency on pyb with more portable machine.
pull/20/head
Calvin McCoy 2018-04-23 18:54:41 -07:00 zatwierdzone przez GitHub
commit e1b69fded7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 12 dodań i 9 usunięć

Wyświetl plik

@ -12,14 +12,13 @@
from math import floor, modf from math import floor, modf
# Import pyb or time for fix time handling # Import utime or time for fix time handling
try: try:
# Assume running on pyboard # Assume running on MicroPython
import pyb import utime
except ImportError: except ImportError:
# Otherwise default to time module for non-embedded implementations # Otherwise default to time module for non-embedded implementations
# Note that this forces the resolution of the fix time 1 second instead # Should still support millisecond resolution.
# of milliseconds as on the pyboard
import time import time
@ -629,7 +628,7 @@ class MicropyGPS(object):
"""Updates a high resolution counter with current time when fix is updated. Currently only triggered from """Updates a high resolution counter with current time when fix is updated. Currently only triggered from
GGA, GSA and RMC sentences""" GGA, GSA and RMC sentences"""
try: try:
self.fix_time = pyb.millis() self.fix_time = utime.ticks_ms()
except NameError: except NameError:
self.fix_time = time.time() self.fix_time = time.time()
@ -663,11 +662,12 @@ class MicropyGPS(object):
if self.fix_time == 0: if self.fix_time == 0:
return -1 return -1
# Try calculating fix time assuming using millis on a pyboard; default to seconds if not # Try calculating fix time using utime; if not running MicroPython
# time.time() returns a floating point value in secs
try: try:
current = pyb.elapsed_millis(self.fix_time) current = utime.ticks_diff(utime.ticks_ms(), self.fix_time)
except NameError: except NameError:
current = time.time() - self.fix_time current = (time.time() - self.fix_time) * 1000 # ms
return current return current

3
tests.py 100644 → 100755
Wyświetl plik

@ -1,3 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" """
tests.py tests.py
Tests for micropyGPS module Tests for micropyGPS module