Skip to content

Commit

Permalink
Drop f-strings for better compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Oct 2, 2020
1 parent 8dd0fb0 commit 5526b29
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
20 changes: 10 additions & 10 deletions examples/latlon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
while True:
result = gps.update()
if result:
print(f"""
T: {gps.timestamp}
N: {gps.longitude}
E: {gps.latitude}
Alt: {gps.altitude}
Sats: {gps.num_sats}
Qual: {gps.gps_qual}
Speed: {gps.speed_over_ground}
Fix Type: {gps.mode_fix_type}
""")
print("""
T: {timestamp}
N: {longitude}
E: {latitude}
Alt: {altitude}
Sats: {num_sats}
Qual: {gps_qual}
Speed: {speed_over_ground}
Fix Type: {mode_fix_type}
""".format(**gps.data))
time.sleep(1.0)
33 changes: 22 additions & 11 deletions library/pa1010d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def __init__(self, i2c_addr=PA1010D_ADDR):
self.speed_over_ground = None
self.mode_fix_type = None

@property
def data(self):
return dict((slot, getattr(self, slot)) for slot in self.__slots__)

def _write_sentence(self, bytestring):
"""Write a sentence to the PA1010D device over i2c.
Expand Down Expand Up @@ -70,7 +74,7 @@ def send_command(self, command, add_checksum=True):
for char in command:
checksum ^= char
buf += b'*' # Delimits checksum value
buf += f"{checksum:02X}".encode("ascii")
buf += "{checksum:02X}".format(checksum=checksum).encode("ascii")
buf += b'\r\n'
self._write_sentence(buf)

Expand Down Expand Up @@ -178,9 +182,9 @@ def update(self, wait_for="GGA", timeout=5):
return True
except AttributeError:
pass
raise RuntimeError(f"Unsupported message type {type(result)} ({sentence})")
raise RuntimeError("Unsupported message type {type} ({sentence})".format(type=type(result), sentence=sentence))

raise TimeoutError(f"Timeout waiting for {wait_for} message.")
raise TimeoutError("Timeout waiting for {wait_for} message.".format(wait_for=wait_for))


if __name__ == "__main__":
Expand All @@ -189,12 +193,19 @@ def update(self, wait_for="GGA", timeout=5):
while True:
result = gps.update()
if result:
print(f"""
T: {gps.timestamp}
N: {gps.longitude}
E: {gps.latitude}
Alt: {gps.altitude}
Sats: {gps.num_sats}
Qual: {gps.gps_qual}
""")
print("""
T: {timestamp}
N: {longitude}
E: {latitude}
Alt: {altitude}
Sats: {num_sats}
Qual: {gps_qual}
""".format(
timestamp=gps.timestamp,
longitude=gps.longitude,
latitude=gps.latitude,
altitude=gps.altitude,
num_sats=gps.num_sats,
gps_qual=gps.gps_qual
))
time.sleep(1.0)

0 comments on commit 5526b29

Please sign in to comment.