Skip to content

Commit 70cea86

Browse files
committed
add glass_attenuation property
1 parent bda9faf commit 70cea86

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

adafruit_tcs34725.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def __init__(self, i2c, address=0x29):
9595
self._device = i2c_device.I2CDevice(i2c, address)
9696
self._active = False
9797
self.integration_time = 2.4
98+
self._glass_attenuation = None
99+
self.glass_attenuation = 1.0
98100
# Check sensor ID is expectd value.
99101
sensor_id = self._read_u8(_REGISTER_SENSORID)
100102
if sensor_id not in (0x44, 0x10):
@@ -247,13 +249,13 @@ def _temperature_and_lux_dn40(self):
247249
R, G, B, C = self.color_raw
248250

249251
# Device specific values (DN40 Table 1 in Appendix I)
250-
GA = 1.0 # Glass Attenuation Factor
251-
DF = 310.0 # Device Factor
252-
R_Coef = 0.136 # |
253-
G_Coef = 1.0 # | used in lux computation
254-
B_Coef = -0.444 # |
255-
CT_Coef = 3810 # Color Temperature Coefficient
256-
CT_Offset = 1391 # Color Temperatuer Offset
252+
GA = self.glass_attenuation # Glass Attenuation Factor
253+
DF = 310.0 # Device Factor
254+
R_Coef = 0.136 # |
255+
G_Coef = 1.0 # | used in lux computation
256+
B_Coef = -0.444 # |
257+
CT_Coef = 3810 # Color Temperature Coefficient
258+
CT_Offset = 1391 # Color Temperatuer Offset
257259

258260
# Analog/Digital saturation (DN40 3.5)
259261
SATURATION = 65535 if 256 - ATIME > 63 else 1024 * (256 - ATIME)
@@ -282,6 +284,23 @@ def _temperature_and_lux_dn40(self):
282284

283285
return lux, CT
284286

287+
@property
288+
def glass_attenuation(self):
289+
"""The Glass Attenuation (FA) factor used to compensate for lower light
290+
levels at the device due to the possible presence of glass. The GA is
291+
the inverse of the glass transmissivity (T), so GA = 1/T. A transmissivity
292+
of 50% gives GA = 1 / 0.50 = 2. If no glass is present, use GA = 1.
293+
See Application Note: DN40-Rev 1.0 – Lux and CCT Calculations using
294+
ams Color Sensors for more details.
295+
"""
296+
return self._glass_attenuation
297+
298+
@glass_attenuation.setter
299+
def glass_attenuation(self, value):
300+
if value < 1:
301+
raise ValueError("Glass attenuation factor must be at least 1.")
302+
self._glass_attenuation = value
303+
285304
def _valid(self):
286305
# Check if the status bit is set and the chip is ready.
287306
return bool(self._read_u8(_REGISTER_STATUS) & 0x01)

0 commit comments

Comments
 (0)