Skip to content

Update Functions To Use @property & setter Structure #5

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

Merged
merged 2 commits into from
Sep 17, 2018
Merged
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
32 changes: 22 additions & 10 deletions adafruit_veml6070.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def __init__(self, i2c_bus, _veml6070_it="VEML6070_1_T", ack=False):
i2c_cmd.write(self.buf)



@property
def read(self):
"""
Expand All @@ -161,27 +160,36 @@ def read(self):

return uvi

def set_ack(self, new_ack=False):
@property
def ack(self):
"""
Turns on or off the ACKnowledge function of the sensor. The ACK function will send
a signal to the host when the value of the sensed UV light changes beyond the
programmed threshold. Use ``[veml6070].set_ack_threshold`` to change between the two
available threshold settings.
programmed threshold.
"""
if new_ack not in (True, False):
return self._ack

@ack.setter
def ack(self, new_ack):
if new_ack != bool(new_ack):
raise ValueError("ACK must be 'True' or 'False'.")
self._ack = int(new_ack)
self.buf[0] = (self._ack << 5 | self._ack_thd << 4 |
_VEML6070_INTEGRATION_TIME[self._it][0] << 2 | 0x02)
with self.i2c_cmd as i2c_cmd:
i2c_cmd.write(self.buf)

def set_ack_threshold(self, new_ack_thd=0):
@property
def ack_threshold(self):
"""
Sets the ACKnowledge Threshold, which alerts the host controller to value changes
The ACKnowledge Threshold, which alerts the host controller to value changes
greater than the threshold. Available settings are: ``0`` = 102 steps; ``1`` = 145 steps.
``0`` is the default setting.
"""
return self._ack_thd

@ack_threshold.setter
def ack_threshold(self, new_ack_thd):
if new_ack_thd not in (0, 1):
raise ValueError("ACK Threshold must be '0' or '1'.")
self._ack_thd = int(new_ack_thd)
Expand All @@ -190,14 +198,18 @@ def set_ack_threshold(self, new_ack_thd=0):
with self.i2c_cmd as i2c_cmd:
i2c_cmd.write(self.buf)


def set_integration_time(self, new_it):
@property
def integration_time(self):
"""
Sets the Integration Time of the sensor. This is the refresh interval of the
The Integration Time of the sensor, which is the refresh interval of the
sensor. The higher the refresh interval, the more accurate the reading is (at
the cost of less sampling). The available settings are: ``VEML6070_HALF_T``,
``VEML6070_1_T``, ``VEML6070_2_T``, ``VEML6070_4_T``.
"""
return self._it

@integration_time.setter
def integration_time(self, new_it):
if new_it not in _VEML6070_INTEGRATION_TIME:
raise ValueError("Integration Time invalid. Valid values are: ",
_VEML6070_INTEGRATION_TIME.keys())
Expand Down