Skip to content

Commit

Permalink
Merge pull request #12 from dglaude/some_pimoroni_improvement
Browse files Browse the repository at this point in the history
Some pimoroni improvement on UART and __init__
  • Loading branch information
tannewt authored Nov 16, 2020
2 parents 21732d8 + d204360 commit 1117e14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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])

0 comments on commit 1117e14

Please sign in to comment.