Skip to content

Ran black, updated to pylint 2.x #7

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 17, 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
49 changes: 30 additions & 19 deletions adafruit_lis2mdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,22 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LIS2MDL.git"

# pylint: disable=bad-whitespace
_ADDRESS_MAG = const(0x1E) # (0x3C >> 1) // 0011110x
_ADDRESS_MAG = const(0x1E) # (0x3C >> 1) // 0011110x


MAG_DEVICE_ID = 0b01000000

class DataRate: # pylint: disable=too-few-public-methods

class DataRate: # pylint: disable=too-few-public-methods
"""Data rate choices to set using `data_rate`"""
Rate_10_HZ = const(0x00)

Rate_10_HZ = const(0x00)
"""10 Hz"""
Rate_20_HZ = const(0x01)
Rate_20_HZ = const(0x01)
"""20 Hz"""
Rate_50_HZ = const(0x02)
Rate_50_HZ = const(0x02)
"""50 Hz"""
Rate_100_HZ = const(0x03)
Rate_100_HZ = const(0x03)
"""100 Hz"""


Expand All @@ -88,7 +90,7 @@ class DataRate: # pylint: disable=too-few-public-methods
CFG_REG_A = 0x60
CFG_REG_B = 0x61
CFG_REG_C = 0x62
INT_CRTL_REG = 0x63
INT_CRTL_REG = 0x63
INT_SOURCE_REG = 0x64
INT_THS_L_REG = 0x65
STATUS_REG = 0x67
Expand All @@ -101,15 +103,17 @@ class DataRate: # pylint: disable=too-few-public-methods

# pylint: enable=bad-whitespace

_MAG_SCALE = 0.15 # 1.5 milligauss/LSB * 0.1 microtesla/milligauss
_MAG_SCALE = 0.15 # 1.5 milligauss/LSB * 0.1 microtesla/milligauss


class LIS2MDL:# pylint: disable=too-many-instance-attributes
class LIS2MDL: # pylint: disable=too-many-instance-attributes
"""
Driver for the LIS2MDL 3-axis magnetometer.

:param busio.I2C i2c_bus: The I2C bus the LIS2MDL is connected to.

"""

_BUFFER = bytearray(6)

_device_id = ROUnaryStruct(WHO_AM_I, "B")
Expand Down Expand Up @@ -139,7 +143,6 @@ class LIS2MDL:# pylint: disable=too-many-instance-attributes

_int_source = ROUnaryStruct(INT_SOURCE_REG, "B")


low_power = RWBit(CFG_REG_A, 4, 1)

"""Enables and disables low power mode"""
Expand Down Expand Up @@ -167,22 +170,26 @@ def reset(self):
self._reboot = True
sleep(0.100)
self._mode = 0x00
self._bdu = True # Make sure high and low bytes are set together
self._bdu = True # Make sure high and low bytes are set together
self._int_latched = True
self._int_reg_polarity = True
self._int_iron_off = False
self._interrupt_pin_putput = True
self._temp_comp = True

sleep(0.030) # sleep 20ms to allow measurements to stabilize
sleep(0.030) # sleep 20ms to allow measurements to stabilize

@property
def magnetic(self):
"""The processed magnetometer sensor values.
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
"""

return (self._raw_x * _MAG_SCALE, self._raw_y * _MAG_SCALE, self._raw_z * _MAG_SCALE)
return (
self._raw_x * _MAG_SCALE,
self._raw_y * _MAG_SCALE,
self._raw_z * _MAG_SCALE,
)

@property
def data_rate(self):
Expand All @@ -191,8 +198,12 @@ def data_rate(self):

@data_rate.setter
def data_rate(self, value):
if not value in (DataRate.Rate_10_HZ, DataRate.Rate_20_HZ,
DataRate.Rate_50_HZ, DataRate.Rate_100_HZ):
if not value in (
DataRate.Rate_10_HZ,
DataRate.Rate_20_HZ,
DataRate.Rate_50_HZ,
DataRate.Rate_100_HZ,
):
raise ValueError("data_rate must be a `DataRate`")
self._data_rate = value

Expand All @@ -206,7 +217,7 @@ def interrupt_threshold(self):
def interrupt_threshold(self, value):
if value < 0:
value = -value
self._interrupt_threshold = int(value/_MAG_SCALE)
self._interrupt_threshold = int(value / _MAG_SCALE)

@property
def interrupt_enabled(self):
Expand Down Expand Up @@ -243,7 +254,7 @@ def x_offset(self):

@x_offset.setter
def x_offset(self, value):
self._x_offset = int(value/_MAG_SCALE)
self._x_offset = int(value / _MAG_SCALE)

@property
def y_offset(self):
Expand All @@ -253,7 +264,7 @@ def y_offset(self):

@y_offset.setter
def y_offset(self, value):
self._y_offset = int(value/_MAG_SCALE)
self._y_offset = int(value / _MAG_SCALE)

@property
def z_offset(self):
Expand All @@ -263,4 +274,4 @@ def z_offset(self):

@z_offset.setter
def z_offset(self, value):
self._z_offset = int(value/_MAG_SCALE)
self._z_offset = int(value / _MAG_SCALE)
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 = ["micropython", "adafruit_bus_device", "adafruit_register"]

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 LIS2MDL 3-axis Magnetometer Library'
copyright = u'2019 Bryan Siepert'
author = u'Bryan Siepert'
project = u"Adafruit LIS2MDL 3-axis Magnetometer Library"
copyright = u"2019 Bryan Siepert"
author = u"Bryan Siepert"

# 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 = 'AdafruitLIS2MDLLibrarydoc'
htmlhelp_basename = "AdafruitLIS2MDLLibrarydoc"

# -- 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, 'AdafruitLIS2MDLLibrary.tex', u'Adafruit LIS2MDL 3-axis Magnetometer Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitLIS2MDLLibrary.tex",
u"Adafruit LIS2MDL 3-axis Magnetometer 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, 'AdafruitLIS2MDLlibrary', u'Adafruit LIS2MDL 3-axis Magnetometer Library Documentation',
[author], 1)
(
master_doc,
"AdafruitLIS2MDLlibrary",
u"Adafruit LIS2MDL 3-axis Magnetometer 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, 'AdafruitLIS2MDLLibrary', u'Adafruit LIS2MDL 3-axis Magnetometer Library Documentation',
author, 'AdafruitLIS2MDLLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitLIS2MDLLibrary",
u"Adafruit LIS2MDL 3-axis Magnetometer Library Documentation",
author,
"AdafruitLIS2MDLLibrary",
"One line description of project.",
"Miscellaneous",
),
]
6 changes: 3 additions & 3 deletions examples/lis2mdl_interrupt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
x_hi, y_hi, z_hi, x_lo, y_lo, z_lo, int_triggered = lis.faults

print(lis.magnetic)
print("Xhi:%s\tYhi:%s\tZhi:%s"%(x_hi, y_hi, z_hi))
print("Xlo:%s\tYlo:%s\tZlo:%s"%(x_lo, y_lo, z_lo))
print("Int triggered: %s"%int_triggered)
print("Xhi:%s\tYhi:%s\tZhi:%s" % (x_hi, y_hi, z_hi))
print("Xlo:%s\tYlo:%s\tZlo:%s" % (x_lo, y_lo, z_lo))
print("Int triggered: %s" % int_triggered)
print()

time.sleep(1)
4 changes: 2 additions & 2 deletions examples/lis2mdl_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
while True:
mag_x, mag_y, mag_z = sensor.magnetic

print('X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT'.format(mag_x, mag_y, mag_z))
print('')
print("X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT".format(mag_x, mag_y, mag_z))
print("")
time.sleep(1.0)
Loading