From 42a3207bee096a4deb85066005b1660effdbf6b5 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Thu, 8 Sep 2022 17:12:16 -0400 Subject: [PATCH 01/26] Moved examples to MIT license --- examples/clue_ble_color_patchwork.py | 2 +- examples/clue_display_sensor_data.py | 2 +- examples/clue_height_calculator.py | 2 +- examples/clue_simpletest.py | 2 +- examples/clue_slideshow/clue_slideshow.py | 2 +- examples/clue_spirit_level.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/clue_ble_color_patchwork.py b/examples/clue_ble_color_patchwork.py index ca5bddc..bd73e0f 100644 --- a/examples/clue_ble_color_patchwork.py +++ b/examples/clue_ble_color_patchwork.py @@ -1,6 +1,6 @@ # SPDX-FileCopyrightText: 2019 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT """ Circuit Python BLE Color Patchwork This demo uses advertising to broadcast a color of the users choice. diff --git a/examples/clue_display_sensor_data.py b/examples/clue_display_sensor_data.py index 8a3f551..909e9ce 100644 --- a/examples/clue_display_sensor_data.py +++ b/examples/clue_display_sensor_data.py @@ -1,6 +1,6 @@ # SPDX-FileCopyrightText: 2019 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT from adafruit_clue import clue clue.sea_level_pressure = 1020 diff --git a/examples/clue_height_calculator.py b/examples/clue_height_calculator.py index 64f0b27..360c1f6 100755 --- a/examples/clue_height_calculator.py +++ b/examples/clue_height_calculator.py @@ -1,6 +1,6 @@ # SPDX-FileCopyrightText: 2019 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT """Calculate the height of an object. Press button A to reset initial height and then lift the CLUE to find the height.""" from adafruit_clue import clue diff --git a/examples/clue_simpletest.py b/examples/clue_simpletest.py index 12ec856..ac1703d 100644 --- a/examples/clue_simpletest.py +++ b/examples/clue_simpletest.py @@ -1,6 +1,6 @@ # SPDX-FileCopyrightText: 2019 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT from adafruit_clue import clue clue.sea_level_pressure = 1020 diff --git a/examples/clue_slideshow/clue_slideshow.py b/examples/clue_slideshow/clue_slideshow.py index 59230b0..1185df3 100755 --- a/examples/clue_slideshow/clue_slideshow.py +++ b/examples/clue_slideshow/clue_slideshow.py @@ -1,6 +1,6 @@ # SPDX-FileCopyrightText: 2019 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT """Display a series of bitmaps using the buttons to advance through the list. To use: place supported bitmap files on your CIRCUITPY drive, then press the buttons on your CLUE to advance through them. diff --git a/examples/clue_spirit_level.py b/examples/clue_spirit_level.py index 6a24400..ed36a70 100755 --- a/examples/clue_spirit_level.py +++ b/examples/clue_spirit_level.py @@ -1,6 +1,6 @@ # SPDX-FileCopyrightText: 2019 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT """CLUE Spirit Level Demo""" import board import displayio From 8a109f5cb3459dc20ce410a07b20dd2791aea430 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:02:49 -0400 Subject: [PATCH 02/26] Switching to composite actions --- .github/workflows/build.yml | 67 +---------------------- .github/workflows/release.yml | 88 ------------------------------ .github/workflows/release_gh.yml | 14 +++++ .github/workflows/release_pypi.yml | 14 +++++ 4 files changed, 30 insertions(+), 153 deletions(-) delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/release_gh.yml create mode 100644 .github/workflows/release_pypi.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb2f60e..041a337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,68 +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.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - 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: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - - 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 pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Build Python package - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - pip install --upgrade build twine - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; - done; - python -m build - twine check dist/* + - 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 f3a0325..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,88 +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.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - 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 pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Set up Python - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - python -m pip install --upgrade pip - pip install --upgrade build twine - - name: Build and publish - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - env: - TWINE_USERNAME: ${{ secrets.pypi_username }} - TWINE_PASSWORD: ${{ secrets.pypi_password }} - run: | - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; - done; - python -m build - twine upload dist/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main From 2ff4019394d2a425859abda963c77b678391b0ab Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:46:59 -0400 Subject: [PATCH 03/26] Updated pylint version to 2.13.0 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3343606..4c43710 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.11.1 + rev: v2.13.0 hooks: - id: pylint name: pylint (library code) From 1e0d6f3964c0d963d60bf55f8addb764629888ab Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 08:15:19 -0400 Subject: [PATCH 04/26] Update pylint to 2.15.5 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c43710..0e5fccc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.13.0 + rev: v2.15.5 hooks: - id: pylint name: pylint (library code) From 7a3256e7affce0cafa3cacfe80b301f81bd1ef48 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:12:43 -0400 Subject: [PATCH 05/26] Fix release CI files --- .github/workflows/release_gh.yml | 14 +++++++++----- .github/workflows/release_pypi.yml | 15 ++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index 041a337..b8aa8d6 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -2,13 +2,17 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: GitHub Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml index 041a337..65775b7 100644 --- a/.github/workflows/release_pypi.yml +++ b/.github/workflows/release_pypi.yml @@ -2,13 +2,18 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: PyPI Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - 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 }} From 3f1d8d07e1d0c42f018f7d271c7cfd15e9aaefdc Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:34:32 -0400 Subject: [PATCH 06/26] Update .pylintrc for v2.15.5 --- .pylintrc | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/.pylintrc b/.pylintrc index 66d688f..40208c3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -26,7 +26,7 @@ jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=pylint.extensions.no_self_use # Pickle collected data for later comparisons. persistent=yes @@ -54,8 +54,8 @@ confidence= # --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 +# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call +disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,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 @@ -225,12 +225,6 @@ 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 @@ -257,38 +251,22 @@ min-similarity-lines=12 [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_]*)|(__.*__))$ @@ -296,9 +274,6 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # 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_]*))$ @@ -309,21 +284,12 @@ 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]+))$ @@ -339,9 +305,6 @@ no-docstring-rgx=^_ # 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_]*))$ From ecb3e0c0d7de18f8cb9416788302d2ee86a198ef Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:16:31 -0400 Subject: [PATCH 07/26] Add .venv to .gitignore Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 544ec4a..db3d538 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ _build # Virtual environment-specific files .env +.venv # MacOS-specific files *.DS_Store From 1ecef426e19bf8dd998e27e1c1a344181d162c97 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:39:55 -0500 Subject: [PATCH 08/26] Add upload url to release action Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .github/workflows/release_gh.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index b8aa8d6..9acec60 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -16,3 +16,4 @@ jobs: uses: adafruit/workflows-circuitpython-libs/release-gh@main with: github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} From 27028b36bcea35e39ddc1fdd14cb91987da99173 Mon Sep 17 00:00:00 2001 From: Juliana Karoline Date: Mon, 24 Apr 2023 10:27:26 -0600 Subject: [PATCH 09/26] Add type hints --- adafruit_clue.py | 97 ++++++++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index 9bca186..f6e0714 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -39,6 +39,11 @@ https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel """ +try: + from typing import Tuple +except ImportError: + pass + import time import array import math @@ -64,12 +69,12 @@ class _ClueSimpleTextDisplay: def __init__( # pylint: disable=too-many-arguments self, - title=None, - title_color=0xFFFFFF, - title_scale=1, - text_scale=1, - font=None, - colors=None, + title: str = None, + title_color: int = 0xFFFFFF, + title_scale: int = 1, + text_scale: int = 1, + font: str = None, + colors: Tuple = None, ): # pylint: disable=import-outside-toplevel import displayio @@ -124,7 +129,7 @@ def __init__( # pylint: disable=too-many-arguments for num in range(1): self._lines.append(self.add_text_line(color=colors[num % len(colors)])) - def __getitem__(self, item): + def __getitem__(self, item: int): """Fetch the Nth text line Group""" if len(self._lines) - 1 < item: for _ in range(item - (len(self._lines) - 1)): @@ -133,7 +138,7 @@ def __getitem__(self, item): ) return self._lines[item] - def add_text_line(self, color=0xFFFFFF): + def add_text_line(self, color: int = 0xFFFFFF): """Adds a line on the display of the specified color and returns the label object.""" text_label = self._label.Label(self._font, text="", color=color) text_label.x = 0 @@ -235,7 +240,7 @@ def __init__(self): # Create displayio object for passing. self.display = board.DISPLAY - def _touch(self, i): + def _touch(self, i: int) -> bool: if not isinstance(self._touches[i], touchio.TouchIn): # First time referenced. Get the pin from the slot for this touch # and replace it with a TouchIn object for the pin. @@ -244,7 +249,7 @@ def _touch(self, i): return self._touches[i].value @property - def touch_0(self): + def touch_0(self) -> bool: """Detect touch on capacitive touch pad 0. .. image :: ../docs/_static/pad_0.jpg @@ -265,7 +270,7 @@ def touch_0(self): return self._touch(0) @property - def touch_1(self): + def touch_1(self) -> bool: """Detect touch on capacitive touch pad 1. .. image :: ../docs/_static/pad_1.jpg @@ -286,7 +291,7 @@ def touch_1(self): return self._touch(1) @property - def touch_2(self): + def touch_2(self) -> bool: """Detect touch on capacitive touch pad 2. .. image :: ../docs/_static/pad_2.jpg @@ -307,7 +312,7 @@ def touch_2(self): return self._touch(2) @property - def button_a(self): + def button_a(self) -> bool: """``True`` when Button A is pressed. ``False`` if not. .. image :: ../docs/_static/button_a.jpg @@ -328,7 +333,7 @@ def button_a(self): return not self._a.value @property - def button_b(self): + def button_b(self) -> bool: """``True`` when Button B is pressed. ``False`` if not. .. image :: ../docs/_static/button_b.jpg @@ -348,7 +353,9 @@ def button_b(self): """ return not self._b.value - def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1): + def shake( + self, shake_threshold: int = 30, avg_count: int = 10, total_delay: float = 0.1 + ) -> bool: """ Detect when the accelerometer is shaken. Optional parameters: @@ -380,7 +387,7 @@ def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1): return total_accel > shake_threshold @property - def acceleration(self): + def acceleration(self) -> Tuple[float, float, float]: """Obtain acceleration data from the x, y and z axes. .. image :: ../docs/_static/accelerometer.jpg @@ -400,7 +407,7 @@ def acceleration(self): return self._accelerometer.acceleration @property - def gyro(self): + def gyro(self) -> Tuple[float, float, float]: """Obtain x, y, z angular velocity values in degrees/second. .. image :: ../docs/_static/accelerometer.jpg @@ -420,7 +427,7 @@ def gyro(self): return self._accelerometer.gyro @property - def magnetic(self): + def magnetic(self) -> Tuple[float, float, float]: """Obtain x, y, z magnetic values in microteslas. .. image :: ../docs/_static/magnetometer.jpg @@ -440,7 +447,7 @@ def magnetic(self): return self._magnetometer.magnetic @property - def proximity(self): + def proximity(self) -> int: """A relative proximity to the sensor in values from 0 - 255. .. image :: ../docs/_static/proximity.jpg @@ -462,7 +469,7 @@ def proximity(self): return self._sensor.proximity @property - def color(self): + def color(self) -> Tuple[int, int, int, int]: """The red, green, blue, and clear light values. (r, g, b, c) .. image :: ../docs/_static/proximity.jpg @@ -484,7 +491,7 @@ def color(self): return self._sensor.color_data @property - def gesture(self): + def gesture(self) -> int: """A gesture code if gesture is detected. Shows ``0`` if no gesture detected. ``1`` if an UP gesture is detected, ``2`` if DOWN, ``3`` if LEFT, and ``4`` if RIGHT. @@ -512,7 +519,7 @@ def gesture(self): return self._sensor.gesture() @property - def humidity(self): + def humidity(self) -> float: """The measured relative humidity in percent. .. image :: ../docs/_static/humidity.jpg @@ -532,7 +539,7 @@ def humidity(self): return self._humidity.relative_humidity @property - def pressure(self): + def pressure(self) -> float: """The barometric pressure in hectoPascals. .. image :: ../docs/_static/pressure.jpg @@ -551,7 +558,7 @@ def pressure(self): return self._pressure.pressure @property - def temperature(self): + def temperature(self) -> float: """The temperature in degrees Celsius. .. image :: ../docs/_static/pressure.jpg @@ -570,7 +577,7 @@ def temperature(self): return self._pressure.temperature @property - def altitude(self): + def altitude(self) -> float: """The altitude in meters based on the sea level pressure at your location. You must set ``sea_level_pressure`` to receive an accurate reading. @@ -590,7 +597,7 @@ def altitude(self): return self._pressure.altitude @property - def sea_level_pressure(self): + def sea_level_pressure(self) -> float: """Set to the pressure at sea level at your location, before reading altitude for the most accurate altitude measurement. @@ -612,11 +619,11 @@ def sea_level_pressure(self): return self._pressure.sea_level_pressure @sea_level_pressure.setter - def sea_level_pressure(self, value): + def sea_level_pressure(self, value: int): self._pressure.sea_level_pressure = value @property - def white_leds(self): + def white_leds(self) -> bool: """The red led next to the USB plug labeled LED. .. image :: ../docs/_static/white_leds.jpg @@ -635,11 +642,11 @@ def white_leds(self): return self._white_leds.value @white_leds.setter - def white_leds(self, value): + def white_leds(self, value: bool): self._white_leds.value = value @property - def red_led(self): + def red_led(self) -> bool: """The red led next to the USB plug labeled LED. .. image :: ../docs/_static/red_led.jpg @@ -658,11 +665,11 @@ def red_led(self): return self._red_led.value @red_led.setter - def red_led(self, value): + def red_led(self, value: bool): self._red_led.value = value @property - def pixel(self): + def pixel(self) -> neopixel.NeoPixel: """The NeoPixel RGB LED. .. image :: ../docs/_static/neopixel.jpg @@ -682,20 +689,20 @@ def pixel(self): return self._pixel @staticmethod - def _sine_sample(length): + def _sine_sample(length: int): tone_volume = (2**15) - 1 shift = 2**15 for i in range(length): yield int(tone_volume * math.sin(2 * math.pi * (i / length)) + shift) - def _generate_sample(self, length=100): + def _generate_sample(self, length: int = 100): if self._audio_out is not None: return self._sine_wave = array.array("H", self._sine_sample(length)) self._audio_out = audiopwmio.PWMAudioOut(board.SPEAKER) self._sine_wave_sample = audiocore.RawSample(self._sine_wave) - def play_tone(self, frequency, duration): + def play_tone(self, frequency: int, duration: int): """Produce a tone using the speaker. Try changing frequency to change the pitch of the tone. @@ -720,7 +727,7 @@ def play_tone(self, frequency, duration): time.sleep(duration) self.stop_tone() - def start_tone(self, frequency): + def start_tone(self, frequency: int): """Produce a tone using the speaker. Try changing frequency to change the pitch of the tone. @@ -785,7 +792,7 @@ def stop_tone(self): self._audio_out = None @staticmethod - def _normalized_rms(values): + def _normalized_rms(values) -> float: mean_values = int(sum(values) / len(values)) return math.sqrt( sum( @@ -796,7 +803,7 @@ def _normalized_rms(values): ) @property - def sound_level(self): + def sound_level(self) -> float: """Obtain the sound level from the microphone (sound sensor). .. image :: ../docs/_static/microphone.jpg @@ -817,7 +824,7 @@ def sound_level(self): self._mic.record(self._mic_samples, len(self._mic_samples)) return self._normalized_rms(self._mic_samples) - def loud_sound(self, sound_threshold=200): + def loud_sound(self, sound_threshold: int = 200) -> bool: """Utilise a loud sound as an input. :param int sound_threshold: Threshold sound level must exceed to return true (Default: 200) @@ -861,12 +868,12 @@ def loud_sound(self, sound_threshold=200): @staticmethod def simple_text_display( # pylint: disable=too-many-arguments - title=None, - title_color=(255, 255, 255), - title_scale=1, - text_scale=1, - font=None, - colors=None, + title: str = None, + title_color: Tuple[int, int, int] = (255, 255, 255), + title_scale: int = 1, + text_scale: int = 1, + font: str = None, + colors: Tuple = None, ): """Display lines of text on the CLUE display. Lines of text are created in order as shown in the example below. If you skip a number, the line will be shown blank on the display, From e222fe3acf833c15f7bf6ada2048e0265721d7da Mon Sep 17 00:00:00 2001 From: Juliana Karoline Date: Mon, 24 Apr 2023 10:43:37 -0600 Subject: [PATCH 10/26] Fix tuple typing --- adafruit_clue.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index f6e0714..7ee8df8 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -40,7 +40,7 @@ """ try: - from typing import Tuple + from typing import Union, Tuple except ImportError: pass @@ -70,7 +70,7 @@ class _ClueSimpleTextDisplay: def __init__( # pylint: disable=too-many-arguments self, title: str = None, - title_color: int = 0xFFFFFF, + title_color: Union[int, Tuple] = 0xFFFFFF, title_scale: int = 1, text_scale: int = 1, font: str = None, @@ -387,7 +387,7 @@ def shake( return total_accel > shake_threshold @property - def acceleration(self) -> Tuple[float, float, float]: + def acceleration(self) -> Tuple: """Obtain acceleration data from the x, y and z axes. .. image :: ../docs/_static/accelerometer.jpg @@ -407,7 +407,7 @@ def acceleration(self) -> Tuple[float, float, float]: return self._accelerometer.acceleration @property - def gyro(self) -> Tuple[float, float, float]: + def gyro(self) -> Tuple: """Obtain x, y, z angular velocity values in degrees/second. .. image :: ../docs/_static/accelerometer.jpg @@ -427,7 +427,7 @@ def gyro(self) -> Tuple[float, float, float]: return self._accelerometer.gyro @property - def magnetic(self) -> Tuple[float, float, float]: + def magnetic(self) -> Tuple: """Obtain x, y, z magnetic values in microteslas. .. image :: ../docs/_static/magnetometer.jpg @@ -469,7 +469,7 @@ def proximity(self) -> int: return self._sensor.proximity @property - def color(self) -> Tuple[int, int, int, int]: + def color(self) -> Tuple: """The red, green, blue, and clear light values. (r, g, b, c) .. image :: ../docs/_static/proximity.jpg @@ -869,7 +869,7 @@ def loud_sound(self, sound_threshold: int = 200) -> bool: @staticmethod def simple_text_display( # pylint: disable=too-many-arguments title: str = None, - title_color: Tuple[int, int, int] = (255, 255, 255), + title_color: Tuple = (255, 255, 255), title_scale: int = 1, text_scale: int = 1, font: str = None, From ccc18fb3beee444c7b1d49cda91f69c2e51325b4 Mon Sep 17 00:00:00 2001 From: Juliana Karoline Date: Mon, 24 Apr 2023 12:00:57 -0600 Subject: [PATCH 11/26] Add Optional --- adafruit_clue.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index 7ee8df8..d072851 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -40,7 +40,7 @@ """ try: - from typing import Union, Tuple + from typing import Union, Tuple, Optional except ImportError: pass @@ -69,12 +69,12 @@ class _ClueSimpleTextDisplay: def __init__( # pylint: disable=too-many-arguments self, - title: str = None, + title: Optional[str] = None, title_color: Union[int, Tuple] = 0xFFFFFF, title_scale: int = 1, text_scale: int = 1, - font: str = None, - colors: Tuple = None, + font: Optional[str] = None, + colors: Optional[Tuple[Tuple[int, int, int], ...]] = None, ): # pylint: disable=import-outside-toplevel import displayio @@ -138,7 +138,7 @@ def __getitem__(self, item: int): ) return self._lines[item] - def add_text_line(self, color: int = 0xFFFFFF): + def add_text_line(self, color: Union[int, Tuple[int, int, int]] = 0xFFFFFF): """Adds a line on the display of the specified color and returns the label object.""" text_label = self._label.Label(self._font, text="", color=color) text_label.x = 0 @@ -387,7 +387,7 @@ def shake( return total_accel > shake_threshold @property - def acceleration(self) -> Tuple: + def acceleration(self) -> Tuple[int, int, int]: """Obtain acceleration data from the x, y and z axes. .. image :: ../docs/_static/accelerometer.jpg @@ -407,7 +407,7 @@ def acceleration(self) -> Tuple: return self._accelerometer.acceleration @property - def gyro(self) -> Tuple: + def gyro(self) -> Tuple[int, int, int]: """Obtain x, y, z angular velocity values in degrees/second. .. image :: ../docs/_static/accelerometer.jpg @@ -427,7 +427,7 @@ def gyro(self) -> Tuple: return self._accelerometer.gyro @property - def magnetic(self) -> Tuple: + def magnetic(self) -> Tuple[int, int, int]: """Obtain x, y, z magnetic values in microteslas. .. image :: ../docs/_static/magnetometer.jpg @@ -469,7 +469,7 @@ def proximity(self) -> int: return self._sensor.proximity @property - def color(self) -> Tuple: + def color(self) -> Tuple[int, int, int, int]: """The red, green, blue, and clear light values. (r, g, b, c) .. image :: ../docs/_static/proximity.jpg @@ -619,7 +619,7 @@ def sea_level_pressure(self) -> float: return self._pressure.sea_level_pressure @sea_level_pressure.setter - def sea_level_pressure(self, value: int): + def sea_level_pressure(self, value: float): self._pressure.sea_level_pressure = value @property @@ -702,7 +702,7 @@ def _generate_sample(self, length: int = 100): self._audio_out = audiopwmio.PWMAudioOut(board.SPEAKER) self._sine_wave_sample = audiocore.RawSample(self._sine_wave) - def play_tone(self, frequency: int, duration: int): + def play_tone(self, frequency: int, duration: float): """Produce a tone using the speaker. Try changing frequency to change the pitch of the tone. @@ -868,12 +868,12 @@ def loud_sound(self, sound_threshold: int = 200) -> bool: @staticmethod def simple_text_display( # pylint: disable=too-many-arguments - title: str = None, + title: Optional[str] = None, title_color: Tuple = (255, 255, 255), title_scale: int = 1, text_scale: int = 1, - font: str = None, - colors: Tuple = None, + font: Optional[str] = None, + colors: Optional[Tuple[Tuple[int, int, int], ...]] = None, ): """Display lines of text on the CLUE display. Lines of text are created in order as shown in the example below. If you skip a number, the line will be shown blank on the display, From 654284a5c82be584f5e56eedcc3fdee661537450 Mon Sep 17 00:00:00 2001 From: Juliana Karoline Date: Mon, 24 Apr 2023 12:04:13 -0600 Subject: [PATCH 12/26] Expand tuple for title_color --- adafruit_clue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index d072851..1628233 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -70,7 +70,7 @@ class _ClueSimpleTextDisplay: def __init__( # pylint: disable=too-many-arguments self, title: Optional[str] = None, - title_color: Union[int, Tuple] = 0xFFFFFF, + title_color: Union[int, Tuple[int, int, int]] = 0xFFFFFF, title_scale: int = 1, text_scale: int = 1, font: Optional[str] = None, From 712a31b012fcdd3568c8c669ff78d861d6da98f7 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 13/26] Update pre-commit hooks Signed-off-by: Tekktrik --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e5fccc..70ade69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,21 +4,21 @@ repos: - repo: https://github.com/python/black - rev: 22.3.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v0.14.0 + rev: v1.1.2 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.4.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.15.5 + rev: v2.17.4 hooks: - id: pylint name: pylint (library code) From 0652683bd16285796a745df40c5d5526a2808f41 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Sun, 14 May 2023 13:00:32 -0400 Subject: [PATCH 14/26] Update .pylintrc, fix jQuery for docs Signed-off-by: Tekktrik --- .pylintrc | 2 +- docs/conf.py | 1 + docs/requirements.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 40208c3..f945e92 100644 --- a/.pylintrc +++ b/.pylintrc @@ -396,4 +396,4 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +overgeneral-exceptions=builtins.Exception diff --git a/docs/conf.py b/docs/conf.py index a98b4d9..159fe49 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,6 +17,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.napoleon", "sphinx.ext.todo", diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..797aa04 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Unlicense sphinx>=4.0.0 +sphinxcontrib-jquery From 2404ef2acbe54f9d081126eef521ad872af1aba9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 16:22:23 -0500 Subject: [PATCH 15/26] "fix rtd theme " --- docs/conf.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 159fe49..6fa3368 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -123,19 +123,10 @@ # 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" +html_theme_path = [sphinx_rtd_theme.get_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, From 6015a6ab60af3bf1ac721267df0f7f6a6d3646d1 Mon Sep 17 00:00:00 2001 From: Paul Cutler Date: Fri, 3 Nov 2023 10:30:22 -0500 Subject: [PATCH 16/26] Update to use root_group for CP 9 compatibility --- examples/clue_ams_remote_advanced.py | 2 +- examples/clue_ble_color_patchwork.py | 2 +- examples/clue_spirit_level.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/clue_ams_remote_advanced.py b/examples/clue_ams_remote_advanced.py index 1f2b002..1b21ac8 100644 --- a/examples/clue_ams_remote_advanced.py +++ b/examples/clue_ams_remote_advanced.py @@ -84,7 +84,7 @@ volume_inner = Rect(15, 170, 1, 20, fill=0xFFFFFF, outline=0xFFFFFF) group.append(volume_inner) -display.show(group) +display.root_group = group time.sleep(0.01) width1 = 1 diff --git a/examples/clue_ble_color_patchwork.py b/examples/clue_ble_color_patchwork.py index bd73e0f..4b8a561 100644 --- a/examples/clue_ble_color_patchwork.py +++ b/examples/clue_ble_color_patchwork.py @@ -207,7 +207,7 @@ def change_advertisement(color): group.append(patchwork_group) # Add the Group to the Display -display.show(group) +display.root_group = group cur_color = 0 diff --git a/examples/clue_spirit_level.py b/examples/clue_spirit_level.py index ed36a70..02d075e 100755 --- a/examples/clue_spirit_level.py +++ b/examples/clue_spirit_level.py @@ -23,7 +23,7 @@ bubble_group.append(level_bubble) clue_group.append(bubble_group) -display.show(clue_group) +display.root_group = clue_group while True: x, y, _ = clue.acceleration From e0bfd1e46b57fae11d9d4fbabeb0fcca2c18ec41 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Oct 2023 14:30:31 -0500 Subject: [PATCH 17/26] unpin sphinx and add sphinx-rtd-theme to docs reqs Signed-off-by: foamyguy --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 797aa04..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme From ef36b5600d95fb0ebfab0c892187328174a7d3b8 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 8 Jan 2024 14:57:31 -0600 Subject: [PATCH 18/26] update simpletext display inner class for root_group displayio API 9.x --- adafruit_clue.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index 1628233..85d4bbf 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -59,6 +59,7 @@ import audiopwmio import audiocore import touchio +from displayio import CIRCUITPYTHON_TERMINAL __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CLUE.git" @@ -150,11 +151,11 @@ def add_text_line(self, color: Union[int, Tuple[int, int, int]] = 0xFFFFFF): def show(self): """Call show() to display the data list.""" - self._display.show(self.text_group) + self._display.root_group = self.text_group def show_terminal(self): """Revert to terminalio screen.""" - self._display.show(None) + self._display.root_group = CIRCUITPYTHON_TERMINAL class Clue: # pylint: disable=too-many-instance-attributes, too-many-public-methods From be1c565d5e10d96c0302d548a105c6c00959d10c Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 8 Jan 2024 15:04:57 -0600 Subject: [PATCH 19/26] change import for sphinx --- adafruit_clue.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index 85d4bbf..84d6a05 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -59,7 +59,7 @@ import audiopwmio import audiocore import touchio -from displayio import CIRCUITPYTHON_TERMINAL +import displayio __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CLUE.git" @@ -155,7 +155,7 @@ def show(self): def show_terminal(self): """Revert to terminalio screen.""" - self._display.root_group = CIRCUITPYTHON_TERMINAL + self._display.root_group = displayio.CIRCUITPYTHON_TERMINAL class Clue: # pylint: disable=too-many-instance-attributes, too-many-public-methods From 31ad24fc1382063ff71502da3ed415de78781da6 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 8 Jan 2024 15:24:03 -0600 Subject: [PATCH 20/26] remove constructor import displayio --- adafruit_clue.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index 84d6a05..1c6ad8d 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -78,7 +78,6 @@ def __init__( # pylint: disable=too-many-arguments colors: Optional[Tuple[Tuple[int, int, int], ...]] = None, ): # pylint: disable=import-outside-toplevel - import displayio import terminalio from adafruit_display_text import label From d8b97baa823cbbffc2ada37cf1f307b30c6b2fe4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 21/26] remove deprecated get_html_theme_path() call Signed-off-by: foamyguy --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 6fa3368..8546317 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -126,7 +126,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_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, From 4135c7936eb45eb89c684bc6615fa17902d755a9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 7 Nov 2024 16:19:02 -0600 Subject: [PATCH 22/26] use higher tones in docstring examples --- adafruit_clue.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index 1c6ad8d..16e339e 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -747,9 +747,9 @@ def start_tone(self, frequency: int): while True: if clue.button_a: - clue.start_tone(523) + clue.start_tone(1600) elif clue.button_b: - clue.start_tone(587) + clue.start_tone(2000) else: clue.stop_tone() """ @@ -779,9 +779,9 @@ def stop_tone(self): while True: if clue.button_a: - clue.start_tone(523) + clue.start_tone(1600) elif clue.button_b: - clue.start_tone(587) + clue.start_tone(2000) else: clue.stop_tone() """ From 0c129367dec34605c32987ef14a8e9d1835a4253 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 13 Nov 2024 11:35:44 -0600 Subject: [PATCH 23/26] iterable touch API --- adafruit_clue.py | 45 ++++++++++++++++++++++++-------------- examples/clue_touch_all.py | 34 ++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 examples/clue_touch_all.py diff --git a/adafruit_clue.py b/adafruit_clue.py index 16e339e..9fcc58a 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -40,7 +40,7 @@ """ try: - from typing import Union, Tuple, Optional + from typing import Union, Tuple, Optional, List except ImportError: pass @@ -48,6 +48,7 @@ import array import math import board +from microcontroller import Pin import digitalio import neopixel import adafruit_apds9960.apds9960 @@ -188,12 +189,13 @@ def __init__(self): self._i2c = board.I2C() # Define touch: - # Initially, self._touches stores the pin used for a particular touch. When that touch is - # used for the first time, the pin is replaced with the corresponding TouchIn object. - # This saves a little RAM over using a separate read-only pin tuple. + # Initially, self._touches is an empty dictionary. When a touch is used + # for the first time, the pin is added as a key to the dictionary, with + # the corresponding TouchIn object added as the value. This saves a + # little RAM by only populating the dictionary as needed. # For example, after `clue.touch_2`, self._touches is equivalent to: - # [board.D0, board.D1, touchio.TouchIn(board.D2)] - self._touches = [board.D0, board.D1, board.D2] + # { board.P2, touchio.TouchIn(board.P2) } + self._touches = {} self._touch_threshold_adjustment = 0 # Define buttons: @@ -240,13 +242,14 @@ def __init__(self): # Create displayio object for passing. self.display = board.DISPLAY - def _touch(self, i: int) -> bool: - if not isinstance(self._touches[i], touchio.TouchIn): - # First time referenced. Get the pin from the slot for this touch - # and replace it with a TouchIn object for the pin. - self._touches[i] = touchio.TouchIn(self._touches[i]) - self._touches[i].threshold += self._touch_threshold_adjustment - return self._touches[i].value + def _touch(self, pin: Pin) -> bool: + touchin = self._touches.get(pin) + if not touchin: + # First time referenced. Make TouchIn object for the pin + touchin = touchio.TouchIn(pin) + touchin.threshold += self._touch_threshold_adjustment + self._touches[pin] = touchin + return touchin.value @property def touch_0(self) -> bool: @@ -267,7 +270,7 @@ def touch_0(self) -> bool: if clue.touch_0: print("Touched pad 0") """ - return self._touch(0) + return self._touch(board.P0) @property def touch_1(self) -> bool: @@ -288,7 +291,7 @@ def touch_1(self) -> bool: if clue.touch_1: print("Touched pad 1") """ - return self._touch(1) + return self._touch(board.P1) @property def touch_2(self) -> bool: @@ -309,7 +312,17 @@ def touch_2(self) -> bool: if clue.touch_2: print("Touched pad 2") """ - return self._touch(2) + return self._touch(board.P2) + + @property + def touch_pins(self) -> List[Pin]: + """A list of all the pins that are set up as touchpad inputs""" + return list(self._touches.keys()) + + @property + def touched(self): + """A list of all the pins that are currently registering a touch""" + return [pin for pin, touchpad in self._touches.items() if touchpad.value] @property def button_a(self) -> bool: diff --git a/examples/clue_touch_all.py b/examples/clue_touch_all.py new file mode 100644 index 0000000..d8b6099 --- /dev/null +++ b/examples/clue_touch_all.py @@ -0,0 +1,34 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +"""This example prints to the serial console when you touch the capacitive touch pads.""" +import time +import board +from adafruit_clue import clue + + +# You'll need to first use the touchpads individually to register them as active touchpads +# You don't have to use the result though +is_p0_touched = clue.touch_0 # This result can be used if you want +if is_p0_touched: + print("P0/D0 was touched upon startup!") +is_p1_touched = clue.touch_1 +is_p2_touched = clue.touch_2 + + +print("Pads that are currently setup as touchpads:") +print(clue.touch_pins) + +while True: + current_touched = clue.touched + + if current_touched: + print("Touchpads currently registering a touch:") + print(current_touched) + else: + print("No touchpads are currently registering a touch.") + + if all(pad in current_touched for pad in (board.P0, board.P1, board.P2)): + print("This only prints when P0, P1, and P2 are being held at the same time!") + + time.sleep(0.25) From 416938e093083f5b5b0c53bf32f173a6dbba0b5c Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 24/26] add sphinx configuration to rtd.yaml Signed-off-by: foamyguy --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: From eb2e918cc8d053deb551dc72b0f3a9f03ffb93fd Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Tue, 11 Feb 2025 16:58:08 -0500 Subject: [PATCH 25/26] Support new version with LSM6DS3TRC --- adafruit_clue.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index 9fcc58a..31d6e29 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -55,6 +55,7 @@ import adafruit_bmp280 import adafruit_lis3mdl import adafruit_lsm6ds.lsm6ds33 +import adafruit_lsm6ds.lsm6ds3trc import adafruit_sht31d import audiobusio import audiopwmio @@ -225,7 +226,10 @@ def __init__(self): # Define sensors: # Accelerometer/gyroscope: - self._accelerometer = adafruit_lsm6ds.lsm6ds33.LSM6DS33(self._i2c) + try: + self._accelerometer = adafruit_lsm6ds.lsm6ds33.LSM6DS33(self._i2c) + except: + self._accelerometer = adafruit_lsm6ds.lsm6ds3trc.LSM6DS3TRC(self._i2c) # Magnetometer: self._magnetometer = adafruit_lis3mdl.LIS3MDL(self._i2c) From 71ba8ed6f2eeb5b92d3626297a632af0b5cc7ab4 Mon Sep 17 00:00:00 2001 From: Dave Astels Date: Tue, 11 Feb 2025 17:32:09 -0500 Subject: [PATCH 26/26] Add RuntimeException specification --- adafruit_clue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_clue.py b/adafruit_clue.py index 31d6e29..33f55b7 100644 --- a/adafruit_clue.py +++ b/adafruit_clue.py @@ -228,7 +228,7 @@ def __init__(self): # Accelerometer/gyroscope: try: self._accelerometer = adafruit_lsm6ds.lsm6ds33.LSM6DS33(self._i2c) - except: + except RuntimeError: self._accelerometer = adafruit_lsm6ds.lsm6ds3trc.LSM6DS3TRC(self._i2c) # Magnetometer: