From 335bebc8f7905cf4ea2d97ec6b0d03c7a3bcdc82 Mon Sep 17 00:00:00 2001 From: WindFishDiety Date: Wed, 8 May 2019 13:58:38 -0400 Subject: [PATCH 1/2] Fixes issue #7 whereby the read method should be renamed to raw_uv --- README.rst | 2 +- adafruit_veml6070.py | 16 ++++++++-------- examples/veml6070_simpletest.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index f376abb..46fd60b 100644 --- a/README.rst +++ b/README.rst @@ -45,7 +45,7 @@ Usage Example # take 10 readings for j in range(10): - uv_raw = uv.read + uv_raw = uv.raw_uv risk_level = uv.get_index(uv_raw) print('Reading: {0} | Risk Level: {1}'.format(uv_raw, risk_level)) time.sleep(1) diff --git a/adafruit_veml6070.py b/adafruit_veml6070.py index edb6940..4f3df72 100644 --- a/adafruit_veml6070.py +++ b/adafruit_veml6070.py @@ -105,7 +105,7 @@ class VEML6070: # take 10 readings for j in range(10): - uv_raw = uv.read + uv_raw = uv.raw_uv risk_level = uv.get_index(uv_raw) print('Reading: ', uv_raw, ' | Risk Level: ', risk_level) time.sleep(1) @@ -145,18 +145,18 @@ def __init__(self, i2c_bus, _veml6070_it="VEML6070_1_T", ack=False): @property - def read(self): + def raw_uv(self): """ Reads and returns the value of the UV intensity. """ - read_buf = bytearray(2) + uv_buf = bytearray(2) with self.i2c_low as i2c_low: - i2c_low.readinto(read_buf, end=1) + i2c_low.readinto(uv_buf, end=1) with self.i2c_high as i2c_high: - i2c_high.readinto(read_buf, start=1) + i2c_high.readinto(uv_buf, start=1) - uvi = read_buf[1] << 8 | read_buf[0] + uvi = uv_buf[1] << 8 | uv_buf[0] return uvi @@ -231,7 +231,7 @@ def sleep(self): def wake(self): """ - Wakes the VEML6070 from sleep. ``[veml6070].read`` will also wake from sleep. + Wakes the VEML6070 from sleep. ``[veml6070].raw_uv`` will also wake from sleep. """ self.buf[0] = (self._ack << 5 | self._ack_thd << 4 | _VEML6070_INTEGRATION_TIME[self._it][0] << 2 | 0x02) @@ -241,7 +241,7 @@ def wake(self): def get_index(self, _raw): """ Calculates the UV Risk Level based on the captured UV reading. Requres the ``_raw`` - argument (from ``veml6070.read``). Risk level is available for Integration Times (IT) + argument (from ``veml6070.raw_uv``). Risk level is available for Integration Times (IT) 1, 2, & 4. The result is automatically scaled to the current IT setting. LEVEL* UV Index diff --git a/examples/veml6070_simpletest.py b/examples/veml6070_simpletest.py index 99414d7..3ac5aef 100644 --- a/examples/veml6070_simpletest.py +++ b/examples/veml6070_simpletest.py @@ -13,7 +13,7 @@ # take 10 readings for j in range(10): - uv_raw = uv.read + uv_raw = uv.raw_uv risk_level = uv.get_index(uv_raw) print('Reading: {0} | Risk Level: {1}'.format(uv_raw, risk_level)) time.sleep(1) From a4a3e470155c535a6d875b052c35316bfbc7ae62 Mon Sep 17 00:00:00 2001 From: WindFishDiety Date: Thu, 9 May 2019 21:27:19 -0400 Subject: [PATCH 2/2] Addressing cosmetic concerns --- README.rst | 2 +- adafruit_veml6070.py | 18 ++++++++---------- examples/veml6070_simpletest.py | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index 46fd60b..2c2949e 100644 --- a/README.rst +++ b/README.rst @@ -45,7 +45,7 @@ Usage Example # take 10 readings for j in range(10): - uv_raw = uv.raw_uv + uv_raw = uv.uv_raw risk_level = uv.get_index(uv_raw) print('Reading: {0} | Risk Level: {1}'.format(uv_raw, risk_level)) time.sleep(1) diff --git a/adafruit_veml6070.py b/adafruit_veml6070.py index 4f3df72..c4dd08f 100644 --- a/adafruit_veml6070.py +++ b/adafruit_veml6070.py @@ -105,7 +105,7 @@ class VEML6070: # take 10 readings for j in range(10): - uv_raw = uv.raw_uv + uv_raw = uv.uv_raw risk_level = uv.get_index(uv_raw) print('Reading: ', uv_raw, ' | Risk Level: ', risk_level) time.sleep(1) @@ -145,20 +145,18 @@ def __init__(self, i2c_bus, _veml6070_it="VEML6070_1_T", ack=False): @property - def raw_uv(self): + def uv_raw(self): """ Reads and returns the value of the UV intensity. """ - uv_buf = bytearray(2) + buffer = bytearray(2) with self.i2c_low as i2c_low: - i2c_low.readinto(uv_buf, end=1) + i2c_low.readinto(buffer, end=1) with self.i2c_high as i2c_high: - i2c_high.readinto(uv_buf, start=1) + i2c_high.readinto(buffer, start=1) - uvi = uv_buf[1] << 8 | uv_buf[0] - - return uvi + return buffer[1] << 8 | buffer[0] @property def ack(self): @@ -231,7 +229,7 @@ def sleep(self): def wake(self): """ - Wakes the VEML6070 from sleep. ``[veml6070].raw_uv`` will also wake from sleep. + Wakes the VEML6070 from sleep. ``[veml6070].uv_raw`` will also wake from sleep. """ self.buf[0] = (self._ack << 5 | self._ack_thd << 4 | _VEML6070_INTEGRATION_TIME[self._it][0] << 2 | 0x02) @@ -241,7 +239,7 @@ def wake(self): def get_index(self, _raw): """ Calculates the UV Risk Level based on the captured UV reading. Requres the ``_raw`` - argument (from ``veml6070.raw_uv``). Risk level is available for Integration Times (IT) + argument (from ``veml6070.uv_raw``). Risk level is available for Integration Times (IT) 1, 2, & 4. The result is automatically scaled to the current IT setting. LEVEL* UV Index diff --git a/examples/veml6070_simpletest.py b/examples/veml6070_simpletest.py index 3ac5aef..727c547 100644 --- a/examples/veml6070_simpletest.py +++ b/examples/veml6070_simpletest.py @@ -13,7 +13,7 @@ # take 10 readings for j in range(10): - uv_raw = uv.raw_uv + uv_raw = uv.uv_raw risk_level = uv.get_index(uv_raw) print('Reading: {0} | Risk Level: {1}'.format(uv_raw, risk_level)) time.sleep(1)