Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions adafruit_tsl2591.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
_TSL2591_LUX_COEFB = 1.64
_TSL2591_LUX_COEFC = 0.59
_TSL2591_LUX_COEFD = 0.86
_TSL2591_MAX_COUNT_100MS = const(36863)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rewrite this number as 0x8fff to match the one below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any aversion to writing the one below to 65535 to reflect what is in the datasheet. This way one can search for 36863 and find it in the datasheet as well as 65535, whereas the hex values are nowhere to be found in the datasheet.

See Control Register (0x01) in the TSL2591 datasheet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about writing one as a comment and one as a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the comments in for the hex representation as well

_TSL2591_MAX_COUNT = const(0xFFFF)

# User-facing constants:
GAIN_LOW = 0x00 # low gain (1x)
Expand Down Expand Up @@ -248,12 +250,21 @@ def lux(self):
and visible light channels.
"""
channel_0, channel_1 = self.raw_luminosity

# Compute the atime in milliseconds
atime = 100.0 * self._integration_time + 100.0

# Set the maximum sensor counts based on the atime setting
if atime == 100:
max_counts = _TSL2591_MAX_COUNT_100MS
else:
max_counts = _TSL2591_MAX_COUNT

# Handle overflow.
if channel_0 == 0xFFFF or channel_1 == 0xFFFF:
if channel_0 >= max_counts or channel_1 >= max_counts:
raise RuntimeError('Overflow reading light channels!')
# Calculate lux using same equation as Arduino library:
# https://github.com/adafruit/Adafruit_TSL2591_Library/blob/master/Adafruit_TSL2591.cpp
atime = 100.0 * self._integration_time + 100.0
again = 1.0
if self._gain == GAIN_MED:
again = 25.0
Expand Down