kopia lustrzana https://github.com/inmcm/micropyGPS
Replace dependency on pyb with more portable machine.
rodzic
a6eda80ef4
commit
7d3efbe170
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
tests.py
|
tests.py
|
||||||
Tests for micropyGPS module
|
Tests for micropyGPS module
|
||||||
|
|
Ładowanie…
Reference in New Issue