From 5772169dfed00899b5162780265a4b0cb48ada8b Mon Sep 17 00:00:00 2001 From: garyk10 <52009419+garyk10@users.noreply.github.com> Date: Wed, 5 Apr 2023 20:26:00 -0400 Subject: [PATCH 1/2] using _all_channels to update efficiently When not changing between low and high, the _channel_#_data was not being updated. Also, the clear and nir data is available when _low_channels_configured, so no need to change to high. --- adafruit_as7341.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_as7341.py b/adafruit_as7341.py index 75800a4..8c2aebf 100644 --- a/adafruit_as7341.py +++ b/adafruit_as7341.py @@ -436,13 +436,13 @@ def channel_680nm(self) -> int: @property def channel_clear(self) -> int: """The current reading for the clear sensor""" - self._configure_f5_f8() + self._all_channels return self._channel_4_data @property def channel_nir(self) -> int: """The current reading for the NIR (near-IR) sensor""" - self._configure_f5_f8() + self._all_channels return self._channel_5_data def _wait_for_data(self, timeout: float = 1.0) -> None: @@ -465,6 +465,7 @@ def _configure_f1_f4(self) -> None: """Configure the sensor to read from elements F1-F4, Clear, and NIR""" # disable SP_EN bit while making config changes if self._low_channels_configured: + self._all_channels return self._high_channels_configured = False self._flicker_detection_1k_configured = False @@ -488,6 +489,7 @@ def _configure_f5_f8(self) -> None: """Configure the sensor to read from elements F5-F8, Clear, and NIR""" # disable SP_EN bit while making config changes if self._high_channels_configured: + self._all_channels return self._low_channels_configured = False From 0afda19db2d26a74f38e2e726759e526cb0717b9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 17 Apr 2023 16:21:42 -0500 Subject: [PATCH 2/2] catch return from all_channels --- adafruit_as7341.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_as7341.py b/adafruit_as7341.py index 8c2aebf..4135b1b 100644 --- a/adafruit_as7341.py +++ b/adafruit_as7341.py @@ -436,13 +436,13 @@ def channel_680nm(self) -> int: @property def channel_clear(self) -> int: """The current reading for the clear sensor""" - self._all_channels + _ = self._all_channels return self._channel_4_data @property def channel_nir(self) -> int: """The current reading for the NIR (near-IR) sensor""" - self._all_channels + _ = self._all_channels return self._channel_5_data def _wait_for_data(self, timeout: float = 1.0) -> None: @@ -465,7 +465,7 @@ def _configure_f1_f4(self) -> None: """Configure the sensor to read from elements F1-F4, Clear, and NIR""" # disable SP_EN bit while making config changes if self._low_channels_configured: - self._all_channels + _ = self._all_channels return self._high_channels_configured = False self._flicker_detection_1k_configured = False @@ -489,7 +489,7 @@ def _configure_f5_f8(self) -> None: """Configure the sensor to read from elements F5-F8, Clear, and NIR""" # disable SP_EN bit while making config changes if self._high_channels_configured: - self._all_channels + _ = self._all_channels return self._low_channels_configured = False