Skip to content

Commit

Permalink
Merge pull request #14 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 authored Mar 20, 2020
2 parents aacea6a + 7dee980 commit 2123c76
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 121 deletions.
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
6 changes: 3 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spelling-store-unknown-words=no
[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
#notes=FIXME,XXX,TODO
# notes=FIXME,XXX,TODO
notes=FIXME,XXX


Expand Down Expand Up @@ -301,7 +301,7 @@ function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Good variable names which should always be accepted, separated by a comma
# good-names=i,j,k,ex,Run,_
good-names=r,g,b,i,j,k,n,ex,Run,_
good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_

# Include a hint for the correct naming format with invalid-name
include-naming-hint=no
Expand Down Expand Up @@ -423,7 +423,7 @@ max-returns=6
max-statements=50

# Minimum number of public methods for a class (see R0903).
min-public-methods=2
min-public-methods=1


[EXCEPTIONS]
Expand Down
79 changes: 41 additions & 38 deletions adafruit_fxas21002c.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
"""
import time

try:
import ustruct as struct
except ImportError:
Expand All @@ -60,31 +61,32 @@

# Internal constants and register values:
# pylint: disable=bad-whitespace
_FXAS21002C_ADDRESS = const(0x21) # 0100001
_FXAS21002C_ID = const(0xD7) # 1101 0111
_GYRO_REGISTER_STATUS = const(0x00)
_GYRO_REGISTER_OUT_X_MSB = const(0x01)
_GYRO_REGISTER_OUT_X_LSB = const(0x02)
_GYRO_REGISTER_OUT_Y_MSB = const(0x03)
_GYRO_REGISTER_OUT_Y_LSB = const(0x04)
_GYRO_REGISTER_OUT_Z_MSB = const(0x05)
_GYRO_REGISTER_OUT_Z_LSB = const(0x06)
_GYRO_REGISTER_WHO_AM_I = const(0x0C) # 11010111 r
_GYRO_REGISTER_CTRL_REG0 = const(0x0D) # 00000000 r/w
_GYRO_REGISTER_CTRL_REG1 = const(0x13) # 00000000 r/w
_GYRO_REGISTER_CTRL_REG2 = const(0x14) # 00000000 r/w
_GYRO_SENSITIVITY_250DPS = 0.0078125 # Table 35 of datasheet
_GYRO_SENSITIVITY_500DPS = 0.015625 # ..
_GYRO_SENSITIVITY_1000DPS = 0.03125 # ..
_GYRO_SENSITIVITY_2000DPS = 0.0625 # ..
_FXAS21002C_ADDRESS = const(0x21) # 0100001
_FXAS21002C_ID = const(0xD7) # 1101 0111
_GYRO_REGISTER_STATUS = const(0x00)
_GYRO_REGISTER_OUT_X_MSB = const(0x01)
_GYRO_REGISTER_OUT_X_LSB = const(0x02)
_GYRO_REGISTER_OUT_Y_MSB = const(0x03)
_GYRO_REGISTER_OUT_Y_LSB = const(0x04)
_GYRO_REGISTER_OUT_Z_MSB = const(0x05)
_GYRO_REGISTER_OUT_Z_LSB = const(0x06)
_GYRO_REGISTER_WHO_AM_I = const(0x0C) # 11010111 r
_GYRO_REGISTER_CTRL_REG0 = const(0x0D) # 00000000 r/w
_GYRO_REGISTER_CTRL_REG1 = const(0x13) # 00000000 r/w
_GYRO_REGISTER_CTRL_REG2 = const(0x14) # 00000000 r/w
_GYRO_SENSITIVITY_250DPS = 0.0078125 # Table 35 of datasheet
_GYRO_SENSITIVITY_500DPS = 0.015625 # ..
_GYRO_SENSITIVITY_1000DPS = 0.03125 # ..
_GYRO_SENSITIVITY_2000DPS = 0.0625 # ..

# User facing constants/module globals:
GYRO_RANGE_250DPS = 250
GYRO_RANGE_500DPS = 500
GYRO_RANGE_1000DPS = 1000
GYRO_RANGE_2000DPS = 2000
GYRO_RANGE_250DPS = 250
GYRO_RANGE_500DPS = 500
GYRO_RANGE_1000DPS = 1000
GYRO_RANGE_2000DPS = 2000
# pylint: enable=bad-whitespace


class FXAS21002C:
"""Driver for the NXP FXAS21002C gyroscope."""

Expand All @@ -93,15 +95,18 @@ class FXAS21002C:
# thread safe!
_BUFFER = bytearray(7)

def __init__(self, i2c, address=_FXAS21002C_ADDRESS,
gyro_range=GYRO_RANGE_250DPS):
assert gyro_range in (GYRO_RANGE_250DPS, GYRO_RANGE_500DPS,
GYRO_RANGE_1000DPS, GYRO_RANGE_2000DPS)
def __init__(self, i2c, address=_FXAS21002C_ADDRESS, gyro_range=GYRO_RANGE_250DPS):
assert gyro_range in (
GYRO_RANGE_250DPS,
GYRO_RANGE_500DPS,
GYRO_RANGE_1000DPS,
GYRO_RANGE_2000DPS,
)
self._gyro_range = gyro_range
self._device = i2c_dev.I2CDevice(i2c, address)
# Check for chip ID value.
if self._read_u8(_GYRO_REGISTER_WHO_AM_I) != _FXAS21002C_ID:
raise RuntimeError('Failed to find FXAS21002C, check wiring!')
raise RuntimeError("Failed to find FXAS21002C, check wiring!")
ctrl_reg0 = 0x00
if gyro_range == GYRO_RANGE_250DPS:
ctrl_reg0 = 0x03
Expand All @@ -115,18 +120,17 @@ def __init__(self, i2c, address=_FXAS21002C_ADDRESS,
# Putting into standy doesn't work as the chip becomes instantly
# unresponsive. Perhaps CircuitPython is too slow to go into standby
# and send reset? Keep these two commented for now:
#self._write_u8(_GYRO_REGISTER_CTRL_REG1, 0x00) # Standby)
#self._write_u8(_GYRO_REGISTER_CTRL_REG1, (1<<6)) # Reset
self._write_u8(_GYRO_REGISTER_CTRL_REG0, ctrl_reg0) # Set sensitivity
self._write_u8(_GYRO_REGISTER_CTRL_REG1, 0x0E) # Active
time.sleep(0.1) # 60 ms + 1/ODR
# self._write_u8(_GYRO_REGISTER_CTRL_REG1, 0x00) # Standby)
# self._write_u8(_GYRO_REGISTER_CTRL_REG1, (1<<6)) # Reset
self._write_u8(_GYRO_REGISTER_CTRL_REG0, ctrl_reg0) # Set sensitivity
self._write_u8(_GYRO_REGISTER_CTRL_REG1, 0x0E) # Active
time.sleep(0.1) # 60 ms + 1/ODR

def _read_u8(self, address):
# Read an 8-bit unsigned value from the specified 8-bit address.
with self._device as i2c:
self._BUFFER[0] = address & 0xFF
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
out_end=1, in_end=1)
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=1)
return self._BUFFER[0]

def _write_u8(self, address, val):
Expand All @@ -144,12 +148,11 @@ def read_raw(self):
# Read gyro data from the sensor.
with self._device as i2c:
self._BUFFER[0] = _GYRO_REGISTER_OUT_X_MSB
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
out_end=1)
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1)
# Parse out the gyroscope data as 16-bit signed data.
raw_x = struct.unpack_from('>h', self._BUFFER[0:2])[0]
raw_y = struct.unpack_from('>h', self._BUFFER[2:4])[0]
raw_z = struct.unpack_from('>h', self._BUFFER[4:6])[0]
raw_x = struct.unpack_from(">h", self._BUFFER[0:2])[0]
raw_y = struct.unpack_from(">h", self._BUFFER[2:4])[0]
raw_z = struct.unpack_from(">h", self._BUFFER[4:6])[0]
return (raw_x, raw_y, raw_z)

# pylint is confused and incorrectly marking this function as bad return
Expand Down
114 changes: 68 additions & 46 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,55 @@

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

# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
# autodoc_mock_imports = ["adafruit_bus_device", "micropython"]

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 FXAS21002C Library'
copyright = u'2017 Tony DiCola'
author = u'Tony DiCola'
project = u"Adafruit FXAS21002C Library"
copyright = u"2017 Tony DiCola"
author = u"Tony DiCola"

# 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 @@ -54,7 +62,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 @@ -66,7 +74,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 @@ -80,68 +88,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 = 'AdafruitFXAS21002CLibrarydoc'
htmlhelp_basename = "AdafruitFXAS21002CLibrarydoc"

# -- 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, 'AdafruitFXAS21002CLibrary.tex', u'Adafruit FXAS21002C Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitFXAS21002CLibrary.tex",
u"Adafruit FXAS21002C 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, 'adafruitFXAS21002Clibrary', u'Adafruit FXAS21002C Library Documentation',
[author], 1)
(
master_doc,
"adafruitFXAS21002Clibrary",
u"Adafruit FXAS21002C Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -150,7 +166,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitFXAS21002CLibrary', u'Adafruit FXAS21002C Library Documentation',
author, 'AdafruitFXAS21002CLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitFXAS21002CLibrary",
u"Adafruit FXAS21002C Library Documentation",
author,
"AdafruitFXAS21002CLibrary",
"One line description of project.",
"Miscellaneous",
),
]
12 changes: 8 additions & 4 deletions examples/fxas21002c_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
sensor = adafruit_fxas21002c.FXAS21002C(i2c)
# Optionally create the sensor with a different gyroscope range (the
# default is 250 DPS, but you can use 500, 1000, or 2000 DPS values):
#sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_500DPS)
#sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_1000DPS)
#sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_2000DPS)
# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_500DPS)
# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_1000DPS)
# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_2000DPS)

# Main loop will read the gyroscope values every second and print them out.
while True:
# Read gyroscope.
gyro_x, gyro_y, gyro_z = sensor.gyroscope
# Print values.
print('Gyroscope (radians/s): ({0:0.3f}, {1:0.3f}, {2:0.3f})'.format(gyro_x, gyro_y, gyro_z))
print(
"Gyroscope (radians/s): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format(
gyro_x, gyro_y, gyro_z
)
)
# Delay for a second.
time.sleep(1.0)
Loading

0 comments on commit 2123c76

Please sign in to comment.