diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md index 71ef8f8..8de294e 100644 --- a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -4,7 +4,7 @@ Thank you for contributing! Before you submit a pull request, please read the following. -Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca35544..041a337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,66 +10,5 @@ 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.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - 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 Sphinx, pre-commit - run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - - name: Library version - run: git describe --dirty --always --tags - - name: Pre-commit hooks - run: | - pre-commit run --all-files - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Archive bundles - uses: actions/upload-artifact@v2 - with: - name: bundles - path: ${{ github.workspace }}/bundles/ - - name: Build docs - working-directory: docs - run: sphinx-build -E -W -b html . _build/html - - name: Check For setup.py - id: need-pypi - run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - - name: Build Python package - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - run: | - pip install --upgrade setuptools wheel twine readme_renderer testresources - python setup.py sdist - python setup.py bdist_wheel --universal - twine check dist/* - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 6d0015a..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,85 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -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/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..9acec60 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: GitHub Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..65775b7 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: PyPI Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Run PyPI Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-pypi@main + with: + pypi-username: ${{ secrets.pypi_username }} + pypi-password: ${{ secrets.pypi_password }} diff --git a/.gitignore b/.gitignore index 9647e71..db3d538 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,48 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT +# Do not include files and directories created by your personal work environment, such as the IDE +# you use, except for those already listed here. Pull requests including changes to this file will +# not be accepted. + +# This .gitignore file contains rules for files generated by working with CircuitPython libraries, +# including building Sphinx, testing with pip, and creating a virual environment, as well as the +# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. + +# If you find that there are files being generated on your machine that should not be included in +# your git commit, you should create a .gitignore_global file on your computer to include the +# files created by your personal setup. To do so, follow the two steps below. + +# First, create a file called .gitignore_global somewhere convenient for you, and add rules for +# the files you want to exclude from git commits. + +# Second, configure Git to use the exclude file for all Git repositories by running the +# following via commandline, replacing "path/to/your/" with the actual path to your newly created +# .gitignore_global file: +# git config --global core.excludesfile path/to/your/.gitignore_global + +# CircuitPython-specific files *.mpy -.idea + +# Python-specific files __pycache__ -_build *.pyc + +# Sphinx build-specific files +_build + +# This file results from running `pip -e install .` in a local repository +*.egg-info + +# Virtual environment-specific files .env -bundles +.venv + +# MacOS-specific files *.DS_Store -.eggs -dist -**/*.egg-info + +# IDE-specific files +.idea +.vscode +*~ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43d1385..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense repos: -- repo: https://github.com/python/black - rev: 20.8b1 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 hooks: - - id: black -- repo: https://github.com/fsfe/reuse-tool - rev: v0.12.1 + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: reuse -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/pycqa/pylint - rev: v2.11.1 - hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string,duplicate-code - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index cfd1c41..0000000 --- a/.pylintrc +++ /dev/null @@ -1,436 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[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 - -# 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,unspecified-encoding - -# 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*(# )??$ - -# 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=yes - -# 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 diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..88bca9f --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +sphinx: + configuration: docs/conf.py + +build: + os: ubuntu-20.04 + tools: + python: "3" + +python: + install: + - requirements: docs/requirements.txt + - requirements: requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 49dcab3..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -python: - version: 3 -requirements_file: docs/requirements.txt diff --git a/README.rst b/README.rst index 15a52e7..2b8c4f7 100644 --- a/README.rst +++ b/README.rst @@ -3,10 +3,10 @@ Introduction ============ .. image:: https://readthedocs.org/projects/adafruit-circuitpython-seesaw/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/seesaw/en/latest/ + :target: https://docs.circuitpython.org/projects/seesaw/en/latest/ :alt: Documentation Status -.. image :: https://img.shields.io/discord/327254708534116352.svg +.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord @@ -14,6 +14,10 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_seesaw/actions :alt: Build Status +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff + CircuitPython module for use with the Adafruit ATSAMD09 seesaw. Dependencies @@ -48,8 +52,8 @@ 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 + python3 -m venv .venv + source .venv/bin/activate pip3 install adafruit-circuitpython-seesaw Usage Example @@ -60,7 +64,9 @@ See examples/seesaw_simpletest.py for usage example. Documentation ============= -API documentation for this library can be found on `Read the Docs `_. +API documentation for this library can be found on `Read the Docs `_. + +For information on building library documentation, please check out `this guide `_. Contributing ============ @@ -68,8 +74,3 @@ Contributing Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. - -Documentation -============= - -For information on building library documentation, please check out `this guide `_. diff --git a/adafruit_seesaw/analoginput.py b/adafruit_seesaw/analoginput.py index dd1ebd3..4020079 100644 --- a/adafruit_seesaw/analoginput.py +++ b/adafruit_seesaw/analoginput.py @@ -2,14 +2,13 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ `adafruit_seesaw.analoginput` ==================================================== """ -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -21,9 +20,10 @@ class AnalogInput: :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device :param int pin: The pin number on the device""" - def __init__(self, seesaw, pin): + def __init__(self, seesaw, pin, delay=0.008): self._seesaw = seesaw self._pin = pin + self._delay = delay def deinit(self): pass @@ -31,7 +31,7 @@ def deinit(self): @property def value(self): """The current analog value on the pin, as an integer from 0..65535 (inclusive)""" - return self._seesaw.analog_read(self._pin) + return self._seesaw.analog_read(self._pin, self._delay) @property def reference_voltage(self): diff --git a/adafruit_seesaw/attiny8x7.py b/adafruit_seesaw/attiny8x7.py index a51e00c..78356ca 100644 --- a/adafruit_seesaw/attiny8x7.py +++ b/adafruit_seesaw/attiny8x7.py @@ -2,14 +2,13 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods """ `adafruit_seesaw.attiny8x7` - Pin definition for Adafruit ATtiny8x7 Breakout with seesaw ================================================================================== """ -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -26,7 +25,8 @@ class ATtiny8x7_Pinmap: pwm_width = 16 # we dont actually use all 16 bits but whatever """The pins capable of PWM output""" - pwm_pins = (0, 1, 9, 12, 13) + pwm_pins = (0, 1, 9, 12, 13) # 8 bit PWM mode + pwm_pins += (6, 7, 8) # 16 bit PWM mode """No pins on this board are capable of touch input""" touch_pins = () diff --git a/adafruit_seesaw/attinyx16.py b/adafruit_seesaw/attinyx16.py new file mode 100644 index 0000000..b80db65 --- /dev/null +++ b/adafruit_seesaw/attinyx16.py @@ -0,0 +1,31 @@ +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_seesaw.attinyx16` - Pin definition for Adafruit ATtinyx16 Breakout with seesaw +================================================================================== +""" + +__version__ = "0.0.0+auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" + + +class ATtinyx16_Pinmap: + """This class is automatically used by `adafruit_seesaw.seesaw.Seesaw` when + a ATtinyx16 Breakout (PID 5690, PID 5681) is detected. + + It is also a reference for the capabilities of each pin.""" + + """The pins capable of analog output""" + analog_pins = (0, 1, 2, 3, 4, 5, 14, 15, 16) + + """The effective bit resolution of the PWM pins""" + pwm_width = 16 # we dont actually use all 16 bits but whatever + + """The pins capable of PWM output""" + pwm_pins = (0, 1, 7, 11, 16) # 8 bit PWM mode + pwm_pins += (4, 5, 6) # 16 bit PWM mode + + """No pins on this board are capable of touch input""" + touch_pins = () diff --git a/adafruit_seesaw/crickit.py b/adafruit_seesaw/crickit.py index 689b1ff..21bf5b3 100644 --- a/adafruit_seesaw/crickit.py +++ b/adafruit_seesaw/crickit.py @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods """ `adafruit_seesaw.crickit` - Pin definition for Adafruit CRICKIT @@ -17,7 +16,7 @@ def const(x): return x -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" # The ordering here reflects the seesaw firmware pinmap for crickit, diff --git a/adafruit_seesaw/digitalio.py b/adafruit_seesaw/digitalio.py index ca9a1f4..1033502 100644 --- a/adafruit_seesaw/digitalio.py +++ b/adafruit_seesaw/digitalio.py @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ `adafruit_seesaw.digitalio` @@ -11,7 +10,7 @@ import digitalio -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" diff --git a/adafruit_seesaw/keypad.py b/adafruit_seesaw/keypad.py index 4a3d6a3..2caf287 100644 --- a/adafruit_seesaw/keypad.py +++ b/adafruit_seesaw/keypad.py @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ `adafruit_seesaw.keypad` @@ -19,7 +18,7 @@ def const(x): from adafruit_seesaw.seesaw import Seesaw -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" _KEYPAD_BASE = const(0x10) @@ -31,7 +30,7 @@ def const(x): _KEYPAD_COUNT = const(0x04) _KEYPAD_FIFO = const(0x10) -# pylint: disable=too-few-public-methods + class KeyEvent: """Holds information about a key event in its properties @@ -74,7 +73,7 @@ def interrupt_enabled(self): @interrupt_enabled.setter def interrupt_enabled(self, value): - if value not in (True, False): + if value not in {True, False}: raise ValueError("interrupt_enabled must be True or False") self._interrupt_enabled = value @@ -84,17 +83,14 @@ def interrupt_enabled(self, value): self.write8(_KEYPAD_BASE, _KEYPAD_INTENCLR, 1) @property - def count(self): + def count(self): # noqa: PLR6301 """Retrieve or set the number of keys""" return self.read8(_KEYPAD_BASE, _KEYPAD_COUNT) - # pylint: disable=unused-argument, no-self-use @count.setter - def count(self, value): + def count(self, value): # noqa: PLR6301 raise AttributeError("count is read only") - # pylint: enable=unused-argument, no-self-use - def set_event(self, key, edge, enable): """Control which kinds of events are set @@ -102,7 +98,7 @@ def set_event(self, key, edge, enable): :param int edge: The type of event :param bool enable: True to enable the event, False to disable it""" - if enable not in (True, False): + if enable not in {True, False}: raise ValueError("event enable must be True or False") if edge > 3 or edge < 0: raise ValueError("invalid edge") diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 68189c8..c9b470e 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -2,17 +2,16 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ `adafruit_seesaw.neopixel` ==================================================== """ -try: - import struct -except ImportError: - import ustruct as struct +import struct + +from adafruit_pixelbuf import PixelBuf + try: from micropython import const except ImportError: @@ -21,7 +20,13 @@ def const(x): return x -__version__ = "0.0.0-auto.0" +### hack to make sure this module is not placed in root CIRCUITPY/lib folder +if "." not in __name__: + raise ImportError( + "seesaw neopixel being imported from unexpected location - is seesaw neopixel use intended?" + ) + +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" _NEOPIXEL_BASE = const(0x0E) @@ -33,18 +38,21 @@ def const(x): _NEOPIXEL_BUF = const(0x04) _NEOPIXEL_SHOW = const(0x05) +# try lower values if IO errors +_OUTPUT_BUFFER_SIZE = const(24) + # Pixel color order constants -RGB = (0, 1, 2) +RGB = "RGB" """Red Green Blue""" -GRB = (1, 0, 2) +GRB = "GRB" """Green Red Blue""" -RGBW = (0, 1, 2, 3) +RGBW = "RGBW" """Red Green Blue White""" -GRBW = (1, 0, 2, 3) +GRBW = "GRBW" """Green Red Blue White""" -class NeoPixel: +class NeoPixel(PixelBuf): """Control NeoPixels connected to a seesaw :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device @@ -57,114 +65,40 @@ class NeoPixel: Use one of the order constants such as RGBW.""" def __init__( - self, - seesaw, - pin, - n, - *, - bpp=3, - brightness=1.0, - auto_write=True, - pixel_order=None + self, seesaw, pin, n, *, bpp=None, brightness=1.0, auto_write=True, pixel_order="GRB" ): - # TODO: brightness not yet implemented. self._seesaw = seesaw self._pin = pin - self._bpp = bpp - self.auto_write = auto_write - self._n = n - self._brightness = min(max(brightness, 0.0), 1.0) - self._pixel_order = GRBW if pixel_order is None else pixel_order + if not pixel_order: + pixel_order = GRB if bpp == 3 else GRBW + elif isinstance(pixel_order, tuple): + # convert legacy pixel order into PixelBuf pixel order + order_list = ["RGBW"[order] for order in pixel_order] + pixel_order = "".join(order_list) + + super().__init__( + n, + byteorder=pixel_order, + brightness=brightness, + auto_write=auto_write, + ) cmd = bytearray([pin]) self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_PIN, cmd) - cmd = struct.pack(">H", n * self._bpp) + cmd = struct.pack(">H", n * self.bpp) self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_BUF_LENGTH, cmd) - self._pre_brightness_color = [None] * n - - @property - def brightness(self): - """Overall brightness of the pixel""" - return self._brightness - - @brightness.setter - def brightness(self, brightness): - # pylint: disable=attribute-defined-outside-init - self._brightness = min(max(brightness, 0.0), 1.0) - - # Suppress auto_write while updating brightness. - current_auto_write = self.auto_write - self.auto_write = False - for i in range(self._n): - if self._pre_brightness_color[i] is not None: - self[i] = self._pre_brightness_color[i] - if current_auto_write: - self.show() - self.auto_write = current_auto_write + self.output_buffer = bytearray(_OUTPUT_BUFFER_SIZE) - def deinit(self): - pass + def _transmit(self, buffer: bytearray) -> None: + """Update the pixels even if auto_write is False""" - def __len__(self): - return self._n - - def __setitem__(self, key, color): - """Set one pixel to a new value""" - cmd = bytearray(2 + self._bpp) - struct.pack_into(">H", cmd, 0, key * self._bpp) - if isinstance(color, int): - w = color >> 24 - r = (color >> 16) & 0xFF - g = (color >> 8) & 0xFF - b = color & 0xFF - else: - if self._bpp == 3: - r, g, b = color - else: - r, g, b, w = color - - self._pre_brightness_color[key] = color - - # If all components are the same and we have a white pixel then use it - # instead of the individual components. - if self._bpp == 4 and r == g == b and w == 0: - w = r - r = 0 - g = 0 - b = 0 - - if self.brightness < 0.99: - r = int(r * self.brightness) - g = int(g * self.brightness) - b = int(b * self.brightness) - if self._bpp == 4: - w = int(w * self.brightness) - - # Store colors in correct slots - cmd[2 + self._pixel_order[0]] = r - cmd[2 + self._pixel_order[1]] = g - cmd[2 + self._pixel_order[2]] = b - if self._bpp == 4: - cmd[2 + self._pixel_order[3]] = w - - self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_BUF, cmd) - if self.auto_write: - self.show() - - def __getitem__(self, key): - pass + step = _OUTPUT_BUFFER_SIZE - 2 + for i in range(0, len(buffer), step): + self.output_buffer[0:2] = struct.pack(">H", i) + self.output_buffer[2:] = buffer[i : i + step] + self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_BUF, self.output_buffer) - def fill(self, color): - """Set all pixels to the same value""" - # Suppress auto_write while filling. - current_auto_write = self.auto_write - self.auto_write = False - for i in range(self._n): - self[i] = color - if current_auto_write: - self.show() - self.auto_write = current_auto_write - - def show(self): - """Update the pixels even if auto_write is False""" self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_SHOW) + + def deinit(self): + pass diff --git a/adafruit_seesaw/pwmout.py b/adafruit_seesaw/pwmout.py index 2c17aaa..869db25 100644 --- a/adafruit_seesaw/pwmout.py +++ b/adafruit_seesaw/pwmout.py @@ -2,14 +2,13 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods """ `adafruit_seesaw.pwmout` ==================================================== """ -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py index 8bd14e9..e8c0be8 100644 --- a/adafruit_seesaw/robohat.py +++ b/adafruit_seesaw/robohat.py @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods """ `adafruit_seesaw.robohat` - Pin definition for RoboHAT @@ -17,7 +16,7 @@ def const(x): return x -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" # Robo HAT MM1 Board: https://www.crowdsupply.com/robotics-masters/robo-hat-mm1 diff --git a/adafruit_seesaw/rotaryio.py b/adafruit_seesaw/rotaryio.py index a698086..8a23d90 100644 --- a/adafruit_seesaw/rotaryio.py +++ b/adafruit_seesaw/rotaryio.py @@ -2,15 +2,13 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods - """ `adafruit_seesaw.rotaryio` ==================================================== """ -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" diff --git a/adafruit_seesaw/samd09.py b/adafruit_seesaw/samd09.py index 5c3ab18..aaa119b 100644 --- a/adafruit_seesaw/samd09.py +++ b/adafruit_seesaw/samd09.py @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods """ `adafruit_seesaw.samd09` - Pin definition for Adafruit SAMD09 Breakout with seesaw @@ -17,7 +16,7 @@ def const(x): return x -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" _ADC_INPUT_0_PIN = const(0x02) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index d42f746..0ec2c89 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -27,14 +27,10 @@ # This code needs to be broken up into analogio, busio, digitalio, and pulseio # compatible classes so we won't bother with some lints until then. -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,no-name-in-module +import struct import time -try: - import struct -except ImportError: - import ustruct as struct try: from micropython import const except ImportError: @@ -45,7 +41,7 @@ def const(x): from adafruit_bus_device.i2c_device import I2CDevice -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" _STATUS_BASE = const(0x00) @@ -108,8 +104,12 @@ def const(x): _TOUCH_CHANNEL_OFFSET = const(0x10) _SAMD09_HW_ID_CODE = const(0x55) -_ATTINY8X7_HW_ID_CODE = const(0x87) -_EEPROM_I2C_ADDR = const(0x3F) +_ATTINY806_HW_ID_CODE = const(0x84) +_ATTINY807_HW_ID_CODE = const(0x85) +_ATTINY816_HW_ID_CODE = const(0x86) +_ATTINY817_HW_ID_CODE = const(0x87) +_ATTINY1616_HW_ID_CODE = const(0x88) +_ATTINY1617_HW_ID_CODE = const(0x89) _ENCODER_STATUS = const(0x00) _ENCODER_INTENSET = const(0x10) @@ -120,6 +120,9 @@ def const(x): # TODO: update when we get real PID _CRICKIT_PID = const(9999) _ROBOHATMM1_PID = const(9998) +_5690_PID = const(5690) +_5681_PID = const(5681) +_5743_PID = const(5743) class Seesaw: @@ -145,39 +148,52 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): self.sw_reset() self.chip_id = self.read8(_STATUS_BASE, _STATUS_HW_ID) - - if self.chip_id not in (_ATTINY8X7_HW_ID_CODE, _SAMD09_HW_ID_CODE): + if self.chip_id not in { + _ATTINY806_HW_ID_CODE, + _ATTINY807_HW_ID_CODE, + _ATTINY816_HW_ID_CODE, + _ATTINY817_HW_ID_CODE, + _ATTINY1616_HW_ID_CODE, + _ATTINY1617_HW_ID_CODE, + _SAMD09_HW_ID_CODE, + }: raise RuntimeError( - "Seesaw hardware ID returned (0x{:x}) is not " - "correct! Expected 0x{:x} or 0x{:x}. Please check your wiring.".format( - self.chip_id, _SAMD09_HW_ID_CODE, _ATTINY8X7_HW_ID_CODE - ) + f"Seesaw hardware ID returned 0x{self.chip_id:x} is not " + "correct! Please check your wiring." ) pid = self.get_version() >> 16 - # pylint: disable=import-outside-toplevel if pid == _CRICKIT_PID: - from adafruit_seesaw.crickit import Crickit_Pinmap + from adafruit_seesaw.crickit import Crickit_Pinmap # noqa: PLC0415 self.pin_mapping = Crickit_Pinmap elif pid == _ROBOHATMM1_PID: - from adafruit_seesaw.robohat import MM1_Pinmap + from adafruit_seesaw.robohat import MM1_Pinmap # noqa: PLC0415 self.pin_mapping = MM1_Pinmap + elif (pid in {_5690_PID, _5681_PID, _5743_PID}) or ( + self.chip_id in {_ATTINY816_HW_ID_CODE, _ATTINY806_HW_ID_CODE, _ATTINY1616_HW_ID_CODE} + ): + from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap # noqa: PLC0415 + + self.pin_mapping = ATtinyx16_Pinmap elif self.chip_id == _SAMD09_HW_ID_CODE: - from adafruit_seesaw.samd09 import SAMD09_Pinmap + from adafruit_seesaw.samd09 import SAMD09_Pinmap # noqa: PLC0415 self.pin_mapping = SAMD09_Pinmap - elif self.chip_id == _ATTINY8X7_HW_ID_CODE: - from adafruit_seesaw.attiny8x7 import ATtiny8x7_Pinmap + elif self.chip_id in { + _ATTINY817_HW_ID_CODE, + _ATTINY807_HW_ID_CODE, + _ATTINY1617_HW_ID_CODE, + }: + from adafruit_seesaw.attiny8x7 import ATtiny8x7_Pinmap # noqa: PLC0415 self.pin_mapping = ATtiny8x7_Pinmap - # pylint: enable=import-outside-toplevel - def sw_reset(self): + def sw_reset(self, post_reset_delay=0.5): """Trigger a software reset of the SeeSaw chip""" self.write8(_STATUS_BASE, _STATUS_SWRST, 0xFF) - time.sleep(0.500) + time.sleep(post_reset_delay) def get_options(self): """Retrieve the 'options' word from the SeeSaw board""" @@ -210,15 +226,18 @@ def digital_write(self, pin, value): def digital_read(self, pin): """Get the value of an input pin by number""" if pin >= 32: - return self.digital_read_bulk_b((1 << (pin - 32))) != 0 - return self.digital_read_bulk((1 << pin)) != 0 + return self.digital_read_bulk_b(1 << (pin - 32)) != 0 + return self.digital_read_bulk(1 << pin) != 0 def digital_read_bulk(self, pins, delay=0.008): """Get the values of all the pins on the 'A' port as a bitmask""" buf = bytearray(4) self.read(_GPIO_BASE, _GPIO_BULK, buf, delay=delay) - buf[0] = buf[0] & 0x3F - ret = struct.unpack(">I", buf)[0] + try: + ret = struct.unpack(">I", buf)[0] + except OverflowError: + buf[0] = buf[0] & 0x3F + ret = struct.unpack(">I", buf)[0] return ret & pins def digital_read_bulk_b(self, pins, delay=0.008): @@ -242,24 +261,19 @@ def get_GPIO_interrupt_flag(self, delay=0.008): self.read(_GPIO_BASE, _GPIO_INTFLAG, buf, delay=delay) return struct.unpack(">I", buf)[0] - def analog_read(self, pin): + def analog_read(self, pin, delay=0.008): """Read the value of an analog pin by number""" buf = bytearray(2) if pin not in self.pin_mapping.analog_pins: raise ValueError("Invalid ADC pin") - if self.chip_id == _ATTINY8X7_HW_ID_CODE: - offset = pin - elif self.chip_id == _SAMD09_HW_ID_CODE: + if self.chip_id == _SAMD09_HW_ID_CODE: offset = self.pin_mapping.analog_pins.index(pin) + else: + offset = pin - self.read( - _ADC_BASE, - _ADC_CHANNEL_OFFSET + offset, - buf, - ) + self.read(_ADC_BASE, _ADC_CHANNEL_OFFSET + offset, buf, delay) ret = struct.unpack(">H", buf)[0] - time.sleep(0.001) return ret def touch_read(self, pin): @@ -349,10 +363,10 @@ def analog_write(self, pin, value): if pin not in self.pin_mapping.pwm_pins: raise ValueError("Invalid PWM pin") - if self.chip_id == _ATTINY8X7_HW_ID_CODE: - offset = pin - elif self.chip_id == _SAMD09_HW_ID_CODE: + if self.chip_id == _SAMD09_HW_ID_CODE: offset = self.pin_mapping.pwm_pins.index(pin) + else: + offset = pin if self.pin_mapping.pwm_width == 16: cmd = bytearray([offset, (value >> 8), value & 0xFF]) @@ -372,14 +386,17 @@ def get_temp(self): def set_pwm_freq(self, pin, freq): """Set the PWM frequency of a pin by number""" - if pin in self.pin_mapping.pwm_pins: - cmd = bytearray( - [self.pin_mapping.pwm_pins.index(pin), (freq >> 8), freq & 0xFF] - ) - self.write(_TIMER_BASE, _TIMER_FREQ, cmd) - else: + if pin not in self.pin_mapping.pwm_pins: raise ValueError("Invalid PWM pin") + if self.chip_id == _SAMD09_HW_ID_CODE: + offset = self.pin_mapping.pwm_pins.index(pin) + else: + offset = pin + + cmd = bytearray([offset, (freq >> 8), freq & 0xFF]) + self.write(_TIMER_BASE, _TIMER_FREQ, cmd) + def encoder_position(self, encoder=0): """The current position of the encoder""" buf = bytearray(4) @@ -421,16 +438,32 @@ def disable_encoder_interrupt(self, encoder=0): # # return self.read8(SEESAW_SERCOM0_BASE + sercom, SEESAW_SERCOM_DATA) + def _get_eeprom_i2c_addr(self): + """Return the EEPROM address used to store I2C address.""" + chip_id = self.chip_id + if chip_id in { + _ATTINY806_HW_ID_CODE, + _ATTINY807_HW_ID_CODE, + _ATTINY816_HW_ID_CODE, + _ATTINY817_HW_ID_CODE, + }: + return 0x7F + if chip_id in { + _ATTINY1616_HW_ID_CODE, + _ATTINY1617_HW_ID_CODE, + }: + return 0xFF + if chip_id in {_SAMD09_HW_ID_CODE}: + return 0x3F + return None + def set_i2c_addr(self, addr): """Store a new address in the device's EEPROM and reboot it.""" - self.eeprom_write8(_EEPROM_I2C_ADDR, addr) - time.sleep(0.250) - self.i2c_device.device_address = addr - self.sw_reset() + self.eeprom_write8(self._get_eeprom_i2c_addr(), addr) def get_i2c_addr(self): """Return the device's I2C address stored in its EEPROM""" - return self.read8(_EEPROM_BASE, _EEPROM_I2C_ADDR) + return self.read8(_EEPROM_BASE, self._get_eeprom_i2c_addr()) def eeprom_write8(self, addr, val): """Write a single byte directly to the device's EEPROM""" diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 494ed57..57f6d43 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ `adafruit_seesaw.tftshield18` - Pin definitions for 1.8" TFT Shield V2 @@ -10,6 +9,7 @@ """ from collections import namedtuple + import board try: @@ -22,7 +22,7 @@ def const(x): from adafruit_seesaw.seesaw import Seesaw -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" _TIMER_BASE = const(0x08) @@ -44,8 +44,7 @@ def const(x): class TFTShield18(Seesaw): - - _BACKLIGHT_ON = b"\xFF\xFF" + _BACKLIGHT_ON = b"\xff\xff" _BACKLIGHT_OFF = b"\x00\x00" try: diff --git a/docs/api.rst b/docs/api.rst index 70ef344..a694a79 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,6 +1,9 @@ .. If you created a package, create one automodule per module in the package. +API Reference +############# + .. automodule:: adafruit_seesaw :members: diff --git a/docs/conf.py b/docs/conf.py index 8932a71..2d5b517 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys @@ -16,6 +15,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.viewcode", ] @@ -23,7 +23,12 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -autodoc_mock_imports = ["adafruit_bus_device", "digitalio", "board"] +autodoc_mock_imports = [ + "adafruit_bus_device", + "adafruit_pixelbuf", + "board", + "digitalio", +] autodoc_default_flags = ["special-members", "members"] @@ -33,16 +38,16 @@ } intersphinx_mapping = { - "python": ("https://docs.python.org/3.4", None), + "python": ("https://docs.python.org/3", None), "BusDevice": ( - "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + "https://docs.circuitpython.org/projects/busdevice/en/latest/", None, ), "Register": ( - "https://circuitpython.readthedocs.io/projects/register/en/latest/", + "https://docs.circuitpython.org/projects/register/en/latest/", None, ), - "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), + "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), } # Add any paths that contain templates here, relative to this directory. @@ -55,7 +60,12 @@ # General information about the project. project = "Adafruit seesaw Library" -copyright = "2017 Dean Miller" +creation_year = "2017" +current_year = str(datetime.datetime.now().year) +year_duration = ( + current_year if current_year == creation_year else creation_year + " - " + current_year +) +copyright = year_duration + " Dean Miller" author = "Dean Miller" # The version info for the project you're documenting, acts as replacement for @@ -72,7 +82,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -103,19 +113,9 @@ # 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" - -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(), "."] - except: - html_theme = "default" - html_theme_path = ["."] -else: - html_theme_path = ["."] +import sphinx_rtd_theme + +html_theme = "sphinx_rtd_theme" # 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, diff --git a/docs/index.rst b/docs/index.rst index c4be833..173aa7a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -55,8 +55,9 @@ Table of Contents .. toctree:: :caption: Other Links - Download - CircuitPython Reference Documentation + Download from GitHub + Download Library Bundle + CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat Adafruit Learning System diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,4 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx +sphinxcontrib-jquery +sphinx-rtd-theme diff --git a/examples/seesaw_analogin_test.py b/examples/seesaw_analogin_test.py index da2741d..52cbed3 100644 --- a/examples/seesaw_analogin_test.py +++ b/examples/seesaw_analogin_test.py @@ -6,11 +6,15 @@ # on Attiny8x7, analog in can be pins 0, 1, 2, 3, 6, 7, 18, 19, 20 import time + import board -from adafruit_seesaw.seesaw import Seesaw + from adafruit_seesaw.analoginput import AnalogInput +from adafruit_seesaw.seesaw import Seesaw -ss = Seesaw(board.I2C()) +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +ss = Seesaw(i2c) analogin_pin = 2 analog_in = AnalogInput(ss, analogin_pin) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py new file mode 100644 index 0000000..862d92b --- /dev/null +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -0,0 +1,68 @@ +# SPDX-FileCopyrightText: 2021 John Furcean +# SPDX-License-Identifier: MIT + +"""I2C ANO rotary encoder with 7 segment display example.""" + +import board +from adafruit_ht16k33 import segments + +from adafruit_seesaw import digitalio, rotaryio, seesaw + +# For use with the STEMMA connector on QT Py RP2040 +# import busio +# i2c = busio.I2C(board.SCL1, board.SDA1) +# seesaw = seesaw.Seesaw(i2c, 0x49) + +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +seesaw = seesaw.Seesaw(i2c, addr=0x49) +display = segments.Seg14x4(i2c, address=0x70) + +seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF +print(f"Found product {seesaw_product}") +if seesaw_product != 5740: + print("Wrong firmware loaded? Expected 5740") + +seesaw.pin_mode(1, seesaw.INPUT_PULLUP) +seesaw.pin_mode(2, seesaw.INPUT_PULLUP) +seesaw.pin_mode(3, seesaw.INPUT_PULLUP) +seesaw.pin_mode(4, seesaw.INPUT_PULLUP) +seesaw.pin_mode(5, seesaw.INPUT_PULLUP) + +select = digitalio.DigitalIO(seesaw, 1) +select_held = False +up = digitalio.DigitalIO(seesaw, 2) +up_held = False +left = digitalio.DigitalIO(seesaw, 3) +left_held = False +down = digitalio.DigitalIO(seesaw, 4) +down_held = False +right = digitalio.DigitalIO(seesaw, 5) +right_held = False + +encoder = rotaryio.IncrementalEncoder(seesaw) +last_position = None + +buttons = [select, up, left, down, right] +button_names = ["Select", "Up", "Left", "Down", "Right"] +button_states = [select_held, up_held, left_held, down_held, right_held] +seven_segment_names = ["SELE", " UP ", "LEFT", "DOWN", "RIGH"] + +while True: + position = encoder.position + + if position != last_position: + last_position = position + display.print(f" {position}") + print(f"Position: {position}") + + for b in range(5): + if not buttons[b].value and button_states[b] is False: + button_states[b] = True + display.print(seven_segment_names[b]) + print(f"{button_names[b]} button pressed") + + if buttons[b].value and button_states[b] is True: + button_states[b] = False + display.print(" ") + print(f"{button_names[b]} button released") diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py new file mode 100644 index 0000000..911c456 --- /dev/null +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -0,0 +1,62 @@ +# SPDX-FileCopyrightText: 2021 John Furcean +# SPDX-License-Identifier: MIT + +"""I2C ANO rotary encoder simple test example.""" + +import board + +from adafruit_seesaw import digitalio, rotaryio, seesaw + +# For use with the STEMMA connector on QT Py RP2040 +# import busio +# i2c = busio.I2C(board.SCL1, board.SDA1) +# seesaw = seesaw.Seesaw(i2c, 0x49) + +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +seesaw = seesaw.Seesaw(i2c, addr=0x49) + +seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF +print(f"Found product {seesaw_product}") +if seesaw_product != 5740: + print("Wrong firmware loaded? Expected 5740") + +seesaw.pin_mode(1, seesaw.INPUT_PULLUP) +seesaw.pin_mode(2, seesaw.INPUT_PULLUP) +seesaw.pin_mode(3, seesaw.INPUT_PULLUP) +seesaw.pin_mode(4, seesaw.INPUT_PULLUP) +seesaw.pin_mode(5, seesaw.INPUT_PULLUP) + +select = digitalio.DigitalIO(seesaw, 1) +select_held = False +up = digitalio.DigitalIO(seesaw, 2) +up_held = False +left = digitalio.DigitalIO(seesaw, 3) +left_held = False +down = digitalio.DigitalIO(seesaw, 4) +down_held = False +right = digitalio.DigitalIO(seesaw, 5) +right_held = False + +encoder = rotaryio.IncrementalEncoder(seesaw) +last_position = None + +buttons = [select, up, left, down, right] +button_names = ["Select", "Up", "Left", "Down", "Right"] +button_states = [select_held, up_held, left_held, down_held, right_held] + +while True: + position = encoder.position + + if position != last_position: + last_position = position + print(f"Position: {position}") + + for b in range(5): + if not buttons[b].value and button_states[b] is False: + button_states[b] = True + print(f"{button_names[b]} button pressed") + + if buttons[b].value and button_states[b] is True: + button_states[b] = False + print(f"{button_names[b]} button released") diff --git a/examples/seesaw_arcade_qt_multi_board.py b/examples/seesaw_arcade_qt_multi_board.py new file mode 100644 index 0000000..0bf2264 --- /dev/null +++ b/examples/seesaw_arcade_qt_multi_board.py @@ -0,0 +1,44 @@ +# SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries +# SPDX-License-Identifier: MIT +"""Arcade QT example for multiple boards that turns on button LED when button is pressed""" + +import board +import digitalio + +from adafruit_seesaw.digitalio import DigitalIO +from adafruit_seesaw.seesaw import Seesaw + +# For most boards. +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller + +# For the QT Py RP2040, QT Py ESP32-S2, other boards that have SCL1/SDA1 as the STEMMA QT port. +# import busio +# i2c = busio.I2C(board.SCL1, board.SDA1) +arcade_qt_one = Seesaw(i2c, addr=0x3A) +arcade_qt_two = Seesaw(i2c, addr=0x3B) + +arcade_qts = (arcade_qt_one, arcade_qt_two) + +# Button pins in order (1, 2, 3, 4) +button_pins = (18, 19, 20, 2) +buttons = [] +for arcade_qt in arcade_qts: + for button_pin in button_pins: + button = DigitalIO(arcade_qt, button_pin) + button.direction = digitalio.Direction.INPUT + button.pull = digitalio.Pull.UP + buttons.append(button) + +# LED pins in order (1, 2, 3, 4) +led_pins = (12, 13, 0, 1) +leds = [] +for arcade_qt in arcade_qts: + for led_pin in led_pins: + led = DigitalIO(arcade_qt, led_pin) + led.direction = digitalio.Direction.OUTPUT + leds.append(led) + +while True: + for led_number, button in enumerate(buttons): + leds[led_number].value = not button.value diff --git a/examples/seesaw_arcade_qt_simpletest.py b/examples/seesaw_arcade_qt_simpletest.py new file mode 100644 index 0000000..29c0774 --- /dev/null +++ b/examples/seesaw_arcade_qt_simpletest.py @@ -0,0 +1,50 @@ +# SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries +# SPDX-License-Identifier: MIT +"""Arcade QT example that pulses the button LED on button press""" + +import time + +import board +import digitalio + +from adafruit_seesaw.digitalio import DigitalIO +from adafruit_seesaw.pwmout import PWMOut +from adafruit_seesaw.seesaw import Seesaw + +# The delay on the PWM cycles. Increase to slow down the LED pulsing, decrease to speed it up. +delay = 0.01 + +# For most boards. +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller + +# For the QT Py RP2040, QT Py ESP32-S2, other boards that have SCL1/SDA1 as the STEMMA QT port. +# import busio +# i2c = busio.I2C(board.SCL1, board.SDA1) +arcade_qt = Seesaw(i2c, addr=0x3A) + +# Button pins in order (1, 2, 3, 4) +button_pins = (18, 19, 20, 2) +buttons = [] +for button_pin in button_pins: + button = DigitalIO(arcade_qt, button_pin) + button.direction = digitalio.Direction.INPUT + button.pull = digitalio.Pull.UP + buttons.append(button) + +# LED pins in order (1, 2, 3, 4) +led_pins = (12, 13, 0, 1) +leds = [] +for led_pin in led_pins: + led = PWMOut(arcade_qt, led_pin) + leds.append(led) + +while True: + for led_number, button in enumerate(buttons): + if not button.value: + for cycle in range(0, 65535, 8000): + leds[led_number].duty_cycle = cycle + time.sleep(delay) + for cycle in range(65534, 0, -8000): + leds[led_number].duty_cycle = cycle + time.sleep(delay) diff --git a/examples/seesaw_attiny_simpletest.py b/examples/seesaw_attiny_simpletest.py index 5b9991e..31dfb28 100644 --- a/examples/seesaw_attiny_simpletest.py +++ b/examples/seesaw_attiny_simpletest.py @@ -3,11 +3,16 @@ """ Simple seesaw test for ATtiny8x7 breakout using built-in LED on pin 5. """ + import time + import board + from adafruit_seesaw.seesaw import Seesaw -ss = Seesaw(board.I2C()) +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +ss = Seesaw(i2c) ss.pin_mode(5, ss.OUTPUT) diff --git a/examples/seesaw_crickit_test.py b/examples/seesaw_crickit_test.py index d77ff25..b93d1c8 100644 --- a/examples/seesaw_crickit_test.py +++ b/examples/seesaw_crickit_test.py @@ -3,13 +3,15 @@ import board from adafruit_motor import servo -from adafruit_seesaw.seesaw import Seesaw + from adafruit_seesaw.pwmout import PWMOut +from adafruit_seesaw.seesaw import Seesaw # from analogio import AnalogOut # import board -i2c_bus = board.I2C() +i2c_bus = board.I2C() # uses board.SCL and board.SDA +# i2c_bus = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller ss = Seesaw(i2c_bus) pwm1 = PWMOut(ss, 17) pwm2 = PWMOut(ss, 16) @@ -150,13 +152,12 @@ else: ss.analog_write(_CRCKIT_M1_A2, 0) ss.analog_write(_CRCKIT_M1_A1, counter * 512) + elif motor1_dir: + ss.analog_write(_CRCKIT_M1_A1, 0) + ss.analog_write(_CRCKIT_M1_A2, (255 - counter) * 512) else: - if motor1_dir: - ss.analog_write(_CRCKIT_M1_A1, 0) - ss.analog_write(_CRCKIT_M1_A2, (255 - counter) * 512) - else: - ss.analog_write(_CRCKIT_M1_A2, 0) - ss.analog_write(_CRCKIT_M1_A1, (255 - counter) * 512) + ss.analog_write(_CRCKIT_M1_A2, 0) + ss.analog_write(_CRCKIT_M1_A1, (255 - counter) * 512) if counter == 255: print("-------------------- motor 1 -----------------------") motor1_dir = not motor1_dir @@ -168,13 +169,12 @@ else: ss.analog_write(_CRCKIT_M1_B2, 0) ss.analog_write(_CRCKIT_M1_B1, counter * 512) + elif motor2_dir: + ss.analog_write(_CRCKIT_M1_B1, 0) + ss.analog_write(_CRCKIT_M1_B2, (255 - counter) * 512) else: - if motor2_dir: - ss.analog_write(_CRCKIT_M1_B1, 0) - ss.analog_write(_CRCKIT_M1_B2, (255 - counter) * 512) - else: - ss.analog_write(_CRCKIT_M1_B2, 0) - ss.analog_write(_CRCKIT_M1_B1, (255 - counter) * 512) + ss.analog_write(_CRCKIT_M1_B2, 0) + ss.analog_write(_CRCKIT_M1_B1, (255 - counter) * 512) if counter == 255: print("-------------------- motor 2 -----------------------") motor2_dir = not motor2_dir diff --git a/examples/seesaw_digitalio_test.py b/examples/seesaw_digitalio_test.py index 2e197ec..f2a4819 100644 --- a/examples/seesaw_digitalio_test.py +++ b/examples/seesaw_digitalio_test.py @@ -10,12 +10,16 @@ # https://learn.adafruit.com/adafruit-attiny817-seesaw/digital-input import time + import board import digitalio -from adafruit_seesaw.seesaw import Seesaw + from adafruit_seesaw.digitalio import DigitalIO +from adafruit_seesaw.seesaw import Seesaw -ss = Seesaw(board.I2C()) +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +ss = Seesaw(i2c) button_pin = 2 led_pin = 5 diff --git a/examples/seesaw_eeprom_test.py b/examples/seesaw_eeprom_test.py index 130a4bb..ae8cb5e 100644 --- a/examples/seesaw_eeprom_test.py +++ b/examples/seesaw_eeprom_test.py @@ -6,10 +6,13 @@ # THE LAST BYTE IS USED FOR I2C ADDRESS CHANGE! import time + import board + from adafruit_seesaw import seesaw -i2c_bus = board.I2C() +i2c_bus = board.I2C() # uses board.SCL and board.SDA +# i2c_bus = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller ss = seesaw.Seesaw(i2c_bus) value = ss.eeprom_read8(0x02) # Read from address 2 diff --git a/examples/seesaw_gamepad_qt.py b/examples/seesaw_gamepad_qt.py new file mode 100644 index 0000000..adf9c4a --- /dev/null +++ b/examples/seesaw_gamepad_qt.py @@ -0,0 +1,67 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries + +# SPDX-License-Identifier: MIT + +import time + +import board +from micropython import const + +from adafruit_seesaw.seesaw import Seesaw + +BUTTON_X = const(6) +BUTTON_Y = const(2) +BUTTON_A = const(5) +BUTTON_B = const(1) +BUTTON_SELECT = const(0) +BUTTON_START = const(16) +button_mask = const( + (1 << BUTTON_X) + | (1 << BUTTON_Y) + | (1 << BUTTON_A) + | (1 << BUTTON_B) + | (1 << BUTTON_SELECT) + | (1 << BUTTON_START) +) + +i2c_bus = board.STEMMA_I2C() # The built-in STEMMA QT connector on the microcontroller +# i2c_bus = board.I2C() # Uses board.SCL and board.SDA. Use with breadboard. + +seesaw = Seesaw(i2c_bus, addr=0x50) + +seesaw.pin_mode_bulk(button_mask, seesaw.INPUT_PULLUP) + +last_x = 0 +last_y = 0 + +while True: + x = 1023 - seesaw.analog_read(14) + y = 1023 - seesaw.analog_read(15) + + if (abs(x - last_x) > 3) or (abs(y - last_y) > 3): + print(x, y) + last_x = x + last_y = y + + buttons = seesaw.digital_read_bulk(button_mask) + + if not buttons & (1 << BUTTON_X): + print("Button x pressed") + + if not buttons & (1 << BUTTON_Y): + print("Button Y pressed") + + if not buttons & (1 << BUTTON_A): + print("Button A pressed") + + if not buttons & (1 << BUTTON_B): + print("Button B pressed") + + if not buttons & (1 << BUTTON_SELECT): + print("Button Select pressed") + + if not buttons & (1 << BUTTON_START): + print("Button Start pressed") + + time.sleep(0.01) diff --git a/examples/seesaw_joy_featherwing.py b/examples/seesaw_joy_featherwing.py index 2512bf0..952051d 100755 --- a/examples/seesaw_joy_featherwing.py +++ b/examples/seesaw_joy_featherwing.py @@ -21,7 +21,8 @@ | (1 << BUTTON_SEL) ) -i2c_bus = board.I2C() +i2c_bus = board.I2C() # uses board.SCL and board.SDA +# i2c_bus = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller ss = Seesaw(i2c_bus) diff --git a/examples/seesaw_minitft_featherwing.py b/examples/seesaw_minitft_featherwing.py index e6f31a3..1103e98 100644 --- a/examples/seesaw_minitft_featherwing.py +++ b/examples/seesaw_minitft_featherwing.py @@ -26,7 +26,8 @@ | (1 << BUTTON_B) ) -i2c_bus = board.I2C() +i2c_bus = board.I2C() # uses board.SCL and board.SDA +# i2c_bus = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller ss = Seesaw(i2c_bus, 0x5E) diff --git a/examples/seesaw_neopixel_test.py b/examples/seesaw_neopixel_test.py index 43e654b..4fbb107 100644 --- a/examples/seesaw_neopixel_test.py +++ b/examples/seesaw_neopixel_test.py @@ -11,11 +11,15 @@ # https://learn.adafruit.com/adafruit-attiny817-seesaw/neopixel import time + import board from rainbowio import colorwheel -from adafruit_seesaw import seesaw, neopixel -ss = seesaw.Seesaw(board.I2C()) +from adafruit_seesaw import neopixel, seesaw + +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +ss = seesaw.Seesaw(i2c) NEOPIXEL_PIN = 19 # Can be any pin NEOPIXEL_NUM = 12 # No more than 60 pixels! diff --git a/examples/seesaw_pc_joystick.py b/examples/seesaw_pc_joystick.py new file mode 100644 index 0000000..3c5735a --- /dev/null +++ b/examples/seesaw_pc_joystick.py @@ -0,0 +1,72 @@ +# SPDX-FileCopyrightText: 2023 Limor Fried for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +import time + +import board +from micropython import const + +from adafruit_seesaw.seesaw import Seesaw + +BUTTON_1 = const(3) +BUTTON_2 = const(13) +BUTTON_3 = const(2) +BUTTON_4 = const(14) + +JOY1_X = const(1) +JOY1_Y = const(15) +JOY2_X = const(0) +JOY2_Y = const(16) + +button_mask = const((1 << BUTTON_1) | (1 << BUTTON_2) | (1 << BUTTON_3) | (1 << BUTTON_4)) + +i2c_bus = board.STEMMA_I2C() # The built-in STEMMA QT connector on the microcontroller +# i2c_bus = board.I2C() # Uses board.SCL and board.SDA. Use with breadboard. + +seesaw = Seesaw(i2c_bus, addr=0x49) + +seesaw.pin_mode_bulk(button_mask, seesaw.INPUT_PULLUP) + +last_x = 0 +last_y = 0 +x = 0 +y = 0 + +while True: + # These joysticks are really jittery so let's take 4 samples of each axis + for i in range(4): + x += seesaw.analog_read(JOY1_X) + y += seesaw.analog_read(JOY1_Y) + + # take average reading + x /= 4 + y /= 4 + + # PC joysticks aren't true voltage divider because we have a fixed 10K + # we dont know the normalized value so we're just going to give you + # the result in 'Kohms' for easier printing + + x = 1024 / x - 1 + y = 1024 / y - 1 + + if (abs(x - last_x) > 3) or (abs(y - last_y) > 3): + print(x, y) + last_x = x + last_y = y + + buttons = seesaw.digital_read_bulk(button_mask) + + if not buttons & (1 << BUTTON_1): + print("Button 1 pressed") + + if not buttons & (1 << BUTTON_2): + print("Button 2 pressed") + + if not buttons & (1 << BUTTON_3): + print("Button 3 pressed") + + if not buttons & (1 << BUTTON_4): + print("Button 4 pressed") + + time.sleep(0.01) diff --git a/examples/seesaw_pwmout_test.py b/examples/seesaw_pwmout_test.py index 06bcc0e..ac98646 100644 --- a/examples/seesaw_pwmout_test.py +++ b/examples/seesaw_pwmout_test.py @@ -12,10 +12,14 @@ # https://learn.adafruit.com/adafruit-attiny817-seesaw/pwmout import time + import board -from adafruit_seesaw import seesaw, pwmout -ss = seesaw.Seesaw(board.I2C()) +from adafruit_seesaw import pwmout, seesaw + +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +ss = seesaw.Seesaw(i2c) PWM_PIN = 12 # If desired, change to any valid PWM output! led = pwmout.PWMOut(ss, PWM_PIN) @@ -24,7 +28,7 @@ while True: # The API PWM range is 0 to 65535, but we increment by 256 since our # resolution is often only 8 bits underneath - for cycle in range(0, 65535, 256): # + for cycle in range(0, 65535, 256): led.duty_cycle = cycle time.sleep(delay) for cycle in range(65534, 0, -256): diff --git a/examples/seesaw_quadrotary.py b/examples/seesaw_quadrotary.py new file mode 100644 index 0000000..ca0cc2f --- /dev/null +++ b/examples/seesaw_quadrotary.py @@ -0,0 +1,54 @@ +# SPDX-FileCopyrightText: 2023 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +"""Quad I2C rotary encoder NeoPixel color picker example.""" + +import board +import digitalio +from rainbowio import colorwheel + +import adafruit_seesaw.digitalio +import adafruit_seesaw.neopixel +import adafruit_seesaw.rotaryio +import adafruit_seesaw.seesaw + +# For boards/chips that don't handle clock-stretching well, try running I2C at 50KHz +# import busio +# i2c = busio.I2C(board.SCL, board.SDA, frequency=50000) +# For using the built-in STEMMA QT connector on a microcontroller +i2c = board.STEMMA_I2C() +seesaw = adafruit_seesaw.seesaw.Seesaw(i2c, 0x49) + +encoders = [adafruit_seesaw.rotaryio.IncrementalEncoder(seesaw, n) for n in range(4)] +switches = [adafruit_seesaw.digitalio.DigitalIO(seesaw, pin) for pin in (12, 14, 17, 9)] +for switch in switches: + switch.switch_to_input(digitalio.Pull.UP) # input & pullup! + +# four neopixels per PCB +pixels = adafruit_seesaw.neopixel.NeoPixel(seesaw, 18, 4) +pixels.brightness = 0.5 + +last_positions = [-1, -1, -1, -1] +colors = [0, 0, 0, 0] # start at red + +while True: + # negate the position to make clockwise rotation positive + positions = [encoder.position for encoder in encoders] + print(positions) + for n, rotary_pos in enumerate(positions): + if rotary_pos != last_positions[n]: + if switches[n].value: # Change the LED color if switch is not pressed + if rotary_pos > last_positions[n]: # Advance forward through the colorwheel. + colors[n] += 8 + else: + colors[n] -= 8 # Advance backward through the colorwheel. + colors[n] = (colors[n] + 256) % 256 # wrap around to 0-256 + # Set last position to current position after evaluating + print(f"Rotary #{n}: {rotary_pos}") + last_positions[n] = rotary_pos + + # if switch is pressed, light up white, otherwise use the stored color + if not switches[n].value: + pixels[n] = 0xFFFFFF + else: + pixels[n] = colorwheel(colors[n]) diff --git a/examples/seesaw_rotary_multiples.py b/examples/seesaw_rotary_multiples.py new file mode 100644 index 0000000..2e9f21c --- /dev/null +++ b/examples/seesaw_rotary_multiples.py @@ -0,0 +1,71 @@ +# SPDX-FileCopyrightText: 2021 John Park +# SPDX-License-Identifier: MIT + +# I2C rotary encoder multiple test example. +# solder the A0 jumper on the second QT Rotary Encoder board + +import board + +from adafruit_seesaw import digitalio, neopixel, rotaryio, seesaw + +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller + +qt_enc1 = seesaw.Seesaw(i2c, addr=0x36) +qt_enc2 = seesaw.Seesaw(i2c, addr=0x37) + +qt_enc1.pin_mode(24, qt_enc1.INPUT_PULLUP) +button1 = digitalio.DigitalIO(qt_enc1, 24) +button_held1 = False + +qt_enc2.pin_mode(24, qt_enc2.INPUT_PULLUP) +button2 = digitalio.DigitalIO(qt_enc2, 24) +button_held2 = False + +encoder1 = rotaryio.IncrementalEncoder(qt_enc1) +last_position1 = None + +encoder2 = rotaryio.IncrementalEncoder(qt_enc2) +last_position2 = None + +pixel1 = neopixel.NeoPixel(qt_enc1, 6, 1) +pixel1.brightness = 0.2 +pixel1.fill(0xFF0000) + +pixel2 = neopixel.NeoPixel(qt_enc2, 6, 1) +pixel2.brightness = 0.2 +pixel2.fill(0x0000FF) + + +while True: + # negate the position to make clockwise rotation positive + position1 = -encoder1.position + position2 = -encoder2.position + + if position1 != last_position1: + last_position1 = position1 + print(f"Position 1: {position1}") + + if not button1.value and not button_held1: + button_held1 = True + pixel1.brightness = 0.5 + print("Button 1 pressed") + + if button1.value and button_held1: + button_held1 = False + pixel1.brightness = 0.2 + print("Button 1 released") + + if position2 != last_position2: + last_position2 = position2 + print(f"Position 2: {position2}") + + if not button2.value and not button_held2: + button_held2 = True + pixel2.brightness = 0.5 + print("Button 2 pressed") + + if button2.value and button_held2: + button_held2 = False + pixel2.brightness = 0.2 + print("Button 2 released") diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index 62e47bd..4577a1b 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -2,17 +2,20 @@ # SPDX-License-Identifier: MIT """I2C rotary encoder NeoPixel color picker and brightness setting example.""" + import board from rainbowio import colorwheel -from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio +from adafruit_seesaw import digitalio, neopixel, rotaryio, seesaw # For use with the STEMMA connector on QT Py RP2040 # import busio # i2c = busio.I2C(board.SCL1, board.SDA1) # seesaw = seesaw.Seesaw(i2c, 0x36) -seesaw = seesaw.Seesaw(board.I2C(), 0x36) +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +seesaw = seesaw.Seesaw(i2c, 0x36) encoder = rotaryio.IncrementalEncoder(seesaw) seesaw.pin_mode(24, seesaw.INPUT_PULLUP) @@ -25,7 +28,6 @@ color = 0 # start at red while True: - # negate the position to make clockwise rotation positive position = -encoder.position @@ -41,11 +43,9 @@ color = (color + 256) % 256 # wrap around to 0-256 pixel.fill(colorwheel(color)) - else: # If the button is pressed... - # ...change the brightness. - if position > last_position: # Increase the brightness. - pixel.brightness = min(1.0, pixel.brightness + 0.1) - else: # Decrease the brightness. - pixel.brightness = max(0, pixel.brightness - 0.1) + elif position > last_position: # Increase the brightness. + pixel.brightness = min(1.0, pixel.brightness + 0.1) + else: # Decrease the brightness. + pixel.brightness = max(0, pixel.brightness - 0.1) last_position = position diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index 7f3bbbc..3e929f9 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -4,35 +4,40 @@ """I2C rotary encoder simple test example.""" import board -from adafruit_seesaw import seesaw, rotaryio, digitalio + +from adafruit_seesaw import digitalio, rotaryio, seesaw # For use with the STEMMA connector on QT Py RP2040 # import busio # i2c = busio.I2C(board.SCL1, board.SDA1) # seesaw = seesaw.Seesaw(i2c, 0x36) -seesaw = seesaw.Seesaw(board.I2C(), addr=0x36) +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +seesaw = seesaw.Seesaw(i2c, addr=0x36) seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF -print("Found product {}".format(seesaw_product)) +print(f"Found product {seesaw_product}") if seesaw_product != 4991: print("Wrong firmware loaded? Expected 4991") +# Configure seesaw pin used to read knob button presses +# The internal pull up is enabled to prevent floating input seesaw.pin_mode(24, seesaw.INPUT_PULLUP) button = digitalio.DigitalIO(seesaw, 24) + button_held = False encoder = rotaryio.IncrementalEncoder(seesaw) last_position = None while True: - # negate the position to make clockwise rotation positive position = -encoder.position if position != last_position: last_position = position - print("Position: {}".format(position)) + print(f"Position: {position}") if not button.value and not button_held: button_held = True diff --git a/examples/seesaw_simpletest.py b/examples/seesaw_simpletest.py index 7b7d35c..f0918f4 100644 --- a/examples/seesaw_simpletest.py +++ b/examples/seesaw_simpletest.py @@ -8,9 +8,11 @@ import time import board + from adafruit_seesaw.seesaw import Seesaw -i2c_bus = board.I2C() +i2c_bus = board.I2C() # uses board.SCL and board.SDA +# i2c_bus = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller ss = Seesaw(i2c_bus) diff --git a/examples/seesaw_soil_simpletest.py b/examples/seesaw_soil_simpletest.py index 9fccd66..735d0f5 100644 --- a/examples/seesaw_soil_simpletest.py +++ b/examples/seesaw_soil_simpletest.py @@ -7,7 +7,8 @@ from adafruit_seesaw.seesaw import Seesaw -i2c_bus = board.I2C() +i2c_bus = board.I2C() # uses board.SCL and board.SDA +# i2c_bus = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller ss = Seesaw(i2c_bus, addr=0x36) diff --git a/optional_requirements.txt b/optional_requirements.txt new file mode 100644 index 0000000..d4e27c4 --- /dev/null +++ b/optional_requirements.txt @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b9ba298 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,44 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +[build-system] +requires = [ + "setuptools", + "wheel", + "setuptools-scm", +] + +[project] +name = "adafruit-circuitpython-seesaw" +description = "CircuitPython library for controlling a SeeSaw helper chip." +version = "0.0.0+auto.0" +readme = "README.rst" +authors = [ + {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} +] +urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw"} +keywords = [ + "adafruit", + "seesaw", + "hardware", + "micropython", + "circuitpython", +] +license = {text = "MIT"} +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Embedded Systems", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", +] +dynamic = ["dependencies", "optional-dependencies"] + +[tool.setuptools] +packages = ["adafruit_seesaw"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt index f40b0b5..03bd9cb 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # # SPDX-License-Identifier: Unlicense -adafruit-circuitpython-busdevice Adafruit-Blinka +adafruit-circuitpython-busdevice +adafruit-circuitpython-pixelbuf diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..36332ff --- /dev/null +++ b/ruff.toml @@ -0,0 +1,105 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions +] + +[format] +line-ending = "lf" diff --git a/setup.py b/setup.py deleted file mode 100755 index bdaed56..0000000 --- a/setup.py +++ /dev/null @@ -1,56 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -"""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-seesaw", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="CircuitPython library for controlling a SeeSaw helper chip.", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/adafruit/Adafruit_CircuitPython_seesaw", - # 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 seesaw hardware micropython circuitpython", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - packages=["adafruit_seesaw"], -)