3636__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SCD4X.git"
3737
3838SCD4X_DEFAULT_ADDR = 0x62
39- SCD4X_REINIT = const (0x3646 )
40- SCD4X_FACTORYRESET = const (0x3632 )
41- SCD4X_FORCEDRECAL = const (0x362F )
42- SCD4X_SELFTEST = const (0x3639 )
43- SCD4X_DATAREADY = const (0xE4B8 )
44- SCD4X_STOPPERIODICMEASUREMENT = const (0x3F86 )
45- SCD4X_STARTPERIODICMEASUREMENT = const (0x21B1 )
46- SCD4X_READMEASUREMENT = const (0xEC05 )
47- SCD4X_SERIALNUMBER = const (0x3682 )
48- SCD4X_GETTEMPOFFSET = const (0x2318 )
49- SCD4X_SETTEMPOFFSET = const (0x241D )
50- SCD4X_GETALTITUDE = const (0x2322 )
51- SCD4X_SETALTITUDE = const (0x2427 )
52- SCD4X_SETPRESSURE = const (0xE000 )
53- SCD4X_PERSISTSETTINGS = const (0x3615 )
54- SCD4X_GETASCE = const (0x2313 )
55- SCD4X_SETASCE = const (0x2416 )
39+ _SCD4X_REINIT = const (0x3646 )
40+ _SCD4X_FACTORYRESET = const (0x3632 )
41+ _SCD4X_FORCEDRECAL = const (0x362F )
42+ _SCD4X_SELFTEST = const (0x3639 )
43+ _SCD4X_DATAREADY = const (0xE4B8 )
44+ _SCD4X_STOPPERIODICMEASUREMENT = const (0x3F86 )
45+ _SCD4X_STARTPERIODICMEASUREMENT = const (0x21B1 )
46+ _SCD4X_READMEASUREMENT = const (0xEC05 )
47+ _SCD4X_SERIALNUMBER = const (0x3682 )
48+ _SCD4X_GETTEMPOFFSET = const (0x2318 )
49+ _SCD4X_SETTEMPOFFSET = const (0x241D )
50+ _SCD4X_GETALTITUDE = const (0x2322 )
51+ _SCD4X_SETALTITUDE = const (0x2427 )
52+ _SCD4X_SETPRESSURE = const (0xE000 )
53+ _SCD4X_PERSISTSETTINGS = const (0x3615 )
54+ _SCD4X_GETASCE = const (0x2313 )
55+ _SCD4X_SETASCE = const (0x2416 )
5656
5757
5858class SCD4X :
@@ -144,18 +144,18 @@ def relative_humidity(self):
144144 def reinit (self ):
145145 """Reinitializes the sensor by reloading user settings from EEPROM."""
146146 self .stop_periodic_measurement ()
147- self ._send_command (SCD4X_REINIT , cmd_delay = 0.02 )
147+ self ._send_command (_SCD4X_REINIT , cmd_delay = 0.02 )
148148
149149 def factory_reset (self ):
150150 """Resets all configuration settings stored in the EEPROM and erases the
151151 FRC and ASC algorithm history."""
152152 self .stop_periodic_measurement ()
153- self ._send_command (SCD4X_FACTORYRESET , cmd_delay = 1.2 )
153+ self ._send_command (_SCD4X_FACTORYRESET , cmd_delay = 1.2 )
154154
155155 def force_calibration (self , target_co2 ):
156156 """Forces the sensor to recalibrate with a given current CO2"""
157157 self .stop_periodic_measurement ()
158- self ._set_command_value (SCD4X_FORCEDRECAL , target_co2 )
158+ self ._set_command_value (_SCD4X_FORCEDRECAL , target_co2 )
159159 time .sleep (0.5 )
160160 self ._read_reply (self ._buffer , 3 )
161161 correction = struct .unpack_from (">h" , self ._buffer [0 :2 ])[0 ]
@@ -176,25 +176,25 @@ def self_calibration_enabled(self):
176176 saved with persist_settings().
177177
178178 """
179- self ._send_command (SCD4X_GETASCE , cmd_delay = 0.001 )
179+ self ._send_command (_SCD4X_GETASCE , cmd_delay = 0.001 )
180180 self ._read_reply (self ._buffer , 3 )
181181 return self ._buffer [1 ] == 1
182182
183183 @self_calibration_enabled .setter
184184 def self_calibration_enabled (self , enabled ):
185- self ._set_command_value (SCD4X_SETASCE , enabled )
185+ self ._set_command_value (_SCD4X_SETASCE , enabled )
186186
187187 def self_test (self ):
188188 """Performs a self test, takes up to 10 seconds"""
189189 self .stop_periodic_measurement ()
190- self ._send_command (SCD4X_SELFTEST , cmd_delay = 10 )
190+ self ._send_command (_SCD4X_SELFTEST , cmd_delay = 10 )
191191 self ._read_reply (self ._buffer , 3 )
192192 if (self ._buffer [0 ] != 0 ) or (self ._buffer [1 ] != 0 ):
193193 raise RuntimeError ("Self test failed" )
194194
195195 def _read_data (self ):
196196 """Reads the temp/hum/co2 from the sensor and caches it"""
197- self ._send_command (SCD4X_READMEASUREMENT , cmd_delay = 0.001 )
197+ self ._send_command (_SCD4X_READMEASUREMENT , cmd_delay = 0.001 )
198198 self ._read_reply (self ._buffer , 9 )
199199 self ._co2 = (self ._buffer [0 ] << 8 ) | self ._buffer [1 ]
200200 temp = (self ._buffer [3 ] << 8 ) | self ._buffer [4 ]
@@ -205,14 +205,14 @@ def _read_data(self):
205205 @property
206206 def data_ready (self ):
207207 """Check the sensor to see if new data is available"""
208- self ._send_command (SCD4X_DATAREADY , cmd_delay = 0.001 )
208+ self ._send_command (_SCD4X_DATAREADY , cmd_delay = 0.001 )
209209 self ._read_reply (self ._buffer , 3 )
210210 return not ((self ._buffer [0 ] & 0x03 == 0 ) and (self ._buffer [1 ] == 0 ))
211211
212212 @property
213213 def serial_number (self ):
214214 """Request a 6-tuple containing the unique serial number for this sensor"""
215- self ._send_command (SCD4X_SERIALNUMBER , cmd_delay = 0.001 )
215+ self ._send_command (_SCD4X_SERIALNUMBER , cmd_delay = 0.001 )
216216 self ._read_reply (self ._buffer , 9 )
217217 return (
218218 self ._buffer [0 ],
@@ -225,21 +225,21 @@ def serial_number(self):
225225
226226 def stop_periodic_measurement (self ):
227227 """Stop measurement mode"""
228- self ._send_command (SCD4X_STOPPERIODICMEASUREMENT , cmd_delay = 0.5 )
228+ self ._send_command (_SCD4X_STOPPERIODICMEASUREMENT , cmd_delay = 0.5 )
229229
230230 def start_periodic_measurement (self ):
231231 """Put sensor into working mode, about 5s per measurement"""
232- self ._send_command (SCD4X_STARTPERIODICMEASUREMENT , cmd_delay = 0.01 )
232+ self ._send_command (_SCD4X_STARTPERIODICMEASUREMENT , cmd_delay = 0.01 )
233233
234234 def persist_settings (self ):
235235 """Save temperature offset, altitude offset, and selfcal enable settings to EEPROM"""
236- self ._send_command (SCD4X_PERSISTSETTINGS , cmd_delay = 0.8 )
236+ self ._send_command (_SCD4X_PERSISTSETTINGS , cmd_delay = 0.8 )
237237
238238 def set_ambient_pressure (self , ambient_pressure ):
239239 """Set the ambient pressure in hPa at any time to adjust CO2 calculations"""
240240 if ambient_pressure < 0 or ambient_pressure > 65535 :
241241 raise AttributeError ("`ambient_pressure` must be from 0~65535 hPascals" )
242- self ._set_command_value (SCD4X_SETPRESSURE , ambient_pressure )
242+ self ._set_command_value (_SCD4X_SETPRESSURE , ambient_pressure )
243243
244244 @property
245245 def temperature_offset (self ):
@@ -252,7 +252,7 @@ def temperature_offset(self):
252252 persist_settings().
253253
254254 """
255- self ._send_command (SCD4X_GETTEMPOFFSET , cmd_delay = 0.001 )
255+ self ._send_command (_SCD4X_GETTEMPOFFSET , cmd_delay = 0.001 )
256256 self ._read_reply (self ._buffer , 3 )
257257 temp = (self ._buffer [0 ] << 8 ) | self ._buffer [1 ]
258258 return 175.0 * temp / 2 ** 16
@@ -264,7 +264,7 @@ def temperature_offset(self, offset):
264264 "Offset value must be less than or equal to 374 degrees Celsius"
265265 )
266266 temp = int (offset * 2 ** 16 / 175 )
267- self ._set_command_value (SCD4X_SETTEMPOFFSET , temp )
267+ self ._set_command_value (_SCD4X_SETTEMPOFFSET , temp )
268268
269269 @property
270270 def altitude (self ):
@@ -276,15 +276,15 @@ def altitude(self):
276276 This value will NOT be saved and will be reset on boot unless saved with
277277 persist_settings().
278278 """
279- self ._send_command (SCD4X_GETALTITUDE , cmd_delay = 0.001 )
279+ self ._send_command (_SCD4X_GETALTITUDE , cmd_delay = 0.001 )
280280 self ._read_reply (self ._buffer , 3 )
281281 return (self ._buffer [0 ] << 8 ) | self ._buffer [1 ]
282282
283283 @altitude .setter
284284 def altitude (self , height ):
285285 if height > 65535 :
286286 raise AttributeError ("Height must be less than or equal to 65535 meters" )
287- self ._set_command_value (SCD4X_SETALTITUDE , height )
287+ self ._set_command_value (_SCD4X_SETALTITUDE , height )
288288
289289 def _check_buffer_crc (self , buf ):
290290 for i in range (0 , len (buf ), 3 ):
@@ -294,7 +294,7 @@ def _check_buffer_crc(self, buf):
294294 raise RuntimeError ("CRC check failed while reading data" )
295295 return True
296296
297- def _send_command (self , cmd , cmd_delay = 0 ) :
297+ def _send_command (self , cmd : int , cmd_delay : float = 0 ) -> None :
298298 self ._cmd [0 ] = (cmd >> 8 ) & 0xFF
299299 self ._cmd [1 ] = cmd & 0xFF
300300
0 commit comments