Skip to content

Commit

Permalink
skip first read before write
Browse files Browse the repository at this point in the history
  • Loading branch information
thetic committed Feb 22, 2025
1 parent 977fd96 commit 572ced5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/klipper_sgp40/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(self, config):
self.humidity_sensor = config.get("ref_humidity_sensor", None)

self._heaters = []
self._measuring = False

self.raw = self.voc = self.temp = self.humidity = 0
self.min_temp = self.max_temp = 0
Expand Down Expand Up @@ -248,10 +249,10 @@ def _handle_step(self, eventtime):
self._is_hot(h, eventtime) for h in self._heaters
)

# TODO: don't do this the first time
# Read latest measurement
response = self._read()
self.raw = response[0]
if self._measuring:
# Read latest measurement
response = self._read()
self.raw = response[0]

# Calculate VOC index
self.voc = self._gia.process(self.raw)
Expand Down Expand Up @@ -285,6 +286,7 @@ def _handle_step(self, eventtime):
+ _temperature_to_ticks(self.temp)
)
self.i2c.i2c_write(cmd)
self._measuring = True

# Schedule next step
measured_time = self.reactor.monotonic()
Expand Down

0 comments on commit 572ced5

Please sign in to comment.