Compare commits
61 commits
chickadee-
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
570da14943 | ||
|
|
64d2709a31 | ||
|
|
3adfd8a151 | ||
|
|
c5c1edaca9 | ||
|
|
ded08dd81f | ||
|
|
f709a6ffae | ||
|
|
74db72c78c | ||
|
|
96e7faf864 | ||
|
|
d182f6bdb1 | ||
|
|
e0d0e164da | ||
|
|
dd954e8531 | ||
|
|
0d615c4323 | ||
|
|
2ea15fffa7 | ||
|
|
00f38c1619 | ||
|
|
dd93f8f0af | ||
|
|
61fddde5a4 | ||
|
|
e8bdf56420 | ||
|
|
538ddc7696 | ||
|
|
ac4d51b0a1 | ||
|
|
ddf279146e | ||
|
|
9211f42be4 | ||
|
|
cad362d0dc | ||
|
|
dab488ae9d | ||
|
|
da222c0163 | ||
|
|
df45c8470a | ||
|
|
967e11c6a2 | ||
|
|
76d5700822 | ||
|
|
f1b9e6c753 | ||
|
|
0d25996200 | ||
|
|
aa97a7a5a6 | ||
|
|
e71564208f | ||
|
|
0dad9a2a6c | ||
|
|
2b9a219fa0 | ||
|
|
8b11e10f42 | ||
|
|
ddbfd4370e | ||
|
|
f1fe707751 | ||
|
|
10b6f918d9 | ||
|
|
4a5daf0bb5 | ||
|
|
1c8dade7c0 | ||
|
|
2d716298de | ||
|
|
3560378eac | ||
|
|
f22ee9740b | ||
|
|
a5a8aea123 | ||
|
|
7b696c4ad2 | ||
|
|
aedba1d651 | ||
|
|
d2689d073f | ||
|
|
8f7905315c | ||
|
|
7c1af7b657 | ||
|
|
d8843dcae3 | ||
|
|
f01e7d21bd | ||
|
|
56fadf72eb | ||
|
|
271f99f78d | ||
|
|
46b72707eb | ||
|
|
aaa757e37a | ||
|
|
2296f0524e | ||
|
|
b043cf5694 | ||
|
|
8465f18089 | ||
|
|
4cb7d7cc66 | ||
|
|
d81552520b | ||
|
|
76cd9435e3 | ||
|
|
4061b4dc10 |
16 changed files with 1221 additions and 281 deletions
57
.github/workflows/build.yml
vendored
Normal file
57
.github/workflows/build.yml
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
name: Build CI
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Dump GitHub context
|
||||
env:
|
||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
||||
run: echo "$GITHUB_CONTEXT"
|
||||
- name: Translate Repo Name For Build Tools filename_prefix
|
||||
id: repo-name
|
||||
run: |
|
||||
echo ::set-output name=repo-name::$(
|
||||
echo ${{ github.repository }} |
|
||||
awk -F '\/' '{ print tolower($2) }' |
|
||||
tr '_' '-'
|
||||
)
|
||||
- name: Set up Python 3.6
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.6
|
||||
- name: Versions
|
||||
run: |
|
||||
python3 --version
|
||||
- name: Checkout Current Repo
|
||||
uses: actions/checkout@v1
|
||||
with:
|
||||
submodules: true
|
||||
- name: Checkout tools repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: adafruit/actions-ci-circuitpython-libs
|
||||
path: actions-ci
|
||||
- name: Install dependencies
|
||||
# (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.)
|
||||
run: |
|
||||
source actions-ci/install.sh
|
||||
- name: Pip install pylint, black, & Sphinx
|
||||
run: |
|
||||
pip install pylint black==19.10b0 Sphinx sphinx-rtd-theme
|
||||
- name: Library version
|
||||
run: git describe --dirty --always --tags
|
||||
- name: Check formatting
|
||||
run: |
|
||||
black --check --target-version=py35 .
|
||||
- name: PyLint
|
||||
run: |
|
||||
pylint $( find . -path './adafruit*.py' )
|
||||
([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" ))
|
||||
- name: Build assets
|
||||
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
|
||||
- name: Build docs
|
||||
working-directory: docs
|
||||
run: sphinx-build -E -W -b html . _build/html
|
||||
81
.github/workflows/release.yml
vendored
Normal file
81
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
name: Release Actions
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
upload-release-assets:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Dump GitHub context
|
||||
env:
|
||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
||||
run: echo "$GITHUB_CONTEXT"
|
||||
- name: Translate Repo Name For Build Tools filename_prefix
|
||||
id: repo-name
|
||||
run: |
|
||||
echo ::set-output name=repo-name::$(
|
||||
echo ${{ github.repository }} |
|
||||
awk -F '\/' '{ print tolower($2) }' |
|
||||
tr '_' '-'
|
||||
)
|
||||
- name: Set up Python 3.6
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.6
|
||||
- name: Versions
|
||||
run: |
|
||||
python3 --version
|
||||
- name: Checkout Current Repo
|
||||
uses: actions/checkout@v1
|
||||
with:
|
||||
submodules: true
|
||||
- name: Checkout tools repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: adafruit/actions-ci-circuitpython-libs
|
||||
path: actions-ci
|
||||
- name: Install deps
|
||||
run: |
|
||||
source actions-ci/install.sh
|
||||
- name: Build assets
|
||||
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
|
||||
- name: Upload Release Assets
|
||||
# the 'official' actions version does not yet support dynamically
|
||||
# supplying asset names to upload. @csexton's version chosen based on
|
||||
# discussion in the issue below, as its the simplest to implement and
|
||||
# allows for selecting files with a pattern.
|
||||
# https://github.com/actions/upload-release-asset/issues/4
|
||||
#uses: actions/upload-release-asset@v1.0.1
|
||||
uses: csexton/release-asset-action@master
|
||||
with:
|
||||
pattern: "bundles/*"
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
upload-pypi:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Check For setup.py
|
||||
id: need-pypi
|
||||
run: |
|
||||
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
|
||||
- name: Set up Python
|
||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- name: Install dependencies
|
||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install setuptools wheel twine
|
||||
- name: Build and publish
|
||||
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
|
||||
env:
|
||||
TWINE_USERNAME: ${{ secrets.pypi_username }}
|
||||
TWINE_PASSWORD: ${{ secrets.pypi_password }}
|
||||
run: |
|
||||
python setup.py sdist
|
||||
twine upload dist/*
|
||||
433
.pylintrc
Normal file
433
.pylintrc
Normal file
|
|
@ -0,0 +1,433 @@
|
|||
[MASTER]
|
||||
|
||||
# A comma-separated list of package or module names from where C extensions may
|
||||
# be loaded. Extensions are loading into the active Python interpreter and may
|
||||
# run arbitrary code
|
||||
extension-pkg-whitelist=
|
||||
|
||||
# Add files or directories to the blacklist. They should be base names, not
|
||||
# paths.
|
||||
ignore=CVS
|
||||
|
||||
# Add files or directories matching the regex patterns to the blacklist. The
|
||||
# regex matches against base names, not paths.
|
||||
ignore-patterns=
|
||||
|
||||
# Python code to execute, usually for sys.path manipulation such as
|
||||
# pygtk.require().
|
||||
#init-hook=
|
||||
|
||||
# Use multiple processes to speed up Pylint.
|
||||
# jobs=1
|
||||
jobs=2
|
||||
|
||||
# List of plugins (as comma separated values of python modules names) to load,
|
||||
# usually to register additional checkers.
|
||||
load-plugins=
|
||||
|
||||
# Pickle collected data for later comparisons.
|
||||
persistent=yes
|
||||
|
||||
# Specify a configuration file.
|
||||
#rcfile=
|
||||
|
||||
# Allow loading of arbitrary C extensions. Extensions are imported into the
|
||||
# active Python interpreter and may run arbitrary code.
|
||||
unsafe-load-any-extension=no
|
||||
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
|
||||
# Only show warnings with the listed confidence levels. Leave empty to show
|
||||
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
|
||||
confidence=
|
||||
|
||||
# Disable the message, report, category or checker with the given id(s). You
|
||||
# can either give multiple identifiers separated by comma (,) or put this
|
||||
# option multiple times (only on the command line, not in the configuration
|
||||
# file where it should appear only once).You can also use "--disable=all" to
|
||||
# disable everything first and then reenable specific checks. For example, if
|
||||
# you want to run only the similarities checker, you can use "--disable=all
|
||||
# --enable=similarities". If you want to run only the classes checker, but have
|
||||
# no Warning level messages displayed, use"--disable=all --enable=classes
|
||||
# --disable=W"
|
||||
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
|
||||
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
|
||||
|
||||
# Enable the message, report, category or checker with the given id(s). You can
|
||||
# either give multiple identifier separated by comma (,) or put this option
|
||||
# multiple time (only on the command line, not in the configuration file where
|
||||
# it should appear only once). See also the "--disable" option for examples.
|
||||
enable=
|
||||
|
||||
|
||||
[REPORTS]
|
||||
|
||||
# Python expression which should return a note less than 10 (10 is the highest
|
||||
# note). You have access to the variables errors warning, statement which
|
||||
# respectively contain the number of errors / warnings messages and the total
|
||||
# number of statements analyzed. This is used by the global evaluation report
|
||||
# (RP0004).
|
||||
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
|
||||
|
||||
# Template used to display messages. This is a python new-style format string
|
||||
# used to format the message information. See doc for all details
|
||||
#msg-template=
|
||||
|
||||
# Set the output format. Available formats are text, parseable, colorized, json
|
||||
# and msvs (visual studio).You can also give a reporter class, eg
|
||||
# mypackage.mymodule.MyReporterClass.
|
||||
output-format=text
|
||||
|
||||
# Tells whether to display a full report or only the messages
|
||||
reports=no
|
||||
|
||||
# Activate the evaluation score.
|
||||
score=yes
|
||||
|
||||
|
||||
[REFACTORING]
|
||||
|
||||
# Maximum number of nested blocks for function / method body
|
||||
max-nested-blocks=5
|
||||
|
||||
|
||||
[LOGGING]
|
||||
|
||||
# Logging modules to check that the string format arguments are in logging
|
||||
# function parameter format
|
||||
logging-modules=logging
|
||||
|
||||
|
||||
[SPELLING]
|
||||
|
||||
# Spelling dictionary name. Available dictionaries: none. To make it working
|
||||
# install python-enchant package.
|
||||
spelling-dict=
|
||||
|
||||
# List of comma separated words that should not be checked.
|
||||
spelling-ignore-words=
|
||||
|
||||
# A path to a file that contains private dictionary; one word per line.
|
||||
spelling-private-dict-file=
|
||||
|
||||
# Tells whether to store unknown words to indicated private dictionary in
|
||||
# --spelling-private-dict-file option instead of raising a message.
|
||||
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
|
||||
|
||||
|
||||
[TYPECHECK]
|
||||
|
||||
# List of decorators that produce context managers, such as
|
||||
# contextlib.contextmanager. Add to this list to register other decorators that
|
||||
# produce valid context managers.
|
||||
contextmanager-decorators=contextlib.contextmanager
|
||||
|
||||
# List of members which are set dynamically and missed by pylint inference
|
||||
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
||||
# expressions are accepted.
|
||||
generated-members=
|
||||
|
||||
# Tells whether missing members accessed in mixin class should be ignored. A
|
||||
# mixin class is detected if its name ends with "mixin" (case insensitive).
|
||||
ignore-mixin-members=yes
|
||||
|
||||
# This flag controls whether pylint should warn about no-member and similar
|
||||
# checks whenever an opaque object is returned when inferring. The inference
|
||||
# can return multiple potential results while evaluating a Python object, but
|
||||
# some branches might not be evaluated, which results in partial inference. In
|
||||
# that case, it might be useful to still emit no-member and other checks for
|
||||
# the rest of the inferred objects.
|
||||
ignore-on-opaque-inference=yes
|
||||
|
||||
# List of class names for which member attributes should not be checked (useful
|
||||
# for classes with dynamically set attributes). This supports the use of
|
||||
# qualified names.
|
||||
ignored-classes=optparse.Values,thread._local,_thread._local
|
||||
|
||||
# List of module names for which member attributes should not be checked
|
||||
# (useful for modules/projects where namespaces are manipulated during runtime
|
||||
# and thus existing member attributes cannot be deduced by static analysis. It
|
||||
# supports qualified module names, as well as Unix pattern matching.
|
||||
ignored-modules=board
|
||||
|
||||
# Show a hint with possible names when a member name was not found. The aspect
|
||||
# of finding the hint is based on edit distance.
|
||||
missing-member-hint=yes
|
||||
|
||||
# The minimum edit distance a name should have in order to be considered a
|
||||
# similar match for a missing member name.
|
||||
missing-member-hint-distance=1
|
||||
|
||||
# The total number of similar names that should be taken in consideration when
|
||||
# showing a hint for a missing member.
|
||||
missing-member-max-choices=1
|
||||
|
||||
|
||||
[VARIABLES]
|
||||
|
||||
# List of additional names supposed to be defined in builtins. Remember that
|
||||
# you should avoid to define new builtins when possible.
|
||||
additional-builtins=
|
||||
|
||||
# Tells whether unused global variables should be treated as a violation.
|
||||
allow-global-unused-variables=yes
|
||||
|
||||
# List of strings which can identify a callback function by name. A callback
|
||||
# name must start or end with one of those strings.
|
||||
callbacks=cb_,_cb
|
||||
|
||||
# A regular expression matching the name of dummy variables (i.e. expectedly
|
||||
# not used).
|
||||
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
|
||||
|
||||
# Argument names that match this expression will be ignored. Default to name
|
||||
# with leading underscore
|
||||
ignored-argument-names=_.*|^ignored_|^unused_
|
||||
|
||||
# Tells whether we should check for unused import in __init__ files.
|
||||
init-import=no
|
||||
|
||||
# List of qualified module names which can have objects that can redefine
|
||||
# builtins.
|
||||
redefining-builtins-modules=six.moves,future.builtins
|
||||
|
||||
|
||||
[FORMAT]
|
||||
|
||||
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
|
||||
# expected-line-ending-format=
|
||||
expected-line-ending-format=LF
|
||||
|
||||
# Regexp for a line that is allowed to be longer than the limit.
|
||||
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
|
||||
|
||||
# Number of spaces of indent required inside a hanging or continued line.
|
||||
indent-after-paren=4
|
||||
|
||||
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
||||
# tab).
|
||||
indent-string=' '
|
||||
|
||||
# Maximum number of characters on a single line.
|
||||
max-line-length=100
|
||||
|
||||
# Maximum number of lines in a module
|
||||
max-module-lines=1000
|
||||
|
||||
# List of optional constructs for which whitespace checking is disabled. `dict-
|
||||
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
|
||||
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
|
||||
# `empty-line` allows space-only lines.
|
||||
no-space-check=trailing-comma,dict-separator
|
||||
|
||||
# Allow the body of a class to be on the same line as the declaration if body
|
||||
# contains single statement.
|
||||
single-line-class-stmt=no
|
||||
|
||||
# Allow the body of an if to be on the same line as the test if there is no
|
||||
# else.
|
||||
single-line-if-stmt=no
|
||||
|
||||
|
||||
[SIMILARITIES]
|
||||
|
||||
# Ignore comments when computing similarities.
|
||||
ignore-comments=yes
|
||||
|
||||
# Ignore docstrings when computing similarities.
|
||||
ignore-docstrings=yes
|
||||
|
||||
# Ignore imports when computing similarities.
|
||||
ignore-imports=no
|
||||
|
||||
# Minimum lines number of a similarity.
|
||||
min-similarity-lines=4
|
||||
|
||||
|
||||
[BASIC]
|
||||
|
||||
# Naming hint for argument names
|
||||
argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct argument names
|
||||
argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Naming hint for attribute names
|
||||
attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct attribute names
|
||||
attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Bad variable names which should always be refused, separated by a comma
|
||||
bad-names=foo,bar,baz,toto,tutu,tata
|
||||
|
||||
# Naming hint for class attribute names
|
||||
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
||||
|
||||
# Regular expression matching correct class attribute names
|
||||
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
||||
|
||||
# Naming hint for class names
|
||||
# class-name-hint=[A-Z_][a-zA-Z0-9]+$
|
||||
class-name-hint=[A-Z_][a-zA-Z0-9_]+$
|
||||
|
||||
# Regular expression matching correct class names
|
||||
# class-rgx=[A-Z_][a-zA-Z0-9]+$
|
||||
class-rgx=[A-Z_][a-zA-Z0-9_]+$
|
||||
|
||||
# Naming hint for constant names
|
||||
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
||||
|
||||
# Regular expression matching correct constant names
|
||||
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
||||
|
||||
# Minimum line length for functions/classes that require docstrings, shorter
|
||||
# ones are exempt.
|
||||
docstring-min-length=-1
|
||||
|
||||
# Naming hint for function names
|
||||
function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct function names
|
||||
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,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
|
||||
|
||||
# Naming hint for inline iteration names
|
||||
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
|
||||
|
||||
# Regular expression matching correct inline iteration names
|
||||
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
|
||||
|
||||
# Naming hint for method names
|
||||
method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct method names
|
||||
method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Naming hint for module names
|
||||
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
||||
|
||||
# Regular expression matching correct module names
|
||||
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
||||
|
||||
# Colon-delimited sets of names that determine each other's naming style when
|
||||
# the name regexes allow several styles.
|
||||
name-group=
|
||||
|
||||
# Regular expression which should only match function or class names that do
|
||||
# not require a docstring.
|
||||
no-docstring-rgx=^_
|
||||
|
||||
# List of decorators that produce properties, such as abc.abstractproperty. Add
|
||||
# to this list to register other decorators that produce valid properties.
|
||||
property-classes=abc.abstractproperty
|
||||
|
||||
# Naming hint for variable names
|
||||
variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
# Regular expression matching correct variable names
|
||||
variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
|
||||
|
||||
|
||||
[IMPORTS]
|
||||
|
||||
# Allow wildcard imports from modules that define __all__.
|
||||
allow-wildcard-with-all=no
|
||||
|
||||
# Analyse import fallback blocks. This can be used to support both Python 2 and
|
||||
# 3 compatible code, which means that the block might have code that exists
|
||||
# only in one or another interpreter, leading to false positives when analysed.
|
||||
analyse-fallback-blocks=no
|
||||
|
||||
# Deprecated modules which should not be used, separated by a comma
|
||||
deprecated-modules=optparse,tkinter.tix
|
||||
|
||||
# Create a graph of external dependencies in the given file (report RP0402 must
|
||||
# not be disabled)
|
||||
ext-import-graph=
|
||||
|
||||
# Create a graph of every (i.e. internal and external) dependencies in the
|
||||
# given file (report RP0402 must not be disabled)
|
||||
import-graph=
|
||||
|
||||
# Create a graph of internal dependencies in the given file (report RP0402 must
|
||||
# not be disabled)
|
||||
int-import-graph=
|
||||
|
||||
# Force import order to recognize a module as part of the standard
|
||||
# compatibility libraries.
|
||||
known-standard-library=
|
||||
|
||||
# Force import order to recognize a module as part of a third party library.
|
||||
known-third-party=enchant
|
||||
|
||||
|
||||
[CLASSES]
|
||||
|
||||
# List of method names used to declare (i.e. assign) instance attributes.
|
||||
defining-attr-methods=__init__,__new__,setUp
|
||||
|
||||
# List of member names, which should be excluded from the protected access
|
||||
# warning.
|
||||
exclude-protected=_asdict,_fields,_replace,_source,_make
|
||||
|
||||
# List of valid names for the first argument in a class method.
|
||||
valid-classmethod-first-arg=cls
|
||||
|
||||
# List of valid names for the first argument in a metaclass class method.
|
||||
valid-metaclass-classmethod-first-arg=mcs
|
||||
|
||||
|
||||
[DESIGN]
|
||||
|
||||
# Maximum number of arguments for function / method
|
||||
max-args=5
|
||||
|
||||
# Maximum number of attributes for a class (see R0902).
|
||||
# max-attributes=7
|
||||
max-attributes=11
|
||||
|
||||
# Maximum number of boolean expressions in a if statement
|
||||
max-bool-expr=5
|
||||
|
||||
# Maximum number of branch for function / method body
|
||||
max-branches=12
|
||||
|
||||
# Maximum number of locals for function / method body
|
||||
max-locals=15
|
||||
|
||||
# Maximum number of parents for a class (see R0901).
|
||||
max-parents=7
|
||||
|
||||
# Maximum number of public methods for a class (see R0904).
|
||||
max-public-methods=20
|
||||
|
||||
# Maximum number of return / yield for function / method body
|
||||
max-returns=6
|
||||
|
||||
# Maximum number of statements in function / method body
|
||||
max-statements=50
|
||||
|
||||
# Minimum number of public methods for a class (see R0903).
|
||||
min-public-methods=1
|
||||
|
||||
|
||||
[EXCEPTIONS]
|
||||
|
||||
# Exceptions that will emit a warning when being caught. Defaults to
|
||||
# "Exception"
|
||||
overgeneral-exceptions=Exception
|
||||
|
|
@ -1,2 +1,3 @@
|
|||
python:
|
||||
version: 3
|
||||
requirements_file: requirements.txt
|
||||
|
||||
53
.travis.yml
53
.travis.yml
|
|
@ -1,53 +0,0 @@
|
|||
# Travis CI configuration for automated .mpy file generation.
|
||||
# Author: Tony DiCola
|
||||
# License: Public Domain
|
||||
# This configuration will work with Travis CI (travis-ci.org) to automacially
|
||||
# build .mpy files for CircuitPython when a new tagged release is created. This
|
||||
# file is relatively generic and can be shared across multiple repositories by
|
||||
# following these steps:
|
||||
# 1. Copy this file into a .travis.yml file in the root of the repository.
|
||||
# 2. Change the deploy > file section below to list each of the .mpy files
|
||||
# that should be generated. The config will automatically look for
|
||||
# .py files with the same name as the source for generating the .mpy files.
|
||||
# Note that the .mpy extension should be lower case!
|
||||
# 3. Commit the .travis.yml file and push it to GitHub.
|
||||
# 4. Go to travis-ci.org and find the repository (it needs to be setup to access
|
||||
# your github account, and your github account needs access to write to the
|
||||
# repo). Flip the 'ON' switch on for Travis and the repo, see the Travis
|
||||
# docs for more details: https://docs.travis-ci.com/user/getting-started/
|
||||
# 5. Get a GitHub 'personal access token' which has at least 'public_repo' or
|
||||
# 'repo' scope: https://help.github.com/articles/creating-an-access-token-for-command-line-use/
|
||||
# Keep this token safe and secure! Anyone with the token will be able to
|
||||
# access and write to your GitHub repositories. Travis will use the token
|
||||
# to attach the .mpy files to the release.
|
||||
# 6. In the Travis CI settings for the repository that was enabled find the
|
||||
# environment variable editing page: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings
|
||||
# Add an environment variable named GITHUB_TOKEN and set it to the value
|
||||
# of the GitHub personal access token above. Keep 'Display value in build
|
||||
# log' flipped off.
|
||||
# 7. That's it! Tag a release and Travis should go to work to add .mpy files
|
||||
# to the release. It takes about a 2-3 minutes for a worker to spin up,
|
||||
# build mpy-cross, and add the binaries to the release.
|
||||
language: generic
|
||||
|
||||
sudo: true
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key: $GITHUB_TOKEN
|
||||
file:
|
||||
- "adafruit_bme680.mpy"
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
|
||||
before_install:
|
||||
- sudo apt-get -yqq update
|
||||
- sudo apt-get install -y build-essential git python python-pip
|
||||
- git clone https://github.com/adafruit/circuitpython.git -b 2.x
|
||||
- make -C circuitpython/mpy-cross
|
||||
- export PATH=$PATH:$PWD/circuitpython/mpy-cross/
|
||||
- sudo pip install shyaml
|
||||
|
||||
before_deploy:
|
||||
- shyaml get-values deploy.file < .travis.yml | sed 's/.mpy/.py/' | xargs -L1 mpy-cross
|
||||
|
|
@ -1,74 +1,129 @@
|
|||
# Contributor Covenant Code of Conduct
|
||||
# Adafruit Community Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
contributors and leaders pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
size, disability, ethnicity, gender identity and expression, level or type of
|
||||
experience, education, socio-economic status, nationality, personal appearance,
|
||||
race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
We are committed to providing a friendly, safe and welcoming environment for
|
||||
all.
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Be kind and courteous to others
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Collaborating with other community members
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* The use of sexualized language or imagery and sexual attention or advances
|
||||
* The use of inappropriate images, including in a community member's avatar
|
||||
* The use of inappropriate language, including in a community member's nickname
|
||||
* Any spamming, flaming, baiting or other attention-stealing behavior
|
||||
* Excessive or unwelcome helping; answering outside the scope of the question
|
||||
asked
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Promoting or spreading disinformation, lies, or conspiracy theories against
|
||||
a person, group, organisation, project, or community
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
* Other conduct which could reasonably be considered inappropriate
|
||||
|
||||
The goal of the standards and moderation guidelines outlined here is to build
|
||||
and maintain a respectful community. We ask that you don’t just aim to be
|
||||
"technically unimpeachable", but rather try to be your best self.
|
||||
|
||||
We value many things beyond technical expertise, including collaboration and
|
||||
supporting others within our community. Providing a positive experience for
|
||||
other community members can have a much more significant impact than simply
|
||||
providing the correct answer.
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
Project leaders are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
Project leaders have the right and responsibility to remove, edit, or
|
||||
reject messages, comments, commits, code, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
permanently any community member for other behaviors that they deem
|
||||
inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Moderation
|
||||
|
||||
Instances of behaviors that violate the Adafruit Community Code of Conduct
|
||||
may be reported by any member of the community. Community members are
|
||||
encouraged to report these situations, including situations they witness
|
||||
involving other community members.
|
||||
|
||||
You may report in the following ways:
|
||||
|
||||
In any situation, you may send an email to <support@adafruit.com>.
|
||||
|
||||
On the Adafruit Discord, you may send an open message from any channel
|
||||
to all Community Moderators by tagging @community moderators. You may
|
||||
also send an open message from any channel, or a direct message to
|
||||
@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442,
|
||||
@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175.
|
||||
|
||||
Email and direct message reports will be kept confidential.
|
||||
|
||||
In situations on Discord where the issue is particularly egregious, possibly
|
||||
illegal, requires immediate action, or violates the Discord terms of service,
|
||||
you should also report the message directly to Discord.
|
||||
|
||||
These are the steps for upholding our community’s standards of conduct.
|
||||
|
||||
1. Any member of the community may report any situation that violates the
|
||||
Adafruit Community Code of Conduct. All reports will be reviewed and
|
||||
investigated.
|
||||
2. If the behavior is an egregious violation, the community member who
|
||||
committed the violation may be banned immediately, without warning.
|
||||
3. Otherwise, moderators will first respond to such behavior with a warning.
|
||||
4. Moderators follow a soft "three strikes" policy - the community member may
|
||||
be given another chance, if they are receptive to the warning and change their
|
||||
behavior.
|
||||
5. If the community member is unreceptive or unreasonable when warned by a
|
||||
moderator, or the warning goes unheeded, they may be banned for a first or
|
||||
second offense. Repeated offenses will result in the community member being
|
||||
banned.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct and the enforcement policies listed above apply to all
|
||||
Adafruit Community venues. This includes but is not limited to any community
|
||||
spaces (both public and private), the entire Adafruit Discord server, and
|
||||
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
|
||||
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
|
||||
interaction at a conference.
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at support@adafruit.com. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
when an individual is representing the project or its community. As a community
|
||||
member, you are representing our community, and are expected to behave
|
||||
accordingly.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 1.4, available at
|
||||
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
|
||||
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
||||
For other projects adopting the Adafruit Community Code of
|
||||
Conduct, please contact the maintainers of those projects for enforcement.
|
||||
If you wish to use this code of conduct for your own project, consider
|
||||
explicitly mentioning your moderation policy or making a copy with your
|
||||
own moderation policy so as to avoid confusion.
|
||||
|
|
|
|||
56
README.rst
56
README.rst
|
|
@ -7,9 +7,13 @@ Introduction
|
|||
:alt: Documentation Status
|
||||
|
||||
.. image :: https://img.shields.io/discord/327254708534116352.svg
|
||||
:target: https://discord.gg/nBQh6qu
|
||||
:target: https://adafru.it/discord
|
||||
:alt: Discord
|
||||
|
||||
.. image:: https://github.com/adafruit/Adafruit_CircuitPython_BME680/workflows/Build%20CI/badge.svg
|
||||
:target: https://github.com/adafruit/Adafruit_CircuitPython_BME680/actions/
|
||||
:alt: Build Status
|
||||
|
||||
CircuitPython driver for BME680 sensor over I2C
|
||||
|
||||
Dependencies
|
||||
|
|
@ -23,32 +27,53 @@ Please ensure all dependencies are available on the CircuitPython filesystem.
|
|||
This is easily achieved by downloading
|
||||
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
|
||||
|
||||
Installing from PyPI
|
||||
=====================
|
||||
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
|
||||
PyPI <https://pypi.org/project/adafruit-circuitpython-bme680/>`_. To install for current user:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
pip3 install adafruit-circuitpython-bme680
|
||||
|
||||
To install system-wide (this may be required in some cases):
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
sudo pip3 install adafruit-circuitpython-bme680
|
||||
|
||||
To install in a virtual environment in your current project:
|
||||
|
||||
.. code-block:: shell
|
||||
|
||||
mkdir project-name && cd project-name
|
||||
python3 -m venv .env
|
||||
source .env/bin/activate
|
||||
pip3 install adafruit-circuitpython-bme680
|
||||
|
||||
Usage Example
|
||||
=============
|
||||
|
||||
.. code-block:: python
|
||||
import gc
|
||||
|
||||
from busio import I2C
|
||||
import adafruit_bme680
|
||||
import time
|
||||
import board
|
||||
|
||||
gc.collect()
|
||||
print("Free mem:",gc.mem_free())
|
||||
|
||||
# Create library object using our Bus I2C port
|
||||
i2c = I2C(board.SCL, board.SDA)
|
||||
bme280 = adafruit_bme680.Adafruit_BME680_I2C(i2c)
|
||||
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c)
|
||||
|
||||
# change this to match the location's pressure (hPa) at sea level
|
||||
bme280.seaLevelhPa = 1013.25
|
||||
bme680.sea_level_pressure = 1013.25
|
||||
|
||||
while True:
|
||||
print("\nTemperature: %0.1f C" % bme280.temperature)
|
||||
print("Gas: %d ohm" % bme280.gas)
|
||||
print("Humidity: %0.1f %%" % bme280.humidity)
|
||||
print("Pressure: %0.1f hPa" % bme280.pressure)
|
||||
print("Altitude = %0.2f meters" % bme280.altitude)
|
||||
print("\nTemperature: %0.1f C" % bme680.temperature)
|
||||
print("Gas: %d ohm" % bme680.gas)
|
||||
print("Humidity: %0.1f %%" % bme680.humidity)
|
||||
print("Pressure: %0.3f hPa" % bme680.pressure)
|
||||
print("Altitude = %0.2f meters" % bme680.altitude)
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
|
|
@ -60,10 +85,7 @@ Contributions are welcome! Please read our `Code of Conduct
|
|||
<https://github.com/adafruit/Adafruit_CircuitPython_bme680/blob/master/CODE_OF_CONDUCT.md>`_
|
||||
before contributing to help this project stay welcoming.
|
||||
|
||||
API Reference
|
||||
Documentation
|
||||
=============
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
api
|
||||
For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
|
||||
|
|
|
|||
|
|
@ -20,39 +20,64 @@
|
|||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
# We have a lot of attributes for this complex sensor.
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
|
||||
"""
|
||||
`adafruit_bme680`
|
||||
====================================================
|
||||
================================================================================
|
||||
|
||||
CircuitPython driver from BME680 air quality sensor
|
||||
CircuitPython library for BME680 temperature, pressure and humidity sensor.
|
||||
|
||||
* Author(s): ladyada
|
||||
|
||||
* Author(s): Limor Fried
|
||||
|
||||
Implementation Notes
|
||||
--------------------
|
||||
|
||||
**Hardware:**
|
||||
|
||||
* `Adafruit BME680 Temp, Humidity, Pressure and Gas Sensor <https://www.adafruit.com/product/3660>`_
|
||||
|
||||
**Software and Dependencies:**
|
||||
|
||||
* Adafruit CircuitPython firmware for the supported boards:
|
||||
https://github.com/adafruit/circuitpython/releases
|
||||
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
|
||||
"""
|
||||
|
||||
import time, math
|
||||
|
||||
import time
|
||||
import math
|
||||
from micropython import const
|
||||
|
||||
try:
|
||||
import struct
|
||||
except ImportError:
|
||||
import ustruct as struct
|
||||
|
||||
__version__ = "0.0.0-auto.0"
|
||||
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BME680.git"
|
||||
|
||||
|
||||
# I2C ADDRESS/BITS/SETTINGS
|
||||
# -----------------------------------------------------------------------
|
||||
_BME680_CHIPID = const(0x61)
|
||||
_BME680_CHIPID = const(0x61)
|
||||
|
||||
_BME680_REG_CHIPID = const(0xD0)
|
||||
_BME680_REG_CHIPID = const(0xD0)
|
||||
_BME680_BME680_COEFF_ADDR1 = const(0x89)
|
||||
_BME680_BME680_COEFF_ADDR2 = const(0xE1)
|
||||
_BME680_BME680_RES_WAIT_0 = const(0x5A)
|
||||
_BME680_BME680_RES_HEAT_0 = const(0x5A)
|
||||
_BME680_BME680_GAS_WAIT_0 = const(0x64)
|
||||
|
||||
_BME680_REG_SOFTRESET = const(0xE0)
|
||||
_BME680_REG_SOFTRESET = const(0xE0)
|
||||
_BME680_REG_CTRL_GAS = const(0x71)
|
||||
_BME680_REG_CTRL_HUM = const(0x72)
|
||||
_BME280_REG_STATUS = const(0xF3)
|
||||
_BME680_REG_STATUS = const(0x73)
|
||||
_BME680_REG_CTRL_MEAS = const(0x74)
|
||||
_BME680_REG_CONFIG = const(0x75)
|
||||
|
||||
_BME680_REG_STATUS = const(0x1D)
|
||||
_BME680_REG_MEAS_STATUS = const(0x1D)
|
||||
_BME680_REG_PDATA = const(0x1F)
|
||||
_BME680_REG_TDATA = const(0x22)
|
||||
_BME680_REG_HDATA = const(0x25)
|
||||
|
|
@ -62,79 +87,142 @@ _BME680_FILTERSIZES = (0, 1, 3, 7, 15, 31, 63, 127)
|
|||
|
||||
_BME680_RUNGAS = const(0x10)
|
||||
|
||||
lookupTable1 = (2147483647.0, 2147483647.0, 2147483647.0, 2147483647.0, 2147483647.0, 2126008810.0, 2147483647.0, 2130303777.0, 2147483647.0, 2147483647.0, 2143188679.0, 2136746228.0, 2147483647.0, 2126008810.0, 2147483647.0, 2147483647.0)
|
||||
_LOOKUP_TABLE_1 = (
|
||||
2147483647.0,
|
||||
2147483647.0,
|
||||
2147483647.0,
|
||||
2147483647.0,
|
||||
2147483647.0,
|
||||
2126008810.0,
|
||||
2147483647.0,
|
||||
2130303777.0,
|
||||
2147483647.0,
|
||||
2147483647.0,
|
||||
2143188679.0,
|
||||
2136746228.0,
|
||||
2147483647.0,
|
||||
2126008810.0,
|
||||
2147483647.0,
|
||||
2147483647.0,
|
||||
)
|
||||
|
||||
lookupTable2 = (4096000000.0, 2048000000.0, 1024000000.0, 512000000.0, 255744255.0, 127110228.0, 64000000.0, 32258064.0, 16016016.0, 8000000.0, 4000000.0, 2000000.0, 1000000.0, 500000.0, 250000.0, 125000.0)
|
||||
_LOOKUP_TABLE_2 = (
|
||||
4096000000.0,
|
||||
2048000000.0,
|
||||
1024000000.0,
|
||||
512000000.0,
|
||||
255744255.0,
|
||||
127110228.0,
|
||||
64000000.0,
|
||||
32258064.0,
|
||||
16016016.0,
|
||||
8000000.0,
|
||||
4000000.0,
|
||||
2000000.0,
|
||||
1000000.0,
|
||||
500000.0,
|
||||
250000.0,
|
||||
125000.0,
|
||||
)
|
||||
|
||||
|
||||
def _read24(arr):
|
||||
"""Parse an unsigned 24-bit value as a floating point and return it."""
|
||||
ret = 0.0
|
||||
# print([hex(i) for i in arr])
|
||||
for b in arr:
|
||||
ret *= 256.0
|
||||
ret += float(b & 0xFF)
|
||||
return ret
|
||||
|
||||
|
||||
class Adafruit_BME680:
|
||||
"""Driver from BME680 air quality sensor"""
|
||||
def __init__(self):
|
||||
"""Check the BME680 was found, read the coefficients and enable the sensor for continuous reads"""
|
||||
"""Driver from BME680 air quality sensor
|
||||
|
||||
:param int refresh_rate: Maximum number of readings per second. Faster property reads
|
||||
will be from the previous reading."""
|
||||
|
||||
def __init__(self, *, refresh_rate=10):
|
||||
"""Check the BME680 was found, read the coefficients and enable the sensor for continuous
|
||||
reads."""
|
||||
self._write(_BME680_REG_SOFTRESET, [0xB6])
|
||||
time.sleep(0.5)
|
||||
time.sleep(0.005)
|
||||
|
||||
# Check device ID.
|
||||
id = self._read_byte(_BME680_REG_CHIPID)
|
||||
if _BME680_CHIPID != id:
|
||||
raise RuntimeError('Failed to find BME680! Chip ID 0x%x' % id)
|
||||
chip_id = self._read_byte(_BME680_REG_CHIPID)
|
||||
if chip_id != _BME680_CHIPID:
|
||||
raise RuntimeError("Failed to find BME680! Chip ID 0x%x" % chip_id)
|
||||
|
||||
self._read_coefficients()
|
||||
self._read_calibration()
|
||||
|
||||
# set up heater
|
||||
self._write(_BME680_BME680_RES_WAIT_0, [0x73, 0x64, 0x65])
|
||||
self.seaLevelhPa = 1013.25
|
||||
"""Pressure in hectoPascals at sea level. Used to calibrate `altitude`."""
|
||||
self.osrs_p = 4
|
||||
self.osrs_t = 8
|
||||
self.osrs_h = 2
|
||||
self.filter = 2
|
||||
self._write(_BME680_BME680_RES_HEAT_0, [0x73])
|
||||
self._write(_BME680_BME680_GAS_WAIT_0, [0x65])
|
||||
|
||||
self.sea_level_pressure = 1013.25
|
||||
"""Pressure in hectoPascals at sea level. Used to calibrate ``altitude``."""
|
||||
|
||||
# Default oversampling and filter register values.
|
||||
self._pressure_oversample = 0b011
|
||||
self._temp_oversample = 0b100
|
||||
self._humidity_oversample = 0b010
|
||||
self._filter = 0b010
|
||||
|
||||
self._adc_pres = None
|
||||
self._adc_temp = None
|
||||
self._adc_hum = None
|
||||
self._adc_gas = None
|
||||
self._gas_range = None
|
||||
self._t_fine = None
|
||||
|
||||
self._last_reading = 0
|
||||
self._min_refresh_time = 1 / refresh_rate
|
||||
|
||||
@property
|
||||
def pressure_oversample(self):
|
||||
"""The oversampling for pressure sensor"""
|
||||
return _BME680_SAMPLERATES[self.osrs_p]
|
||||
return _BME680_SAMPLERATES[self._pressure_oversample]
|
||||
|
||||
@pressure_oversample.setter
|
||||
def pressure_oversample(self, os):
|
||||
if os in _BME680_SAMPLERATES:
|
||||
self.osrs_p = _BME680_SAMPLERATES.index(os)
|
||||
def pressure_oversample(self, sample_rate):
|
||||
if sample_rate in _BME680_SAMPLERATES:
|
||||
self._pressure_oversample = _BME680_SAMPLERATES.index(sample_rate)
|
||||
else:
|
||||
raise RuntimeError("Invalid oversample")
|
||||
|
||||
@property
|
||||
def humidity_oversample(self):
|
||||
"""The oversampling for humidity sensor"""
|
||||
return _BME680_SAMPLERATES[self.osrs_h]
|
||||
return _BME680_SAMPLERATES[self._humidity_oversample]
|
||||
|
||||
@humidity_oversample.setter
|
||||
def humidity_oversample(self, os):
|
||||
if os in _BME680_SAMPLERATES:
|
||||
self.osrs_h = _BME680_SAMPLERATES.index(os)
|
||||
def humidity_oversample(self, sample_rate):
|
||||
if sample_rate in _BME680_SAMPLERATES:
|
||||
self._humidity_oversample = _BME680_SAMPLERATES.index(sample_rate)
|
||||
else:
|
||||
raise RuntimeError("Invalid oversample")
|
||||
|
||||
@property
|
||||
def temperature_oversample(self):
|
||||
"""The oversampling for temperature sensor"""
|
||||
return _BME680_SAMPLERATES[self.osrs_p]
|
||||
return _BME680_SAMPLERATES[self._temp_oversample]
|
||||
|
||||
@temperature_oversample.setter
|
||||
def temperature_oversample(self, os):
|
||||
if os in _BME680_SAMPLERATES:
|
||||
self.osrs_t = _BME680_SAMPLERATES.index(os)
|
||||
def temperature_oversample(self, sample_rate):
|
||||
if sample_rate in _BME680_SAMPLERATES:
|
||||
self._temp_oversample = _BME680_SAMPLERATES.index(sample_rate)
|
||||
else:
|
||||
raise RuntimeError("Invalid oversample")
|
||||
|
||||
@property
|
||||
def filter_size(self):
|
||||
"""The filter size for the built in IIR filter"""
|
||||
return _BME680_FILTERSIZES[self.filter]
|
||||
return _BME680_FILTERSIZES[self._filter]
|
||||
|
||||
@filter_size.setter
|
||||
def filter_size(self, fs):
|
||||
if fs in _BME680_FILTERSIZES:
|
||||
self.filter = _BME680_FILTERSIZES(fs)
|
||||
def filter_size(self, size):
|
||||
if size in _BME680_FILTERSIZES:
|
||||
self._filter = _BME680_FILTERSIZES.index(size)
|
||||
else:
|
||||
raise RuntimeError("Invalid size")
|
||||
|
||||
|
|
@ -142,46 +230,64 @@ class Adafruit_BME680:
|
|||
def temperature(self):
|
||||
"""The compensated temperature in degrees celsius."""
|
||||
self._perform_reading()
|
||||
var1 = (self._adc_temp / 8) - (self._T1 * 2)
|
||||
var2 = (var1 * self._T2) / 2048
|
||||
var3 = ((var1 / 2) * (var1 / 2)) / 4096
|
||||
var3 = (var3 * self._T3 * 16) / 16384
|
||||
self.t_fine = int(var2 + var3)
|
||||
calc_temp = (((self.t_fine * 5) + 128) / 256)
|
||||
calc_temp = ((self._t_fine * 5) + 128) / 256
|
||||
return calc_temp / 100
|
||||
|
||||
@property
|
||||
def pressure(self):
|
||||
"""The barometric pressure in hectoPascals"""
|
||||
self.temperature
|
||||
var1 = (self.t_fine / 2) - 64000
|
||||
self._perform_reading()
|
||||
var1 = (self._t_fine / 2) - 64000
|
||||
var2 = ((var1 / 4) * (var1 / 4)) / 2048
|
||||
var2 = (var2 * self._P6) / 4
|
||||
var2 = var2 + (var1 * self._P5 * 2)
|
||||
var2 = (var2 / 4) + (self._P4 * 65536)
|
||||
var1 = ((var1 / 4) * (var1 / 4)) / 8192
|
||||
var1 = ((var1 * self._P3 * 32) / 8) + ((self._P2 * var1) / 2)
|
||||
var2 = (var2 * self._pressure_calibration[5]) / 4
|
||||
var2 = var2 + (var1 * self._pressure_calibration[4] * 2)
|
||||
var2 = (var2 / 4) + (self._pressure_calibration[3] * 65536)
|
||||
var1 = (
|
||||
(((var1 / 4) * (var1 / 4)) / 8192)
|
||||
* (self._pressure_calibration[2] * 32)
|
||||
/ 8
|
||||
) + ((self._pressure_calibration[1] * var1) / 2)
|
||||
var1 = var1 / 262144
|
||||
var1 = ((32768 + var1) * self._P1) / 32768
|
||||
var1 = ((32768 + var1) * self._pressure_calibration[0]) / 32768
|
||||
calc_pres = 1048576 - self._adc_pres
|
||||
calc_pres = (calc_pres - (var2 / 4096)) * 3125
|
||||
calc_pres = (calc_pres / var1) * 2
|
||||
var1 = (self._P9 * (((calc_pres / 8) * (calc_pres / 8)) / 8192)) / 4096
|
||||
var2 = ((calc_pres / 4) * self._P8) / 8192
|
||||
var3 = ((calc_pres / 256) * (calc_pres / 256) * (calc_pres / 256) * self._P10) / 131072
|
||||
calc_pres += ((var1 + var2 + var3 + (self._P7 * 128)) / 16)
|
||||
return calc_pres/100
|
||||
var1 = (
|
||||
self._pressure_calibration[8] * (((calc_pres / 8) * (calc_pres / 8)) / 8192)
|
||||
) / 4096
|
||||
var2 = ((calc_pres / 4) * self._pressure_calibration[7]) / 8192
|
||||
var3 = (((calc_pres / 256) ** 3) * self._pressure_calibration[9]) / 131072
|
||||
calc_pres += (var1 + var2 + var3 + (self._pressure_calibration[6] * 128)) / 16
|
||||
return calc_pres / 100
|
||||
|
||||
@property
|
||||
def humidity(self):
|
||||
"""The relative humidity in RH %"""
|
||||
self.temperature # Trigger a read
|
||||
temp_scaled = ((self.t_fine * 5) + 128) / 256
|
||||
var1 = (self._adc_hum - (self._H1 * 16)) - ((temp_scaled * self._H3) / 200)
|
||||
var2 = (self._H2 * (((temp_scaled * self._H4) / 100) + (((temp_scaled * ((temp_scaled * self._H5) / 100)) / 64) / 100) + 16384)) / 1024
|
||||
self._perform_reading()
|
||||
temp_scaled = ((self._t_fine * 5) + 128) / 256
|
||||
var1 = (self._adc_hum - (self._humidity_calibration[0] * 16)) - (
|
||||
(temp_scaled * self._humidity_calibration[2]) / 200
|
||||
)
|
||||
var2 = (
|
||||
self._humidity_calibration[1]
|
||||
* (
|
||||
((temp_scaled * self._humidity_calibration[3]) / 100)
|
||||
+ (
|
||||
(
|
||||
(
|
||||
temp_scaled
|
||||
* ((temp_scaled * self._humidity_calibration[4]) / 100)
|
||||
)
|
||||
/ 64
|
||||
)
|
||||
/ 100
|
||||
)
|
||||
+ 16384
|
||||
)
|
||||
) / 1024
|
||||
var3 = var1 * var2
|
||||
var4 = self._H6 * 128
|
||||
var4 = (var4 + ((temp_scaled * self._H7) / 100)) / 16
|
||||
var4 = self._humidity_calibration[5] * 128
|
||||
var4 = (var4 + ((temp_scaled * self._humidity_calibration[6]) / 100)) / 16
|
||||
var5 = ((var3 / 16384) * (var3 / 16384)) / 1024
|
||||
var6 = (var4 * var5) / 2
|
||||
calc_hum = (((var3 + var6) / 1024) * 1000) / 4096
|
||||
|
|
@ -195,100 +301,115 @@ class Adafruit_BME680:
|
|||
|
||||
@property
|
||||
def altitude(self):
|
||||
"""The altitude based on current `pressure` vs the sea level pressure (`seaLevelhPa`) - which you must enter ahead of time)"""
|
||||
p = self.pressure # in Si units for hPascal
|
||||
return 44330 * (1.0 - math.pow(p / self.seaLevelhPa, 0.1903));
|
||||
"""The altitude based on current ``pressure`` vs the sea level pressure
|
||||
(``sea_level_pressure``) - which you must enter ahead of time)"""
|
||||
pressure = self.pressure # in Si units for hPascal
|
||||
return 44330 * (1.0 - math.pow(pressure / self.sea_level_pressure, 0.1903))
|
||||
|
||||
@property
|
||||
def gas(self):
|
||||
"""The gas resistance in ohms"""
|
||||
self._perform_reading()
|
||||
var1 = ((1340 + (5 * self._sw_err)) * (lookupTable1[self._gas_range])) / 65536
|
||||
var1 = (
|
||||
(1340 + (5 * self._sw_err)) * (_LOOKUP_TABLE_1[self._gas_range])
|
||||
) / 65536
|
||||
var2 = ((self._adc_gas * 32768) - 16777216) + var1
|
||||
var3 = (lookupTable2[self._gas_range] * var1) / 512
|
||||
var3 = (_LOOKUP_TABLE_2[self._gas_range] * var1) / 512
|
||||
calc_gas_res = (var3 + (var2 / 2)) / var2
|
||||
return int(calc_gas_res)
|
||||
|
||||
def _perform_reading(self):
|
||||
"""Perform a single-shot reading from the sensor and fill internal data structure for calculations"""
|
||||
"""Perform a single-shot reading from the sensor and fill internal data structure for
|
||||
calculations"""
|
||||
if time.monotonic() - self._last_reading < self._min_refresh_time:
|
||||
return
|
||||
|
||||
# set filter
|
||||
self._write(_BME680_REG_CONFIG, [self.filter << 2])
|
||||
self._write(_BME680_REG_CONFIG, [self._filter << 2])
|
||||
# turn on temp oversample & pressure oversample
|
||||
self._write(_BME680_REG_CTRL_MEAS, [(self.osrs_t << 5)|(self.osrs_p << 2)])
|
||||
self._write(
|
||||
_BME680_REG_CTRL_MEAS,
|
||||
[(self._temp_oversample << 5) | (self._pressure_oversample << 2)],
|
||||
)
|
||||
# turn on humidity oversample
|
||||
self._write(_BME680_REG_CTRL_HUM, [self.osrs_h])
|
||||
self._write(_BME680_REG_CTRL_HUM, [self._humidity_oversample])
|
||||
# gas measurements enabled
|
||||
self._write(_BME680_REG_CTRL_GAS, [_BME680_RUNGAS])
|
||||
|
||||
v = self._read(_BME680_REG_CTRL_MEAS, 1)[0]
|
||||
v = (v & 0xFC) | 0x01 # enable single shot!
|
||||
self._write(_BME680_REG_CTRL_MEAS, [v])
|
||||
time.sleep(0.5)
|
||||
data = self._read(_BME680_REG_STATUS, 15)
|
||||
self._status = data[0] & 0x80
|
||||
gas_idx = data[0] & 0x0F
|
||||
meas_idx = data[1]
|
||||
#print("status 0x%x gas_idx %d meas_idx %d" % (status, gas_idx, meas_idx))
|
||||
ctrl = self._read_byte(_BME680_REG_CTRL_MEAS)
|
||||
ctrl = (ctrl & 0xFC) | 0x01 # enable single shot!
|
||||
self._write(_BME680_REG_CTRL_MEAS, [ctrl])
|
||||
new_data = False
|
||||
while not new_data:
|
||||
data = self._read(_BME680_REG_MEAS_STATUS, 15)
|
||||
new_data = data[0] & 0x80 != 0
|
||||
time.sleep(0.005)
|
||||
self._last_reading = time.monotonic()
|
||||
|
||||
self._adc_pres = self._read24(data[2:5]) / 16
|
||||
self._adc_temp = self._read24(data[5:8]) / 16
|
||||
self._adc_hum = struct.unpack('>H', bytes(data[8:10]))[0]
|
||||
self._adc_gas = int(struct.unpack('>H', bytes(data[13:15]))[0] / 64)
|
||||
self._adc_pres = _read24(data[2:5]) / 16
|
||||
self._adc_temp = _read24(data[5:8]) / 16
|
||||
self._adc_hum = struct.unpack(">H", bytes(data[8:10]))[0]
|
||||
self._adc_gas = int(struct.unpack(">H", bytes(data[13:15]))[0] / 64)
|
||||
self._gas_range = data[14] & 0x0F
|
||||
#print(self._adc_hum)
|
||||
#print(self._adc_gas)
|
||||
self._status |= data[14] & 0x30 # VALID + STABILITY mask
|
||||
|
||||
def _read24(self, arr):
|
||||
"""Parse an unsigned 24-bit value as a floating point and return it."""
|
||||
ret = 0.0
|
||||
#print([hex(i) for i in arr])
|
||||
for b in arr:
|
||||
ret *= 256.0
|
||||
ret += float(b & 0xFF)
|
||||
return ret
|
||||
var1 = (self._adc_temp / 8) - (self._temp_calibration[0] * 2)
|
||||
var2 = (var1 * self._temp_calibration[1]) / 2048
|
||||
var3 = ((var1 / 2) * (var1 / 2)) / 4096
|
||||
var3 = (var3 * self._temp_calibration[2] * 16) / 16384
|
||||
self._t_fine = int(var2 + var3)
|
||||
|
||||
def _read_coefficients(self):
|
||||
def _read_calibration(self):
|
||||
"""Read & save the calibration coefficients"""
|
||||
coeff = self._read(_BME680_BME680_COEFF_ADDR1, 25)
|
||||
coeff += self._read(_BME680_BME680_COEFF_ADDR2, 16)
|
||||
|
||||
coeff = list(struct.unpack('<hbBHhbBhhbbHhhBBBHbbbBbHhbb', bytes(coeff[1:])))
|
||||
#print("\n\n",coeff)
|
||||
coeff = list(struct.unpack("<hbBHhbBhhbbHhhBBBHbbbBbHhbb", bytes(coeff[1:39])))
|
||||
# print("\n\n",coeff)
|
||||
coeff = [float(i) for i in coeff]
|
||||
self._T2,self._T3, skip, self._P1,self._P2,self._P3, skip, self._P4,self._P5,self._P7,self._P6, skip,self._P8,self._P9,self._P10, skip, h2m, self._H1,self._H3,self._H4,self._H5,self._H6,self._H7,self._T1,self._G2,self._G1,self._G3 = coeff
|
||||
self._temp_calibration = [coeff[x] for x in [23, 0, 1]]
|
||||
self._pressure_calibration = [
|
||||
coeff[x] for x in [3, 4, 5, 7, 8, 10, 9, 12, 13, 14]
|
||||
]
|
||||
self._humidity_calibration = [coeff[x] for x in [17, 16, 18, 19, 20, 21, 22]]
|
||||
self._gas_calibration = [coeff[x] for x in [25, 24, 26]]
|
||||
|
||||
# flip around H1 & H2
|
||||
self._H2 = h2m * 16 + (self._H1 % 16)
|
||||
self._H1 /= 16
|
||||
self._humidity_calibration[1] *= 16
|
||||
self._humidity_calibration[1] += self._humidity_calibration[0] % 16
|
||||
self._humidity_calibration[0] /= 16
|
||||
|
||||
self._heat_range = (self._read(0x02, 1)[0] & 0x30) / 16
|
||||
self._heat_val = self._read(0x00, 1)[0]
|
||||
self._sw_err = (self._read(0x04, 1)[0] & 0xF0) / 16
|
||||
|
||||
#print("T1-3: %d %d %d" % (self._T1, self._T2, self._T3))
|
||||
#print("P1-3: %d %d %d" % (self._P1, self._P2, self._P3))
|
||||
#print("P4-6: %d %d %d" % (self._P4, self._P5, self._P6))
|
||||
#print("P7-9: %d %d %d" % (self._P7, self._P8, self._P9))
|
||||
#print("P10: %d" % self._P10)
|
||||
#print("H1-3: %d %d %d" % (self._H1, self._H2, self._H3))
|
||||
#print("H4-7: %d %d %d %d" % (self._H4, self._H5, self._H6, self._H7))
|
||||
#print("G1-3: %d %d %d" % (self._G1, self._G2, self._G3))
|
||||
#print("HR %d HV %d SWERR %d" % (self._HEATRANGE, self._HEATVAL, self._SWERR))
|
||||
self._heat_range = (self._read_byte(0x02) & 0x30) / 16
|
||||
self._heat_val = self._read_byte(0x00)
|
||||
self._sw_err = (self._read_byte(0x04) & 0xF0) / 16
|
||||
|
||||
def _read_byte(self, register):
|
||||
"""Read a byte register value and return it"""
|
||||
return self._read(register, 1)[0]
|
||||
|
||||
def _read(self, register, length):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _write(self, register, values):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class Adafruit_BME680_I2C(Adafruit_BME680):
|
||||
"""Driver for I2C connected BME680."""
|
||||
def __init__(self, i2c, address=0x77, debug=False):
|
||||
"""Driver for I2C connected BME680.
|
||||
|
||||
:param int address: I2C device address
|
||||
:param bool debug: Print debug statements when True.
|
||||
:param int refresh_rate: Maximum number of readings per second. Faster property reads
|
||||
will be from the previous reading."""
|
||||
|
||||
def __init__(self, i2c, address=0x77, debug=False, *, refresh_rate=10):
|
||||
"""Initialize the I2C device at the 'address' given"""
|
||||
import adafruit_bus_device.i2c_device as i2c_device
|
||||
from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel
|
||||
i2c_device,
|
||||
)
|
||||
|
||||
self._i2c = i2c_device.I2CDevice(i2c, address)
|
||||
self._debug = debug
|
||||
super().__init__()
|
||||
super().__init__(refresh_rate=refresh_rate)
|
||||
|
||||
def _read(self, register, length):
|
||||
"""Returns an array of 'length' bytes from the 'register'"""
|
||||
|
|
@ -303,7 +424,67 @@ class Adafruit_BME680_I2C(Adafruit_BME680):
|
|||
def _write(self, register, values):
|
||||
"""Writes an array of 'length' bytes to the 'register'"""
|
||||
with self._i2c as i2c:
|
||||
values = [(v & 0xFF) for v in [register]+values]
|
||||
i2c.write(bytes(values))
|
||||
buffer = bytearray(2 * len(values))
|
||||
for i, value in enumerate(values):
|
||||
buffer[2 * i] = register + i
|
||||
buffer[2 * i + 1] = value
|
||||
i2c.write(buffer)
|
||||
if self._debug:
|
||||
print("\t$%02X <= %s" % (values[0], [hex(i) for i in values[1:]]))
|
||||
|
||||
|
||||
class Adafruit_BME680_SPI(Adafruit_BME680):
|
||||
"""Driver for SPI connected BME680.
|
||||
|
||||
:param busio.SPI spi: SPI device
|
||||
:param digitalio.DigitalInOut cs: Chip Select
|
||||
:param bool debug: Print debug statements when True.
|
||||
:param int baudrate: Clock rate, default is 100000
|
||||
:param int refresh_rate: Maximum number of readings per second. Faster property reads
|
||||
will be from the previous reading.
|
||||
"""
|
||||
|
||||
def __init__(self, spi, cs, baudrate=100000, debug=False, *, refresh_rate=10):
|
||||
from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel
|
||||
spi_device,
|
||||
)
|
||||
|
||||
self._spi = spi_device.SPIDevice(spi, cs, baudrate=baudrate)
|
||||
self._debug = debug
|
||||
super().__init__(refresh_rate=refresh_rate)
|
||||
|
||||
def _read(self, register, length):
|
||||
if register != _BME680_REG_STATUS:
|
||||
# _BME680_REG_STATUS exists in both SPI memory pages
|
||||
# For all other registers, we must set the correct memory page
|
||||
self._set_spi_mem_page(register)
|
||||
|
||||
register = (register | 0x80) & 0xFF # Read single, bit 7 high.
|
||||
with self._spi as spi:
|
||||
spi.write(bytearray([register])) # pylint: disable=no-member
|
||||
result = bytearray(length)
|
||||
spi.readinto(result) # pylint: disable=no-member
|
||||
if self._debug:
|
||||
print("\t$%02X => %s" % (register, [hex(i) for i in result]))
|
||||
return result
|
||||
|
||||
def _write(self, register, values):
|
||||
if register != _BME680_REG_STATUS:
|
||||
# _BME680_REG_STATUS exists in both SPI memory pages
|
||||
# For all other registers, we must set the correct memory page
|
||||
self._set_spi_mem_page(register)
|
||||
register &= 0x7F # Write, bit 7 low.
|
||||
with self._spi as spi:
|
||||
buffer = bytearray(2 * len(values))
|
||||
for i, value in enumerate(values):
|
||||
buffer[2 * i] = register + i
|
||||
buffer[2 * i + 1] = value & 0xFF
|
||||
spi.write(buffer) # pylint: disable=no-member
|
||||
if self._debug:
|
||||
print("\t$%02X <= %s" % (values[0], [hex(i) for i in values[1:]]))
|
||||
|
||||
def _set_spi_mem_page(self, register):
|
||||
spi_mem_page = 0x00
|
||||
if register < 0x80:
|
||||
spi_mem_page = 0x10
|
||||
self._write(_BME680_REG_STATUS, [spi_mem_page])
|
||||
|
|
|
|||
BIN
docs/_static/favicon.ico
vendored
Normal file
BIN
docs/_static/favicon.ico
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
sys.path.insert(0, os.path.abspath(".."))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
|
|
@ -10,36 +11,41 @@ sys.path.insert(0, os.path.abspath('.'))
|
|||
# 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",
|
||||
]
|
||||
|
||||
autodoc_mock_imports = ['micropython']
|
||||
|
||||
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/bus_device/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 = 'README'
|
||||
master_doc = "index"
|
||||
|
||||
# General information about the project.
|
||||
project = u'Adafruit BME680 Library'
|
||||
copyright = u'2017 ladyada'
|
||||
author = u'ladyada'
|
||||
project = "Adafruit BME680 Library"
|
||||
copyright = "2017 ladyada"
|
||||
author = "ladyada"
|
||||
|
||||
# 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 = "1.0"
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = u'1.0'
|
||||
release = "1.0"
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
@ -51,7 +57,7 @@ language = None
|
|||
# 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']
|
||||
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.
|
||||
|
|
@ -63,64 +69,76 @@ default_role = "any"
|
|||
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
|
||||
|
||||
# If this is True, todo emits a warning for each TODO entries. The default is False.
|
||||
todo_emit_warnings = True
|
||||
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# 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"
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'AdafruitBME680Librarydoc'
|
||||
htmlhelp_basename = "AdafruitBME680Librarydoc"
|
||||
|
||||
# -- 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, 'AdafruitBME680Library.tex', u'Adafruit BME680 Library Documentation',
|
||||
author, 'manual'),
|
||||
(
|
||||
master_doc,
|
||||
"AdafruitBME680Library.tex",
|
||||
"Adafruit BME680 Library Documentation",
|
||||
author,
|
||||
"manual",
|
||||
),
|
||||
]
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
|
@ -128,8 +146,13 @@ latex_documents = [
|
|||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'adafruitBME680library', u'Adafruit BME680 Library Documentation',
|
||||
[author], 1)
|
||||
(
|
||||
master_doc,
|
||||
"adafruitBME680library",
|
||||
"Adafruit BME680 Library Documentation",
|
||||
[author],
|
||||
1,
|
||||
)
|
||||
]
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
|
@ -138,7 +161,13 @@ man_pages = [
|
|||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'AdafruitBME680Library', u'Adafruit BME680 Library Documentation',
|
||||
author, 'AdafruitBME680Library', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
(
|
||||
master_doc,
|
||||
"AdafruitBME680Library",
|
||||
"Adafruit BME680 Library Documentation",
|
||||
author,
|
||||
"AdafruitBME680Library",
|
||||
"One line description of project.",
|
||||
"Miscellaneous",
|
||||
),
|
||||
]
|
||||
8
docs/examples.rst
Normal file
8
docs/examples.rst
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Simple test
|
||||
------------
|
||||
|
||||
Ensure your device works with this simple test.
|
||||
|
||||
.. literalinclude:: ../examples/bme680_simpletest.py
|
||||
:caption: examples/bme680_simpletest.py
|
||||
:linenos:
|
||||
47
docs/index.rst
Normal file
47
docs/index.rst
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
.. include:: ../README.rst
|
||||
|
||||
Table of Contents
|
||||
=================
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 4
|
||||
:hidden:
|
||||
|
||||
self
|
||||
|
||||
.. toctree::
|
||||
:caption: Examples
|
||||
|
||||
examples
|
||||
|
||||
.. toctree::
|
||||
:caption: API Reference
|
||||
:maxdepth: 3
|
||||
|
||||
api
|
||||
|
||||
.. toctree::
|
||||
:caption: Tutorials
|
||||
|
||||
.. toctree::
|
||||
:caption: Related Products
|
||||
|
||||
Adafruit BME680 - Temperature, Humidity, Pressure and Gas Sensor <https://www.adafruit.com/product/3660>
|
||||
|
||||
.. toctree::
|
||||
:caption: Other Links
|
||||
|
||||
Download <https://github.com/adafruit/Adafruit_CircuitPython_BME680/releases/latest>
|
||||
CircuitPython Reference Documentation <https://circuitpython.readthedocs.io>
|
||||
CircuitPython Support Forum <https://forums.adafruit.com/viewforum.php?f=60>
|
||||
Discord Chat <https://adafru.it/discord>
|
||||
Adafruit Learning System <https://learn.adafruit.com>
|
||||
Adafruit Blog <https://blog.adafruit.com>
|
||||
Adafruit Store <https://www.adafruit.com>
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
25
examples/bme680_simpletest.py
Normal file
25
examples/bme680_simpletest.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import time
|
||||
import board
|
||||
from busio import I2C
|
||||
import adafruit_bme680
|
||||
|
||||
# Create library object using our Bus I2C port
|
||||
i2c = I2C(board.SCL, board.SDA)
|
||||
bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False)
|
||||
|
||||
# change this to match the location's pressure (hPa) at sea level
|
||||
bme680.sea_level_pressure = 1013.25
|
||||
|
||||
# You will usually have to add an offset to account for the temperature of
|
||||
# the sensor. This is usually around 5 degrees but varies by use. Use a
|
||||
# separate temperature sensor to calibrate this one.
|
||||
temperature_offset = -5
|
||||
|
||||
while True:
|
||||
print("\nTemperature: %0.1f C" % bme680.temperature + temperature_offset)
|
||||
print("Gas: %d ohm" % bme680.gas)
|
||||
print("Humidity: %0.1f %%" % bme680.humidity)
|
||||
print("Pressure: %0.3f hPa" % bme680.pressure)
|
||||
print("Altitude = %0.2f meters" % bme680.altitude)
|
||||
|
||||
time.sleep(1)
|
||||
|
|
@ -1 +1,2 @@
|
|||
adafruit-circuitpython-bus-device
|
||||
Adafruit-Blinka
|
||||
adafruit-circuitpython-busdevice
|
||||
|
|
|
|||
53
setup.py
Normal file
53
setup.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
"""A setuptools based setup module.
|
||||
|
||||
See:
|
||||
https://packaging.python.org/en/latest/distributing.html
|
||||
https://github.com/pypa/sampleproject
|
||||
"""
|
||||
|
||||
# Always prefer setuptools over distutils
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
# To use a consistent encoding
|
||||
from codecs import open
|
||||
from os import path
|
||||
|
||||
here = path.abspath(path.dirname(__file__))
|
||||
|
||||
# Get the long description from the README file
|
||||
with open(path.join(here, "README.rst"), encoding="utf-8") as f:
|
||||
long_description = f.read()
|
||||
|
||||
setup(
|
||||
name="adafruit-circuitpython-bme680",
|
||||
use_scm_version=True,
|
||||
setup_requires=["setuptools_scm"],
|
||||
description="CircuitPython library for BME680 temperature, pressure and humidity sensor.",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/x-rst",
|
||||
# The project's main homepage.
|
||||
url="https://github.com/adafruit/Adafruit_CircuitPython_BME680",
|
||||
# Author details
|
||||
author="Adafruit Industries",
|
||||
author_email="circuitpython@adafruit.com",
|
||||
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"],
|
||||
# Choose your license
|
||||
license="MIT",
|
||||
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
|
||||
classifiers=[
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Intended Audience :: Developers",
|
||||
"Topic :: Software Development :: Libraries",
|
||||
"Topic :: System :: Hardware",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.4",
|
||||
"Programming Language :: Python :: 3.5",
|
||||
],
|
||||
# What does your project relate to?
|
||||
keywords="adafruit blinka circuitpython micropython bme680 hardware temperature pressure "
|
||||
"humidity gas",
|
||||
# You can just specify the packages manually here if your project is
|
||||
# simple. Or you can use find_packages().
|
||||
py_modules=["adafruit_bme680"],
|
||||
)
|
||||
Loading…
Reference in a new issue