Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some pimoroni improvement on UART and __init__ #12

Merged
merged 5 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions adafruit_pm25/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def read(self):
# print([hex(i) for i in self._buffer])

# check packet header
if (self._buffer[0] != 0x42) or (self._buffer[1] != 0x4D):
if not self._buffer[0:2] == b"BM":
raise RuntimeError("Invalid PM2.5 header")

# check frame length
Expand All @@ -96,7 +96,6 @@ def read(self):
raise RuntimeError("Invalid PM2.5 checksum")

# unpack data
frame = struct.unpack(">HHHHHHHHHHHH", self._buffer[4:28])
(
self.aqi_reading["pm10 standard"],
self.aqi_reading["pm25 standard"],
Expand All @@ -110,6 +109,6 @@ def read(self):
self.aqi_reading["particles 25um"],
self.aqi_reading["particles 50um"],
self.aqi_reading["particles 100um"],
) = frame
) = struct.unpack(">HHHHHHHHHHHH", self._buffer[4:28])

return self.aqi_reading
7 changes: 4 additions & 3 deletions adafruit_pm25/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def _read_into_buffer(self):
remain = self._uart.read(31)
if not remain or len(remain) != 31:
raise RuntimeError("Unable to read from PM2.5 (incomplete frame)")
for i in range(31):
self._buffer[i + 1] = remain[i]
# print([hex(i) for i in self._buffer])
self._buffer[1:] = remain


# print([hex(i) for i in self._buffer])