Skip to content

Commit

Permalink
Merge pull request #17 from adafruit/pylint-update
Browse files Browse the repository at this point in the history
Ran black, updated to pylint 2.x
  • Loading branch information
kattni committed Mar 23, 2020
2 parents 5643572 + f19543c commit 102ed40
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
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
42 changes: 24 additions & 18 deletions adafruit_l3gd20.py
Expand Up @@ -54,6 +54,7 @@

from micropython import const
from adafruit_register.i2c_struct import Struct

try:
from struct import unpack
except ImportError:
Expand All @@ -78,9 +79,9 @@
_L3GD20_CHIP_ID = const(0xD4)
_L3GD20H_CHIP_ID = const(0xD7)

_L3GD20_SENSITIVITY_250DPS = 0.00875 ## Roughly 22/256 for fixed point match
_L3GD20_SENSITIVITY_500DPS = 0.0175 ## Roughly 45/256
_L3GD20_SENSITIVITY_2000DPS = 0.070 ## Roughly 18/256
_L3GD20_SENSITIVITY_250DPS = 0.00875 ## Roughly 22/256 for fixed point match
_L3GD20_SENSITIVITY_500DPS = 0.0175 ## Roughly 45/256
_L3GD20_SENSITIVITY_2000DPS = 0.070 ## Roughly 18/256


# pylint: disable=no-member
Expand All @@ -94,15 +95,17 @@ class L3GD20:

def __init__(self, rng=L3DS20_RANGE_250DPS):
chip_id = self.read_register(_ID_REGISTER)
if chip_id != _L3GD20_CHIP_ID and chip_id != _L3GD20H_CHIP_ID:
raise RuntimeError("bad chip id (%x != %x or %x)" %
(chip_id, _L3GD20_CHIP_ID, _L3GD20H_CHIP_ID))

if rng != L3DS20_RANGE_250DPS and \
rng != L3DS20_RANGE_500DPS and \
rng != L3DS20_RANGE_2000DPS:
raise ValueError("Range value must be one of L3DS20_RANGE_250DPS, "
"L3DS20_RANGE_500DPS, or L3DS20_RANGE_2000DPS")
if chip_id not in (_L3GD20_CHIP_ID, _L3GD20H_CHIP_ID):
raise RuntimeError(
"bad chip id (%x != %x or %x)"
% (chip_id, _L3GD20_CHIP_ID, _L3GD20H_CHIP_ID)
)

if rng not in (L3DS20_RANGE_250DPS, L3DS20_RANGE_500DPS, L3DS20_RANGE_2000DPS):
raise ValueError(
"Range value must be one of L3DS20_RANGE_250DPS, "
"L3DS20_RANGE_500DPS, or L3DS20_RANGE_2000DPS"
)

# Set CTRL_REG1 (0x20)
# ====================================================================
Expand Down Expand Up @@ -186,15 +189,14 @@ def __init__(self, rng=L3DS20_RANGE_250DPS):
# Nothing to do ... keep default values
# ------------------------------------------------------------------


@property
def gyro(self):
"""
x, y, z angular momentum tuple floats, rescaled appropriately for
range selected
"""
raw = self.gyro_raw
return tuple(self.scale*v for v in raw)
return tuple(self.scale * v for v in raw)


class L3GD20_I2C(L3GD20):
Expand All @@ -207,11 +209,12 @@ class L3GD20_I2C(L3GD20):
:param address: the optional device address, 0x68 is the default address
"""

gyro_raw = Struct(_L3GD20_REGISTER_OUT_X_L_X80, '<hhh')
gyro_raw = Struct(_L3GD20_REGISTER_OUT_X_L_X80, "<hhh")
"""Gives the raw gyro readings, in units of rad/s."""

def __init__(self, i2c, rng=L3DS20_RANGE_250DPS, address=0x6B):
import adafruit_bus_device.i2c_device as i2c_device
import adafruit_bus_device.i2c_device as i2c_device # pylint: disable=import-outside-toplevel

self.i2c_device = i2c_device.I2CDevice(i2c, address)
self.buffer = bytearray(2)
super().__init__(rng)
Expand Down Expand Up @@ -239,6 +242,7 @@ def read_register(self, register):
i2c.write_then_readinto(self.buffer, self.buffer, out_end=1, in_start=1)
return self.buffer[1]


class L3GD20_SPI(L3GD20):
"""
Driver for L3GD20 Gyroscope using SPI communications
Expand All @@ -249,8 +253,10 @@ class L3GD20_SPI(L3GD20):
L3DS20_RANGE_2000DPS
:param baudrate: spi baud rate default is 100000
"""

def __init__(self, spi_busio, cs, rng=L3DS20_RANGE_250DPS, baudrate=100000):
import adafruit_bus_device.spi_device as spi_device
import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel

self._spi = spi_device.SPIDevice(spi_busio, cs, baudrate=baudrate)
self._spi_bytearray1 = bytearray(1)
self._spi_bytearray6 = bytearray(6)
Expand Down Expand Up @@ -300,4 +306,4 @@ def gyro_raw(self):
"""Gives the raw gyro readings, in units of rad/s."""
buffer = self._spi_bytearray6
self.read_bytes(_L3GD20_REGISTER_OUT_X_L_X40, buffer)
return unpack('<hhh', buffer)
return unpack("<hhh", buffer)
116 changes: 69 additions & 47 deletions docs/conf.py
Expand Up @@ -2,18 +2,19 @@

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.napoleon',
'sphinx.ext.todo',
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.todo",
]

# TODO: Please Read!
Expand All @@ -23,29 +24,36 @@
# autodoc_mock_imports = ["micropython", "adafruit_register"]


intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", 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 l3gd20 Library'
copyright = u'2018 Michael McWethy'
author = u'Michael McWethy'
project = u"Adafruit l3gd20 Library"
copyright = u"2018 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.
Expand All @@ -57,7 +65,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 @@ -69,7 +77,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 @@ -84,68 +92,76 @@
# 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 = 'AdafruitL3gd20Librarydoc'
htmlhelp_basename = "AdafruitL3gd20Librarydoc"

# -- 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, 'Adafruitl3gd20Library.tex', u'Adafruitl3gd20 Library Documentation',
author, 'manual'),
(
master_doc,
"Adafruitl3gd20Library.tex",
u"Adafruitl3gd20 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, 'Adafruitl3gd20library', u'Adafruit l3gd20 Library Documentation',
[author], 1)
(
master_doc,
"Adafruitl3gd20library",
u"Adafruit l3gd20 Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -154,7 +170,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Adafruitl3gd20Library', u'Adafruit l3gd20 Library Documentation',
author, 'Adafruitl3gd20Library', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"Adafruitl3gd20Library",
u"Adafruit l3gd20 Library Documentation",
author,
"Adafruitl3gd20Library",
"One line description of project.",
"Miscellaneous",
),
]
2 changes: 1 addition & 1 deletion examples/l3gd20_simpletest.py
Expand Up @@ -14,6 +14,6 @@
# SENSOR = adafruit_l3gd20.L3GD20_SPI(SPIB, CS)

while True:
print('Angular Momentum (rad/s): {}'.format(SENSOR.gyro))
print("Angular Momentum (rad/s): {}".format(SENSOR.gyro))
print()
time.sleep(1)

0 comments on commit 102ed40

Please sign in to comment.