Skip to content

Commit 82368d6

Browse files
committed
black
1 parent 69b093c commit 82368d6

File tree

3 files changed

+21
-34
lines changed

3 files changed

+21
-34
lines changed

adafruit_sgp40/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ def initialize(self):
133133
featureset = self._read_word_from_command()
134134
if featureset[0] != 0x3220:
135135

136-
raise RuntimeError("Feature set does not match: %s" %
137-
hex(featureset[0]))
136+
raise RuntimeError("Feature set does not match: %s" % hex(featureset[0]))
138137

139138
self._voc_algorithm.vocalgorithm_init()
140139

@@ -281,9 +280,9 @@ def _read_word_from_command(
281280
i2c.readinto(replybuffer, end=replylen)
282281

283282
for i in range(0, replylen, 3):
284-
if not self._check_crc8(replybuffer[i: i + 2], replybuffer[i + 2]):
283+
if not self._check_crc8(replybuffer[i : i + 2], replybuffer[i + 2]):
285284
raise RuntimeError("CRC check failed while reading data")
286-
readdata_buffer.append(unpack_from(">H", replybuffer[i: i + 2])[0])
285+
readdata_buffer.append(unpack_from(">H", replybuffer[i : i + 2])[0])
287286

288287
return readdata_buffer
289288

adafruit_sgp40/voc_algorithm.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646

4747

4848
class DFRobot_vocalgorithmParams:
49-
"""Class for voc index algorithm
50-
"""
49+
"""Class for voc index algorithm"""
5150

5251
# pylint: disable=all
5352
# Complex math conversion from C
@@ -127,8 +126,7 @@ def _fix16_mul(self, inarg0, inarg1):
127126
return FIX16_OVERFLOW
128127
product_lo_tmp = product_lo & 0xFFFFFFFF
129128
product_lo = (product_lo - 0x8000) & 0xFFFFFFFF
130-
product_lo = (
131-
product_lo - ((product_hi & 0xFFFFFFFF) >> 31)) & 0xFFFFFFFF
129+
product_lo = (product_lo - ((product_hi & 0xFFFFFFFF) >> 31)) & 0xFFFFFFFF
132130
if product_lo > product_lo_tmp:
133131
product_hi = product_hi - 1
134132
result = (product_hi << 16) | (product_lo >> 16)
@@ -237,16 +235,14 @@ def _fix16_exp(self, x):
237235
return res
238236

239237
def vocalgorithm_init(self):
240-
self.params.mvoc_index_offset = self._f16(
241-
VOCALGORITHM_VOC_INDEX_OFFSET_DEFAULT)
238+
self.params.mvoc_index_offset = self._f16(VOCALGORITHM_VOC_INDEX_OFFSET_DEFAULT)
242239
self.params.mtau_mean_variance_hours = self._f16(
243240
VOCALGORITHM_TAU_MEAN_VARIANCE_HOURS
244241
)
245242
self.params.mgating_max_duration_minutes = self._f16(
246243
VOCALGORITHM_GATING_MAX_DURATION_MINUTES
247244
)
248-
self.params.msraw_std_initial = self._f16(
249-
VOCALGORITHM_SRAW_STD_INITIAL)
245+
self.params.msraw_std_initial = self._f16(VOCALGORITHM_SRAW_STD_INITIAL)
250246
self.params.muptime = self._f16(0.0)
251247
self.params.msraw = self._f16(0.0)
252248
self.params.mvoc_index = 0
@@ -278,8 +274,10 @@ def _vocalgorithm_get_states(self, state0, state1):
278274

279275
def _vocalgorithm_set_states(self, state0, state1):
280276
self._vocalgorithm__mean_variance_estimator__set_states(
281-
self.params, state0, state1, self._f16(
282-
VOCALGORITHM_PERSISTENCE_UPTIME_GAMMA)
277+
self.params,
278+
state0,
279+
state1,
280+
self._f16(VOCALGORITHM_PERSISTENCE_UPTIME_GAMMA),
283281
)
284282
self.params.msraw = state0
285283

@@ -291,8 +289,7 @@ def _vocalgorithm_set_tuning_parameters(
291289
std_initial,
292290
):
293291
self.params.mvoc_index_offset = self._fix16_from_int(voc_index_offset)
294-
self.params.mtau_mean_variance_hours = self._fix16_from_int(
295-
learning_time_hours)
292+
self.params.mtau_mean_variance_hours = self._fix16_from_int(learning_time_hours)
296293
self.params.mgating_max_duration_minutes = self._fix16_from_int(
297294
gating_max_duration_minutes
298295
)
@@ -330,8 +327,7 @@ def vocalgorithm_process(self, sraw):
330327
self._vocalgorithm__mean_variance_estimator__get_std(),
331328
self._vocalgorithm__mean_variance_estimator__get_mean(),
332329
)
333-
voc_index = self._fix16_cast_to_int(
334-
(self.params.mvoc_index + self._f16(0.5)))
330+
voc_index = self._fix16_cast_to_int((self.params.mvoc_index + self._f16(0.5)))
335331
return voc_index
336332

337333
def _vocalgorithm__mean_variance_estimator__init(self):
@@ -387,8 +383,7 @@ def _vocalgorithm__mean_variance_estimator__set_parameters(
387383
self.params.m_mean_variance_estimator__gamma_variance = self._f16(0.0)
388384
self.params.m_mean_variance_estimator_uptime_gamma = self._f16(0.0)
389385
self.params.m_mean_variance_estimator_uptime_gating = self._f16(0.0)
390-
self.params.m_mean_variance_estimator_gating_duration_minutes = self._f16(
391-
0.0)
386+
self.params.m_mean_variance_estimator_gating_duration_minutes = self._f16(0.0)
392387

393388
def _vocalgorithm__mean_variance_estimator__set_states(
394389
self, mean, std, uptime_gamma
@@ -536,8 +531,7 @@ def _vocalgorithm__mean_variance_estimator___calculate_gamma(
536531
(
537532
self._fix16_mul(
538533
(self._f16(1.0) - sigmoid_gating_mean),
539-
self._f16(
540-
(1.0 + VOCALGORITHM_GATING_MAX_RATIO)),
534+
self._f16((1.0 + VOCALGORITHM_GATING_MAX_RATIO)),
541535
)
542536
)
543537
- self._f16(VOCALGORITHM_GATING_MAX_RATIO)
@@ -557,8 +551,7 @@ def _vocalgorithm__mean_variance_estimator___calculate_gamma(
557551
self.params.m_mean_variance_estimator_gating_duration_minutes
558552
> self.params.m_mean_variance_estimator_gating_max_duration_minutes
559553
):
560-
self.params.m_mean_variance_estimator_uptime_gating = self._f16(
561-
0.0)
554+
self.params.m_mean_variance_estimator_uptime_gating = self._f16(0.0)
562555

563556
def _vocalgorithm__mean_variance_estimator__process(
564557
self, sraw, voc_index_from_prior
@@ -682,8 +675,7 @@ def _vocalgorithm__mean_variance_estimator___sigmoid__process(self, sample):
682675
)
683676

684677
def _vocalgorithm__mox_model__init(self):
685-
self._vocalgorithm__mox_model__set_parameters(
686-
self._f16(1.0), self._f16(0.0))
678+
self._vocalgorithm__mox_model__set_parameters(self._f16(1.0), self._f16(0.0))
687679

688680
def _vocalgorithm__mox_model__set_parameters(self, SRAW_STD, SRAW_MEAN):
689681
self.params.m_mox_model_sraw_std = SRAW_STD
@@ -727,8 +719,7 @@ def _vocalgorithm__sigmoid_scaled__process(self, sample):
727719
self._f16(VOCALGORITHM_SIGMOID_L)
728720
- (
729721
self._fix16_mul(
730-
self._f16(
731-
5.0), self.params.m_sigmoid_scaled_offset
722+
self._f16(5.0), self.params.m_sigmoid_scaled_offset
732723
)
733724
)
734725
),
@@ -805,16 +796,14 @@ def _vocalgorithm__adaptive_lowpass__process(self, sample):
805796
)
806797
tau_a = (
807798
self._fix16_mul(
808-
self._f16((VOCALGORITHM_LP_TAU_SLOW -
809-
VOCALGORITHM_LP_TAU_FAST)), F1
799+
self._f16((VOCALGORITHM_LP_TAU_SLOW - VOCALGORITHM_LP_TAU_FAST)), F1
810800
)
811801
) + self._f16(VOCALGORITHM_LP_TAU_FAST)
812802
a3 = self._fix16_div(
813803
self._f16(VOCALGORITHM_SAMPLING_INTERVAL),
814804
(self._f16(VOCALGORITHM_SAMPLING_INTERVAL) + tau_a),
815805
)
816806
self.params.m_adaptive_lowpass_x3 = (
817-
self._fix16_mul((self._f16(1.0) - a3),
818-
self.params.m_adaptive_lowpass_x3)
807+
self._fix16_mul((self._f16(1.0) - a3), self.params.m_adaptive_lowpass_x3)
819808
) + (self._fix16_mul(a3, sample))
820809
return self.params.m_adaptive_lowpass_x3

examples/sgp40_indextest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
# For Compensated voc index readings
2626
# It may take several minutes for the VOC index to start changing
2727
# as it calibrates the baseline readings.
28-
voc_index = sgp.measure_raw(
29-
temperature=temperature, relative_humidity=humidity)
28+
voc_index = sgp.measure_raw(temperature=temperature, relative_humidity=humidity)
3029

3130
print(compensated_raw_gas)
3231
print(voc_index)

0 commit comments

Comments
 (0)