Skip to content

Commit

Permalink
Merge pull request #15 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 17, 2020
2 parents d95a20e + fd96579 commit 7648851
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 107 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
60 changes: 30 additions & 30 deletions adafruit_mlx90393.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"""

import time

try:
import struct
except ImportError:
Expand All @@ -57,19 +58,19 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MLX90393.git"

_CMD_SB = const(0b00010000) # Start burst mode
_CMD_SW = const(0b00100000) # Start wakeup on change mode
_CMD_SM = const(0b00110000) # Start single-measurement mode
_CMD_RM = const(0b01000000) # Read measurement
_CMD_RR = const(0b01010000) # Read register
_CMD_WR = const(0b01100000) # Write register
_CMD_EX = const(0b10000000) # Exit mode
_CMD_HR = const(0b11010000) # Memory recall
_CMD_HS = const(0b11100000) # Memory store
_CMD_RT = const(0b11110000) # Reset
_CMD_NOP = const(0x00) # NOP
_CMD_SB = const(0b00010000) # Start burst mode
_CMD_SW = const(0b00100000) # Start wakeup on change mode
_CMD_SM = const(0b00110000) # Start single-measurement mode
_CMD_RM = const(0b01000000) # Read measurement
_CMD_RR = const(0b01010000) # Read register
_CMD_WR = const(0b01100000) # Write register
_CMD_EX = const(0b10000000) # Exit mode
_CMD_HR = const(0b11010000) # Memory recall
_CMD_HS = const(0b11100000) # Memory store
_CMD_RT = const(0b11110000) # Reset
_CMD_NOP = const(0x00) # NOP

_CMD_AXIS_ALL = const(0xE) # X+Y+Z axis bits for commands
_CMD_AXIS_ALL = const(0xE) # X+Y+Z axis bits for commands

_CMD_REG_CONF1 = const(0x00) # Gain
_CMD_REG_CONF2 = const(0x01) # Burst, comm mode
Expand All @@ -86,13 +87,13 @@
GAIN_1X = 0x7
_GAIN_SHIFT = const(4)

_RES_2_15 = const(0) # +/- 2^15
_RES_2_15 = const(0) # +/- 2^15
_RES_2_15B = const(1) # +/- 2^15
_RES_22000 = const(2) # +/- 22000
_RES_11000 = const(3) # +/- 11000
_RES_SHIFT = const(5)

_HALLCONF = const(0x0C) # Hall plate spinning rate adjust.
_HALLCONF = const(0x0C) # Hall plate spinning rate adjust.

STATUS_OK = 0x3

Expand All @@ -116,7 +117,7 @@
# 1.333x gain: res0(xy)(z), res1(xy)(z), res2(xy)(z), res3(xy)(z)
((0.200, 0.323), (0.401, 0.645), (0.801, 1.291), (1.602, 2.581)),
# 1x gain: res0(xy)(z), res1(xy)(z), res2(xy)(z), res3(xy)(z)
((0.150, 0.242), (0.300, 0.484), (0.601, 0.968), (1.202, 1.936))
((0.150, 0.242), (0.300, 0.484), (0.601, 0.968), (1.202, 1.936)),
)


Expand All @@ -143,7 +144,6 @@ def __init__(self, i2c_bus, address=0x0C, gain=GAIN_1X, debug=False):
# Set gain to the supplied level
self.gain = self._gain_current


def _transceive(self, payload, rxlen=0):
"""
Writes the specified 'payload' to the sensor
Expand All @@ -152,7 +152,7 @@ def _transceive(self, payload, rxlen=0):
:param rxlen: (optional) The numbers of bytes to read back (default=0)
"""
# Read the response (+1 to account for the mandatory status byte!)
data = bytearray(rxlen+1)
data = bytearray(rxlen + 1)

if len(payload) == 1:
# Transceive with repeated start
Expand Down Expand Up @@ -185,23 +185,20 @@ def _transceive(self, payload, rxlen=0):
print("\t Status :", hex(data[0]))
return data


@property
def last_status(self):
"""
Returns the last status byte received from the sensor.
"""
return self._status_last


@property
def gain(self):
"""
Gets the current gain setting for the device.
"""
return self._gain_current


@gain.setter
def gain(self, value):
"""
Expand All @@ -212,11 +209,16 @@ def gain(self, value):
if self._debug:
print("\tSetting gain: {}".format(value))
self._gain_current = value
self._transceive(bytes([_CMD_WR,
0x00,
self._gain_current << _GAIN_SHIFT | _HALLCONF,
(_CMD_REG_CONF1 & 0x3F) << 2]))

self._transceive(
bytes(
[
_CMD_WR,
0x00,
self._gain_current << _GAIN_SHIFT | _HALLCONF,
(_CMD_REG_CONF1 & 0x3F) << 2,
]
)
)

def display_status(self):
"""
Expand All @@ -235,7 +237,6 @@ def display_status(self):
print("Reset status :", (self._status_last & (1 << 2)) > 0)
print("Response bytes available :", avail)


def read_reg(self, reg):
"""
Gets the current value of the specified register.
Expand All @@ -258,7 +259,6 @@ def read_reg(self, reg):
print("\t Status :", hex(data[0]))
return val


def reset(self):
"""
Performs a software reset of the sensor.
Expand All @@ -274,12 +274,13 @@ def reset(self):
pass
return self._status_last


@property
def read_data(self, delay=0.01):
def read_data(self):
"""
Reads a single X/Y/Z sample from the magnetometer.
"""
delay = 0.01

# Set the device to single measurement mode
self._transceive(bytes([_CMD_SM | _CMD_AXIS_ALL]))

Expand All @@ -293,7 +294,6 @@ def read_data(self, delay=0.01):
# Return the raw int values if requested
return (m_x, m_y, m_z)


@property
def magnetic(self):
"""
Expand Down
120 changes: 73 additions & 47 deletions docs/conf.py
Original file line number Diff line number Diff line change
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,40 @@
# autodoc_mock_imports = ["digitalio", "busio"]


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)}
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_CircuitPython_MLX90393 Library'
copyright = u'2018 Kevin Townsend'
author = u'Kevin Townsend'
project = u"Adafruit_CircuitPython_MLX90393 Library"
copyright = u"2018 Kevin Townsend"
author = u"Kevin Townsend"

# 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 +69,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 +81,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 +96,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 = 'Adafruit_circuitpython_mlx90393Librarydoc'
htmlhelp_basename = "Adafruit_circuitpython_mlx90393Librarydoc"

# -- 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, 'Adafruit_CircuitPython_MLX90393Library.tex', u'Adafruit_CircuitPython_MLX90393 Library Documentation',
author, 'manual'),
(
master_doc,
"Adafruit_CircuitPython_MLX90393Library.tex",
u"Adafruit_CircuitPython_MLX90393 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, 'Adafruit_CircuitPython_MLX90393library', u'Adafruit_CircuitPython_MLX90393 Library Documentation',
[author], 1)
(
master_doc,
"Adafruit_CircuitPython_MLX90393library",
u"Adafruit_CircuitPython_MLX90393 Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -154,7 +174,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Adafruit_CircuitPython_MLX90393Library', u' Adafruit_CircuitPython_MLX90393 Library Documentation',
author, 'Adafruit_CircuitPython_MLX90393Library', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"Adafruit_CircuitPython_MLX90393Library",
u" Adafruit_CircuitPython_MLX90393 Library Documentation",
author,
"Adafruit_CircuitPython_MLX90393Library",
"One line description of project.",
"Miscellaneous",
),
]

0 comments on commit 7648851

Please sign in to comment.