36
36
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SCD4X.git"
37
37
38
38
SCD4X_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 )
56
56
57
57
58
58
class SCD4X :
@@ -144,18 +144,18 @@ def relative_humidity(self):
144
144
def reinit (self ):
145
145
"""Reinitializes the sensor by reloading user settings from EEPROM."""
146
146
self .stop_periodic_measurement ()
147
- self ._send_command (SCD4X_REINIT , cmd_delay = 0.02 )
147
+ self ._send_command (_SCD4X_REINIT , cmd_delay = 0.02 )
148
148
149
149
def factory_reset (self ):
150
150
"""Resets all configuration settings stored in the EEPROM and erases the
151
151
FRC and ASC algorithm history."""
152
152
self .stop_periodic_measurement ()
153
- self ._send_command (SCD4X_FACTORYRESET , cmd_delay = 1.2 )
153
+ self ._send_command (_SCD4X_FACTORYRESET , cmd_delay = 1.2 )
154
154
155
155
def force_calibration (self , target_co2 ):
156
156
"""Forces the sensor to recalibrate with a given current CO2"""
157
157
self .stop_periodic_measurement ()
158
- self ._set_command_value (SCD4X_FORCEDRECAL , target_co2 )
158
+ self ._set_command_value (_SCD4X_FORCEDRECAL , target_co2 )
159
159
time .sleep (0.5 )
160
160
self ._read_reply (self ._buffer , 3 )
161
161
correction = struct .unpack_from (">h" , self ._buffer [0 :2 ])[0 ]
@@ -176,25 +176,25 @@ def self_calibration_enabled(self):
176
176
saved with persist_settings().
177
177
178
178
"""
179
- self ._send_command (SCD4X_GETASCE , cmd_delay = 0.001 )
179
+ self ._send_command (_SCD4X_GETASCE , cmd_delay = 0.001 )
180
180
self ._read_reply (self ._buffer , 3 )
181
181
return self ._buffer [1 ] == 1
182
182
183
183
@self_calibration_enabled .setter
184
184
def self_calibration_enabled (self , enabled ):
185
- self ._set_command_value (SCD4X_SETASCE , enabled )
185
+ self ._set_command_value (_SCD4X_SETASCE , enabled )
186
186
187
187
def self_test (self ):
188
188
"""Performs a self test, takes up to 10 seconds"""
189
189
self .stop_periodic_measurement ()
190
- self ._send_command (SCD4X_SELFTEST , cmd_delay = 10 )
190
+ self ._send_command (_SCD4X_SELFTEST , cmd_delay = 10 )
191
191
self ._read_reply (self ._buffer , 3 )
192
192
if (self ._buffer [0 ] != 0 ) or (self ._buffer [1 ] != 0 ):
193
193
raise RuntimeError ("Self test failed" )
194
194
195
195
def _read_data (self ):
196
196
"""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 )
198
198
self ._read_reply (self ._buffer , 9 )
199
199
self ._co2 = (self ._buffer [0 ] << 8 ) | self ._buffer [1 ]
200
200
temp = (self ._buffer [3 ] << 8 ) | self ._buffer [4 ]
@@ -205,14 +205,14 @@ def _read_data(self):
205
205
@property
206
206
def data_ready (self ):
207
207
"""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 )
209
209
self ._read_reply (self ._buffer , 3 )
210
210
return not ((self ._buffer [0 ] & 0x03 == 0 ) and (self ._buffer [1 ] == 0 ))
211
211
212
212
@property
213
213
def serial_number (self ):
214
214
"""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 )
216
216
self ._read_reply (self ._buffer , 9 )
217
217
return (
218
218
self ._buffer [0 ],
@@ -225,21 +225,21 @@ def serial_number(self):
225
225
226
226
def stop_periodic_measurement (self ):
227
227
"""Stop measurement mode"""
228
- self ._send_command (SCD4X_STOPPERIODICMEASUREMENT , cmd_delay = 0.5 )
228
+ self ._send_command (_SCD4X_STOPPERIODICMEASUREMENT , cmd_delay = 0.5 )
229
229
230
230
def start_periodic_measurement (self ):
231
231
"""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 )
233
233
234
234
def persist_settings (self ):
235
235
"""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 )
237
237
238
238
def set_ambient_pressure (self , ambient_pressure ):
239
239
"""Set the ambient pressure in hPa at any time to adjust CO2 calculations"""
240
240
if ambient_pressure < 0 or ambient_pressure > 65535 :
241
241
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 )
243
243
244
244
@property
245
245
def temperature_offset (self ):
@@ -252,7 +252,7 @@ def temperature_offset(self):
252
252
persist_settings().
253
253
254
254
"""
255
- self ._send_command (SCD4X_GETTEMPOFFSET , cmd_delay = 0.001 )
255
+ self ._send_command (_SCD4X_GETTEMPOFFSET , cmd_delay = 0.001 )
256
256
self ._read_reply (self ._buffer , 3 )
257
257
temp = (self ._buffer [0 ] << 8 ) | self ._buffer [1 ]
258
258
return 175.0 * temp / 2 ** 16
@@ -264,7 +264,7 @@ def temperature_offset(self, offset):
264
264
"Offset value must be less than or equal to 374 degrees Celsius"
265
265
)
266
266
temp = int (offset * 2 ** 16 / 175 )
267
- self ._set_command_value (SCD4X_SETTEMPOFFSET , temp )
267
+ self ._set_command_value (_SCD4X_SETTEMPOFFSET , temp )
268
268
269
269
@property
270
270
def altitude (self ):
@@ -276,15 +276,15 @@ def altitude(self):
276
276
This value will NOT be saved and will be reset on boot unless saved with
277
277
persist_settings().
278
278
"""
279
- self ._send_command (SCD4X_GETALTITUDE , cmd_delay = 0.001 )
279
+ self ._send_command (_SCD4X_GETALTITUDE , cmd_delay = 0.001 )
280
280
self ._read_reply (self ._buffer , 3 )
281
281
return (self ._buffer [0 ] << 8 ) | self ._buffer [1 ]
282
282
283
283
@altitude .setter
284
284
def altitude (self , height ):
285
285
if height > 65535 :
286
286
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 )
288
288
289
289
def _check_buffer_crc (self , buf ):
290
290
for i in range (0 , len (buf ), 3 ):
@@ -294,7 +294,7 @@ def _check_buffer_crc(self, buf):
294
294
raise RuntimeError ("CRC check failed while reading data" )
295
295
return True
296
296
297
- def _send_command (self , cmd , cmd_delay = 0 ) :
297
+ def _send_command (self , cmd : int , cmd_delay : float = 0 ) -> None :
298
298
self ._cmd [0 ] = (cmd >> 8 ) & 0xFF
299
299
self ._cmd [1 ] = cmd & 0xFF
300
300
0 commit comments