Skip to content

Ran black, updated to pylint 2.x #12

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 16, 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
38 changes: 20 additions & 18 deletions adafruit_as726x.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
_AS726X_DEVICE_TEMP = const(0x06)
_AS726X_LED_CONTROL = const(0x07)

#for reading sensor data
# for reading sensor data
_AS7262_V_HIGH = const(0x08)
_AS7262_V_LOW = const(0x09)
_AS7262_B_HIGH = const(0x0A)
Expand All @@ -70,7 +70,7 @@
_AS7262_O_CAL = const(0x24)
_AS7262_R_CAL = const(0x28)

#hardware registers
# hardware registers
_AS726X_SLAVE_STATUS_REG = const(0x00)
_AS726X_SLAVE_WRITE_REG = const(0x01)
_AS726X_SLAVE_READ_REG = const(0x02)
Expand All @@ -92,9 +92,9 @@

_AS726X_NUM_CHANNELS = const(6)

#pylint: disable=too-many-instance-attributes
#pylint: disable=too-many-public-methods
class Adafruit_AS726x(object):
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-public-methods
class Adafruit_AS726x():
"""AS726x spectral sensor.

:param ~busio.I2C i2c_bus: The I2C bus connected to the sensor
Expand All @@ -108,7 +108,7 @@ class Adafruit_AS726x(object):
"""Continuously gather samples of green, yellow, orange and red. Violet and blue are skipped
and read zero."""

MODE_2 = 0b10 #default
MODE_2 = 0b10 # default
"""Continuously gather samples of all colors"""

ONE_SHOT = 0b11
Expand All @@ -132,18 +132,20 @@ def __init__(self, i2c_bus):

self.i2c_device = I2CDevice(i2c_bus, _AS726X_ADDRESS)

#reset device
# reset device
self._virtual_write(_AS726X_CONTROL_SETUP, 0x80)

#wait for it to boot up
# wait for it to boot up
time.sleep(1)

#try to read the version reg to make sure we can connect
# try to read the version reg to make sure we can connect
version = self._virtual_read(_AS726X_HW_VERSION)

#TODO: add support for other devices
# TODO: add support for other devices
if version != 0x40:
raise ValueError("device could not be reached or this device is not supported!")
raise ValueError(
"device could not be reached or this device is not supported!"
)

self.integration_time = 140
self.conversion_mode = Adafruit_AS726x.MODE_2
Expand Down Expand Up @@ -258,7 +260,7 @@ def gain(self, val):
self._gain = val
state = self._virtual_read(_AS726X_CONTROL_SETUP)
state &= ~(0x3 << 4)
state |= (Adafruit_AS726x.GAIN.index(val) << 4)
state |= Adafruit_AS726x.GAIN.index(val) << 4
self._virtual_write(_AS726X_CONTROL_SETUP, state)

@property
Expand All @@ -274,7 +276,7 @@ def integration_time(self, val):
if self._integration_time == val:
return
self._integration_time = val
self._virtual_write(_AS726X_INT_T, int(val/2.8))
self._virtual_write(_AS726X_INT_T, int(val / 2.8))

def start_measurement(self):
"""Begin a measurement.
Expand All @@ -298,7 +300,7 @@ def read_calibrated_value(self, channel):
val[1] = self._virtual_read(channel + 1)
val[2] = self._virtual_read(channel + 2)
val[3] = self._virtual_read(channel + 3)
return struct.unpack('!f', val)[0]
return struct.unpack("!f", val)[0]

@property
def data_ready(self):
Expand Down Expand Up @@ -413,18 +415,18 @@ def _virtual_write(self, addr, value):
# Read slave I2C status to see if the write buffer is ready.
status = self._read_u8(_AS726X_SLAVE_STATUS_REG)
if (status & _AS726X_SLAVE_TX_VALID) == 0:
break # No inbound TX pending at slave. Okay to write now.
break # No inbound TX pending at slave. Okay to write now.
# Send the virtual register address (setting bit 7 to indicate a pending write).
self.__write_u8(_AS726X_SLAVE_WRITE_REG, (addr | 0x80))
while True:
# Read the slave I2C status to see if the write buffer is ready.
status = self._read_u8(_AS726X_SLAVE_STATUS_REG)
if (status & _AS726X_SLAVE_TX_VALID) == 0:
break # No inbound TX pending at slave. Okay to write data now.
break # No inbound TX pending at slave. Okay to write data now.

# Send the data to complete the operation.
self.__write_u8(_AS726X_SLAVE_WRITE_REG, value)


#pylint: enable=too-many-instance-attributes
#pylint: enable=too-many-public-methods
# pylint: enable=too-many-instance-attributes
# pylint: enable=too-many-public-methods
120 changes: 73 additions & 47 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,56 @@

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))

# -- General configuration ------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
]

autodoc_member_order = 'bysource'

intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
autodoc_member_order = "bysource"

intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None),
"BusDevice": (
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
None,
),
"Register": (
"https://circuitpython.readthedocs.io/projects/register/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 AS726x Library'
copyright = u'2017 Dean Miller'
author = u'Dean Miller'
project = u"Adafruit AS726x Library"
copyright = u"2017 Dean Miller"
author = u"Dean Miller"

# 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.
Expand All @@ -51,7 +63,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.
Expand All @@ -63,7 +75,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
Expand All @@ -77,62 +89,70 @@
# 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"]

# Output file base name for HTML help builder.
htmlhelp_basename = 'AdafruitAs726xLibrarydoc'
htmlhelp_basename = "AdafruitAs726xLibrarydoc"

# -- 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, 'AdafruitAS726xLibrary.tex', u'AdafruitAS726x Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitAS726xLibrary.tex",
u"AdafruitAS726x Library Documentation",
author,
"manual",
),
]

# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'AdafruitAS726xlibrary', u'Adafruit AS726x Library Documentation',
[author], 1)
(
master_doc,
"AdafruitAS726xlibrary",
u"Adafruit AS726x Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -141,7 +161,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitAS726xLibrary', u'Adafruit AS726x Library Documentation',
author, 'AdafruitAS726xLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitAS726xLibrary",
u"Adafruit AS726x Library Documentation",
author,
"AdafruitAS726xLibrary",
"One line description of project.",
"Miscellaneous",
),
]
22 changes: 12 additions & 10 deletions examples/as726x_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

from adafruit_as726x import Adafruit_AS726x

#maximum value for sensor reading
# maximum value for sensor reading
max_val = 16000

#max number of characters in each graph
# max number of characters in each graph
max_graph = 80


def graph_map(x):
return min(int(x * max_graph / max_val), max_graph)


# Initialize I2C bus and sensor.
i2c = busio.I2C(board.SCL, board.SDA)
sensor = Adafruit_AS726x(i2c)
Expand All @@ -23,15 +25,15 @@ def graph_map(x):
while True:
# Wait for data to be ready
while not sensor.data_ready:
time.sleep(.1)
time.sleep(0.1)

#plot plot the data
# plot plot the data
print("\n")
print("V: " + graph_map(sensor.violet)*'=')
print("B: " + graph_map(sensor.blue)*'=')
print("G: " + graph_map(sensor.green)*'=')
print("Y: " + graph_map(sensor.yellow)*'=')
print("O: " + graph_map(sensor.orange)*'=')
print("R: " + graph_map(sensor.red)*'=')
print("V: " + graph_map(sensor.violet) * "=")
print("B: " + graph_map(sensor.blue) * "=")
print("G: " + graph_map(sensor.green) * "=")
print("Y: " + graph_map(sensor.yellow) * "=")
print("O: " + graph_map(sensor.orange) * "=")
print("R: " + graph_map(sensor.red) * "=")

time.sleep(1)
Loading