Skip to content

Commit

Permalink
Skip initial blackout period
Browse files Browse the repository at this point in the history
  • Loading branch information
thetic committed Jan 21, 2025
1 parent 309ab82 commit 687fd15
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/klipper_sgp40/gia.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def __init__(self, sampling_interval=1.0):
self._adaptive_lowpass_x1 = 0.0
self._adaptive_lowpass_x2 = 0.0
self._adaptive_lowpass_x3 = 0.0
self._uptime = 0.0
self._sraw = 0.0
self._gas_index = 0
self.reset()
Expand Down Expand Up @@ -132,24 +131,20 @@ def process(self, sraw):
Calculated gas index value from the raw sensor value.
Zero during initial blackout period and 1..500 afterwards
"""
initial_blackout = 45.0
if self._uptime <= initial_blackout:
self._uptime = self._uptime + self._sampling_interval
else:
if (sraw > 0) and (sraw < 65000):
if sraw < (self._sraw_minimum + 1):
sraw = self._sraw_minimum + 1
elif sraw > (self._sraw_minimum + 32767):
sraw = self._sraw_minimum + 32767
self._sraw = float(sraw - self._sraw_minimum)
self._gas_index = self._mox_process(self._sraw)
self._gas_index = self._sigmoid_scaled_process(self._gas_index)
self._gas_index = self._adaptive_lowpass_process(self._gas_index)
if self._gas_index < 0.5:
self._gas_index = 0.5
if self._sraw > 0.0:
self._mve_process(self._sraw)
self._mox_set_parameters(self._mve_std, self._mve_offset_mean)
if (sraw > 0) and (sraw < 65000):
if sraw < (self._sraw_minimum + 1):
sraw = self._sraw_minimum + 1
elif sraw > (self._sraw_minimum + 32767):
sraw = self._sraw_minimum + 32767
self._sraw = float(sraw - self._sraw_minimum)
self._gas_index = self._mox_process(self._sraw)
self._gas_index = self._sigmoid_scaled_process(self._gas_index)
self._gas_index = self._adaptive_lowpass_process(self._gas_index)
if self._gas_index < 0.5:
self._gas_index = 0.5
if self._sraw > 0.0:
self._mve_process(self._sraw)
self._mox_set_parameters(self._mve_std, self._mve_offset_mean)
return round(self._gas_index)

def _init_instances(self):
Expand Down

0 comments on commit 687fd15

Please sign in to comment.