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
113 changes: 65 additions & 48 deletions adafruit_lsm303dlh_mag.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,53 +57,51 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM303DHL_Mag.git"

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

# Magnetometer registers
_REG_MAG_CRA_REG_M = const(0x00)
_REG_MAG_CRB_REG_M = const(0x01)
_REG_MAG_MR_REG_M = const(0x02)
_REG_MAG_OUT_X_H_M = const(0x03)
_REG_MAG_OUT_X_L_M = const(0x04)
_REG_MAG_OUT_Z_H_M = const(0x05)
_REG_MAG_OUT_Z_L_M = const(0x06)
_REG_MAG_OUT_Y_H_M = const(0x07)
_REG_MAG_OUT_Y_L_M = const(0x08)
_REG_MAG_SR_REG_M = const(0x09)
_REG_MAG_IRA_REG_M = const(0x0A)
_REG_MAG_IRB_REG_M = const(0x0B)
_REG_MAG_IRC_REG_M = const(0x0C)

_REG_MAG_TEMP_OUT_H_M = const(0x31)
_REG_MAG_TEMP_OUT_L_M = const(0x32)


_REG_MAG_CRA_REG_M = const(0x00)
_REG_MAG_CRB_REG_M = const(0x01)
_REG_MAG_MR_REG_M = const(0x02)
_REG_MAG_OUT_X_H_M = const(0x03)
_REG_MAG_OUT_X_L_M = const(0x04)
_REG_MAG_OUT_Z_H_M = const(0x05)
_REG_MAG_OUT_Z_L_M = const(0x06)
_REG_MAG_OUT_Y_H_M = const(0x07)
_REG_MAG_OUT_Y_L_M = const(0x08)
_REG_MAG_SR_REG_M = const(0x09)
_REG_MAG_IRA_REG_M = const(0x0A)
_REG_MAG_IRB_REG_M = const(0x0B)
_REG_MAG_IRC_REG_M = const(0x0C)

_REG_MAG_TEMP_OUT_H_M = const(0x31)
_REG_MAG_TEMP_OUT_L_M = const(0x32)


MAG_DEVICE_ID = 0b01000000
# Magnetometer gains
MAGGAIN_1_3 = const(0x20) # +/- 1.3
MAGGAIN_1_9 = const(0x40) # +/- 1.9
MAGGAIN_2_5 = const(0x60) # +/- 2.5
MAGGAIN_4_0 = const(0x80) # +/- 4.0
MAGGAIN_4_7 = const(0xA0) # +/- 4.7
MAGGAIN_5_6 = const(0xC0) # +/- 5.6
MAGGAIN_8_1 = const(0xE0) # +/- 8.1
MAGGAIN_1_3 = const(0x20) # +/- 1.3
MAGGAIN_1_9 = const(0x40) # +/- 1.9
MAGGAIN_2_5 = const(0x60) # +/- 2.5
MAGGAIN_4_0 = const(0x80) # +/- 4.0
MAGGAIN_4_7 = const(0xA0) # +/- 4.7
MAGGAIN_5_6 = const(0xC0) # +/- 5.6
MAGGAIN_8_1 = const(0xE0) # +/- 8.1

# Magentometer rates
MAGRATE_0_7 = const(0x00) # 0.75 Hz
MAGRATE_1_5 = const(0x01) # 1.5 Hz
MAGRATE_3_0 = const(0x02) # 3.0 Hz
MAGRATE_7_5 = const(0x03) # 7.5 Hz
MAGRATE_15 = const(0x04) # 15 Hz
MAGRATE_30 = const(0x05) # 30 Hz
MAGRATE_75 = const(0x06) # 75 Hz
MAGRATE_220 = const(0x07) # 220 Hz
MAGRATE_0_7 = const(0x00) # 0.75 Hz
MAGRATE_1_5 = const(0x01) # 1.5 Hz
MAGRATE_3_0 = const(0x02) # 3.0 Hz
MAGRATE_7_5 = const(0x03) # 7.5 Hz
MAGRATE_15 = const(0x04) # 15 Hz
MAGRATE_30 = const(0x05) # 30 Hz
MAGRATE_75 = const(0x06) # 75 Hz
MAGRATE_220 = const(0x07) # 220 Hz

# Conversion constants
_GRAVITY_STANDARD = 9.80665 # Earth's gravity in m/s^2
_GAUSS_TO_MICROTESLA = 100.0 # Gauss to micro-Tesla multiplier
_GRAVITY_STANDARD = 9.80665 # Earth's gravity in m/s^2
_GAUSS_TO_MICROTESLA = 100.0 # Gauss to micro-Tesla multiplier
# pylint: enable=bad-whitespace


Expand All @@ -113,14 +111,17 @@ class LSM303DLH_Mag:
:param busio.I2C i2c_bus: The I2C bus the LSM303DLH is connected to.

"""

# Class-level buffer for reading and writing data with the sensor.
# This reduces memory allocations but means the code is not re-entrant or
# thread safe!
_BUFFER = bytearray(6)

def __init__(self, i2c):
self._mag_device = I2CDevice(i2c, _ADDRESS_MAG)
self._write_u8(self._mag_device, _REG_MAG_MR_REG_M, 0x00) # Enable the magnetometer
self._write_u8(
self._mag_device, _REG_MAG_MR_REG_M, 0x00
) # Enable the magnetometer
self._lsm303mag_gauss_lsb_xy = 1100.0
self._lsm303mag_gauss_lsb_z = 980.0
self._mag_gain = MAGGAIN_1_3
Expand All @@ -132,7 +133,7 @@ def _raw_magnetic(self):
A 3-tuple of X, Y, Z axis values that are 16-bit signed integers.
"""
self._read_bytes(self._mag_device, _REG_MAG_OUT_X_H_M, 6, self._BUFFER)
raw_values = struct.unpack_from('>hhh', self._BUFFER[0:6])
raw_values = struct.unpack_from(">hhh", self._BUFFER[0:6])
return (raw_values[0], raw_values[2], raw_values[1])

@property
Expand All @@ -141,9 +142,11 @@ def magnetic(self):
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
"""
mag_x, mag_y, mag_z = self._raw_magnetic
return (mag_x / self._lsm303mag_gauss_lsb_xy * _GAUSS_TO_MICROTESLA,
mag_y / self._lsm303mag_gauss_lsb_xy * _GAUSS_TO_MICROTESLA,
mag_z / self._lsm303mag_gauss_lsb_z * _GAUSS_TO_MICROTESLA)
return (
mag_x / self._lsm303mag_gauss_lsb_xy * _GAUSS_TO_MICROTESLA,
mag_y / self._lsm303mag_gauss_lsb_xy * _GAUSS_TO_MICROTESLA,
mag_z / self._lsm303mag_gauss_lsb_z * _GAUSS_TO_MICROTESLA,
)

@property
def mag_gain(self):
Expand All @@ -152,8 +155,15 @@ def mag_gain(self):

@mag_gain.setter
def mag_gain(self, value):
assert value in (MAGGAIN_1_3, MAGGAIN_1_9, MAGGAIN_2_5, MAGGAIN_4_0, MAGGAIN_4_7,
MAGGAIN_5_6, MAGGAIN_8_1)
assert value in (
MAGGAIN_1_3,
MAGGAIN_1_9,
MAGGAIN_2_5,
MAGGAIN_4_0,
MAGGAIN_4_7,
MAGGAIN_5_6,
MAGGAIN_8_1,
)

self._mag_gain = value
self._write_u8(self._mag_device, _REG_MAG_CRB_REG_M, self._mag_gain)
Expand Down Expand Up @@ -186,8 +196,16 @@ def mag_rate(self):

@mag_rate.setter
def mag_rate(self, value):
assert value in (MAGRATE_0_7, MAGRATE_1_5, MAGRATE_3_0, MAGRATE_7_5, MAGRATE_15, MAGRATE_30,
MAGRATE_75, MAGRATE_220)
assert value in (
MAGRATE_0_7,
MAGRATE_1_5,
MAGRATE_3_0,
MAGRATE_7_5,
MAGRATE_15,
MAGRATE_30,
MAGRATE_75,
MAGRATE_220,
)

self._mag_rate = value
reg_m = ((value & 0x07) << 2) & 0xFF
Expand All @@ -196,8 +214,7 @@ def mag_rate(self, value):
def _read_u8(self, device, address):
with 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, device, address, val):
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 = ["micropython", "adafruit_bus_device"]

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 LSM303DLH Magnetometer Library'
copyright = u'2019 Bryan Siepert'
author = u'Bryan Siepert'
project = u"Adafruit LSM303DLH 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 = 'AdafruitLsm303DlhMagLibrarydoc'
htmlhelp_basename = "AdafruitLsm303DlhMagLibrarydoc"

# -- 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, 'AdafruitLSM303DLHMagLibrary.tex', u'Adafruit LSM303DLH Magnetometer Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitLSM303DLHMagLibrary.tex",
u"Adafruit LSM303DLH 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, 'AdafruitLSM303DLHMaglibrary', u'Adafruit LSM303DLH Magnetometer Library Documentation',
[author], 1)
(
master_doc,
"AdafruitLSM303DLHMaglibrary",
u"Adafruit LSM303DLH 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, 'AdafruitLSM303DLHMagLibrary', u'Adafruit LSM303DLH Magnetometer Library Documentation',
author, 'AdafruitLSM303DLHMAgLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitLSM303DLHMagLibrary",
u"Adafruit LSM303DLH Magnetometer Library Documentation",
author,
"AdafruitLSM303DLHMAgLibrary",
"One line description of project.",
"Miscellaneous",
),
]
Loading