From 0450119e163df782930a887022e197d6d25ca666 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 9 Nov 2021 13:31:14 -0500 Subject: [PATCH 01/87] Updated readthedocs file Signed-off-by: dherrada --- .readthedocs.yaml | 15 +++++++++++++++ .readthedocs.yml | 7 ------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .readthedocs.yaml delete mode 100644 .readthedocs.yml diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..95ec218 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,15 @@ +# 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 + +python: + version: "3.6" + 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 From d561fd7c8e3d61e04a8f9e1e91173bcc83250fe7 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 23 Nov 2021 13:07:32 -0600 Subject: [PATCH 02/87] update rtd py version --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 95ec218..1335112 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.6" + version: "3.7" install: - requirements: docs/requirements.txt - requirements: requirements.txt From fad78ab5303459504b3501efc806de521c513ffe Mon Sep 17 00:00:00 2001 From: Tod Kurt Date: Fri, 10 Dec 2021 11:04:17 -0800 Subject: [PATCH 03/87] propagate delay param from read() to analog_read() --- adafruit_seesaw/analoginput.py | 5 +++-- adafruit_seesaw/seesaw.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/adafruit_seesaw/analoginput.py b/adafruit_seesaw/analoginput.py index dd1ebd3..4f9825c 100644 --- a/adafruit_seesaw/analoginput.py +++ b/adafruit_seesaw/analoginput.py @@ -21,9 +21,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 +32,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/seesaw.py b/adafruit_seesaw/seesaw.py index d42f746..2471fb7 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -242,7 +242,7 @@ 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: @@ -257,9 +257,9 @@ def analog_read(self, pin): _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): From 9fa9b6160bb879477004ee5fd2d492efbdac4bb0 Mon Sep 17 00:00:00 2001 From: Tod Kurt Date: Fri, 10 Dec 2021 11:27:45 -0800 Subject: [PATCH 04/87] attempt to appease black --- adafruit_seesaw/seesaw.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 2471fb7..20eb0d3 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -253,12 +253,7 @@ def analog_read(self, pin, delay=0.008): elif self.chip_id == _SAMD09_HW_ID_CODE: offset = self.pin_mapping.analog_pins.index(pin) - self.read( - _ADC_BASE, - _ADC_CHANNEL_OFFSET + offset, - buf, - delay - ) + self.read(_ADC_BASE, _ADC_CHANNEL_OFFSET + offset, buf, delay) ret = struct.unpack(">H", buf)[0] return ret From 9aece7c586b5c021241e843b98c00fcd8fd0fdca Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 22 Dec 2021 09:41:32 -0500 Subject: [PATCH 05/87] Remove obsolete reference to ustruct --- adafruit_seesaw/neopixel.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 68189c8..f55c1ea 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -8,11 +8,8 @@ `adafruit_seesaw.neopixel` ==================================================== """ +import struct -try: - import struct -except ImportError: - import ustruct as struct try: from micropython import const except ImportError: From 61302b7fe348459712dfc921e9ba3e0e6fd362c1 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 22 Dec 2021 09:42:16 -0500 Subject: [PATCH 06/87] Remove obsolete reference to ustruct --- adafruit_seesaw/seesaw.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 20eb0d3..60fbd72 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -29,12 +29,9 @@ # 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: From 823e44deb4dfa2f23acbd9ffb3c130aadc4aff7e Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 13 Jan 2022 16:27:30 -0500 Subject: [PATCH 07/87] First part of patch Signed-off-by: dherrada --- .../PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md | 2 +- .github/workflows/build.yml | 6 +++--- .github/workflows/release.yml | 8 ++++---- .readthedocs.yaml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) 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..474520d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.7 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: "3.x" - name: Versions run: | python3 --version diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d0015a..a65e5de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,10 +24,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.6 + python-version: "3.x" - name: Versions run: | python3 --version @@ -67,7 +67,7 @@ jobs: 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 + uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 1335112..f8b2891 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.7" + version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From c04551218624e774cfb44ecca3dc22c6a4f8c7a5 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 Jan 2022 16:46:17 -0500 Subject: [PATCH 08/87] Updated docs link, updated python docs link, updated setup.py --- README.rst | 4 ++-- docs/conf.py | 8 ++++---- docs/index.rst | 2 +- setup.py | 2 -- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index 15a52e7..c067bf4 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ 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 @@ -60,7 +60,7 @@ 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 `_. Contributing ============ diff --git a/docs/conf.py b/docs/conf.py index 8932a71..1139768 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -33,16 +33,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. diff --git a/docs/index.rst b/docs/index.rst index c4be833..bd8d867 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -56,7 +56,7 @@ Table of Contents :caption: Other Links Download - CircuitPython Reference Documentation + CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat Adafruit Learning System diff --git a/setup.py b/setup.py index bdaed56..08494f3 100755 --- a/setup.py +++ b/setup.py @@ -45,8 +45,6 @@ "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", From 3c7cb9a51a3ec88f4a9496c568bbf604ad052be1 Mon Sep 17 00:00:00 2001 From: John Park Date: Wed, 2 Feb 2022 09:13:06 -0800 Subject: [PATCH 09/87] adding multiple qt rotary example --- examples/seesaw_rotary_multiples.py | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 examples/seesaw_rotary_multiples.py diff --git a/examples/seesaw_rotary_multiples.py b/examples/seesaw_rotary_multiples.py new file mode 100644 index 0000000..097c86a --- /dev/null +++ b/examples/seesaw_rotary_multiples.py @@ -0,0 +1,68 @@ +# 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 seesaw, rotaryio, digitalio, neopixel + +qt_enc1 = seesaw.Seesaw(board.I2C(), addr=0x36) +qt_enc2 = seesaw.Seesaw(board.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("Position 1: {}".format(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("Position 2: {}".format(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") From 891efab8a644420a624c6b3c6590be9320dd4db7 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Wed, 2 Feb 2022 13:28:57 -0500 Subject: [PATCH 10/87] Adding Arcade QT examples. --- examples/seesaw_arcade_qt_multi_board.py | 41 +++++++++++++++++++++ examples/seesaw_arcade_qt_simpletest.py | 46 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 examples/seesaw_arcade_qt_multi_board.py create mode 100644 examples/seesaw_arcade_qt_simpletest.py diff --git a/examples/seesaw_arcade_qt_multi_board.py b/examples/seesaw_arcade_qt_multi_board.py new file mode 100644 index 0000000..b58e2c8 --- /dev/null +++ b/examples/seesaw_arcade_qt_multi_board.py @@ -0,0 +1,41 @@ +# 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.seesaw import Seesaw +from adafruit_seesaw.digitalio import DigitalIO + +# For most boards. +i2c = board.I2C() + +# 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..f11fd56 --- /dev/null +++ b/examples/seesaw_arcade_qt_simpletest.py @@ -0,0 +1,46 @@ +# 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.seesaw import Seesaw +from adafruit_seesaw.digitalio import DigitalIO +from adafruit_seesaw.pwmout import PWMOut + +# 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() + +# 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) From 00f48733d789b8ae50a8843c0162a8a707d5570a Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 9 Feb 2022 13:05:52 -0500 Subject: [PATCH 11/87] Consolidate Documentation sections of README --- README.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index c067bf4..3f21ed6 100644 --- a/README.rst +++ b/README.rst @@ -62,14 +62,11 @@ Documentation API documentation for this library can be found on `Read the Docs `_. +For information on building library documentation, please check out `this guide `_. + 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 `_. From c3a35db881298f74f9b08d4636464ac5e85a3aca Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 14 Feb 2022 15:35:02 -0500 Subject: [PATCH 12/87] Fixed readthedocs build Signed-off-by: dherrada --- .readthedocs.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index f8b2891..33c2a61 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,8 +8,12 @@ # Required version: 2 +build: + os: ubuntu-20.04 + tools: + python: "3" + python: - version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From b347681ab6dc7c06e0a196a73053607d937051c9 Mon Sep 17 00:00:00 2001 From: lady ada Date: Fri, 25 Feb 2022 19:25:17 -0500 Subject: [PATCH 13/87] allow faster reset --- adafruit_seesaw/seesaw.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 60fbd72..79dffc1 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -171,10 +171,10 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): 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""" From c128e2d592fabc0e1bb81edb2f4620e7db2711d3 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 28 Mar 2022 15:52:04 -0400 Subject: [PATCH 14/87] Update Black to latest. Signed-off-by: Kattni Rembor --- .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 43d1385..29230db 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/python/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool From d92217cf68cb97a4627a661322af6cb1ca403ef5 Mon Sep 17 00:00:00 2001 From: Mathias Kende Date: Mon, 4 Apr 2022 22:27:18 +0200 Subject: [PATCH 15/87] Do not blank out the value read for pins PA30 and PA31. --- adafruit_seesaw/seesaw.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 79dffc1..2227d74 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -214,7 +214,6 @@ 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] return ret & pins From ae8533617d042988b1f67f4c7011ee922c3445d7 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Thu, 21 Apr 2022 15:00:27 -0400 Subject: [PATCH 16/87] Updated gitignore Signed-off-by: evaherrada --- .gitignore | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 9647e71..544ec4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,47 @@ -# 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 + +# MacOS-specific files *.DS_Store -.eggs -dist -**/*.egg-info + +# IDE-specific files +.idea +.vscode +*~ From ce96ee915e32b1ea51360a1f603a292cba466d63 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Apr 2022 15:59:15 -0400 Subject: [PATCH 17/87] Patch: Replaced discord badge image --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 3f21ed6..31e9e80 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Introduction :target: https://docs.circuitpython.org/projects/seesaw/en/latest/ :alt: Documentation Status -.. image :: https://img.shields.io/discord/327254708534116352.svg +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From b4cb661e6997782b68d2fb027993f9f1dc47825a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 24 Apr 2022 13:57:11 -0500 Subject: [PATCH 18/87] change discord badge --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 31e9e80..49a84b0 100644 --- a/README.rst +++ b/README.rst @@ -6,7 +6,7 @@ Introduction :target: https://docs.circuitpython.org/projects/seesaw/en/latest/ :alt: Documentation Status -.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg +.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From 9d2109e999fb860f6208b1a89c08b1fea2e2c6c2 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 15 May 2022 12:21:07 -0400 Subject: [PATCH 19/87] Patch .pre-commit-config.yaml --- .pre-commit-config.yaml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 29230db..0a91a11 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,40 +3,40 @@ # SPDX-License-Identifier: Unlicense repos: -- repo: https://github.com/python/black + - repo: https://github.com/python/black rev: 22.3.0 hooks: - - id: black -- repo: https://github.com/fsfe/reuse-tool - rev: v0.12.1 + - id: black + - repo: https://github.com/fsfe/reuse-tool + rev: v0.14.0 hooks: - - id: reuse -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + - id: reuse + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/pycqa/pylint + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/pycqa/pylint rev: v2.11.1 hooks: - - id: pylint + - id: pylint name: pylint (library code) types: [python] args: - --disable=consider-using-f-string,duplicate-code exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint + - 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 + - --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 + - --disable=missing-docstring,consider-using-f-string,duplicate-code From 23932d585550bca54546b2b1bc349205bbb58a60 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:55 -0400 Subject: [PATCH 20/87] Increase min lines similarity Signed-off-by: Alec Delaney --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index cfd1c41..f006a4a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From 5af940235f8b02ed4b84c840439fb26417287d28 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:23 -0400 Subject: [PATCH 21/87] Switch to inclusive terminology Signed-off-by: Alec Delaney --- .pylintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index f006a4a..f772971 100644 --- a/.pylintrc +++ b/.pylintrc @@ -9,11 +9,11 @@ # run arbitrary code extension-pkg-whitelist= -# Add files or directories to the blacklist. They should be base names, not +# Add files or directories to the ignore-list. They should be base names, not # paths. ignore=CVS -# Add files or directories matching the regex patterns to the blacklist. The +# Add files or directories matching the regex patterns to the ignore-list. The # regex matches against base names, not paths. ignore-patterns= From 81a20a350384b92e5243b761e223a91b37d16aef Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 30 May 2022 14:25:04 -0400 Subject: [PATCH 22/87] Set language to "en" for documentation Signed-off-by: Alec Delaney --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 1139768..bf87e97 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -72,7 +72,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. From 7c7b5fe3e1073afdad056b1c26f42489fa5b3ec3 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 7 Jun 2022 15:34:55 -0400 Subject: [PATCH 23/87] Added cp.org link to index.rst --- docs/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index bd8d867..173aa7a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -55,7 +55,8 @@ Table of Contents .. toctree:: :caption: Other Links - Download + Download from GitHub + Download Library Bundle CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat From 6bfc0e93b5578cba49a692f780c3f9e2ef9b7a2c Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 7 Jun 2022 15:38:00 -0700 Subject: [PATCH 24/87] fix bpp for RGBW --- adafruit_seesaw/neopixel.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index f55c1ea..d4a2fd5 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -59,7 +59,7 @@ def __init__( pin, n, *, - bpp=3, + bpp=None, brightness=1.0, auto_write=True, pixel_order=None @@ -67,11 +67,13 @@ def __init__( # 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 + self._bpp = len(self._pixel_order) if bpp is None else bpp + if self._bpp != len(self._pixel_order): + raise ValueError("Pixel order and bpp value do not agree.") cmd = bytearray([pin]) self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_PIN, cmd) From 251489c0fb56ba9e0a81b8662d47f6e6f0fc4163 Mon Sep 17 00:00:00 2001 From: lady ada Date: Fri, 17 Jun 2022 11:46:08 -0400 Subject: [PATCH 25/87] fix default color order --- adafruit_seesaw/neopixel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index d4a2fd5..e975357 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -70,7 +70,7 @@ def __init__( 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 + self._pixel_order = GRB if pixel_order is None else pixel_order self._bpp = len(self._pixel_order) if bpp is None else bpp if self._bpp != len(self._pixel_order): raise ValueError("Pixel order and bpp value do not agree.") From 04048e72fe3da7f51b030f8a8c4b23b4cda0c244 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 21 Jun 2022 17:00:37 -0400 Subject: [PATCH 26/87] Removed duplicate-code from library pylint disable Signed-off-by: evaherrada --- .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 0a91a11..3343606 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: name: pylint (library code) types: [python] args: - - --disable=consider-using-f-string,duplicate-code + - --disable=consider-using-f-string exclude: "^(docs/|examples/|tests/|setup.py$)" - id: pylint name: pylint (example code) From a8b3958a9f28d4da24fe7b59f07aa3b2c67f4d56 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Mon, 11 Jul 2022 18:07:21 +0200 Subject: [PATCH 27/87] rework neopixel to work with PixelBuf - use PixelBuf to back the pixels buffer in the neopixel submodule - this adds compatibility with the adafruit_led_animation library - in particular it adds getitem and slices support - sends pixel data on show() un chunks to avoid IO errors - no longer sends pixel data as they are changed --- adafruit_seesaw/neopixel.py | 127 +++++++++--------------------------- 1 file changed, 32 insertions(+), 95 deletions(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index e975357..3ca0e39 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -9,6 +9,7 @@ ==================================================== """ import struct +from adafruit_pixelbuf import PixelBuf try: from micropython import const @@ -30,6 +31,9 @@ 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) """Red Green Blue""" @@ -40,8 +44,9 @@ def const(x): GRBW = (1, 0, 2, 3) """Green Red Blue White""" +_pixel_orders = {GRB:"GRB", RGB:"RGB", RGBW:"RGBW", GRBW:"GRBW"} -class NeoPixel: +class NeoPixel(PixelBuf): """Control NeoPixels connected to a seesaw :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device @@ -62,108 +67,40 @@ def __init__( bpp=None, brightness=1.0, auto_write=True, - pixel_order=None + pixel_order="GRB" ): - # TODO: brightness not yet implemented. self._seesaw = seesaw self._pin = pin - self.auto_write = auto_write - self._n = n - self._brightness = min(max(brightness, 0.0), 1.0) - self._pixel_order = GRB if pixel_order is None else pixel_order - self._bpp = len(self._pixel_order) if bpp is None else bpp - if self._bpp != len(self._pixel_order): - raise ValueError("Pixel order and bpp value do not agree.") + # convert legacy pixel order into PixelBuf pixel order + if not pixel_order: + pixel_order = GRB if bpp == 3 else GRBW + elif isinstance(pixel_order, tuple): + order_list = ["RGBW"[order] for order in pixel_order] + pixel_order = "".join(order_list) + + super().__init__( + size=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 From 80bb336463641a9207fc9f5a1ee1838292fd4c90 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Mon, 11 Jul 2022 19:13:56 +0200 Subject: [PATCH 28/87] make pixel order constants new values, not legacy --- adafruit_seesaw/neopixel.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 3ca0e39..ddc7b2f 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -35,17 +35,15 @@ def const(x): _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""" -_pixel_orders = {GRB:"GRB", RGB:"RGB", RGBW:"RGBW", GRBW:"GRBW"} - class NeoPixel(PixelBuf): """Control NeoPixels connected to a seesaw @@ -71,10 +69,10 @@ def __init__( ): self._seesaw = seesaw self._pin = pin - # convert legacy pixel order into PixelBuf 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) From fddc58b1156bda7a30b29e3454945f7a58dfe177 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Mon, 11 Jul 2022 21:15:28 +0200 Subject: [PATCH 29/87] pre-commit fix --- adafruit_seesaw/neopixel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index ddc7b2f..16713f2 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -44,6 +44,7 @@ def const(x): GRBW = "GRBW" """Green Red Blue White""" + class NeoPixel(PixelBuf): """Control NeoPixels connected to a seesaw @@ -95,7 +96,7 @@ def _transmit(self, buffer: bytearray) -> None: 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.output_buffer[2:] = buffer[i : i + step] self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_BUF, self.output_buffer) self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_SHOW) From e9bdb783abb5d21d260a6dc12fcbe628952276f9 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Tue, 12 Jul 2022 03:09:22 +0200 Subject: [PATCH 30/87] fix docs (mock builtin adafruit_pixelbuf) and requirements.txt --- docs/conf.py | 7 ++++++- requirements.txt | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index bf87e97..6103433 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -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"] diff --git a/requirements.txt b/requirements.txt index f40b0b5..23c318c 100755 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ # SPDX-License-Identifier: Unlicense adafruit-circuitpython-busdevice +adafruit-circuitpython-pixelbuf Adafruit-Blinka From dcffa7c7eb932a902ba9c9559c797b51a215d14e Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Jul 2022 13:59:16 -0400 Subject: [PATCH 31/87] Changed .env to .venv in README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 49a84b0..6556d0b 100644 --- a/README.rst +++ b/README.rst @@ -48,8 +48,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 From 6dadb4517faf2aecc48106d493da70063e5ed819 Mon Sep 17 00:00:00 2001 From: Carl Jensen Date: Mon, 25 Jul 2022 16:03:11 +0200 Subject: [PATCH 32/87] Ignore last 2 bits of digital input, only on boards without long ints For compatibility on boards that don't support arbitrary integers. Bit 31 and 32 are scrubbed on these boards instead of throwing OverflowError, while builds with long ints retain this extra functionality. --- adafruit_seesaw/seesaw.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 2227d74..79222c2 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -214,7 +214,11 @@ 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) - 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): From 1c285acf8262783a3f5ff6a5f93756f0c927d4ed Mon Sep 17 00:00:00 2001 From: Neradoc Date: Mon, 25 Jul 2022 20:42:46 +0200 Subject: [PATCH 33/87] The size argument to Pixelbuf is positoinal (and called n in the python version) --- adafruit_seesaw/neopixel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 16713f2..1f89206 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -78,7 +78,7 @@ def __init__( pixel_order = "".join(order_list) super().__init__( - size=n, + n, byteorder=pixel_order, brightness=brightness, auto_write=auto_write, From c7d1b1dbf10abda55ecf412bc1ab410eb1fede50 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 2 Aug 2022 17:01:02 -0400 Subject: [PATCH 34/87] Added Black formatting badge --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index 6556d0b..3fb6633 100644 --- a/README.rst +++ b/README.rst @@ -14,6 +14,10 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_seesaw/actions :alt: Build Status +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code Style: Black + CircuitPython module for use with the Adafruit ATSAMD09 seesaw. Dependencies From a3be28290286eb4320c8e8503ec30b197fa5f591 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 8 Aug 2022 22:05:53 -0400 Subject: [PATCH 35/87] Switched to pyproject.toml --- .github/workflows/build.yml | 18 ++++++------ .github/workflows/release.yml | 17 ++++++----- optional_requirements.txt | 3 ++ pyproject.toml | 43 ++++++++++++++++++++++++++++ requirements.txt | 4 +-- setup.py | 54 ----------------------------------- 6 files changed, 68 insertions(+), 71 deletions(-) create mode 100644 optional_requirements.txt create mode 100644 pyproject.toml delete mode 100755 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 474520d..22f6582 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,8 @@ jobs: 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 @@ -60,16 +62,16 @@ jobs: - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Build Python package - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | - pip install --upgrade setuptools wheel twine readme_renderer testresources - python setup.py sdist - python setup.py bdist_wheel --universal + 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: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a65e5de..d1b4f8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,25 +61,28 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Set up Python - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + 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.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install --upgrade build twine - name: Build and publish - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') env: TWINE_USERNAME: ${{ secrets.pypi_username }} TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | - python setup.py sdist + 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/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..3d0d3ff --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +[build-system] +requires = [ + "setuptools", + "wheel", +] + +[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 23c318c..03bd9cb 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # # SPDX-License-Identifier: Unlicense +Adafruit-Blinka adafruit-circuitpython-busdevice adafruit-circuitpython-pixelbuf -Adafruit-Blinka diff --git a/setup.py b/setup.py deleted file mode 100755 index 08494f3..0000000 --- a/setup.py +++ /dev/null @@ -1,54 +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", - ], - # 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"], -) From 73b78e242424b865785d5e66ccef949bdacf7214 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 9 Aug 2022 12:03:54 -0400 Subject: [PATCH 36/87] Add setuptools-scm to build system requirements Signed-off-by: Alec Delaney --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 3d0d3ff..7bdce36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ requires = [ "setuptools", "wheel", + "setuptools-scm", ] [project] From ff32685365d7596d2e415f4cc930ef4196633cbe Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 18:09:14 -0400 Subject: [PATCH 37/87] Update version string --- adafruit_seesaw/analoginput.py | 2 +- adafruit_seesaw/attiny8x7.py | 2 +- adafruit_seesaw/crickit.py | 2 +- adafruit_seesaw/digitalio.py | 2 +- adafruit_seesaw/keypad.py | 2 +- adafruit_seesaw/neopixel.py | 2 +- adafruit_seesaw/pwmout.py | 2 +- adafruit_seesaw/robohat.py | 2 +- adafruit_seesaw/rotaryio.py | 2 +- adafruit_seesaw/samd09.py | 2 +- adafruit_seesaw/seesaw.py | 2 +- adafruit_seesaw/tftshield18.py | 2 +- pyproject.toml | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/adafruit_seesaw/analoginput.py b/adafruit_seesaw/analoginput.py index 4f9825c..419dc1d 100644 --- a/adafruit_seesaw/analoginput.py +++ b/adafruit_seesaw/analoginput.py @@ -9,7 +9,7 @@ ==================================================== """ -__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/attiny8x7.py b/adafruit_seesaw/attiny8x7.py index a51e00c..d8e59b4 100644 --- a/adafruit_seesaw/attiny8x7.py +++ b/adafruit_seesaw/attiny8x7.py @@ -9,7 +9,7 @@ ================================================================================== """ -__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/crickit.py b/adafruit_seesaw/crickit.py index 689b1ff..eec8ad2 100644 --- a/adafruit_seesaw/crickit.py +++ b/adafruit_seesaw/crickit.py @@ -17,7 +17,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..417912c 100644 --- a/adafruit_seesaw/digitalio.py +++ b/adafruit_seesaw/digitalio.py @@ -11,7 +11,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..a8d7d34 100644 --- a/adafruit_seesaw/keypad.py +++ b/adafruit_seesaw/keypad.py @@ -19,7 +19,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) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 1f89206..79ab9ae 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -19,7 +19,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" _NEOPIXEL_BASE = const(0x0E) diff --git a/adafruit_seesaw/pwmout.py b/adafruit_seesaw/pwmout.py index 2c17aaa..d31bbff 100644 --- a/adafruit_seesaw/pwmout.py +++ b/adafruit_seesaw/pwmout.py @@ -9,7 +9,7 @@ ==================================================== """ -__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..9ad4e8d 100644 --- a/adafruit_seesaw/robohat.py +++ b/adafruit_seesaw/robohat.py @@ -17,7 +17,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..9901134 100644 --- a/adafruit_seesaw/rotaryio.py +++ b/adafruit_seesaw/rotaryio.py @@ -10,7 +10,7 @@ ==================================================== """ -__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..8d10fdc 100644 --- a/adafruit_seesaw/samd09.py +++ b/adafruit_seesaw/samd09.py @@ -17,7 +17,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 79222c2..1af6029 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -42,7 +42,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) diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 494ed57..6ae3529 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 7bdce36..b9ba298 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires = [ [project] name = "adafruit-circuitpython-seesaw" description = "CircuitPython library for controlling a SeeSaw helper chip." -version = "0.0.0-auto.0" +version = "0.0.0+auto.0" readme = "README.rst" authors = [ {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} From 209b4ebc12ece3f223a09473935ebede7ccfb4b0 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 21:09:14 -0400 Subject: [PATCH 38/87] Fix version strings in workflow files --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 22f6582..cb2f60e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: 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; + sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; done; python -m build twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1b4f8d..f3a0325 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: 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; + sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; done; python -m build twine upload dist/* From 34eab633ece0bc5e71c3890c962e1efedb5bf3cb Mon Sep 17 00:00:00 2001 From: caternuson Date: Thu, 18 Aug 2022 12:40:34 -0700 Subject: [PATCH 39/87] add path check for neopixel --- adafruit_seesaw/neopixel.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 79ab9ae..3023b48 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -18,6 +18,9 @@ def const(x): return x +### hack to make sure this module is not placed in root CIRCUITPY/lib folder +if __file__.split('/')[-2] != 'adafruit_seesaw': + raise ImportError("seesaw neopixel being imported from wrong location") __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" From f5bc2ee742b1e8915cbcc51c29db41456a65d020 Mon Sep 17 00:00:00 2001 From: caternuson Date: Thu, 18 Aug 2022 12:49:26 -0700 Subject: [PATCH 40/87] black --- adafruit_seesaw/neopixel.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 3023b48..7866844 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -18,8 +18,9 @@ def const(x): return x + ### hack to make sure this module is not placed in root CIRCUITPY/lib folder -if __file__.split('/')[-2] != 'adafruit_seesaw': +if __file__.split("/")[-2] != "adafruit_seesaw": raise ImportError("seesaw neopixel being imported from wrong location") __version__ = "0.0.0+auto.0" From 56e6cec7a9526a4f9918a2650dd04cc371e417b3 Mon Sep 17 00:00:00 2001 From: caternuson Date: Thu, 18 Aug 2022 13:45:04 -0700 Subject: [PATCH 41/87] change conditional --- adafruit_seesaw/neopixel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 7866844..813f044 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -20,7 +20,7 @@ def const(x): ### hack to make sure this module is not placed in root CIRCUITPY/lib folder -if __file__.split("/")[-2] != "adafruit_seesaw": +if "." not in __name__: raise ImportError("seesaw neopixel being imported from wrong location") __version__ = "0.0.0+auto.0" From 1dc8fcacfb390b45ae1344e15181abb913cf5cc4 Mon Sep 17 00:00:00 2001 From: caternuson Date: Mon, 22 Aug 2022 10:12:19 -0700 Subject: [PATCH 42/87] update message --- adafruit_seesaw/neopixel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 813f044..8f95fb4 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -21,7 +21,9 @@ def const(x): ### 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 wrong location") + 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" From aa72bbb33e520fd56726b6d2747cf8e7672a0ec3 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 22 Aug 2022 21:36:31 -0400 Subject: [PATCH 43/87] Keep copyright up to date in documentation --- docs/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 6103433..cb62812 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,6 +6,7 @@ import os import sys +import datetime sys.path.insert(0, os.path.abspath("..")) @@ -60,7 +61,8 @@ # General information about the project. project = "Adafruit seesaw Library" -copyright = "2017 Dean Miller" +current_year = str(datetime.datetime.now().year) +copyright = current_year + " Dean Miller" author = "Dean Miller" # The version info for the project you're documenting, acts as replacement for From 6234787515e2f0ece40b6408722ff0b42824038e Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 23 Aug 2022 17:26:21 -0400 Subject: [PATCH 44/87] Use year duration range for copyright attribution --- docs/conf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index cb62812..d9bda5f 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -61,8 +61,14 @@ # General information about the project. project = "Adafruit seesaw Library" +creation_year = "2017" current_year = str(datetime.datetime.now().year) -copyright = current_year + " Dean Miller" +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 From dba8954240cc5b1c4dc417c961aa2faaf874dc8c 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 45/87] 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 7064effed113a88da1167e7db37d2bc4047bcaf9 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 46/87] 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 54f05a2fddaf5382474a9f76972d33985f19dba5 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 08:15:20 -0400 Subject: [PATCH 47/87] 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 c6614355838e7ea00af36c22a7ddf9b120a4d13d Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:12:44 -0400 Subject: [PATCH 48/87] 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 7b99130af65f78d2396270be953e29357a3ccc7c Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:34:33 -0400 Subject: [PATCH 49/87] Update .pylintrc for v2.15.5 --- .pylintrc | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/.pylintrc b/.pylintrc index f772971..40208c3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense @@ -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 7d6fa55c02c19280a7ab1a92b496d6e96a7fa3d9 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 18 Nov 2022 13:05:29 -0500 Subject: [PATCH 50/87] Added commented out board.STEMMA_I2C with explanation --- examples/seesaw_analogin_test.py | 4 +++- examples/seesaw_arcade_qt_multi_board.py | 3 ++- examples/seesaw_arcade_qt_simpletest.py | 3 ++- examples/seesaw_attiny_simpletest.py | 4 +++- examples/seesaw_crickit_test.py | 3 ++- examples/seesaw_digitalio_test.py | 4 +++- examples/seesaw_eeprom_test.py | 3 ++- examples/seesaw_joy_featherwing.py | 3 ++- examples/seesaw_minitft_featherwing.py | 3 ++- examples/seesaw_neopixel_test.py | 4 +++- examples/seesaw_pwmout_test.py | 4 +++- examples/seesaw_rotary_multiples.py | 7 +++++-- examples/seesaw_rotary_neopixel.py | 4 +++- examples/seesaw_rotary_simpletest.py | 4 +++- examples/seesaw_simpletest.py | 3 ++- examples/seesaw_soil_simpletest.py | 3 ++- 16 files changed, 42 insertions(+), 17 deletions(-) diff --git a/examples/seesaw_analogin_test.py b/examples/seesaw_analogin_test.py index da2741d..97af324 100644 --- a/examples/seesaw_analogin_test.py +++ b/examples/seesaw_analogin_test.py @@ -10,7 +10,9 @@ from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.analoginput import AnalogInput -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_arcade_qt_multi_board.py b/examples/seesaw_arcade_qt_multi_board.py index b58e2c8..cc602a5 100644 --- a/examples/seesaw_arcade_qt_multi_board.py +++ b/examples/seesaw_arcade_qt_multi_board.py @@ -7,7 +7,8 @@ from adafruit_seesaw.digitalio import DigitalIO # For most boards. -i2c = 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 # For the QT Py RP2040, QT Py ESP32-S2, other boards that have SCL1/SDA1 as the STEMMA QT port. # import busio diff --git a/examples/seesaw_arcade_qt_simpletest.py b/examples/seesaw_arcade_qt_simpletest.py index f11fd56..3b55180 100644 --- a/examples/seesaw_arcade_qt_simpletest.py +++ b/examples/seesaw_arcade_qt_simpletest.py @@ -12,7 +12,8 @@ delay = 0.01 # For most boards. -i2c = 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 # For the QT Py RP2040, QT Py ESP32-S2, other boards that have SCL1/SDA1 as the STEMMA QT port. # import busio diff --git a/examples/seesaw_attiny_simpletest.py b/examples/seesaw_attiny_simpletest.py index 5b9991e..f32e189 100644 --- a/examples/seesaw_attiny_simpletest.py +++ b/examples/seesaw_attiny_simpletest.py @@ -7,7 +7,9 @@ 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..971b0b8 100644 --- a/examples/seesaw_crickit_test.py +++ b/examples/seesaw_crickit_test.py @@ -9,7 +9,8 @@ # 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) diff --git a/examples/seesaw_digitalio_test.py b/examples/seesaw_digitalio_test.py index 2e197ec..6b64fac 100644 --- a/examples/seesaw_digitalio_test.py +++ b/examples/seesaw_digitalio_test.py @@ -15,7 +15,9 @@ from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.digitalio import DigitalIO -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..e9835cb 100644 --- a/examples/seesaw_eeprom_test.py +++ b/examples/seesaw_eeprom_test.py @@ -9,7 +9,8 @@ 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_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..aa68b5f 100644 --- a/examples/seesaw_neopixel_test.py +++ b/examples/seesaw_neopixel_test.py @@ -15,7 +15,9 @@ from rainbowio import colorwheel from adafruit_seesaw import seesaw, neopixel -ss = seesaw.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.Seesaw(i2c) NEOPIXEL_PIN = 19 # Can be any pin NEOPIXEL_NUM = 12 # No more than 60 pixels! diff --git a/examples/seesaw_pwmout_test.py b/examples/seesaw_pwmout_test.py index 06bcc0e..4efe1b5 100644 --- a/examples/seesaw_pwmout_test.py +++ b/examples/seesaw_pwmout_test.py @@ -15,7 +15,9 @@ import board from adafruit_seesaw import seesaw, pwmout -ss = seesaw.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.Seesaw(i2c) PWM_PIN = 12 # If desired, change to any valid PWM output! led = pwmout.PWMOut(ss, PWM_PIN) diff --git a/examples/seesaw_rotary_multiples.py b/examples/seesaw_rotary_multiples.py index 097c86a..e349746 100644 --- a/examples/seesaw_rotary_multiples.py +++ b/examples/seesaw_rotary_multiples.py @@ -7,8 +7,11 @@ import board from adafruit_seesaw import seesaw, rotaryio, digitalio, neopixel -qt_enc1 = seesaw.Seesaw(board.I2C(), addr=0x36) -qt_enc2 = seesaw.Seesaw(board.I2C(), addr=0x37) +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) diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index 62e47bd..3c6f5de 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -12,7 +12,9 @@ # 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) diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index 7f3bbbc..8470318 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -11,7 +11,9 @@ # 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)) diff --git a/examples/seesaw_simpletest.py b/examples/seesaw_simpletest.py index 7b7d35c..4f85270 100644 --- a/examples/seesaw_simpletest.py +++ b/examples/seesaw_simpletest.py @@ -10,7 +10,8 @@ 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) From 07a5f840fe2dbe8d873fef7f65a948cec8e76bf5 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 51/87] 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 276028d1c83a2165d0945697bcbe4b0f7055a13a 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 52/87] 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 627f5b846cd6cf0dca8656feaeed7c35b0c52a49 Mon Sep 17 00:00:00 2001 From: Tod Kurt Date: Mon, 10 Apr 2023 12:33:22 -0700 Subject: [PATCH 53/87] support PID 5690 and 5681 --- adafruit_seesaw/attinyx16.py | 17 +++++++++++++++++ adafruit_seesaw/seesaw.py | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 adafruit_seesaw/attinyx16.py diff --git a/adafruit_seesaw/attinyx16.py b/adafruit_seesaw/attinyx16.py new file mode 100644 index 0000000..8554003 --- /dev/null +++ b/adafruit_seesaw/attinyx16.py @@ -0,0 +1,17 @@ +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) + + """No pins on this board are capable of touch input""" + touch_pins = () diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 1af6029..92ac33c 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -117,7 +117,8 @@ 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) class Seesaw: """Driver for Seesaw i2c generic conversion trip @@ -161,6 +162,10 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): from adafruit_seesaw.robohat import MM1_Pinmap self.pin_mapping = MM1_Pinmap + elif pid == _5690_PID or pid == _5681_PID: + from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap + + self.pin_mapping = ATtinyx16_Pinmap elif self.chip_id == _SAMD09_HW_ID_CODE: from adafruit_seesaw.samd09 import SAMD09_Pinmap From 1221dbb954e4666ed3b72fad877b2500d89475be Mon Sep 17 00:00:00 2001 From: Tod Kurt Date: Mon, 10 Apr 2023 13:42:45 -0700 Subject: [PATCH 54/87] cleanup for pylint --- adafruit_seesaw/attinyx16.py | 16 +++++++++++++++- adafruit_seesaw/seesaw.py | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/adafruit_seesaw/attinyx16.py b/adafruit_seesaw/attinyx16.py index 8554003..3ff5de3 100644 --- a/adafruit_seesaw/attinyx16.py +++ b/adafruit_seesaw/attinyx16.py @@ -1,10 +1,24 @@ +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods +""" +`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 + """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""" diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 92ac33c..bbd3884 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -120,6 +120,7 @@ def const(x): _5690_PID = const(5690) _5681_PID = const(5681) + class Seesaw: """Driver for Seesaw i2c generic conversion trip @@ -162,7 +163,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): from adafruit_seesaw.robohat import MM1_Pinmap self.pin_mapping = MM1_Pinmap - elif pid == _5690_PID or pid == _5681_PID: + elif pid in (_5690_PID, _5681_PID): from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap self.pin_mapping = ATtinyx16_Pinmap From 137b0c278ed95e4763343b806aaca00281cc5f5e Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 55/87] 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 0f247274fd5820341c34d815074266b9fb6c5554 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Wed, 10 May 2023 22:43:24 -0400 Subject: [PATCH 56/87] Run pre-commit --- adafruit_seesaw/keypad.py | 1 + adafruit_seesaw/tftshield18.py | 1 - examples/seesaw_rotary_multiples.py | 1 - examples/seesaw_rotary_neopixel.py | 1 - examples/seesaw_rotary_simpletest.py | 1 - 5 files changed, 1 insertion(+), 4 deletions(-) diff --git a/adafruit_seesaw/keypad.py b/adafruit_seesaw/keypad.py index a8d7d34..37246e8 100644 --- a/adafruit_seesaw/keypad.py +++ b/adafruit_seesaw/keypad.py @@ -31,6 +31,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 diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 6ae3529..84d471b 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -44,7 +44,6 @@ def const(x): class TFTShield18(Seesaw): - _BACKLIGHT_ON = b"\xFF\xFF" _BACKLIGHT_OFF = b"\x00\x00" diff --git a/examples/seesaw_rotary_multiples.py b/examples/seesaw_rotary_multiples.py index e349746..e5fbb8b 100644 --- a/examples/seesaw_rotary_multiples.py +++ b/examples/seesaw_rotary_multiples.py @@ -37,7 +37,6 @@ while True: - # negate the position to make clockwise rotation positive position1 = -encoder1.position position2 = -encoder2.position diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index 3c6f5de..d37772c 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -27,7 +27,6 @@ color = 0 # start at red while True: - # negate the position to make clockwise rotation positive position = -encoder.position diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index 8470318..2e33b41 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -28,7 +28,6 @@ last_position = None while True: - # negate the position to make clockwise rotation positive position = -encoder.position From c2d282324a74ea825f5f2533e43439d7dfa7785d Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 19 May 2023 19:43:30 -0400 Subject: [PATCH 57/87] Adding examples for ANO rotary encoder Adding two examples for the ANO rotary encoder. Ports of the Arduino example code. --- examples/seesaw_ano_rotary_7segment_demo.py | 66 +++++++++++++++++++++ examples/seesaw_ano_rotary_simpletest.py | 61 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 examples/seesaw_ano_rotary_7segment_demo.py create mode 100644 examples/seesaw_ano_rotary_simpletest.py diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py new file mode 100644 index 0000000..974973b --- /dev/null +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -0,0 +1,66 @@ +# SPDX-FileCopyrightText: 2021 John Furcean +# SPDX-License-Identifier: MIT + +"""I2C ANO rotary encoder simple test example.""" + +import board +from adafruit_seesaw import seesaw, rotaryio, digitalio +from adafruit_ht16k33 import segments + +# 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("Found product {}".format(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(" %s" % str(position)) + print("Position: {}".format(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("%s button pressed" % (button_names[b])) + + if buttons[b].value and button_states[b] is True: + button_states[b] = False + display.print(" ") + print("%s button released" % (button_names[b])) diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py new file mode 100644 index 0000000..c62165f --- /dev/null +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -0,0 +1,61 @@ +# SPDX-FileCopyrightText: 2021 John Furcean +# SPDX-License-Identifier: MIT + +"""I2C ANO rotary encoder simple test example.""" + +import board +from adafruit_seesaw import seesaw, rotaryio, digitalio + +# 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("Found product {}".format(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("Position: {}".format(position)) + + for b in range(5): + if not buttons[b].value and button_states[b] is False: + button_states[b] = True + print("%s button pressed" % (button_names[b])) + + if buttons[b].value and button_states[b] is True: + button_states[b] = False + print("%s button released" % (button_names[b])) From b33334de17aa1e1cde5b489f7d68dc267d7305ce Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 19 May 2023 19:46:57 -0400 Subject: [PATCH 58/87] fixing library import order --- examples/seesaw_ano_rotary_7segment_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index 974973b..7b4c865 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -4,8 +4,8 @@ """I2C ANO rotary encoder simple test example.""" import board -from adafruit_seesaw import seesaw, rotaryio, digitalio from adafruit_ht16k33 import segments +from adafruit_seesaw import seesaw, rotaryio, digitalio # For use with the STEMMA connector on QT Py RP2040 # import busio From 2d69849727553e95266a48616b1a7b7a05d610cf Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 19 May 2023 19:57:41 -0400 Subject: [PATCH 59/87] update 7 segment description --- examples/seesaw_ano_rotary_7segment_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index 7b4c865..d5a1a7c 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2021 John Furcean # SPDX-License-Identifier: MIT -"""I2C ANO rotary encoder simple test example.""" +"""I2C ANO rotary encoder with 7 segment display example.""" import board from adafruit_ht16k33 import segments From 08ff00005ebe686dd5b59b0ecafeca5e899bbc59 Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 19 May 2023 21:27:10 -0400 Subject: [PATCH 60/87] updating to use f-strings --- examples/seesaw_ano_rotary_7segment_demo.py | 6 +++--- examples/seesaw_ano_rotary_simpletest.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index d5a1a7c..383076a 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -52,15 +52,15 @@ if position != last_position: last_position = position - display.print(" %s" % str(position)) + display.print(" {}".format(position)) print("Position: {}".format(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("%s button pressed" % (button_names[b])) + print("{} button pressed".format(button_names[b])) if buttons[b].value and button_states[b] is True: button_states[b] = False display.print(" ") - print("%s button released" % (button_names[b])) + print("{} button released".format(button_names[b])) diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py index c62165f..dc8ce69 100644 --- a/examples/seesaw_ano_rotary_simpletest.py +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -54,8 +54,8 @@ for b in range(5): if not buttons[b].value and button_states[b] is False: button_states[b] = True - print("%s button pressed" % (button_names[b])) + print("{} button pressed".format(button_names[b])) if buttons[b].value and button_states[b] is True: button_states[b] = False - print("%s button released" % (button_names[b])) + print("{} button released".format(button_names[b])) From c481937f4b8152b2333f7acbcdd2c14f0554c37c Mon Sep 17 00:00:00 2001 From: Liz Date: Sun, 21 May 2023 09:47:39 -0400 Subject: [PATCH 61/87] actually updating to use f-strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it would be helpful if i actually updated the examples to use f-strings 😅 --- examples/seesaw_ano_rotary_7segment_demo.py | 9 +++++---- examples/seesaw_ano_rotary_simpletest.py | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index 383076a..3bccc2f 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -52,15 +52,16 @@ if position != last_position: last_position = position - display.print(" {}".format(position)) - print("Position: {}".format(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("{} button pressed".format(button_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("{} button released".format(button_names[b])) + print(f"{button_names[b]} button released") diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py index dc8ce69..1856046 100644 --- a/examples/seesaw_ano_rotary_simpletest.py +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -49,13 +49,13 @@ if position != last_position: last_position = position - print("Position: {}".format(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("{} button pressed".format(button_names[b])) + print(f"{button_names[b]} button pressed") if buttons[b].value and button_states[b] is True: button_states[b] = False - print("{} button released".format(button_names[b])) + print(f"{button_names[b]} button released") From 89daaec507fa2f5fa4bd7aa9bedf7e8eae09ac44 Mon Sep 17 00:00:00 2001 From: Liz Date: Mon, 22 May 2023 19:08:27 -0400 Subject: [PATCH 62/87] f-string for seesaw_product --- examples/seesaw_ano_rotary_7segment_demo.py | 2 +- examples/seesaw_ano_rotary_simpletest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index 3bccc2f..0930c13 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -18,7 +18,7 @@ display = segments.Seg14x4(i2c, address=0x70) seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF -print("Found product {}".format(seesaw_product)) +print(f"Found product {seesaw_product}") if seesaw_product != 5740: print("Wrong firmware loaded? Expected 5740") diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py index 1856046..1fc845e 100644 --- a/examples/seesaw_ano_rotary_simpletest.py +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -16,7 +16,7 @@ seesaw = seesaw.Seesaw(i2c, addr=0x49) seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF -print("Found product {}".format(seesaw_product)) +print(f"Found product {seesaw_product}") if seesaw_product != 5740: print("Wrong firmware loaded? Expected 5740") From 5d012652274d9fdea022b41b3c1a52445360a185 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Tue, 23 May 2023 23:19:57 -0400 Subject: [PATCH 63/87] Update .pylintrc, fix jQuery for docs --- .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 d9bda5f..8e225ec 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,6 +17,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.viewcode", ] 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 ebc019850190292c8771b32b39938d851440b1c0 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Fri, 23 Jun 2023 19:34:06 -0400 Subject: [PATCH 64/87] Add Gamepad QT compatibility, example. --- adafruit_seesaw/seesaw.py | 3 +- examples/seesaw_gamepad_qt.py | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 examples/seesaw_gamepad_qt.py diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index bbd3884..91a1512 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -119,6 +119,7 @@ def const(x): _ROBOHATMM1_PID = const(9998) _5690_PID = const(5690) _5681_PID = const(5681) +_5743_PID = const(5743) class Seesaw: @@ -163,7 +164,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): from adafruit_seesaw.robohat import MM1_Pinmap self.pin_mapping = MM1_Pinmap - elif pid in (_5690_PID, _5681_PID): + elif pid in (_5690_PID, _5681_PID, _5743_PID): from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap self.pin_mapping = ATtinyx16_Pinmap diff --git a/examples/seesaw_gamepad_qt.py b/examples/seesaw_gamepad_qt.py new file mode 100644 index 0000000..b6ed18b --- /dev/null +++ b/examples/seesaw_gamepad_qt.py @@ -0,0 +1,65 @@ +# 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) From 3dab6e6ffd7a5482b2ec56ec5d7890fa70b9e5c2 Mon Sep 17 00:00:00 2001 From: lady ada Date: Mon, 26 Jun 2023 22:08:57 -0400 Subject: [PATCH 65/87] add support for different chip detection + quad rotary demo --- adafruit_seesaw/seesaw.py | 23 ++++++++++----- examples/seesaw_quadrotary.py | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 examples/seesaw_quadrotary.py diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 91a1512..daa8a22 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -105,7 +105,12 @@ def const(x): _TOUCH_CHANNEL_OFFSET = const(0x10) _SAMD09_HW_ID_CODE = const(0x55) -_ATTINY8X7_HW_ID_CODE = const(0x87) +_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) _EEPROM_I2C_ADDR = const(0x3F) _ENCODER_STATUS = const(0x00) @@ -145,13 +150,13 @@ 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 - ) + "correct! Please check your wiring.".format(self.chip_id,) ) pid = self.get_version() >> 16 @@ -164,7 +169,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): from adafruit_seesaw.robohat import MM1_Pinmap self.pin_mapping = MM1_Pinmap - elif pid in (_5690_PID, _5681_PID, _5743_PID): + elif (pid in (_5690_PID, _5681_PID, _5743_PID)) or (self.chip_id in (_ATTINY817_HW_ID_CODE, _ATTINY807_HW_ID_CODE, _ATTINY1617_HW_ID_CODE)): from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap self.pin_mapping = ATtinyx16_Pinmap @@ -172,7 +177,9 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): from adafruit_seesaw.samd09 import SAMD09_Pinmap self.pin_mapping = SAMD09_Pinmap - elif self.chip_id == _ATTINY8X7_HW_ID_CODE: + elif self.chip_id in (_ATTINY817_HW_ID_CODE, + _ATTINY807_HW_ID_CODE, + _ATTINY1617_HW_ID_CODE): from adafruit_seesaw.attiny8x7 import ATtiny8x7_Pinmap self.pin_mapping = ATtiny8x7_Pinmap diff --git a/examples/seesaw_quadrotary.py b/examples/seesaw_quadrotary.py new file mode 100644 index 0000000..aae830e --- /dev/null +++ b/examples/seesaw_quadrotary.py @@ -0,0 +1,55 @@ +# SPDX-FileCopyrightText: 2023 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +"""I2C rotary encoder NeoPixel color picker and brightness setting example.""" +import board +from rainbowio import colorwheel +import digitalio +import adafruit_seesaw.seesaw +import adafruit_seesaw.neopixel +import adafruit_seesaw.rotaryio +import adafruit_seesaw.digitalio +import time + +# 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 = 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 'stick' +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] + + for n, rotary_pos in enumerate(positions): + if rotary_pos != last_positions[n]: + print("Rotary #%d: %d" % (n, rotary_pos)) + last_positions[n] = rotary_pos + + 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 + + # 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]) From da9a46c99fd7b441f631d2dd535f27bc6884ca69 Mon Sep 17 00:00:00 2001 From: Liz Date: Tue, 27 Jun 2023 08:22:40 -0400 Subject: [PATCH 66/87] linting --- adafruit_seesaw/seesaw.py | 5 ++++- examples/seesaw_quadrotary.py | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index daa8a22..de71fb7 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -169,7 +169,10 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): from adafruit_seesaw.robohat import MM1_Pinmap self.pin_mapping = MM1_Pinmap - elif (pid in (_5690_PID, _5681_PID, _5743_PID)) or (self.chip_id in (_ATTINY817_HW_ID_CODE, _ATTINY807_HW_ID_CODE, _ATTINY1617_HW_ID_CODE)): + elif (pid in (_5690_PID, _5681_PID, _5743_PID)) or (self.chip_id in + (_ATTINY817_HW_ID_CODE, + _ATTINY807_HW_ID_CODE, + _ATTINY1617_HW_ID_CODE)): from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap self.pin_mapping = ATtinyx16_Pinmap diff --git a/examples/seesaw_quadrotary.py b/examples/seesaw_quadrotary.py index aae830e..b91053d 100644 --- a/examples/seesaw_quadrotary.py +++ b/examples/seesaw_quadrotary.py @@ -9,7 +9,6 @@ import adafruit_seesaw.neopixel import adafruit_seesaw.rotaryio import adafruit_seesaw.digitalio -import time # For use with the STEMMA connector on QT Py RP2040 # import busio @@ -38,7 +37,7 @@ for n, rotary_pos in enumerate(positions): if rotary_pos != last_positions[n]: - print("Rotary #%d: %d" % (n, rotary_pos)) + print(f"Rotary #{n}: {rotary_pos}") last_positions[n] = rotary_pos if switches[n].value: # Change the LED color if switch is not pressed @@ -50,6 +49,6 @@ # if switch is pressed, light up white, otherwise use the stored color if not switches[n].value: - pixels[n] = 0xFFFFFF + pixels[n] = 0xFFFFFF else: - pixels[n] = colorwheel(colors[n]) + pixels[n] = colorwheel(colors[n]) From 2310a9b7509b7d3fc7071ca3f1e90b2bf51f90d8 Mon Sep 17 00:00:00 2001 From: lady ada Date: Tue, 27 Jun 2023 17:54:02 -0400 Subject: [PATCH 67/87] tested on m4 & raspi --- examples/seesaw_quadrotary.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/seesaw_quadrotary.py b/examples/seesaw_quadrotary.py index aae830e..a2e0ec3 100644 --- a/examples/seesaw_quadrotary.py +++ b/examples/seesaw_quadrotary.py @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2023 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -"""I2C rotary encoder NeoPixel color picker and brightness setting example.""" +"""Quad I2C rotary encoder NeoPixel color picker example.""" import board from rainbowio import colorwheel import digitalio @@ -12,11 +12,11 @@ import time # For use with the STEMMA connector on QT Py RP2040 -# import busio -# i2c = busio.I2C(board.SCL1, board.SDA1) -# seesaw = seesaw.Seesaw(i2c, 0x49) +import busio +from adafruit_debug_i2c import DebugI2C -i2c = board.I2C() # uses board.SCL and board.SDA +# For boards/chips that don't handle clock-stretching well, try running I2C at 50KHz +# i2c = busio.I2C(board.SCL, board.SDA, frequency=50000) # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller seesaw = adafruit_seesaw.seesaw.Seesaw(i2c, 0x49) @@ -25,7 +25,7 @@ for switch in switches: switch.switch_to_input(digitalio.Pull.UP) # input & pullup! -# four neopixels per 'stick' +# four neopixels per PCB pixels = adafruit_seesaw.neopixel.NeoPixel(seesaw, 18, 4) pixels.brightness = 0.5 @@ -35,7 +35,8 @@ while True: # negate the position to make clockwise rotation positive positions = [encoder.position for encoder in encoders] - + print(positions) + continue for n, rotary_pos in enumerate(positions): if rotary_pos != last_positions[n]: print("Rotary #%d: %d" % (n, rotary_pos)) From 64742309bd2b8de80e9b11c24ec5ede4210416be Mon Sep 17 00:00:00 2001 From: lady ada Date: Tue, 27 Jun 2023 17:57:08 -0400 Subject: [PATCH 68/87] fix typo and make 'default' use the native pin names going forward --- adafruit_seesaw/seesaw.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index de71fb7..83b244e 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -170,9 +170,9 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): self.pin_mapping = MM1_Pinmap elif (pid in (_5690_PID, _5681_PID, _5743_PID)) or (self.chip_id in - (_ATTINY817_HW_ID_CODE, - _ATTINY807_HW_ID_CODE, - _ATTINY1617_HW_ID_CODE)): + (_ATTINY816_HW_ID_CODE, + _ATTINY806_HW_ID_CODE, + _ATTINY1616_HW_ID_CODE)): from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap self.pin_mapping = ATtinyx16_Pinmap @@ -265,10 +265,10 @@ def analog_read(self, pin, delay=0.008): 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: + 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, delay) ret = struct.unpack(">H", buf)[0] @@ -361,10 +361,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]) From 79c87383a1a8c4f3370b918491afaafecf1e751e Mon Sep 17 00:00:00 2001 From: lady ada Date: Wed, 28 Jun 2023 12:47:47 -0400 Subject: [PATCH 69/87] fix two complaints --- examples/seesaw_quadrotary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/seesaw_quadrotary.py b/examples/seesaw_quadrotary.py index dd75f8c..6028666 100644 --- a/examples/seesaw_quadrotary.py +++ b/examples/seesaw_quadrotary.py @@ -15,7 +15,7 @@ from adafruit_debug_i2c import DebugI2C # For boards/chips that don't handle clock-stretching well, try running I2C at 50KHz -# i2c = busio.I2C(board.SCL, board.SDA, frequency=50000) +i2c = busio.I2C(board.SCL, board.SDA, frequency=50000) # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller seesaw = adafruit_seesaw.seesaw.Seesaw(i2c, 0x49) From 9b0033c782bbca090e3077454903dc77cbcb52d5 Mon Sep 17 00:00:00 2001 From: lady ada Date: Wed, 28 Jun 2023 14:06:47 -0400 Subject: [PATCH 70/87] fix missing if --- adafruit_seesaw/seesaw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 83b244e..1840d53 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -265,7 +265,7 @@ def analog_read(self, pin, delay=0.008): if pin not in self.pin_mapping.analog_pins: raise ValueError("Invalid ADC pin") - 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 From 8b20eea24b4f4ac6d601f14e3d7e480aca12d63b Mon Sep 17 00:00:00 2001 From: Liz Date: Wed, 28 Jun 2023 16:24:03 -0400 Subject: [PATCH 71/87] lint && black --- adafruit_seesaw/seesaw.py | 33 ++++++++++++++++++++------------- examples/seesaw_quadrotary.py | 17 ++++++++--------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 1840d53..39c6ccf 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -150,13 +150,18 @@ 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 (_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): + 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! Please check your wiring.".format(self.chip_id,) + f"Seesaw hardware ID returned 0x{self.chip_id} is not " + "correct! Please check your wiring." ) pid = self.get_version() >> 16 @@ -169,10 +174,10 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): from adafruit_seesaw.robohat import MM1_Pinmap 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)): + 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 self.pin_mapping = ATtinyx16_Pinmap @@ -180,9 +185,11 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): from adafruit_seesaw.samd09 import SAMD09_Pinmap self.pin_mapping = SAMD09_Pinmap - elif self.chip_id in (_ATTINY817_HW_ID_CODE, - _ATTINY807_HW_ID_CODE, - _ATTINY1617_HW_ID_CODE): + elif self.chip_id in ( + _ATTINY817_HW_ID_CODE, + _ATTINY807_HW_ID_CODE, + _ATTINY1617_HW_ID_CODE, + ): from adafruit_seesaw.attiny8x7 import ATtiny8x7_Pinmap self.pin_mapping = ATtiny8x7_Pinmap diff --git a/examples/seesaw_quadrotary.py b/examples/seesaw_quadrotary.py index 6028666..5cca3fa 100644 --- a/examples/seesaw_quadrotary.py +++ b/examples/seesaw_quadrotary.py @@ -10,13 +10,11 @@ import adafruit_seesaw.rotaryio import adafruit_seesaw.digitalio -# For use with the STEMMA connector on QT Py RP2040 -import busio -from adafruit_debug_i2c import DebugI2C - # For boards/chips that don't handle clock-stretching well, try running I2C at 50KHz -i2c = busio.I2C(board.SCL, board.SDA, frequency=50000) -# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller +# 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)] @@ -35,14 +33,15 @@ # negate the position to make clockwise rotation positive positions = [encoder.position for encoder in encoders] print(positions) - continue for n, rotary_pos in enumerate(positions): if rotary_pos != last_positions[n]: print(f"Rotary #{n}: {rotary_pos}") last_positions[n] = rotary_pos - if switches[n].value: # Change the LED color if switch is not pressed - if rotary_pos > last_positions[n]: # Advance forward through the colorwheel. + 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. From 9a2df8ccb20ca9f270e86657c1d9e6f32a34e2d5 Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 11 Aug 2023 11:47:55 -0400 Subject: [PATCH 72/87] Adding example for pc joystick Adding example code for the PC joystick adapter (PID5753) --- examples/seesaw_pc_joystick.py | 72 ++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 examples/seesaw_pc_joystick.py diff --git a/examples/seesaw_pc_joystick.py b/examples/seesaw_pc_joystick.py new file mode 100644 index 0000000..fc1c969 --- /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) From c43206fcdbbb2c250660830237efca7aea266ebc Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 16:23:46 -0500 Subject: [PATCH 73/87] "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 8e225ec..6523570 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -117,19 +117,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 f58dea611607b4fb0e829e8599ff52a7db24f957 Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 3 Nov 2023 14:35:12 -0700 Subject: [PATCH 74/87] update eeprom i2c addr for attiny --- adafruit_seesaw/seesaw.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 39c6ccf..0a75a9b 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -111,7 +111,6 @@ def const(x): _ATTINY817_HW_ID_CODE = const(0x87) _ATTINY1616_HW_ID_CODE = const(0x88) _ATTINY1617_HW_ID_CODE = const(0x89) -_EEPROM_I2C_ADDR = const(0x3F) _ENCODER_STATUS = const(0x00) _ENCODER_INTENSET = const(0x10) @@ -440,16 +439,36 @@ 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 + elif chip_id in ( + _ATTINY1616_HW_ID_CODE, + _ATTINY1617_HW_ID_CODE, + ): + return 0xFF + elif chip_id in ( + _SAMD09_HW_ID_CODE, + ): + return 0x3F + else: + raise RuntimeError("Unknown chip id", hex(chip_id)) + 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""" From 54f38e52fad63073898c2487a9450792b6779a8b Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 3 Nov 2023 14:42:12 -0700 Subject: [PATCH 75/87] black hole sun! --- adafruit_seesaw/seesaw.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 0a75a9b..d8d751a 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -439,7 +439,6 @@ 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 @@ -455,9 +454,7 @@ def _get_eeprom_i2c_addr(self): _ATTINY1617_HW_ID_CODE, ): return 0xFF - elif chip_id in ( - _SAMD09_HW_ID_CODE, - ): + elif chip_id in (_SAMD09_HW_ID_CODE,): return 0x3F else: raise RuntimeError("Unknown chip id", hex(chip_id)) From 828493a669e957bd012bc8ce4a99efd7e3d2534c Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 3 Nov 2023 14:53:39 -0700 Subject: [PATCH 76/87] even better black --- adafruit_seesaw/seesaw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index d8d751a..efd8a7f 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -440,7 +440,7 @@ 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.""" + """Return the EEPROM address used to store I2C address.""" chip_id = self.chip_id if chip_id in ( _ATTINY806_HW_ID_CODE, From 490a166267b650b1474a2b384ebd0105ca465da2 Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 3 Nov 2023 14:57:00 -0700 Subject: [PATCH 77/87] return none so pylint is happy --- adafruit_seesaw/seesaw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index efd8a7f..0ee3544 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -457,7 +457,7 @@ def _get_eeprom_i2c_addr(self): elif chip_id in (_SAMD09_HW_ID_CODE,): return 0x3F else: - raise RuntimeError("Unknown chip id", hex(chip_id)) + return None def set_i2c_addr(self, addr): """Store a new address in the device's EEPROM and reboot it.""" From 3443b3cc36dbda6cc3f1c485a4755302545c9d2d Mon Sep 17 00:00:00 2001 From: caternuson Date: Fri, 3 Nov 2023 15:00:43 -0700 Subject: [PATCH 78/87] fine pylint have it your way --- adafruit_seesaw/seesaw.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 0ee3544..4857300 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -449,15 +449,14 @@ def _get_eeprom_i2c_addr(self): _ATTINY817_HW_ID_CODE, ): return 0x7F - elif chip_id in ( + if chip_id in ( _ATTINY1616_HW_ID_CODE, _ATTINY1617_HW_ID_CODE, ): return 0xFF - elif chip_id in (_SAMD09_HW_ID_CODE,): + if chip_id in (_SAMD09_HW_ID_CODE,): return 0x3F - else: - return None + return None def set_i2c_addr(self, addr): """Store a new address in the device's EEPROM and reboot it.""" From a0440760a02d8e2cbc98bf67647031f3e393b242 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 7 Nov 2023 08:39:14 -0800 Subject: [PATCH 79/87] add code comment --- examples/seesaw_rotary_simpletest.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index 2e33b41..0b22085 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -20,8 +20,11 @@ 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) From 5daef994293900260897ff9b97d2a0a82d95ff16 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 7 Nov 2023 14:28:20 -0800 Subject: [PATCH 80/87] fix set_pwm_freq for attinys --- adafruit_seesaw/attiny8x7.py | 3 ++- adafruit_seesaw/attinyx16.py | 3 ++- adafruit_seesaw/seesaw.py | 15 +++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/adafruit_seesaw/attiny8x7.py b/adafruit_seesaw/attiny8x7.py index d8e59b4..ce96861 100644 --- a/adafruit_seesaw/attiny8x7.py +++ b/adafruit_seesaw/attiny8x7.py @@ -26,7 +26,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 index 3ff5de3..cc14cdf 100644 --- a/adafruit_seesaw/attinyx16.py +++ b/adafruit_seesaw/attinyx16.py @@ -25,7 +25,8 @@ class ATtinyx16_Pinmap: 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) + 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/seesaw.py b/adafruit_seesaw/seesaw.py index 4857300..67e1d75 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -390,14 +390,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) From 4da237e6ed19f46f3b948e531b7b5f7c82b131b2 Mon Sep 17 00:00:00 2001 From: caternuson Date: Tue, 7 Nov 2023 14:55:12 -0800 Subject: [PATCH 81/87] black --- adafruit_seesaw/attiny8x7.py | 4 ++-- adafruit_seesaw/attinyx16.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_seesaw/attiny8x7.py b/adafruit_seesaw/attiny8x7.py index ce96861..bdddf54 100644 --- a/adafruit_seesaw/attiny8x7.py +++ b/adafruit_seesaw/attiny8x7.py @@ -26,8 +26,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) # 8 bit PWM mode - pwm_pins += (6, 7, 8) # 16 bit PWM mode + 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 index cc14cdf..874ccd5 100644 --- a/adafruit_seesaw/attinyx16.py +++ b/adafruit_seesaw/attinyx16.py @@ -25,8 +25,8 @@ class ATtinyx16_Pinmap: 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 + 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 = () From dad627c4fed48e2d2b059d12560108ac41d830af Mon Sep 17 00:00:00 2001 From: Logan Smith <32109138+logandgsmith@users.noreply.github.com> Date: Sat, 25 Nov 2023 15:46:09 -0500 Subject: [PATCH 82/87] Update seesaw_quadrotary.py Move `last_position[n] = rotary_pos` to after current position is evaluated. Without this, `last_position[n]` was being overwritten before it was compared to `rotary_pos`. --- examples/seesaw_quadrotary.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/seesaw_quadrotary.py b/examples/seesaw_quadrotary.py index 5cca3fa..6a6196f 100644 --- a/examples/seesaw_quadrotary.py +++ b/examples/seesaw_quadrotary.py @@ -35,9 +35,6 @@ print(positions) for n, rotary_pos in enumerate(positions): if rotary_pos != last_positions[n]: - print(f"Rotary #{n}: {rotary_pos}") - last_positions[n] = rotary_pos - if switches[n].value: # Change the LED color if switch is not pressed if ( rotary_pos > last_positions[n] @@ -46,6 +43,9 @@ 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: From 5c2ebbb394a6537fd4626fab54a711689f09c78c Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Oct 2023 14:30:31 -0500 Subject: [PATCH 83/87] 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 6229da8d3b1b49e78e4d6d12742cf93cb998cd67 Mon Sep 17 00:00:00 2001 From: Steve Cirelli Date: Tue, 30 Jan 2024 15:05:39 -0500 Subject: [PATCH 84/87] Fixed an error message that was using the wrong number system. See issue #128. --- adafruit_seesaw/seesaw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 67e1d75..5a96218 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -159,7 +159,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): _SAMD09_HW_ID_CODE, ): raise RuntimeError( - f"Seesaw hardware ID returned 0x{self.chip_id} is not " + f"Seesaw hardware ID returned 0x{self.chip_id:x} is not " "correct! Please check your wiring." ) From 02e69c67231a71e51b98ac39040dfd6d45a6dff1 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 85/87] 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 6523570..78ef207 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -120,7 +120,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 8464fcbeb2789dc81709f6476d63f5ad7cdc26ba Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 86/87] 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 9b3a888acfd2664021ed126aa893ae214a03f9b1 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 15 May 2025 15:03:39 +0000 Subject: [PATCH 87/87] change to ruff --- .gitattributes | 11 + .pre-commit-config.yaml | 43 +-- .pylintrc | 399 -------------------- README.rst | 6 +- adafruit_seesaw/analoginput.py | 1 - adafruit_seesaw/attiny8x7.py | 1 - adafruit_seesaw/attinyx16.py | 1 - adafruit_seesaw/crickit.py | 1 - adafruit_seesaw/digitalio.py | 1 - adafruit_seesaw/keypad.py | 13 +- adafruit_seesaw/neopixel.py | 13 +- adafruit_seesaw/pwmout.py | 1 - adafruit_seesaw/robohat.py | 1 - adafruit_seesaw/rotaryio.py | 2 - adafruit_seesaw/samd09.py | 1 - adafruit_seesaw/seesaw.py | 40 +- adafruit_seesaw/tftshield18.py | 4 +- docs/api.rst | 3 + docs/conf.py | 8 +- examples/seesaw_analogin_test.py | 4 +- examples/seesaw_ano_rotary_7segment_demo.py | 3 +- examples/seesaw_ano_rotary_simpletest.py | 3 +- examples/seesaw_arcade_qt_multi_board.py | 4 +- examples/seesaw_arcade_qt_simpletest.py | 5 +- examples/seesaw_attiny_simpletest.py | 3 + examples/seesaw_crickit_test.py | 25 +- examples/seesaw_digitalio_test.py | 4 +- examples/seesaw_eeprom_test.py | 2 + examples/seesaw_gamepad_qt.py | 2 + examples/seesaw_neopixel_test.py | 4 +- examples/seesaw_pc_joystick.py | 6 +- examples/seesaw_pwmout_test.py | 6 +- examples/seesaw_quadrotary.py | 12 +- examples/seesaw_rotary_multiples.py | 7 +- examples/seesaw_rotary_neopixel.py | 13 +- examples/seesaw_rotary_simpletest.py | 7 +- examples/seesaw_simpletest.py | 1 + ruff.toml | 105 ++++++ 38 files changed, 229 insertions(+), 537 deletions(-) create mode 100644 .gitattributes delete mode 100644 .pylintrc create mode 100644 ruff.toml 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/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..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: 23.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string - 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: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index f945e92..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written 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 ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. 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=pylint.extensions.no_self_use - -# 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,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 -# 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 - -# 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=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([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 - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-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 - -# 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 - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-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 - -# 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=builtins.Exception diff --git a/README.rst b/README.rst index 3fb6633..2b8c4f7 100644 --- a/README.rst +++ b/README.rst @@ -14,9 +14,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_seesaw/actions :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. 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. diff --git a/adafruit_seesaw/analoginput.py b/adafruit_seesaw/analoginput.py index 419dc1d..4020079 100644 --- a/adafruit_seesaw/analoginput.py +++ b/adafruit_seesaw/analoginput.py @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ `adafruit_seesaw.analoginput` diff --git a/adafruit_seesaw/attiny8x7.py b/adafruit_seesaw/attiny8x7.py index bdddf54..78356ca 100644 --- a/adafruit_seesaw/attiny8x7.py +++ b/adafruit_seesaw/attiny8x7.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.attiny8x7` - Pin definition for Adafruit ATtiny8x7 Breakout with seesaw diff --git a/adafruit_seesaw/attinyx16.py b/adafruit_seesaw/attinyx16.py index 874ccd5..b80db65 100644 --- a/adafruit_seesaw/attinyx16.py +++ b/adafruit_seesaw/attinyx16.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.attinyx16` - Pin definition for Adafruit ATtinyx16 Breakout with seesaw ================================================================================== diff --git a/adafruit_seesaw/crickit.py b/adafruit_seesaw/crickit.py index eec8ad2..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 diff --git a/adafruit_seesaw/digitalio.py b/adafruit_seesaw/digitalio.py index 417912c..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` diff --git a/adafruit_seesaw/keypad.py b/adafruit_seesaw/keypad.py index 37246e8..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` @@ -32,7 +31,6 @@ def const(x): _KEYPAD_FIFO = const(0x10) -# pylint: disable=too-few-public-methods class KeyEvent: """Holds information about a key event in its properties @@ -75,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 @@ -85,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 @@ -103,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 8f95fb4..c9b470e 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -2,13 +2,14 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ `adafruit_seesaw.neopixel` ==================================================== """ + import struct + from adafruit_pixelbuf import PixelBuf try: @@ -64,15 +65,7 @@ class NeoPixel(PixelBuf): Use one of the order constants such as RGBW.""" def __init__( - self, - seesaw, - pin, - n, - *, - bpp=None, - brightness=1.0, - auto_write=True, - pixel_order="GRB" + self, seesaw, pin, n, *, bpp=None, brightness=1.0, auto_write=True, pixel_order="GRB" ): self._seesaw = seesaw self._pin = pin diff --git a/adafruit_seesaw/pwmout.py b/adafruit_seesaw/pwmout.py index d31bbff..869db25 100644 --- a/adafruit_seesaw/pwmout.py +++ b/adafruit_seesaw/pwmout.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.pwmout` diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py index 9ad4e8d..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 diff --git a/adafruit_seesaw/rotaryio.py b/adafruit_seesaw/rotaryio.py index 9901134..8a23d90 100644 --- a/adafruit_seesaw/rotaryio.py +++ b/adafruit_seesaw/rotaryio.py @@ -2,8 +2,6 @@ # # SPDX-License-Identifier: MIT -# pylint: disable=missing-docstring,invalid-name,too-many-public-methods - """ `adafruit_seesaw.rotaryio` diff --git a/adafruit_seesaw/samd09.py b/adafruit_seesaw/samd09.py index 8d10fdc..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 diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 5a96218..0ec2c89 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -27,7 +27,6 @@ # 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 @@ -149,7 +148,7 @@ 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 ( + if self.chip_id not in { _ATTINY806_HW_ID_CODE, _ATTINY807_HW_ID_CODE, _ATTINY816_HW_ID_CODE, @@ -157,42 +156,39 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): _ATTINY1616_HW_ID_CODE, _ATTINY1617_HW_ID_CODE, _SAMD09_HW_ID_CODE, - ): + }: raise RuntimeError( 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) + 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 + 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 in ( + elif self.chip_id in { _ATTINY817_HW_ID_CODE, _ATTINY807_HW_ID_CODE, _ATTINY1617_HW_ID_CODE, - ): - from adafruit_seesaw.attiny8x7 import ATtiny8x7_Pinmap + }: + from adafruit_seesaw.attiny8x7 import ATtiny8x7_Pinmap # noqa: PLC0415 self.pin_mapping = ATtiny8x7_Pinmap - # pylint: enable=import-outside-toplevel def sw_reset(self, post_reset_delay=0.5): """Trigger a software reset of the SeeSaw chip""" @@ -230,8 +226,8 @@ 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""" @@ -445,19 +441,19 @@ def disable_encoder_interrupt(self, encoder=0): def _get_eeprom_i2c_addr(self): """Return the EEPROM address used to store I2C address.""" chip_id = self.chip_id - if chip_id in ( + 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 ( + if chip_id in { _ATTINY1616_HW_ID_CODE, _ATTINY1617_HW_ID_CODE, - ): + }: return 0xFF - if chip_id in (_SAMD09_HW_ID_CODE,): + if chip_id in {_SAMD09_HW_ID_CODE}: return 0x3F return None diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 84d471b..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: @@ -44,7 +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 78ef207..2d5b517 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -65,9 +63,7 @@ creation_year = "2017" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " Dean Miller" author = "Dean Miller" diff --git a/examples/seesaw_analogin_test.py b/examples/seesaw_analogin_test.py index 97af324..52cbed3 100644 --- a/examples/seesaw_analogin_test.py +++ b/examples/seesaw_analogin_test.py @@ -6,9 +6,11 @@ # 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 i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller diff --git a/examples/seesaw_ano_rotary_7segment_demo.py b/examples/seesaw_ano_rotary_7segment_demo.py index 0930c13..862d92b 100644 --- a/examples/seesaw_ano_rotary_7segment_demo.py +++ b/examples/seesaw_ano_rotary_7segment_demo.py @@ -5,7 +5,8 @@ import board from adafruit_ht16k33 import segments -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 diff --git a/examples/seesaw_ano_rotary_simpletest.py b/examples/seesaw_ano_rotary_simpletest.py index 1fc845e..911c456 100644 --- a/examples/seesaw_ano_rotary_simpletest.py +++ b/examples/seesaw_ano_rotary_simpletest.py @@ -4,7 +4,8 @@ """I2C ANO 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 diff --git a/examples/seesaw_arcade_qt_multi_board.py b/examples/seesaw_arcade_qt_multi_board.py index cc602a5..0bf2264 100644 --- a/examples/seesaw_arcade_qt_multi_board.py +++ b/examples/seesaw_arcade_qt_multi_board.py @@ -1,10 +1,12 @@ # 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.seesaw import Seesaw + from adafruit_seesaw.digitalio import DigitalIO +from adafruit_seesaw.seesaw import Seesaw # For most boards. i2c = board.I2C() # uses board.SCL and board.SDA diff --git a/examples/seesaw_arcade_qt_simpletest.py b/examples/seesaw_arcade_qt_simpletest.py index 3b55180..29c0774 100644 --- a/examples/seesaw_arcade_qt_simpletest.py +++ b/examples/seesaw_arcade_qt_simpletest.py @@ -1,12 +1,15 @@ # 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.seesaw import Seesaw + 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 diff --git a/examples/seesaw_attiny_simpletest.py b/examples/seesaw_attiny_simpletest.py index f32e189..31dfb28 100644 --- a/examples/seesaw_attiny_simpletest.py +++ b/examples/seesaw_attiny_simpletest.py @@ -3,8 +3,11 @@ """ Simple seesaw test for ATtiny8x7 breakout using built-in LED on pin 5. """ + import time + import board + from adafruit_seesaw.seesaw import Seesaw i2c = board.I2C() # uses board.SCL and board.SDA diff --git a/examples/seesaw_crickit_test.py b/examples/seesaw_crickit_test.py index 971b0b8..b93d1c8 100644 --- a/examples/seesaw_crickit_test.py +++ b/examples/seesaw_crickit_test.py @@ -3,8 +3,9 @@ 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 @@ -151,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 @@ -169,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 6b64fac..f2a4819 100644 --- a/examples/seesaw_digitalio_test.py +++ b/examples/seesaw_digitalio_test.py @@ -10,10 +10,12 @@ # 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 i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller diff --git a/examples/seesaw_eeprom_test.py b/examples/seesaw_eeprom_test.py index e9835cb..ae8cb5e 100644 --- a/examples/seesaw_eeprom_test.py +++ b/examples/seesaw_eeprom_test.py @@ -6,7 +6,9 @@ # THE LAST BYTE IS USED FOR I2C ADDRESS CHANGE! import time + import board + from adafruit_seesaw import seesaw i2c_bus = board.I2C() # uses board.SCL and board.SDA diff --git a/examples/seesaw_gamepad_qt.py b/examples/seesaw_gamepad_qt.py index b6ed18b..adf9c4a 100644 --- a/examples/seesaw_gamepad_qt.py +++ b/examples/seesaw_gamepad_qt.py @@ -4,8 +4,10 @@ # SPDX-License-Identifier: MIT import time + import board from micropython import const + from adafruit_seesaw.seesaw import Seesaw BUTTON_X = const(6) diff --git a/examples/seesaw_neopixel_test.py b/examples/seesaw_neopixel_test.py index aa68b5f..4fbb107 100644 --- a/examples/seesaw_neopixel_test.py +++ b/examples/seesaw_neopixel_test.py @@ -11,9 +11,11 @@ # https://learn.adafruit.com/adafruit-attiny817-seesaw/neopixel import time + import board from rainbowio import colorwheel -from adafruit_seesaw import seesaw, neopixel + +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 diff --git a/examples/seesaw_pc_joystick.py b/examples/seesaw_pc_joystick.py index fc1c969..3c5735a 100644 --- a/examples/seesaw_pc_joystick.py +++ b/examples/seesaw_pc_joystick.py @@ -3,8 +3,10 @@ # SPDX-License-Identifier: MIT import time + import board from micropython import const + from adafruit_seesaw.seesaw import Seesaw BUTTON_1 = const(3) @@ -17,9 +19,7 @@ JOY2_X = const(0) JOY2_Y = const(16) -button_mask = const( - (1 << BUTTON_1) | (1 << BUTTON_2) | (1 << BUTTON_3) | (1 << BUTTON_4) -) +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. diff --git a/examples/seesaw_pwmout_test.py b/examples/seesaw_pwmout_test.py index 4efe1b5..ac98646 100644 --- a/examples/seesaw_pwmout_test.py +++ b/examples/seesaw_pwmout_test.py @@ -12,8 +12,10 @@ # https://learn.adafruit.com/adafruit-attiny817-seesaw/pwmout import time + import board -from adafruit_seesaw import seesaw, pwmout + +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 @@ -26,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 index 6a6196f..ca0cc2f 100644 --- a/examples/seesaw_quadrotary.py +++ b/examples/seesaw_quadrotary.py @@ -2,13 +2,15 @@ # SPDX-License-Identifier: MIT """Quad I2C rotary encoder NeoPixel color picker example.""" + import board -from rainbowio import colorwheel import digitalio -import adafruit_seesaw.seesaw +from rainbowio import colorwheel + +import adafruit_seesaw.digitalio import adafruit_seesaw.neopixel import adafruit_seesaw.rotaryio -import adafruit_seesaw.digitalio +import adafruit_seesaw.seesaw # For boards/chips that don't handle clock-stretching well, try running I2C at 50KHz # import busio @@ -36,9 +38,7 @@ 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. + if rotary_pos > last_positions[n]: # Advance forward through the colorwheel. colors[n] += 8 else: colors[n] -= 8 # Advance backward through the colorwheel. diff --git a/examples/seesaw_rotary_multiples.py b/examples/seesaw_rotary_multiples.py index e5fbb8b..2e9f21c 100644 --- a/examples/seesaw_rotary_multiples.py +++ b/examples/seesaw_rotary_multiples.py @@ -5,7 +5,8 @@ # solder the A0 jumper on the second QT Rotary Encoder board import board -from adafruit_seesaw import seesaw, rotaryio, digitalio, neopixel + +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 @@ -43,7 +44,7 @@ if position1 != last_position1: last_position1 = position1 - print("Position 1: {}".format(position1)) + print(f"Position 1: {position1}") if not button1.value and not button_held1: button_held1 = True @@ -57,7 +58,7 @@ if position2 != last_position2: last_position2 = position2 - print("Position 2: {}".format(position2)) + print(f"Position 2: {position2}") if not button2.value and not button_held2: button_held2 = True diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index d37772c..4577a1b 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -2,10 +2,11 @@ # 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 @@ -42,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 0b22085..3e929f9 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -4,7 +4,8 @@ """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 @@ -16,7 +17,7 @@ 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") @@ -36,7 +37,7 @@ 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 4f85270..f0918f4 100644 --- a/examples/seesaw_simpletest.py +++ b/examples/seesaw_simpletest.py @@ -8,6 +8,7 @@ import time import board + from adafruit_seesaw.seesaw import Seesaw i2c_bus = board.I2C() # uses board.SCL and board.SDA 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"