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):
82
82
# print([hex(i) for i in self._buffer])
83
83
84
84
# check packet header
85
- if ( self ._buffer [0 ] != 0x42 ) or ( self . _buffer [ 1 ] != 0x4D ) :
85
+ if not self ._buffer [0 : 2 ] == b"BM" :
86
86
raise RuntimeError ("Invalid PM2.5 header" )
87
87
88
88
# check frame length
@@ -96,7 +96,6 @@ def read(self):
96
96
raise RuntimeError ("Invalid PM2.5 checksum" )
97
97
98
98
# unpack data
99
- frame = struct .unpack (">HHHHHHHHHHHH" , self ._buffer [4 :28 ])
100
99
(
101
100
self .aqi_reading ["pm10 standard" ],
102
101
self .aqi_reading ["pm25 standard" ],
@@ -110,6 +109,6 @@ def read(self):
110
109
self .aqi_reading ["particles 25um" ],
111
110
self .aqi_reading ["particles 50um" ],
112
111
self .aqi_reading ["particles 100um" ],
113
- ) = frame
112
+ ) = struct . unpack ( ">HHHHHHHHHHHH" , self . _buffer [ 4 : 28 ])
114
113
115
114
return self .aqi_reading
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ def _read_into_buffer(self):
77
77
remain = self ._uart .read (31 )
78
78
if not remain or len (remain ) != 31 :
79
79
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