diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/adafruit_apds9960/apds9960.py b/adafruit_apds9960/apds9960.py index 70fcd08..2e3ed69 100644 --- a/adafruit_apds9960/apds9960.py +++ b/adafruit_apds9960/apds9960.py @@ -42,25 +42,25 @@ # 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) @@ -68,35 +68,35 @@ # 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 @@ -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) @@ -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() @@ -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) @@ -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 """ @@ -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: @@ -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 @@ -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 @@ -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 @@ -295,9 +298,11 @@ 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): @@ -305,12 +310,11 @@ def proximity_interrupt_threshold(self, 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""" @@ -318,7 +322,7 @@ def gesture_proximity_threshold(self): @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): @@ -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): diff --git a/adafruit_apds9960/colorutility.py b/adafruit_apds9960/colorutility.py index 1b79080..793ce70 100644 --- a/adafruit_apds9960/colorutility.py +++ b/adafruit_apds9960/colorutility.py @@ -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""" @@ -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 diff --git a/docs/conf.py b/docs/conf.py index 32563aa..f4f3427 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,40 +11,48 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", ] # Mock out micropython ourselves so that we can make const a lambda. import imp + m = imp.new_module("micropython") m.const = lambda x: x sys.modules["micropython"] = m -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice": ( + "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + None, + ), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit APDS9960 Library' -copyright = u'2017 Michael McWethy' -author = u'Michael McWethy' +project = u"Adafruit APDS9960 Library" +copyright = u"2017 Michael McWethy" +author = u"Michael McWethy" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -55,7 +64,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -67,7 +76,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -81,59 +90,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitApds9960Librarydoc' +htmlhelp_basename = "AdafruitApds9960Librarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitAPDS9960Library.tex', u'AdafruitAPDS9960 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitAPDS9960Library.tex", + u"AdafruitAPDS9960 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -141,8 +153,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitAPDS9960library', u'Adafruit APDS9960 Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitAPDS9960library", + u"Adafruit APDS9960 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -151,7 +168,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitAPDS9960Library', u'Adafruit APDS9960 Library Documentation', - author, 'AdafruitAPDS9960Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitAPDS9960Library", + u"Adafruit APDS9960 Library Documentation", + author, + "AdafruitAPDS9960Library", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/apds9960_color_simpletest.py b/examples/apds9960_color_simpletest.py index 2887d0b..0158a45 100644 --- a/examples/apds9960_color_simpletest.py +++ b/examples/apds9960_color_simpletest.py @@ -10,14 +10,13 @@ while True: - #create some variables to store the color data in + # create some variables to store the color data in - #wait for color data to be ready + # wait for color data to be ready while not apds.color_data_ready: time.sleep(0.005) - - #get the data and print the different channels + # get the data and print the different channels r, g, b, c = apds.color_data print("red: ", r) print("green: ", g) diff --git a/setup.py b/setup.py index 4d15cf2..b154203 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -14,47 +15,42 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-apds9960', - + name="adafruit-circuitpython-apds9960", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython driver for APSD9960 Gesture breakout board', + setup_requires=["setuptools_scm"], + description="CircuitPython driver for APSD9960 Gesture breakout board", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_APDS9960', - + url="https://github.com/adafruit/Adafruit_CircuitPython_APDS9960", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-register', 'adafruit-circuitpython-busdevice'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=[ + "Adafruit-Blinka", + "adafruit-circuitpython-register", + "adafruit-circuitpython-busdevice", + ], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit apsd9960 gesture color proximity light sensor hardware micropython circuitpython', - + keywords="adafruit apsd9960 gesture color proximity light sensor hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - packages=['adafruit_apds9960'], + packages=["adafruit_apds9960"], )