Skip to content

Commit

Permalink
Prep for v0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Oct 7, 2020
1 parent f0ac269 commit 3eff919
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 53 deletions.
6 changes: 2 additions & 4 deletions examples/latlon.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env python3
import time

from pa1010d import PA1010D, PPS
from pa1010d import PA1010D

gps = PA1010D()

# Blink PPS LED always, but with less obnoxious pulse width
gps.set_pps(PPS.ALWAYS, pulse_width=5)
gps = PA1010D()

while True:
result = gps.update()
Expand Down
8 changes: 8 additions & 0 deletions library/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.0.2
-----

* Add support for disabling PPS LED
* Handle spurious newlines in sentences
* Add PDOP, VDOP and HDOP output
* Handle GLL messages

0.0.1
-----

Expand Down
8 changes: 8 additions & 0 deletions library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ Stable (library only) from PyPi:
* Just run `sudo pip3 install pa1010d`

# Changelog
0.0.2
-----

* Add support for disabling PPS LED
* Handle spurious newlines in sentences
* Add PDOP, VDOP and HDOP output
* Handle GLL messages

0.0.1
-----

Expand Down
54 changes: 6 additions & 48 deletions library/pa1010d/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
import time
import smbus
import enum


import pynmea2


__version__ = '0.0.1'
__version__ = '0.0.2'

PA1010D_ADDR = 0x10


class PPS(enum.Enum):
"""Available states for the PA1010D PPS LED"""

"""Disable PPS LED"""
DISABLE = 0

"""Blink after the first fix"""
AFTER_FIRST_FIX = 1

"""Blink only for 3D fix"""
ONLY_3D = 2

"""Blink for 2D or 3D fix"""
ONLY_2D_3D = 3

"""Blink always"""
ALWAYS = 4


class PA1010D():
__slots__ = (
"timestamp",
Expand Down Expand Up @@ -80,21 +60,18 @@ def _write_sentence(self, bytestring):
"""
for char_index in bytestring:
self._i2c.write_byte(self._i2c_addr, char_index)
self._i2c.write_byte(self._i2c_addr, ord(char_index))

def send_command(self, command, add_checksum=True):
"""Send a command string to the PA1010D.
If add_checksum is True (the default) a NMEA checksum will automatically be computed and added.
"""
if type(command) is str:
command = command.encode("ascii")

# TODO replace with pynmea2 functionality
if command.startswith(b"$"):
if command.startswith("$"):
command = command[1:]
if command.endswith(b"*"):
if command.endswith("*"):
command = command[:-1]

buf = bytearray()
Expand Down Expand Up @@ -128,25 +105,10 @@ def read_sentence(self, timeout=5):
# Should be a full \r\n since the GPS emits spurious newlines
if buf[-2:] == [ord("\r"), ord("\n")]:
# Remove line ending and spurious newlines from the sentence
return bytearray(buf).decode("ascii").strip().replace("\n", "")
return bytearray(buf).decode("ascii").strip().replace("\n","")

raise TimeoutError("Timeout waiting for readline")

def set_pps(self, mode=PPS.ALWAYS, pulse_width=100):
"""Set pulse per second config.
Define the status LED behaviour on the PA1010d.
:param mode: One PPS enum types
:param pulse_width: LED pulse with in ms (1ms to 999ms)
"""
if not isinstance(mode, PPS):
raise ValueError("Mode must be of type PPS")

sentence = "PMTK285,{mode},{pulse_width}".format(mode=mode.value, pulse_width=pulse_width)
self.send_command(sentence)

def update(self, wait_for="GGA", timeout=5):
"""Attempt to update from PA1010D.
Expand Down Expand Up @@ -226,11 +188,7 @@ def update(self, wait_for="GGA", timeout=5):
# $PMTK011,MTKGPS*08 Successful bootup
# $PMTK010,001*2E Startup
# $PMTK010,002*2D Wake from standby, normal operation

# set_pps will produce a:
# $PMTK001,285,3*3F Confirm PPS LED setting
if self._debug:
print(sentence)
print(sentence)
return True

else:
Expand Down
2 changes: 1 addition & 1 deletion library/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
[metadata]
name = pa1010d
version = 0.0.1
version = 0.0.2
author = Philip Howard
author_email = [email protected]
description = Python library for the PA1010D i2c GPS module
Expand Down

0 comments on commit 3eff919

Please sign in to comment.