Skip to content

Ran black, updated to pylint 2.x #21

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 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
114 changes: 59 additions & 55 deletions adafruit_apds9960/apds9960.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,61 +42,61 @@
# INTEGRATION_TIME_DEF = const(0x01)
# GAIN_DEF = const(0x01)

#pylint: disable-msg=bad-whitespace
#APDS9960_RAM = const(0x00)
APDS9960_ENABLE = const(0x80)
APDS9960_ATIME = const(0x81)
#APDS9960_WTIME = const(0x83)
#APDS9960_AILTIL = const(0x84)
# pylint: disable-msg=bad-whitespace
# APDS9960_RAM = const(0x00)
APDS9960_ENABLE = const(0x80)
APDS9960_ATIME = const(0x81)
# APDS9960_WTIME = const(0x83)
# APDS9960_AILTIL = const(0x84)
# APDS9960_AILTH = const(0x85)
# APDS9960_AIHTL = const(0x86)
# APDS9960_AIHTH = const(0x87)
APDS9960_PILT = const(0x89)
APDS9960_PIHT = const(0x8B)
APDS9960_PERS = const(0x8C)
APDS9960_PILT = const(0x89)
APDS9960_PIHT = const(0x8B)
APDS9960_PERS = const(0x8C)
# APDS9960_CONFIG1 = const(0x8D)
# APDS9960_PPULSE = const(0x8E)
APDS9960_CONTROL = const(0x8F)
APDS9960_CONTROL = const(0x8F)
# APDS9960_CONFIG2 = const(0x90)
APDS9960_ID = const(0x92)
APDS9960_STATUS = const(0x93)
APDS9960_CDATAL = const(0x94)
APDS9960_ID = const(0x92)
APDS9960_STATUS = const(0x93)
APDS9960_CDATAL = const(0x94)
# APDS9960_CDATAH = const(0x95)
# APDS9960_RDATAL = const(0x96)
# APDS9960_RDATAH = const(0x97)
# APDS9960_GDATAL = const(0x98)
# APDS9960_GDATAH = const(0x99)
# APDS9960_BDATAL = const(0x9A)
# APDS9960_BDATAH = const(0x9B)
APDS9960_PDATA = const(0x9C)
APDS9960_PDATA = const(0x9C)
# APDS9960_POFFSET_UR = const(0x9D)
# APDS9960_POFFSET_DL = const(0x9E)
# APDS9960_CONFIG3 = const(0x9F)
APDS9960_GPENTH = const(0xA0)
APDS9960_GPENTH = const(0xA0)
# APDS9960_GEXTH = const(0xA1)
APDS9960_GCONF1 = const(0xA2)
APDS9960_GCONF2 = const(0xA3)
APDS9960_GCONF1 = const(0xA2)
APDS9960_GCONF2 = const(0xA3)
# APDS9960_GOFFSET_U = const(0xA4)
# APDS9960_GOFFSET_D = const(0xA5)
# APDS9960_GOFFSET_L = const(0xA7)
# APDS9960_GOFFSET_R = const(0xA9)
APDS9960_GPULSE = const(0xA6)
APDS9960_GCONF3 = const(0xAA)
APDS9960_GCONF4 = const(0xAB)
APDS9960_GFLVL = const(0xAE)
APDS9960_GSTATUS = const(0xAF)
APDS9960_GPULSE = const(0xA6)
APDS9960_GCONF3 = const(0xAA)
APDS9960_GCONF4 = const(0xAB)
APDS9960_GFLVL = const(0xAE)
APDS9960_GSTATUS = const(0xAF)
# APDS9960_IFORCE = const(0xE4)
# APDS9960_PICLEAR = const(0xE5)
# APDS9960_CICLEAR = const(0xE6)
APDS9960_AICLEAR = const(0xE7)
APDS9960_GFIFO_U = const(0xFC)
APDS9960_AICLEAR = const(0xE7)
APDS9960_GFIFO_U = const(0xFC)
# APDS9960_GFIFO_D = const(0xFD)
# APDS9960_GFIFO_L = const(0xFE)
# APDS9960_GFIFO_R = const(0xFF)
#pylint: enable-msg=bad-whitespace
# pylint: enable-msg=bad-whitespace


#pylint: disable-msg=too-many-instance-attributes
# pylint: disable-msg=too-many-instance-attributes
class APDS9960:
"""
APDS9900 provide basic driver services for the ASDS9960 breakout board
Expand All @@ -107,12 +107,9 @@ class APDS9960:
_gesture_mode = RWBit(APDS9960_GCONF4, 0)
_proximity_persistance = RWBits(4, APDS9960_PERS, 4)

def __init__(self,
i2c, *,
interrupt_pin=None,
address=0x39,
integration_time=0x01,
gain=0x01):
def __init__(
self, i2c, *, interrupt_pin=None, address=0x39, integration_time=0x01, gain=0x01
):

self.buf129 = None
self.buf2 = bytearray(2)
Expand All @@ -138,9 +135,9 @@ def __init__(self,

self.color_gain = gain
self.integration_time = integration_time
self.gesture_dimensions = 0x00 # all
self.gesture_fifo_threshold = 0x01 # fifo 4
self.gesture_gain = 0x02 # gain 4
self.gesture_dimensions = 0x00 # all
self.gesture_fifo_threshold = 0x01 # fifo 4
self.gesture_gain = 0x02 # gain 4
self.gesture_proximity_threshold = 50
self._reset_counts()

Expand All @@ -155,7 +152,6 @@ def _reset_counts(self):
self._saw_left_start = 0
self._saw_right_start = 0


enable = RWBit(APDS9960_ENABLE, 0)
"""Board enable. True to enable, False to disable"""
enable_color = RWBit(APDS9960_ENABLE, 1)
Expand Down Expand Up @@ -186,7 +182,7 @@ def enable_gesture(self, enable_flag):
self._gesture_mode = False
self._gesture_enable = enable_flag

def gesture(self): #pylint: disable-msg=too-many-branches
def gesture(self): # pylint: disable-msg=too-many-branches
"""Returns gesture code if detected. =0 if no gesture detected
=1 if an UP, =2 if a DOWN, =3 if an LEFT, =4 if a RIGHT
"""
Expand All @@ -206,14 +202,19 @@ def gesture(self): #pylint: disable-msg=too-many-branches
up_down_diff = 0
left_right_diff = 0
gesture_received = 0
time.sleep(0.030) # 30 ms
time.sleep(0.030) # 30 ms

n_recs = self._read8(APDS9960_GFLVL)
if n_recs:

with self.i2c_device as i2c:
i2c.write_then_readinto(buffer, buffer, out_end=1, in_start=1,
in_end=min(129, 1 + n_recs * 4))
i2c.write_then_readinto(
buffer,
buffer,
out_end=1,
in_start=1,
in_end=min(129, 1 + n_recs * 4),
)
upp, down, left, right = buffer[1:5]

if abs(upp - down) > 13:
Expand All @@ -227,14 +228,14 @@ def gesture(self): #pylint: disable-msg=too-many-branches
# either leading edge of down movement
# or trailing edge of up movement
if self._saw_up_start:
gesture_received = 0x01 # up
gesture_received = 0x01 # up
else:
self._saw_down_start += 1
elif up_down_diff > 0:
# either leading edge of up movement
# or trailing edge of down movement
if self._saw_down_start:
gesture_received = 0x02 # down
gesture_received = 0x02 # down
else:
self._saw_up_start += 1

Expand All @@ -243,14 +244,14 @@ def gesture(self): #pylint: disable-msg=too-many-branches
# either leading edge of right movement
# trailing edge of left movement
if self._saw_left_start:
gesture_received = 0x03 # left
gesture_received = 0x03 # left
else:
self._saw_right_start += 1
elif left_right_diff > 0:
# either leading edge of left movement
# trailing edge of right movement
if self._saw_right_start:
gesture_received = 0x04 #right
gesture_received = 0x04 # right
else:
self._saw_left_start += 1

Expand Down Expand Up @@ -282,10 +283,12 @@ def color_data_ready(self):
@property
def color_data(self):
"""Tuple containing r, g, b, c values"""
return self._color_data16(APDS9960_CDATAL + 2), \
self._color_data16(APDS9960_CDATAL + 4), \
self._color_data16(APDS9960_CDATAL + 6), \
self._color_data16(APDS9960_CDATAL)
return (
self._color_data16(APDS9960_CDATAL + 2),
self._color_data16(APDS9960_CDATAL + 4),
self._color_data16(APDS9960_CDATAL + 6),
self._color_data16(APDS9960_CDATAL),
)

### PROXIMITY
@property
Expand All @@ -295,30 +298,31 @@ def proximity_interrupt_threshold(self):
When setting the proximity interrupt threshold values using a tuple of
zero to three values: low threshold, high threshold, persistance.
persistance defaults to 4 if not provided"""
return self._read8(APDS9960_PILT), \
self._read8(APDS9960_PIHT), \
self._proximity_persistance
return (
self._read8(APDS9960_PILT),
self._read8(APDS9960_PIHT),
self._proximity_persistance,
)

@proximity_interrupt_threshold.setter
def proximity_interrupt_threshold(self, setting_tuple):
if setting_tuple:
self._write8(APDS9960_PILT, setting_tuple[0])
if len(setting_tuple) > 1:
self._write8(APDS9960_PIHT, setting_tuple[1])
persist = 4 # default 4
persist = 4 # default 4
if len(setting_tuple) > 2:
persist = min(setting_tuple[2], 7)
self._proximity_persistance = persist


@property
def gesture_proximity_threshold(self):
"""Proximity threshold value: range 0-255"""
return self._read8(APDS9960_GPENTH)

@gesture_proximity_threshold.setter
def gesture_proximity_threshold(self, thresh):
self._write8(APDS9960_GPENTH, thresh & 0xff)
self._write8(APDS9960_GPENTH, thresh & 0xFF)

@property
def proximity(self):
Expand All @@ -336,7 +340,7 @@ def integration_time(self):

@integration_time.setter
def integration_time(self, int_time):
self._write8(APDS9960_ATIME, int_time & 0xff)
self._write8(APDS9960_ATIME, int_time & 0xFF)

# method for reading and writing to I2C
def _write8(self, command, abyte):
Expand Down
2 changes: 2 additions & 0 deletions adafruit_apds9960/colorutility.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_APDS9960.git"


def calculate_color_temperature(r, g, b):
"""Converts the raw R/G/B values to color temperature in degrees Kelvin"""

Expand All @@ -55,6 +56,7 @@ def calculate_color_temperature(r, g, b):
# Return the results in degrees Kelvin
return cct


def calculate_lux(r, g, b):
"""Calculate ambient light values"""
# This only uses RGB ... how can we integrate clear or calculate lux
Expand Down
Loading