Skip to content

Added power saving support #36

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
29 changes: 29 additions & 0 deletions adafruit_veml7700.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ class VEML7700:
ALS_800MS,
]

# Power saving mode settings
PSM_500 = const(0x0)
PSM_1000 = const(0x1)
PSM_2000 = const(0x2)
PSM_4000 = const(0x3)

# Power saving mode value integers
psm_values = {
PSM_500: 500,
PSM_1000: 1000,
PSM_2000: 2000,
PSM_4000: 4000,
}

# Convenience list of power saving mode settings
psm_settings = [PSM_500, PSM_1000, PSM_2000, PSM_4000]

# ALS - Ambient light sensor high resolution output data
light = ROUnaryStruct(0x04, "<H")
"""Ambient light data.
Expand Down Expand Up @@ -193,6 +210,13 @@ class VEML7700:

"""

# Power saving register
light_psm = RWBits(2, 0x03, 1, register_width=2)
"""Power saving mode setting. Power saving settings are 500, 1000, 2000, 4000 ms.
Settings options are: PSM_500, PSM_1000, PSM_2000, PSM_4000"""
light_psm_en = RWBit(0x03, 0, register_width=2)
"""Power saving mode enable setting. When ``True``, power saving mode is enabled."""

def __init__(self, i2c_bus: I2C, address: int = 0x10) -> None:
self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
for _ in range(3):
Expand Down Expand Up @@ -348,3 +372,8 @@ def wait_autolux(self, wait_time: float) -> None:
minimum_wait_time = self.integration_time_value() / 1000
actual_wait_time = max(minimum_wait_time, wait_time)
time.sleep(actual_wait_time)

def psm_value(self) -> float:
"""Power saving mode value in integer form. Used for calculating refresh time."""
psm = self.light_psm
return self.psm_values[psm]