Skip to content

Coerce led_current to be between 4-258mA. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
11 changes: 6 additions & 5 deletions adafruit_as7341.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ class AS7341: # pylint:disable=too-many-instance-attributes
"""Library for the AS7341 Sensor


:param ~busio.I2C i2c_bus: The I2C bus the AS7341 is connected to.
:param address: The I2C address of the sensor
:param ~busio.I2C i2c_bus: The I2C bus the AS7341 is connected to.
:param address: The I2C address of the sensor

"""

Expand Down Expand Up @@ -583,8 +583,7 @@ def _set_smux(self, smux_addr, smux_out1, smux_out2):

@property
def gain(self):
"""The ADC gain multiplier. Must be a valid `adafruit_as7341.Gain`
"""
"""The ADC gain multiplier. Must be a valid `adafruit_as7341.Gain`"""
return self._gain

@gain.setter
Expand Down Expand Up @@ -616,7 +615,9 @@ def led_current(self):
@led_current.setter
@_low_bank
def led_current(self, led_curent):
new_current = int((led_curent - 4) / 2)
"""coerce led_curent to be between 4 & 258, then calculate value
to be put into register on chip"""
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment will not be rendered in the documentation because only the docstring for the getter/@property is rendered. That said, I'm OK with leaving it as a explanation of the code below it. It could also be a comment.

Please edit the setter docstring to mention the range of valid values, and to add something like "invalid values will be rounded to the closest valid number". No need to get overly specific. People who care about the nitty gritty details can read the source ;)

Please keep in mind that we try to talk about properties as nouns and not verbs. led_current doesn't do something, it is something. Apologies if this sounds a bit pedantic, but we try our best to remain consistent in style.

For more info you can see the design guide here:
https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html

new_current = int((min(258, max(4, led_curent)) - 4) / 2)
self._led_current_bits = new_current

@property
Expand Down