Skip to content

Gain 0.5 inaccessible due to CV structure? #44

@bobthechemist

Description

@bobthechemist

adafruit_as7341.Gain.is_valid(0.5) returns False even though 0.5 is valid (see here). Gain inherits CV which limits the 2nd and third positions of the tuple to INT (see here) which is - I think - the cause of the issue. adafruit_as7341.Gain.is_valid(0) returns True, so 0.5 has probably been rounded down when the Gain class is created.

Setting gain to 0 doesn't stop functionality:

import board
import adafruit_as7341
from time import sleep

i2c = board.I2C()
s = adafruit_as7341.AS7341(i2c)

s.led = True

# first reading is usually trash
junk = s.channel_480nm
sleep(0.5)

for g in [0, 1, 2, 4, 8]:
    s.gain = g
    sleep(0.5)
    print(f"gain:{g}, channel 480 nm: {s.channel_480nm}")

s.led = False

outputs the following

gain:0, channel 480 nm: 18
gain:1, channel 480 nm: 36
gain:2, channel 480 nm: 70
gain:4, channel 480 nm: 249
gain:8, channel 480 nm: 4268

Other objects rely on CV, but they all seem to have INT in the third slot of the tuple, so perhaps a simple return int(value) here might do the trick?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions