51
51
from adafruit_register .i2c_bit import RWBit , ROBit
52
52
from adafruit_register .i2c_bits import RWBits , ROBits
53
53
54
- _DPS310_DEFAULT_ADDRESS = 0x77 # DPS310 default i2c address
55
- _DPS310_DEVICE_ID = 0x10 # DPS310 device identifier
56
-
57
- _DPS310_PRSB2 = 0x00 # Highest byte of pressure data
58
- _DPS310_TMPB2 = 0x03 # Highest byte of temperature data
59
- _DPS310_PRSCFG = 0x06 # Pressure configuration
60
- _DPS310_TMPCFG = 0x07 # Temperature configuration
61
- _DPS310_MEASCFG = 0x08 # Sensor configuration
62
- _DPS310_CFGREG = 0x09 # Interrupt/FIFO configuration
63
- _DPS310_RESET = 0x0C # Soft reset
64
- _DPS310_PRODREVID = 0x0D # Register that contains the part ID
65
- _DPS310_TMPCOEFSRCE = 0x28 # Temperature calibration src
66
-
67
- #pylint: enable=bad-whitespace
68
- #pylint: disable=no-member,unnecessary-pass
54
+ _DPS310_DEFAULT_ADDRESS = 0x77 # DPS310 default i2c address
55
+ _DPS310_DEVICE_ID = 0x10 # DPS310 device identifier
56
+
57
+ _DPS310_PRSB2 = 0x00 # Highest byte of pressure data
58
+ _DPS310_TMPB2 = 0x03 # Highest byte of temperature data
59
+ _DPS310_PRSCFG = 0x06 # Pressure configuration
60
+ _DPS310_TMPCFG = 0x07 # Temperature configuration
61
+ _DPS310_MEASCFG = 0x08 # Sensor configuration
62
+ _DPS310_CFGREG = 0x09 # Interrupt/FIFO configuration
63
+ _DPS310_RESET = 0x0C # Soft reset
64
+ _DPS310_PRODREVID = 0x0D # Register that contains the part ID
65
+ _DPS310_TMPCOEFSRCE = 0x28 # Temperature calibration src
66
+
67
+ # pylint: enable=bad-whitespace
68
+ # pylint: disable=no-member,unnecessary-pass
69
+
69
70
70
71
class CV :
71
72
"""struct helper"""
@@ -87,6 +88,7 @@ def is_valid(cls, value):
87
88
"""Validate that a given value is a member"""
88
89
return value in cls .string
89
90
91
+
90
92
class Mode (CV ):
91
93
"""Options for ``mode``
92
94
@@ -112,49 +114,63 @@ class Mode(CV):
112
114
+--------------------------+------------------------------------------------------------------+
113
115
114
116
"""
115
- pass #pylint: disable=unnecessary-pass
116
117
117
- Mode .add_values ((
118
- ('IDLE' , 0 , "Idle" , None ),
119
- ('ONE_PRESSURE' , 1 , "One-Shot Pressure" , None ),
120
- ('ONE_TEMPERATURE' , 2 , "One-Shot Temperature" , None ),
121
- ('CONT_PRESSURE' , 5 , "Continuous Pressure" , None ),
122
- ('CONT_TEMP' , 6 , "Continuous Temperature" , None ),
123
- ('CONT_PRESTEMP' , 7 , "Continuous Pressure & Temperature" , None ),
124
- ))
118
+ pass # pylint: disable=unnecessary-pass
119
+
120
+
121
+ Mode .add_values (
122
+ (
123
+ ("IDLE" , 0 , "Idle" , None ),
124
+ ("ONE_PRESSURE" , 1 , "One-Shot Pressure" , None ),
125
+ ("ONE_TEMPERATURE" , 2 , "One-Shot Temperature" , None ),
126
+ ("CONT_PRESSURE" , 5 , "Continuous Pressure" , None ),
127
+ ("CONT_TEMP" , 6 , "Continuous Temperature" , None ),
128
+ ("CONT_PRESTEMP" , 7 , "Continuous Pressure & Temperature" , None ),
129
+ )
130
+ )
131
+
125
132
126
133
class Rate (CV ):
127
134
"""Options for `pressure_rate` and `temperature_rate`"""
135
+
128
136
pass
129
137
130
- Rate .add_values ((
131
- ('RATE_1_HZ' , 0 , 1 , None ),
132
- ('RATE_2_HZ' , 1 , 2 , None ),
133
- ('RATE_4_HZ' , 2 , 4 , None ),
134
- ('RATE_8_HZ' , 3 , 8 , None ),
135
- ('RATE_16_HZ' , 4 , 16 , None ),
136
- ('RATE_32_HZ' , 5 , 32 , None ),
137
- ('RATE_64_HZ' , 6 , 64 , None ),
138
- ('RATE_128_HZ' , 7 , 128 , None )
139
- ))
138
+
139
+ Rate .add_values (
140
+ (
141
+ ("RATE_1_HZ" , 0 , 1 , None ),
142
+ ("RATE_2_HZ" , 1 , 2 , None ),
143
+ ("RATE_4_HZ" , 2 , 4 , None ),
144
+ ("RATE_8_HZ" , 3 , 8 , None ),
145
+ ("RATE_16_HZ" , 4 , 16 , None ),
146
+ ("RATE_32_HZ" , 5 , 32 , None ),
147
+ ("RATE_64_HZ" , 6 , 64 , None ),
148
+ ("RATE_128_HZ" , 7 , 128 , None ),
149
+ )
150
+ )
151
+
140
152
141
153
class SampleCount (CV ):
142
154
"""Options for `temperature_oversample_count` and `pressure_oversample_count`"""
155
+
143
156
pass
144
157
145
- SampleCount .add_values ((
146
- ('COUNT_1' , 0 , 1 , None ),
147
- ('COUNT_2' , 1 , 2 , None ),
148
- ('COUNT_4' , 2 , 4 , None ),
149
- ('COUNT_8' , 3 , 8 , None ),
150
- ('COUNT_16' , 4 , 16 , None ),
151
- ('COUNT_32' , 5 , 32 , None ),
152
- ('COUNT_64' , 6 , 64 , None ),
153
- ('COUNT_128' , 7 , 128 , None ),
154
- ))
155
- #pylint: enable=unnecessary-pass
158
+
159
+ SampleCount .add_values (
160
+ (
161
+ ("COUNT_1" , 0 , 1 , None ),
162
+ ("COUNT_2" , 1 , 2 , None ),
163
+ ("COUNT_4" , 2 , 4 , None ),
164
+ ("COUNT_8" , 3 , 8 , None ),
165
+ ("COUNT_16" , 4 , 16 , None ),
166
+ ("COUNT_32" , 5 , 32 , None ),
167
+ ("COUNT_64" , 6 , 64 , None ),
168
+ ("COUNT_128" , 7 , 128 , None ),
169
+ )
170
+ )
171
+ # pylint: enable=unnecessary-pass
156
172
class DPS310 :
157
- #pylint: disable=too-many-instance-attributes
173
+ # pylint: disable=too-many-instance-attributes
158
174
"""Library for the DPS310 Precision Barometric Pressure Sensor.
159
175
160
176
:param ~busio.I2C i2c_bus: The I2C bus the DPS310 is connected to.
@@ -205,8 +221,16 @@ def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
205
221
self ._c20 = None
206
222
self ._c21 = None
207
223
self ._c30 = None
208
- self ._oversample_scalefactor = (524288 , 1572864 , 3670016 , 7864320 , 253952 ,
209
- 516096 , 1040384 , 2088960 )
224
+ self ._oversample_scalefactor = (
225
+ 524288 ,
226
+ 1572864 ,
227
+ 3670016 ,
228
+ 7864320 ,
229
+ 253952 ,
230
+ 516096 ,
231
+ 1040384 ,
232
+ 2088960 ,
233
+ )
210
234
self .initialize ()
211
235
212
236
def initialize (self ):
@@ -251,9 +275,11 @@ def pressure(self):
251
275
252
276
p_red = raw_pressure / self ._pressure_scale
253
277
254
-
255
- pres_calc = (self ._c00 + p_red * (self ._c10 + p_red * (self ._c20 + p_red * self ._c30 )) +
256
- _scaled_rawtemp * (self ._c01 + p_red * (self ._c11 + p_red * self ._c21 )))
278
+ pres_calc = (
279
+ self ._c00
280
+ + p_red * (self ._c10 + p_red * (self ._c20 + p_red * self ._c30 ))
281
+ + _scaled_rawtemp * (self ._c01 + p_red * (self ._c11 + p_red * self ._c21 ))
282
+ )
257
283
258
284
final_pressure = pres_calc / 100
259
285
return final_pressure
@@ -309,7 +335,7 @@ def pressure_oversample_count(self, value):
309
335
raise AttributeError ("pressure_oversample_count must be a SampleCount" )
310
336
311
337
self ._pressure_osbits = value
312
- self ._pressure_shiftbit = ( value > SampleCount .COUNT_8 )
338
+ self ._pressure_shiftbit = value > SampleCount .COUNT_8
313
339
self ._pressure_scale = self ._oversample_scalefactor [value ]
314
340
315
341
@property
@@ -335,12 +361,12 @@ def temperature_oversample_count(self, value):
335
361
336
362
self ._temp_osbits = value
337
363
self ._temp_scale = self ._oversample_scalefactor [value ]
338
- self ._temp_shiftbit = ( value > SampleCount .COUNT_8 )
364
+ self ._temp_shiftbit = value > SampleCount .COUNT_8
339
365
340
366
@staticmethod
341
367
def _twos_complement (val , bits ):
342
368
if val & (1 << (bits - 1 )):
343
- val -= ( 1 << bits )
369
+ val -= 1 << bits
344
370
345
371
return val
346
372
@@ -350,7 +376,7 @@ def _read_calibration(self):
350
376
sleep (0.001 )
351
377
352
378
buffer = bytearray (19 )
353
- coeffs = [None ]* 18
379
+ coeffs = [None ] * 18
354
380
for offset in range (18 ):
355
381
buffer = bytearray (2 )
356
382
buffer [0 ] = 0x10 + offset
@@ -369,7 +395,7 @@ def _read_calibration(self):
369
395
self ._c00 = (coeffs [3 ] << 12 ) | (coeffs [4 ] << 4 ) | ((coeffs [5 ] >> 4 ) & 0x0F )
370
396
self ._c00 = self ._twos_complement (self ._c00 , 20 )
371
397
372
- self ._c10 = ((coeffs [5 ] & 0x0F ) << 16 ) | (coeffs [6 ] << 8 ) | coeffs [7 ]
398
+ self ._c10 = ((coeffs [5 ] & 0x0F ) << 16 ) | (coeffs [6 ] << 8 ) | coeffs [7 ]
373
399
self ._c10 = self ._twos_complement (self ._c10 , 20 )
374
400
375
401
self ._c01 = self ._twos_complement ((coeffs [8 ] << 8 ) | coeffs [9 ], 16 )
0 commit comments