File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ def read(self):
8282 # print([hex(i) for i in self._buffer])
8383
8484 # check packet header
85- if ( self ._buffer [0 ] != 0x42 ) or ( self . _buffer [ 1 ] != 0x4D ) :
85+ if not self ._buffer [0 : 2 ] == b"BM" :
8686 raise RuntimeError ("Invalid PM2.5 header" )
8787
8888 # check frame length
@@ -96,7 +96,6 @@ def read(self):
9696 raise RuntimeError ("Invalid PM2.5 checksum" )
9797
9898 # unpack data
99- frame = struct .unpack (">HHHHHHHHHHHH" , self ._buffer [4 :28 ])
10099 (
101100 self .aqi_reading ["pm10 standard" ],
102101 self .aqi_reading ["pm25 standard" ],
@@ -110,6 +109,6 @@ def read(self):
110109 self .aqi_reading ["particles 25um" ],
111110 self .aqi_reading ["particles 50um" ],
112111 self .aqi_reading ["particles 100um" ],
113- ) = frame
112+ ) = struct . unpack ( ">HHHHHHHHHHHH" , self . _buffer [ 4 : 28 ])
114113
115114 return self .aqi_reading
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ def _read_into_buffer(self):
7777 remain = self ._uart .read (31 )
7878 if not remain or len (remain ) != 31 :
7979 raise RuntimeError ("Unable to read from PM2.5 (incomplete frame)" )
80- for i in range (31 ):
81- self ._buffer [i + 1 ] = remain [i ]
82- # print([hex(i) for i in self._buffer])
80+ self ._buffer [1 :] = remain
81+
82+
83+ # print([hex(i) for i in self._buffer])
You can’t perform that action at this time.
0 commit comments