From 2f0f8f35062d7a097a4aaa544295eb1b56a442e1 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 21 Dec 2018 13:27:35 -0600 Subject: [PATCH 001/182] change 'travis-ci.org' to 'travis-ci.com' --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 145c6d6..5d9fbc3 100644 --- a/README.rst +++ b/README.rst @@ -10,8 +10,8 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord -.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_seesaw.svg?branch=master - :target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_seesaw +.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_seesaw.svg?branch=master + :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_seesaw :alt: Build Status CircuitPython module for use with the Adafruit ATSAMD09 seesaw. From e6049408d79c60ed3a71e27b4a543ea02c1ba2f6 Mon Sep 17 00:00:00 2001 From: Carter Nelson Date: Fri, 22 Feb 2019 01:06:56 +0000 Subject: [PATCH 002/182] add retry for moisture read --- adafruit_seesaw/seesaw.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 63e3258..2af8325 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -236,6 +236,17 @@ def moisture_read(self): self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, .005) ret = struct.unpack(">H", buf)[0] time.sleep(.001) + + # retry if reading was bad + count = 0 + while ret > 4095: + self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, .005) + ret = struct.unpack(">H", buf)[0] + time.sleep(.001) + count += 1 + if count > 3: + raise RuntimeError("Could not get a valid moisture reading.") + return ret def pin_mode_bulk(self, pins, mode): From b2f3210f687b64bf480a19cfb6ad5b92918f21ee Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 18 Mar 2019 21:55:11 -0700 Subject: [PATCH 003/182] Added MiniTFT FeatherWing Example and renamed files --- docs/examples.rst | 21 +++++++ ...crickit_test.py => seesaw_crickit_test.py} | 0 ...atherwing.py => seesaw_joy_featherwing.py} | 0 examples/seesaw_minitft_featherwing.py | 58 +++++++++++++++++++ ...impletest.py => seesaw_soil_simpletest.py} | 0 5 files changed, 79 insertions(+) rename examples/{crickit_test.py => seesaw_crickit_test.py} (100%) rename examples/{Joy_Featherwing.py => seesaw_joy_featherwing.py} (100%) create mode 100644 examples/seesaw_minitft_featherwing.py rename examples/{soil_simpletest.py => seesaw_soil_simpletest.py} (100%) diff --git a/docs/examples.rst b/docs/examples.rst index 3b2e7d0..b2dd1fb 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,24 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/seesaw_simpletest.py :caption: examples/seesaw_simpletest.py :linenos: + +Other Examples +--------------- + +Here are some other examples using the Seesaw library + +.. literalinclude:: ../examples/seesaw_crickit_test.py + :caption: examples/seesaw_crickit_test.py + :linenos: + +.. literalinclude:: ../examples/seesaw_joy_featherwing.py + :caption: examples/seesaw_joy_featherwing.py + :linenos: + +.. literalinclude:: ../examples/seesaw_soil_simpletest.py + :caption: examples/seesaw_soil_simpletest.py + :linenos: + +.. literalinclude:: ../examples/seesaw_minitft_featherwing.py + :caption: examples/seesaw_minitft_featherwing.py + :linenos: diff --git a/examples/crickit_test.py b/examples/seesaw_crickit_test.py similarity index 100% rename from examples/crickit_test.py rename to examples/seesaw_crickit_test.py diff --git a/examples/Joy_Featherwing.py b/examples/seesaw_joy_featherwing.py similarity index 100% rename from examples/Joy_Featherwing.py rename to examples/seesaw_joy_featherwing.py diff --git a/examples/seesaw_minitft_featherwing.py b/examples/seesaw_minitft_featherwing.py new file mode 100644 index 0000000..fbec202 --- /dev/null +++ b/examples/seesaw_minitft_featherwing.py @@ -0,0 +1,58 @@ +import time + +import board +from micropython import const + +from adafruit_seesaw.seesaw import Seesaw + +# pylint: disable=bad-whitespace +BUTTON_RIGHT = const(7) +BUTTON_DOWN = const(4) +BUTTON_LEFT = const(3) +BUTTON_UP = const(2) +BUTTON_SEL = const(11) +BUTTON_A = const(10) +BUTTON_B = const(9) + +# pylint: enable=bad-whitespace +button_mask = const((1 << BUTTON_RIGHT) | + (1 << BUTTON_DOWN) | + (1 << BUTTON_LEFT) | + (1 << BUTTON_UP) | + (1 << BUTTON_SEL) | + (1 << BUTTON_A) | + (1 << BUTTON_B)) + +i2c_bus = board.I2C() + +ss = Seesaw(i2c_bus, 0x5E) + +ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP) + +last_x = 0 +last_y = 0 + +while True: + buttons = ss.digital_read_bulk(button_mask) + if not buttons & (1 << BUTTON_RIGHT): + print("Button RIGHT pressed") + + if not buttons & (1 << BUTTON_DOWN): + print("Button DOWN pressed") + + if not buttons & (1 << BUTTON_LEFT): + print("Button LEFT pressed") + + if not buttons & (1 << BUTTON_UP): + print("Button UP pressed") + + if not buttons & (1 << BUTTON_SEL): + print("Button SEL pressed") + + if not buttons & (1 << BUTTON_A): + print("Button A pressed") + + if not buttons & (1 << BUTTON_B): + print("Button B pressed") + + time.sleep(.01) diff --git a/examples/soil_simpletest.py b/examples/seesaw_soil_simpletest.py similarity index 100% rename from examples/soil_simpletest.py rename to examples/seesaw_soil_simpletest.py From c40e40db597c365b1ee0fe8c522c1c7f4de6835b Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 9 Apr 2019 23:00:12 -0700 Subject: [PATCH 004/182] Removed unused lines from example --- examples/seesaw_minitft_featherwing.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/seesaw_minitft_featherwing.py b/examples/seesaw_minitft_featherwing.py index fbec202..60a1da9 100644 --- a/examples/seesaw_minitft_featherwing.py +++ b/examples/seesaw_minitft_featherwing.py @@ -29,9 +29,6 @@ ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP) -last_x = 0 -last_y = 0 - while True: buttons = ss.digital_read_bulk(button_mask) if not buttons & (1 << BUTTON_RIGHT): From 5947fb977df98bca1f9b0da93f2215709b2638c5 Mon Sep 17 00:00:00 2001 From: wallarug Date: Sat, 27 Apr 2019 23:21:21 +1000 Subject: [PATCH 005/182] added robohatmm1 board to seesaw library --- adafruit_seesaw/robohat.py | 93 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 adafruit_seesaw/robohat.py diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py new file mode 100644 index 0000000..72b2226 --- /dev/null +++ b/adafruit_seesaw/robohat.py @@ -0,0 +1,93 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 wallarug for Robotics Masters +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods + +from micropython import const + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" + + +# The ordering here reflects the seesaw firmware (mm1_hat) pinmap for Robo HAT MM1, +# not logical ordering of the HAT terminals. + +_MM1_D0 = const(55) # (RX to RPI_TX) +_MM1_D1 = const(54) # (TX to RPI_RX) +_MM1_D2 = const(34) # ADC (GPS_TX) +_MM1_D3 = const(35) # ADC (GPS_RX) +_MM1_D4 = const(0) # (GPS_SDA) +_MM1_D5 = const(1) # (GPS_SCL) +_MM1_D6 = const(28) # (POWER_ENABLE) +_MM1_D7 = const(2) # (BATTERY) +_MM1_D8 = const(20) # (NEOPIXEL) +_MM1_D9 = const(43) # PWM (SPI_SCK) +_MM1_D10 = const(41) # PWM (SPI_SS) +_MM1_D11 = const(42) # PWM (SPI_MOSI) +_MM1_D12 = const(40) # PWM (SPI_MISO) +_MM1_D13 = const(21) # LED +_MM1_D14 = const(3) # (POWER_OFF) + +_MM1_SERVO8 = const(8) +_MM1_SERVO7 = const(9) +_MM1_SERVO6 = const(10) +_MM1_SERVO5 = const(11) +_MM1_SERVO4 = const(19) +_MM1_SERVO3 = const(18) +_MM1_SERVO2 = const(17) +_MM1_SERVO1 = const(16) + +_MM1_RCH1 = const(7) +_MM1_RCH2 = const(6) +_MM1_RCH3 = const(5) +_MM1_RCH4 = const(4) + + +# seesaw firmware has indexed lists of pins by function. +# These "pin" numbers map to real PAxx, PBxx pins on the board implementing seesaaw +# They may or may not match. +# See seesaw/include/SeesawConfig.h and seesaw/boards/robohatmm1/board_config.h for the pin choices. + +# You must look at both files and combine the defaults in SeesawConfig.h with the +# overrides in robohatmm1/board_config.h. +# PA pins are nn +# PB pins are 32+nn + +class MM1_Pinmap: + # seesaw firmware (mm1_hat) analog pin map: + # analog[0]:47 analog[1]:48 analog[2]: analog[3]: + # analog[4]: analog[5]: analog[6]: analog[7]: + # + analog_pins = (_MM1_SIGNAL3, _MM1_SIGNAL2) + + pwm_width = 16 + + # seesaw firmware (mm1_hat) pwm pin map: + # pwm[0]: pwm[1]: pwm[2]: pwm[3]: pwm[4]: pwm[5]: + # pwm[6]: pwm[7]: pwm[8]: pwm[9]: pwm[10]: pwm[11]: + # + pwm_pins = (_MM1_SERVO1, _MM1_SERVO2, _MM1_SERVO3, _MM1_SERVO4, + _MM1_SERVO5, _MM1_SERVO6, _MM1_SERVO7, _MM1_SERVO8, + _MM1_SIGNAL12, _MM1_SIGNAL10, _MM1_SIGNAL11, _MM1_SIGNAL9) + + # seesaw firmware touch pin map: + # touch[0]: 7 touch[1]: 6 touch[2]: 5 touch[3]: 4 + touch_pins = (_MM1_RCH1, _MM1_RCH2, _MM1_RCH3, _MM1_RCH4) From 8c94d5ee746d0b9f215fc4a23a6d91a129ef5a95 Mon Sep 17 00:00:00 2001 From: wallarug Date: Sat, 27 Apr 2019 23:25:57 +1000 Subject: [PATCH 006/182] updated names --- adafruit_seesaw/robohat.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py index 72b2226..bf22eea 100644 --- a/adafruit_seesaw/robohat.py +++ b/adafruit_seesaw/robohat.py @@ -26,6 +26,7 @@ __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 # The ordering here reflects the seesaw firmware (mm1_hat) pinmap for Robo HAT MM1, # not logical ordering of the HAT terminals. @@ -76,17 +77,17 @@ class MM1_Pinmap: # analog[0]:47 analog[1]:48 analog[2]: analog[3]: # analog[4]: analog[5]: analog[6]: analog[7]: # - analog_pins = (_MM1_SIGNAL3, _MM1_SIGNAL2) + analog_pins = (_MM1_D3, _MM1_D2) pwm_width = 16 # seesaw firmware (mm1_hat) pwm pin map: - # pwm[0]: pwm[1]: pwm[2]: pwm[3]: pwm[4]: pwm[5]: - # pwm[6]: pwm[7]: pwm[8]: pwm[9]: pwm[10]: pwm[11]: + # pwm[0]:16 pwm[1]:17 pwm[2]:18 pwm[3]:19 pwm[4]:11 pwm[5]:10 + # pwm[6]:9 pwm[7]:8 pwm[8]:40 pwm[9]:41 pwm[10]:42 pwm[11]:43 # pwm_pins = (_MM1_SERVO1, _MM1_SERVO2, _MM1_SERVO3, _MM1_SERVO4, _MM1_SERVO5, _MM1_SERVO6, _MM1_SERVO7, _MM1_SERVO8, - _MM1_SIGNAL12, _MM1_SIGNAL10, _MM1_SIGNAL11, _MM1_SIGNAL9) + _MM1_D12, _MM1_D10, _MM1_D11, _MM1_D9) # seesaw firmware touch pin map: # touch[0]: 7 touch[1]: 6 touch[2]: 5 touch[3]: 4 From 19db4e54674b6f54668dcb578dec94a5d779def2 Mon Sep 17 00:00:00 2001 From: wallarug Date: Sun, 28 Apr 2019 00:04:34 +1000 Subject: [PATCH 007/182] changes to seesaw.py --- adafruit_seesaw/seesaw.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 2af8325..19ea3ad 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -121,6 +121,7 @@ #TODO: update when we get real PID _CRICKIT_PID = const(9999) +_ROBOHATMM1_PID = const(9998) class Seesaw: """Driver for Seesaw i2c generic conversion trip @@ -156,6 +157,9 @@ def sw_reset(self): if pid == _CRICKIT_PID: from adafruit_seesaw.crickit import Crickit_Pinmap self.pin_mapping = Crickit_Pinmap + elif pid == _ROBOHATMM1_PID: + from adafruit_seesaw.robohat import MM1_Pinmap + self.pin_mapping = MM1_Pinmap else: from adafruit_seesaw.samd09 import SAMD09_Pinmap self.pin_mapping = SAMD09_Pinmap From 8c8b5879ae66874b94e7620811799a725b7514d5 Mon Sep 17 00:00:00 2001 From: wallarug Date: Sun, 28 Apr 2019 02:53:44 +1000 Subject: [PATCH 008/182] Fixed whitespace complains from Travis. --- adafruit_seesaw/seesaw.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 19ea3ad..afdaf19 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -157,9 +157,9 @@ def sw_reset(self): if pid == _CRICKIT_PID: from adafruit_seesaw.crickit import Crickit_Pinmap self.pin_mapping = Crickit_Pinmap - elif pid == _ROBOHATMM1_PID: - from adafruit_seesaw.robohat import MM1_Pinmap - self.pin_mapping = MM1_Pinmap + elif pid == _ROBOHATMM1_PID: + from adafruit_seesaw.robohat import MM1_Pinmap + self.pin_mapping = MM1_Pinmap else: from adafruit_seesaw.samd09 import SAMD09_Pinmap self.pin_mapping = SAMD09_Pinmap From b8d95d488d437cfd234a86e2c570304fa9ed2f04 Mon Sep 17 00:00:00 2001 From: wallarug Date: Sun, 28 Apr 2019 02:55:35 +1000 Subject: [PATCH 009/182] Fix travis complaint. --- adafruit_seesaw/robohat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py index bf22eea..cf5601b 100644 --- a/adafruit_seesaw/robohat.py +++ b/adafruit_seesaw/robohat.py @@ -40,7 +40,7 @@ _MM1_D6 = const(28) # (POWER_ENABLE) _MM1_D7 = const(2) # (BATTERY) _MM1_D8 = const(20) # (NEOPIXEL) -_MM1_D9 = const(43) # PWM (SPI_SCK) +_MM1_D9 = const(43) # PWM (SPI_SCK) _MM1_D10 = const(41) # PWM (SPI_SS) _MM1_D11 = const(42) # PWM (SPI_MOSI) _MM1_D12 = const(40) # PWM (SPI_MISO) From d18c2ec18c90b4a49dcccf1a745a6dc4e2921f98 Mon Sep 17 00:00:00 2001 From: wallarug Date: Sun, 28 Apr 2019 02:57:45 +1000 Subject: [PATCH 010/182] more whitespace rule fixes. --- adafruit_seesaw/robohat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py index cf5601b..6cf3cc3 100644 --- a/adafruit_seesaw/robohat.py +++ b/adafruit_seesaw/robohat.py @@ -39,7 +39,7 @@ _MM1_D5 = const(1) # (GPS_SCL) _MM1_D6 = const(28) # (POWER_ENABLE) _MM1_D7 = const(2) # (BATTERY) -_MM1_D8 = const(20) # (NEOPIXEL) +_MM1_D8 = const(20) # (NEOPIXEL) _MM1_D9 = const(43) # PWM (SPI_SCK) _MM1_D10 = const(41) # PWM (SPI_SS) _MM1_D11 = const(42) # PWM (SPI_MOSI) @@ -74,9 +74,9 @@ class MM1_Pinmap: # seesaw firmware (mm1_hat) analog pin map: - # analog[0]:47 analog[1]:48 analog[2]: analog[3]: + # analog[0]:47 analog[1]:48 analog[2]: analog[3]: # analog[4]: analog[5]: analog[6]: analog[7]: - # + # analog_pins = (_MM1_D3, _MM1_D2) pwm_width = 16 From e34ccd6625c88405f3c492e200c44ca81c291a52 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 23 Jun 2019 05:29:24 -0400 Subject: [PATCH 011/182] add delay to I2Cread for temperature reading --- 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 afdaf19..6be55df 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -328,7 +328,7 @@ def analog_write(self, pin, value): def get_temp(self): buf = bytearray(4) - self.read(_STATUS_BASE, _STATUS_TEMP, buf) + self.read(_STATUS_BASE, _STATUS_TEMP, buf, .005) buf[0] = buf[0] & 0x3F ret = struct.unpack(">I", buf)[0] return 0.00001525878 * ret From e0fd3df23272328cd35e247d07ee42eb8bf2506a Mon Sep 17 00:00:00 2001 From: Sterling Hanenkamp Date: Mon, 8 Jul 2019 20:59:16 -0500 Subject: [PATCH 012/182] Eliminate duplicated code in pin_mode_bulk* --- adafruit_seesaw/seesaw.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 6be55df..0e0cce5 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -253,8 +253,9 @@ def moisture_read(self): return ret - def pin_mode_bulk(self, pins, mode): - cmd = struct.pack(">I", pins) + def _pin_mode_bulk_x(self, capacity, offset, pins, mode): + cmd = bytearray(capacity) + cmd[offset:] = struct.pack(">I", pins) if mode == self.OUTPUT: self.write(_GPIO_BASE, _GPIO_DIRSET_BULK, cmd) elif mode == self.INPUT: @@ -273,26 +274,11 @@ def pin_mode_bulk(self, pins, mode): else: raise ValueError("Invalid pin mode") - def pin_mode_bulk_b(self, pins, mode): - cmd = bytearray(8) - cmd[4:] = struct.pack(">I", pins) - if mode == self.OUTPUT: - self.write(_GPIO_BASE, _GPIO_DIRSET_BULK, cmd) - elif mode == self.INPUT: - self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd) - - elif mode == self.INPUT_PULLUP: - self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd) - self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd) - self.write(_GPIO_BASE, _GPIO_BULK_SET, cmd) - - elif mode == self.INPUT_PULLDOWN: - self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd) - self.write(_GPIO_BASE, _GPIO_PULLENSET, cmd) - self.write(_GPIO_BASE, _GPIO_BULK_CLR, cmd) + def pin_mode_bulk(self, pins, mode): + self._pin_mode_bulk_x(4, 0, pins, mode) - else: - raise ValueError("Invalid pin mode") + def pin_mode_bulk_b(self, pins, mode): + self._pin_mode_bulk_x(8, 4, pins, mode) def digital_write_bulk(self, pins, value): cmd = struct.pack(">I", pins) From bf78e7dff75a29177c3d18caaa337a1b5479d8d5 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 25 Jul 2019 15:42:52 -0700 Subject: [PATCH 013/182] Added file for 1.8 inch TFT Shield --- .gitignore | 6 ++ adafruit_seesaw/tftshield18.py | 100 +++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100755 adafruit_seesaw/tftshield18.py diff --git a/.gitignore b/.gitignore index 0dd8629..cc1a9c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,12 @@ +*.mpy +.idea __pycache__ _build *.pyc .env build* bundles +*.DS_Store +.eggs +dist +**/*.egg-info diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py new file mode 100755 index 0000000..14ede8d --- /dev/null +++ b/adafruit_seesaw/tftshield18.py @@ -0,0 +1,100 @@ +# The MIT License (MIT) +# +# Copyright (c) 2018 Dean Miller for Adafruit Industries +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# pylint: disable=missing-docstring,invalid-name,too-many-public-methods + +from collections import namedtuple +import board +from micropython import const +from adafruit_seesaw.seesaw import Seesaw + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" + +_TIMER_BASE = const(0x08) +_TIMER_PWM = const(0x01) +_TIMER_FREQ = const(0x02) + +_TFTSHIELD_RESET_PIN = const(3) + +_BUTTON_UP = const(5) +_BUTTON_DOWN = const(8) +_BUTTON_LEFT = const(6) +_BUTTON_RIGHT = const(9) +_BUTTON_SELECT = const(7) +_BUTTON_A = const(10) +_BUTTON_B = const(11) +_BUTTON_C = const(14) + +Buttons = namedtuple("Buttons", "right down left up select a b c") + +class TFTShield18(Seesaw): + + _BACKLIGHT_ON = b"\xFF\xFF" + _BACKLIGHT_OFF = b"\x00\x00" + + _button_mask = ((1 << _BUTTON_RIGHT) | + (1 << _BUTTON_DOWN) | + (1 << _BUTTON_LEFT) | + (1 << _BUTTON_UP) | + (1 << _BUTTON_SELECT) | + (1 << _BUTTON_A) | + (1 << _BUTTON_B) | + (1 << _BUTTON_C)) + + def __init__(self, i2c_bus=board.I2C(), addr=0x2E): + super(TFTShield18, self).__init__(i2c_bus, addr) + self.pin_mode(_TFTSHIELD_RESET_PIN, self.OUTPUT) + self.pin_mode_bulk(self._button_mask, self.INPUT_PULLUP) + + def set_backlight(self, value): + """ + Set the backlight on + """ + if not isinstance(value, bool): + raise ValueError("Value must be of boolean type") + command = self._BACKLIGHT_ON if value else self._BACKLIGHT_OFF + self.write(_TIMER_BASE, _TIMER_PWM, b"\x00" + command) + + def set_backlight_freq(self, freq): + """ + Set the backlight frequency of the TFT Display + """ + if not isinstance(freq, int): + raise ValueError("Value must be of integer type") + value = b"\x00" + bytearray((freq >> 8) & 0xFF, freq & 0xFF) + self.write(_TIMER_BASE, _TIMER_FREQ, value) + + def tft_reset(self, rst=True): + """ + Reset the TFT Display + """ + self.digital_write(_TFTSHIELD_RESET_PIN, rst) + + @property + def buttons(self): + """ + Return a set of buttons with current push values + """ + button_values = self.digital_read_bulk(self._button_mask) + return Buttons(*[not button_values & (1 << button) for button in + (_BUTTON_RIGHT, _BUTTON_DOWN, _BUTTON_LEFT, _BUTTON_UP, + _BUTTON_SELECT, _BUTTON_A, _BUTTON_B, _BUTTON_C)]) From 7af662b74aaecca1b82d3299ba9de3cd558a37a9 Mon Sep 17 00:00:00 2001 From: Carter Nelson Date: Wed, 21 Aug 2019 04:04:19 +0100 Subject: [PATCH 014/182] fix white getting set 0 --- 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 e3d0410..a994901 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -99,7 +99,7 @@ def __setitem__(self, 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: + if self._bpp == 4 and r == g == b and w == 0: w = r r = 0 g = 0 From 395e86a284e5772cc31f18520ea06d0d4a4fe9ec Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Sun, 15 Sep 2019 13:54:42 -0700 Subject: [PATCH 015/182] Increased default delay because faster cp means it crashes sometimes --- 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 0e0cce5..2f57a7e 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -372,7 +372,7 @@ def read8(self, reg_base, reg): self.read(reg_base, reg, ret) return ret[0] - def read(self, reg_base, reg, buf, delay=.001): + def read(self, reg_base, reg, buf, delay=.003): self.write(reg_base, reg) if self._drdy is not None: while self._drdy.value is False: From 1b6ccba5cdf7d8ca46cbe5985f0986c810987ece Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 17 Sep 2019 18:03:57 -0700 Subject: [PATCH 016/182] Increased read delay for MiniTFT FeatherWing --- 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 2f57a7e..1675228 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -372,7 +372,7 @@ def read8(self, reg_base, reg): self.read(reg_base, reg, ret) return ret[0] - def read(self, reg_base, reg, buf, delay=.003): + def read(self, reg_base, reg, buf, delay=.005): self.write(reg_base, reg) if self._drdy is not None: while self._drdy.value is False: From e178844ee7661b2e1a39690f193fcd0d9cd4c2fb Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Thu, 17 Oct 2019 20:19:33 -0400 Subject: [PATCH 017/182] Removed building locally section from README, replaced with documentation section --- README.rst | 48 +++--------------------------------------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/README.rst b/README.rst index 5d9fbc3..6018dc1 100644 --- a/README.rst +++ b/README.rst @@ -39,49 +39,7 @@ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. -Building locally -================ - -To build this library locally you'll need to install the -`circuitpython-build-tools `_ package. - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip install circuitpython-build-tools - -Once installed, make sure you are in the virtual environment: - -.. code-block:: shell - - source .env/bin/activate - -Then run the build: - -.. code-block:: shell - - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-seesaw --library_location . - -Sphinx documentation ------------------------ - -Sphinx is used to build the documentation based on rST files and comments in the code. First, -install dependencies (feel free to reuse the virtual environment from above): - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip install Sphinx sphinx-rtd-theme - -Now, once you have the virtual environment activated: - -.. code-block:: shell - - cd docs - sphinx-build -E -W -b html . _build/html +Documentation +============= -This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to -view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to -locally verify it will pass. \ No newline at end of file +For information on building library documentation, please check out `this guide `_. From 002bb88e1f32d9462e43a97ae784824fff7e2f09 Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Fri, 18 Oct 2019 10:45:52 -0400 Subject: [PATCH 018/182] Added PyPi installation instructions --- README.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.rst b/README.rst index 6018dc1..486be22 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,31 @@ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading `the Adafruit library and driver bundle `_. +Installing from PyPI +==================== + +On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from +PyPI `_. To install for current user: + +.. code-block:: shell + + pip3 install adafruit-circuitpython-seesaw + +To install system-wide (this may be required in some cases): + +.. code-block:: shell + + sudo pip3 install adafruit-circuitpython-seesaw + +To install in a virtual environment in your current project: + +.. code-block:: shell + + mkdir project-name && cd project-name + python3 -m venv .env + source .env/bin/activate + pip3 install adafruit-circuitpython-seesaw + Usage Example ============= From fe4c7b15836691a2dc83c0608871ca26d68faf92 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 28 Dec 2019 21:05:59 -0600 Subject: [PATCH 019/182] Improve documentation --- adafruit_seesaw/analoginput.py | 14 +++++++++++ adafruit_seesaw/crickit.py | 10 +++++++- adafruit_seesaw/digitalio.py | 20 ++++++++++++++++ adafruit_seesaw/keypad.py | 35 ++++++++++++++++++++++++++- adafruit_seesaw/neopixel.py | 23 +++++++++++++++++- adafruit_seesaw/pwmout.py | 7 +++++- adafruit_seesaw/robohat.py | 18 +++++++++++++- adafruit_seesaw/samd09.py | 19 ++++++++++++++- adafruit_seesaw/seesaw.py | 43 ++++++++++++++++++++++++++++++---- adafruit_seesaw/tftshield18.py | 33 +++++++++++++++++++------- docs/api.rst | 34 +++++++++++++++++++++++++++ docs/conf.py | 9 ++++++- 12 files changed, 244 insertions(+), 21 deletions(-) diff --git a/adafruit_seesaw/analoginput.py b/adafruit_seesaw/analoginput.py index 548eadd..55acb72 100644 --- a/adafruit_seesaw/analoginput.py +++ b/adafruit_seesaw/analoginput.py @@ -21,10 +21,22 @@ # THE SOFTWARE. # pylint: disable=missing-docstring,invalid-name,too-many-public-methods +""" +`adafruit_seesaw.analoginput` +==================================================== +""" + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" class AnalogInput: + """CircuitPython-compatible class for analog inputs + + This class is intended to be a compatible subset of `analogio.AnalogIn` + + :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device + :param int pin: The pin number on the device +""" def __init__(self, seesaw, pin): self._seesaw = seesaw self._pin = pin @@ -34,8 +46,10 @@ 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) @property def reference_voltage(self): + """The reference voltage for the pin""" return 3.3 diff --git a/adafruit_seesaw/crickit.py b/adafruit_seesaw/crickit.py index 0e52d41..6f415e5 100644 --- a/adafruit_seesaw/crickit.py +++ b/adafruit_seesaw/crickit.py @@ -21,7 +21,15 @@ # THE SOFTWARE. # pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods -from micropython import const +""" +`adafruit_seesaw.crickit` - Pin definition for Adafruit CRICKIT +=============================================================== +""" + +try: + from micropython import const +except ImportError: + def const(x): return x __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" diff --git a/adafruit_seesaw/digitalio.py b/adafruit_seesaw/digitalio.py index 45ccd4c..7e77819 100644 --- a/adafruit_seesaw/digitalio.py +++ b/adafruit_seesaw/digitalio.py @@ -21,12 +21,26 @@ # THE SOFTWARE. # pylint: disable=missing-docstring,invalid-name,too-many-public-methods +""" +`adafruit_seesaw.digitalio` +==================================================== +""" + import digitalio __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" class DigitalIO: + """CircuitPython-compatible class for digital I/O pins + + This class is intended to be a compatible subset of `digitalio.DigitalInOut`. + + Due to technical limitations, PULL_DOWNs are not supported. + + :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device + :param int pin: The pin number on the device +""" def __init__(self, seesaw, pin): self._seesaw = seesaw self._pin = pin @@ -39,12 +53,14 @@ def deinit(self): pass def switch_to_output(self, value=False, drive_mode=digitalio.DriveMode.PUSH_PULL): + """Switch the pin to output mode""" self._seesaw.pin_mode(self._pin, self._seesaw.OUTPUT) self._seesaw.digital_write(self._pin, value) self._drive_mode = drive_mode self._pull = None def switch_to_input(self, pull=None): + """Switch the pin to input mode""" if pull == digitalio.Pull.DOWN: raise ValueError("Pull Down currently not supported") elif pull == digitalio.Pull.UP: @@ -55,6 +71,7 @@ def switch_to_input(self, pull=None): @property def direction(self): + """Retrieve or set the direction of the pin""" return self._direction @direction.setter @@ -69,6 +86,7 @@ def direction(self, value): @property def value(self): + """Retrieve or set the value of the pin""" if self._direction == digitalio.Direction.OUTPUT: return self._value return self._seesaw.digital_read(self._pin) @@ -82,6 +100,7 @@ def value(self, val): @property def drive_mode(self): + """Retrieve or set the drive mode of an output pin""" return self._drive_mode @drive_mode.setter @@ -90,6 +109,7 @@ def drive_mode(self, mode): @property def pull(self): + """Retrieve or set the pull mode of an input pin""" return self._pull @pull.setter diff --git a/adafruit_seesaw/keypad.py b/adafruit_seesaw/keypad.py index 414708b..c05bb10 100644 --- a/adafruit_seesaw/keypad.py +++ b/adafruit_seesaw/keypad.py @@ -21,7 +21,15 @@ # THE SOFTWARE. # pylint: disable=missing-docstring,invalid-name,too-many-public-methods -from micropython import const +""" +`adafruit_seesaw.keypad` +==================================================== +""" + +try: + from micropython import const +except ImportError: + def const(x): return x from adafruit_seesaw.seesaw import Seesaw __version__ = "0.0.0-auto.0" @@ -38,16 +46,30 @@ # pylint: disable=too-few-public-methods class KeyEvent: + """Holds information about a key event in its properties + + :param int num: The number of the key + :param int edge: One of the EDGE propertes of `adafruit_seesaw.keypad.Keypad` + """ def __init__(self, num, edge): self.number = int(num) self.edge = int(edge) # pylint: enable=too-few-public-methods class Keypad(Seesaw): + """On compatible SeeSaw devices, reads from a keypad. + + :param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to + :param int addr: I2C address of the SeeSaw device + :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output""" + """Indicates that the key is currently pressed""" EDGE_HIGH = 0 + """Indicates that the key is currently released""" EDGE_LOW = 1 + """Indicates that the key was recently pressed""" EDGE_FALLING = 2 + """Indicates that the key was recently released""" EDGE_RISING = 3 def __init__(self, i2c_bus, addr=0x49, drdy=None): @@ -56,6 +78,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None): @property def interrupt_enabled(self): + """Retrieve or set the interrupt enable flag""" return self._interrupt_enabled @interrupt_enabled.setter @@ -71,6 +94,7 @@ def interrupt_enabled(self, value): @property def count(self): + """Retrieve or set the number of keys""" return self.read8(_KEYPAD_BASE, _KEYPAD_COUNT) # pylint: disable=unused-argument, no-self-use @@ -80,6 +104,12 @@ def count(self, value): # pylint: enable=unused-argument, no-self-use def set_event(self, key, edge, enable): + """Control which kinds of events are set + + :param int key: The key number + :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): raise ValueError("event enable must be True or False") if edge > 3 or edge < 0: @@ -92,6 +122,9 @@ def set_event(self, key, edge, enable): self.write(_KEYPAD_BASE, _KEYPAD_EVENT, cmd) def read_keypad(self, num): + """Read data from the keypad + + :param int num: The number of bytes to read""" ret = bytearray(num) self.read(_KEYPAD_BASE, _KEYPAD_FIFO, ret) return ret diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index a994901..35586f6 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -21,11 +21,19 @@ # THE SOFTWARE. # pylint: disable=missing-docstring,invalid-name,too-many-public-methods +""" +`adafruit_seesaw.neopixel` +==================================================== +""" + try: import struct except ImportError: import ustruct as struct -from micropython import const +try: + from micropython import const +except ImportError: + def const(x): return x __version__ = "1.2.3" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -50,6 +58,16 @@ """Green Red Blue White""" class NeoPixel: + """Control NeoPixels connected to a seesaw + + :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device + :param int pin: The pin number on the device + :param int n: The number of pixels + :param int bpp: The number of bytes per pixel + :param float brightness: The brightness, from 0.0 to 1.0 + :param bool auto_write: Automatically update the pixels when changed + :param tuple pixel_order: The layout of the pixels. Use one of the order constants such as RGBW. +""" def __init__(self, seesaw, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_order=None): # TODO: brightness not yet implemented. self._seesaw = seesaw @@ -84,6 +102,7 @@ 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): @@ -127,6 +146,7 @@ def __getitem__(self, key): pass 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 @@ -137,4 +157,5 @@ def fill(self, color): 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) diff --git a/adafruit_seesaw/pwmout.py b/adafruit_seesaw/pwmout.py index 1ab5457..0eacf44 100644 --- a/adafruit_seesaw/pwmout.py +++ b/adafruit_seesaw/pwmout.py @@ -21,6 +21,11 @@ # THE SOFTWARE. # pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods +""" +`adafruit_seesaw.pwmout` +==================================================== +""" + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -34,7 +39,7 @@ def __init__(self, seesaw, pin): @property def frequency(self): - """The overall PWM frequency in herz.""" + """The overall PWM frequency in Hertz.""" return self._frequency @frequency.setter diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py index 6cf3cc3..12b9cbe 100644 --- a/adafruit_seesaw/robohat.py +++ b/adafruit_seesaw/robohat.py @@ -21,7 +21,15 @@ # THE SOFTWARE. # pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods -from micropython import const +""" +`adafruit_seesaw.robohat` - Pin definition for RoboHAT +====================================================== +""" + +try: + from micropython import const +except ImportError: + def const(x): return x __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -73,22 +81,30 @@ # PB pins are 32+nn class MM1_Pinmap: + """This class is automatically used by `adafruit_seesaw.seesaw.Seesaw` when + a RoboHAT board is detected. + + It is also a reference for the capabilities of each pin.""" # seesaw firmware (mm1_hat) analog pin map: # analog[0]:47 analog[1]:48 analog[2]: analog[3]: # analog[4]: analog[5]: analog[6]: analog[7]: # + """The pins capable of analog output""" analog_pins = (_MM1_D3, _MM1_D2) + """The effective bit resolution of the PWM pins""" pwm_width = 16 # seesaw firmware (mm1_hat) pwm pin map: # pwm[0]:16 pwm[1]:17 pwm[2]:18 pwm[3]:19 pwm[4]:11 pwm[5]:10 # pwm[6]:9 pwm[7]:8 pwm[8]:40 pwm[9]:41 pwm[10]:42 pwm[11]:43 # + """The pins capable of PWM output""" pwm_pins = (_MM1_SERVO1, _MM1_SERVO2, _MM1_SERVO3, _MM1_SERVO4, _MM1_SERVO5, _MM1_SERVO6, _MM1_SERVO7, _MM1_SERVO8, _MM1_D12, _MM1_D10, _MM1_D11, _MM1_D9) # seesaw firmware touch pin map: # touch[0]: 7 touch[1]: 6 touch[2]: 5 touch[3]: 4 + """The pins capable of touch input""" touch_pins = (_MM1_RCH1, _MM1_RCH2, _MM1_RCH3, _MM1_RCH4) diff --git a/adafruit_seesaw/samd09.py b/adafruit_seesaw/samd09.py index dd19627..a10c9b2 100644 --- a/adafruit_seesaw/samd09.py +++ b/adafruit_seesaw/samd09.py @@ -21,7 +21,15 @@ # THE SOFTWARE. # pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods -from micropython import const +""" +`adafruit_seesaw.samd09` - Pin definition for Adafruit SAMD09 Breakout with seesaw +================================================================================== +""" + +try: + from micropython import const +except ImportError: + def const(x): return x __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -37,11 +45,20 @@ _PWM_3_PIN = const(0x07) class SAMD09_Pinmap: + """This class is automatically used by `adafruit_seesaw.seesaw.Seesaw` when + a SAMD09 Breakout is detected. + + It is also a reference for the capabilities of each pin.""" + + """The pins capable of analog output""" analog_pins = (_ADC_INPUT_0_PIN, _ADC_INPUT_1_PIN, _ADC_INPUT_2_PIN, _ADC_INPUT_3_PIN) + """The effective bit resolution of the PWM pins""" pwm_width = 8 + """The pins capable of PWM output""" pwm_pins = (_PWM_0_PIN, _PWM_1_PIN, _PWM_2_PIN, _PWM_3_PIN) + """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 1675228..b55999f 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -20,7 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`seesaw` +`adafruit_seesaw.seesaw` ==================================================== An I2C to whatever helper chip. @@ -37,8 +37,8 @@ **Software and Dependencies:** -* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: - https://github.com/adafruit/circuitpython/releases +* Adafruit CircuitPython firmware: https://circuitpython.org/ +* or Adafruit Blinka: https://circuitpython.org/blinka * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice """ @@ -52,7 +52,11 @@ import struct except ImportError: import ustruct as struct -from micropython import const +try: + from micropython import const +except ImportError: + def const(x): return x + from adafruit_bus_device.i2c_device import I2CDevice __version__ = "0.0.0-auto.0" @@ -127,7 +131,8 @@ class Seesaw: """Driver for Seesaw i2c generic conversion trip :param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to - :param int addr: I2C address of the SeeSaw device""" + :param int addr: I2C address of the SeeSaw device + :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output""" INPUT = const(0x00) OUTPUT = const(0x01) INPUT_PULLUP = const(0x02) @@ -165,35 +170,41 @@ def sw_reset(self): self.pin_mapping = SAMD09_Pinmap def get_options(self): + """Retrieve the 'options' word from the SeeSaw board""" buf = bytearray(4) self.read(_STATUS_BASE, _STATUS_OPTIONS, buf) ret = struct.unpack(">I", buf)[0] return ret def get_version(self): + """Retrieve the 'version' word from the SeeSaw board""" buf = bytearray(4) self.read(_STATUS_BASE, _STATUS_VERSION, buf) ret = struct.unpack(">I", buf)[0] return ret def pin_mode(self, pin, mode): + """Set the mode of a pin by number""" if pin >= 32: self.pin_mode_bulk_b(1 << (pin - 32), mode) else: self.pin_mode_bulk(1 << pin, mode) def digital_write(self, pin, value): + """Set the value of an output pin by number""" if pin >= 32: self.digital_write_bulk_b(1 << (pin - 32), value) else: self.digital_write_bulk(1 << 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 def digital_read_bulk(self, pins): + """Get the values of all the pins on the 'A' port as a bitmask""" buf = bytearray(4) self.read(_GPIO_BASE, _GPIO_BULK, buf) buf[0] = buf[0] & 0x3F @@ -201,6 +212,7 @@ def digital_read_bulk(self, pins): return ret & pins def digital_read_bulk_b(self, pins): + """Get the values of all the pins on the 'B' port as a bitmask""" buf = bytearray(8) self.read(_GPIO_BASE, _GPIO_BULK, buf) ret = struct.unpack(">I", buf[4:])[0] @@ -208,6 +220,7 @@ def digital_read_bulk_b(self, pins): def set_GPIO_interrupts(self, pins, enabled): + """Enable or disable the GPIO interrupt""" cmd = struct.pack(">I", pins) if enabled: self.write(_GPIO_BASE, _GPIO_INTENSET, cmd) @@ -215,6 +228,7 @@ def set_GPIO_interrupts(self, pins, enabled): self.write(_GPIO_BASE, _GPIO_INTENCLR, cmd) def analog_read(self, pin): + """Read the value of an analog pin by number""" buf = bytearray(2) if pin not in self.pin_mapping.analog_pins: raise ValueError("Invalid ADC pin") @@ -225,6 +239,7 @@ def analog_read(self, pin): return ret def touch_read(self, pin): + """Read the value of a touch pin by number""" buf = bytearray(2) if pin not in self.pin_mapping.touch_pins: @@ -235,6 +250,7 @@ def touch_read(self, pin): return ret def moisture_read(self): + """Read the value of the moisture sensor""" buf = bytearray(2) self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, .005) @@ -275,12 +291,15 @@ def _pin_mode_bulk_x(self, capacity, offset, pins, mode): raise ValueError("Invalid pin mode") def pin_mode_bulk(self, pins, mode): + """Set the mode of all the pins on the 'A' port as a bitmask""" self._pin_mode_bulk_x(4, 0, pins, mode) def pin_mode_bulk_b(self, pins, mode): + """Set the mode of all the pins on the 'B' port as a bitmask""" self._pin_mode_bulk_x(8, 4, pins, mode) def digital_write_bulk(self, pins, value): + """Set the mode of pins on the 'A' port as a bitmask""" cmd = struct.pack(">I", pins) if value: self.write(_GPIO_BASE, _GPIO_BULK_SET, cmd) @@ -289,6 +308,7 @@ def digital_write_bulk(self, pins, value): def digital_write_bulk_b(self, pins, value): + """Set the mode of pins on the 'B' port as a bitmask""" cmd = bytearray(8) cmd[4:] = struct.pack(">I", pins) if value: @@ -297,6 +317,7 @@ def digital_write_bulk_b(self, pins, value): self.write(_GPIO_BASE, _GPIO_BULK_CLR, cmd) def analog_write(self, pin, value): + """Set the value of an analog output by number""" pin_found = False if self.pin_mapping.pwm_width == 16: if pin in self.pin_mapping.pwm_pins: @@ -313,6 +334,7 @@ def analog_write(self, pin, value): time.sleep(.001) def get_temp(self): + """Read the temperature""" buf = bytearray(4) self.read(_STATUS_BASE, _STATUS_TEMP, buf, .005) buf[0] = buf[0] & 0x3F @@ -320,6 +342,7 @@ def get_temp(self): return 0.00001525878 * ret 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) @@ -343,36 +366,45 @@ def set_pwm_freq(self, pin, freq): # return self.read8(SEESAW_SERCOM0_BASE + sercom, SEESAW_SERCOM_DATA) 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(.250) self.i2c_device.device_address = addr self.sw_reset() def get_i2c_addr(self): + """Return the device's I2C address stored in its EEPROM""" return self.read8(_EEPROM_BASE, _EEPROM_I2C_ADDR) def eeprom_write8(self, addr, val): + """Write a single byte directly to the device's EEPROM""" self.eeprom_write(addr, bytearray([val])) def eeprom_write(self, addr, buf): + """Write multiple bytes directly to the device's EEPROM""" self.write(_EEPROM_BASE, addr, buf) def eeprom_read8(self, addr): + """Read a single byte directly to the device's EEPROM""" return self.read8(_EEPROM_BASE, addr) def uart_set_baud(self, baud): + """Set the serial baudrate of the device""" cmd = struct.pack(">I", baud) self.write(_SERCOM0_BASE, _SERCOM_BAUD, cmd) def write8(self, reg_base, reg, value): + """Write an arbitrary I2C byte register on the device""" self.write(reg_base, reg, bytearray([value])) def read8(self, reg_base, reg): + """Read an arbitrary I2C byte register on the device""" ret = bytearray(1) self.read(reg_base, reg, ret) return ret[0] def read(self, reg_base, reg, buf, delay=.005): + """Read an arbitrary I2C register range on the device""" self.write(reg_base, reg) if self._drdy is not None: while self._drdy.value is False: @@ -383,6 +415,7 @@ def read(self, reg_base, reg, buf, delay=.005): i2c.readinto(buf) def write(self, reg_base, reg, buf=None): + """Write an arbitrary I2C register range on the device""" full_buffer = bytearray([reg_base, reg]) if buf is not None: full_buffer += buf diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 14ede8d..09aae8b 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -21,9 +21,17 @@ # THE SOFTWARE. # pylint: disable=missing-docstring,invalid-name,too-many-public-methods +""" +`adafruit_seesaw.tftshield18` - Pin definitions for 1.8" TFT Shield V2 +====================================================================== +""" + from collections import namedtuple import board -from micropython import const +try: + from micropython import const +except ImportError: + def const(x): return x from adafruit_seesaw.seesaw import Seesaw __version__ = "0.0.0-auto.0" @@ -51,14 +59,21 @@ class TFTShield18(Seesaw): _BACKLIGHT_ON = b"\xFF\xFF" _BACKLIGHT_OFF = b"\x00\x00" - _button_mask = ((1 << _BUTTON_RIGHT) | - (1 << _BUTTON_DOWN) | - (1 << _BUTTON_LEFT) | - (1 << _BUTTON_UP) | - (1 << _BUTTON_SELECT) | - (1 << _BUTTON_A) | - (1 << _BUTTON_B) | - (1 << _BUTTON_C)) + try: + _button_mask = ((1 << _BUTTON_RIGHT) | + (1 << _BUTTON_DOWN) | + (1 << _BUTTON_LEFT) | + (1 << _BUTTON_UP) | + (1 << _BUTTON_SELECT) | + (1 << _BUTTON_A) | + (1 << _BUTTON_B) | + (1 << _BUTTON_C)) + except TypeError: +# During Sphinx build, the following error occurs: +# File "/home/jepler/src/Adafruit_CircuitPython_seesaw/adafruit_seesaw/tftshield18.py", line 60, in TFTShield18 +# (1 << _BUTTON_B) | +# TypeError: unsupported operand type(s) for <<: 'int' and '_MockObject' + _button_mask = 0xff def __init__(self, i2c_bus=board.I2C(), addr=0x2E): super(TFTShield18, self).__init__(i2c_bus, addr) diff --git a/docs/api.rst b/docs/api.rst index 88fde53..d307888 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,5 +1,39 @@ .. If you created a package, create one automodule per module in the package. +.. automodule:: adafruit_seesaw + :members: + .. automodule:: adafruit_seesaw.seesaw :members: + +.. automodule:: adafruit_seesaw.crickit + :members: + +.. automodule:: adafruit_seesaw.analoginput + :members: + +.. automodule:: adafruit_seesaw.digitalio + :members: + +.. automodule:: adafruit_seesaw.__init__ + :members: + +.. automodule:: adafruit_seesaw.keypad + :members: + +.. automodule:: adafruit_seesaw.neopixel + :members: + +.. automodule:: adafruit_seesaw.pwmout + :members: + +.. automodule:: adafruit_seesaw.robohat + :members: + +.. automodule:: adafruit_seesaw.samd09 + :members: + +.. automodule:: adafruit_seesaw.tftshield18 + :members: + diff --git a/docs/conf.py b/docs/conf.py index 20732c4..dbd03c5 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,7 +18,14 @@ # 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 = [] +autodoc_mock_imports = ['adafruit_bus_device', 'digitalio', 'board'] + +autodoc_default_flags = ['special-members', 'members'] + +autodoc_default_options = { + 'member-order': 'bysource', + 'exclude-members': '__weakref__,__getnewargs__,__dict__,__module__,__init__', +} intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} From 22432fe85a280e3f32784d0bc2526dfee6e6e61e Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 28 Dec 2019 21:24:58 -0600 Subject: [PATCH 020/182] Fix pylint fluff --- adafruit_seesaw/crickit.py | 3 ++- adafruit_seesaw/digitalio.py | 6 +++--- adafruit_seesaw/keypad.py | 11 ++++++----- adafruit_seesaw/neopixel.py | 6 ++++-- adafruit_seesaw/robohat.py | 11 ++++++----- adafruit_seesaw/samd09.py | 5 +++-- adafruit_seesaw/seesaw.py | 5 ++++- adafruit_seesaw/tftshield18.py | 5 +++-- 8 files changed, 31 insertions(+), 21 deletions(-) diff --git a/adafruit_seesaw/crickit.py b/adafruit_seesaw/crickit.py index 6f415e5..55b8ba0 100644 --- a/adafruit_seesaw/crickit.py +++ b/adafruit_seesaw/crickit.py @@ -29,7 +29,8 @@ try: from micropython import const except ImportError: - def const(x): return x + def const(x): + return x __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" diff --git a/adafruit_seesaw/digitalio.py b/adafruit_seesaw/digitalio.py index 7e77819..764c259 100644 --- a/adafruit_seesaw/digitalio.py +++ b/adafruit_seesaw/digitalio.py @@ -63,7 +63,7 @@ def switch_to_input(self, pull=None): """Switch the pin to input mode""" if pull == digitalio.Pull.DOWN: raise ValueError("Pull Down currently not supported") - elif pull == digitalio.Pull.UP: + if pull == digitalio.Pull.UP: self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLUP) else: self._seesaw.pin_mode(self._pin, self._seesaw.INPUT) @@ -116,9 +116,9 @@ def pull(self): def pull(self, mode): if self._direction == digitalio.Direction.OUTPUT: raise AttributeError("cannot set pull on an output pin") - elif mode == digitalio.Pull.DOWN: + if mode == digitalio.Pull.DOWN: raise ValueError("Pull Down currently not supported") - elif mode == digitalio.Pull.UP: + if mode == digitalio.Pull.UP: self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLUP) elif mode is None: self._seesaw.pin_mode(self._pin, self._seesaw.INPUT) diff --git a/adafruit_seesaw/keypad.py b/adafruit_seesaw/keypad.py index c05bb10..68e6f15 100644 --- a/adafruit_seesaw/keypad.py +++ b/adafruit_seesaw/keypad.py @@ -29,7 +29,8 @@ try: from micropython import const except ImportError: - def const(x): return x + def const(x): + return x from adafruit_seesaw.seesaw import Seesaw __version__ = "0.0.0-auto.0" @@ -63,13 +64,13 @@ class Keypad(Seesaw): :param int addr: I2C address of the SeeSaw device :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output""" - """Indicates that the key is currently pressed""" + #: Indicates that the key is currently pressed EDGE_HIGH = 0 - """Indicates that the key is currently released""" + #: Indicates that the key is currently released EDGE_LOW = 1 - """Indicates that the key was recently pressed""" + #: Indicates that the key was recently pressed EDGE_FALLING = 2 - """Indicates that the key was recently released""" + #: Indicates that the key was recently released EDGE_RISING = 3 def __init__(self, i2c_bus, addr=0x49, drdy=None): diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 35586f6..92ea493 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -33,7 +33,8 @@ try: from micropython import const except ImportError: - def const(x): return x + def const(x): + return x __version__ = "1.2.3" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -66,7 +67,8 @@ class NeoPixel: :param int bpp: The number of bytes per pixel :param float brightness: The brightness, from 0.0 to 1.0 :param bool auto_write: Automatically update the pixels when changed - :param tuple pixel_order: The layout of the pixels. Use one of the order constants such as RGBW. + :param tuple pixel_order: The layout of the pixels. + Use one of the order constants such as RGBW. """ def __init__(self, seesaw, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_order=None): # TODO: brightness not yet implemented. diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py index 12b9cbe..12985bf 100644 --- a/adafruit_seesaw/robohat.py +++ b/adafruit_seesaw/robohat.py @@ -29,7 +29,8 @@ try: from micropython import const except ImportError: - def const(x): return x + def const(x): + return x __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -89,22 +90,22 @@ class MM1_Pinmap: # analog[0]:47 analog[1]:48 analog[2]: analog[3]: # analog[4]: analog[5]: analog[6]: analog[7]: # - """The pins capable of analog output""" + #: The pins capable of analog output analog_pins = (_MM1_D3, _MM1_D2) - """The effective bit resolution of the PWM pins""" + #: The effective bit resolution of the PWM pins pwm_width = 16 # seesaw firmware (mm1_hat) pwm pin map: # pwm[0]:16 pwm[1]:17 pwm[2]:18 pwm[3]:19 pwm[4]:11 pwm[5]:10 # pwm[6]:9 pwm[7]:8 pwm[8]:40 pwm[9]:41 pwm[10]:42 pwm[11]:43 # - """The pins capable of PWM output""" + #: The pins capable of PWM output pwm_pins = (_MM1_SERVO1, _MM1_SERVO2, _MM1_SERVO3, _MM1_SERVO4, _MM1_SERVO5, _MM1_SERVO6, _MM1_SERVO7, _MM1_SERVO8, _MM1_D12, _MM1_D10, _MM1_D11, _MM1_D9) # seesaw firmware touch pin map: # touch[0]: 7 touch[1]: 6 touch[2]: 5 touch[3]: 4 - """The pins capable of touch input""" + #: The pins capable of touch input touch_pins = (_MM1_RCH1, _MM1_RCH2, _MM1_RCH3, _MM1_RCH4) diff --git a/adafruit_seesaw/samd09.py b/adafruit_seesaw/samd09.py index a10c9b2..67c7a03 100644 --- a/adafruit_seesaw/samd09.py +++ b/adafruit_seesaw/samd09.py @@ -29,7 +29,8 @@ try: from micropython import const except ImportError: - def const(x): return x + def const(x): + return x __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -50,7 +51,7 @@ class SAMD09_Pinmap: 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 = (_ADC_INPUT_0_PIN, _ADC_INPUT_1_PIN, _ADC_INPUT_2_PIN, _ADC_INPUT_3_PIN) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index b55999f..6148a36 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -55,7 +55,8 @@ try: from micropython import const except ImportError: - def const(x): return x + def const(x): + return x from adafruit_bus_device.i2c_device import I2CDevice @@ -159,6 +160,7 @@ def sw_reset(self): .format(chip_id, _HW_ID_CODE)) pid = self.get_version() >> 16 + # pylint: disable=import-outside-toplevel if pid == _CRICKIT_PID: from adafruit_seesaw.crickit import Crickit_Pinmap self.pin_mapping = Crickit_Pinmap @@ -168,6 +170,7 @@ def sw_reset(self): else: from adafruit_seesaw.samd09 import SAMD09_Pinmap self.pin_mapping = SAMD09_Pinmap + # pylint: enable=import-outside-toplevel def get_options(self): """Retrieve the 'options' word from the SeeSaw board""" diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 09aae8b..b3d54f4 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -31,7 +31,8 @@ try: from micropython import const except ImportError: - def const(x): return x + def const(x): + return x from adafruit_seesaw.seesaw import Seesaw __version__ = "0.0.0-auto.0" @@ -70,7 +71,7 @@ class TFTShield18(Seesaw): (1 << _BUTTON_C)) except TypeError: # During Sphinx build, the following error occurs: -# File "/home/jepler/src/Adafruit_CircuitPython_seesaw/adafruit_seesaw/tftshield18.py", line 60, in TFTShield18 +# File ".../tftshield18.py", line 60, in TFTShield18 # (1 << _BUTTON_B) | # TypeError: unsupported operand type(s) for <<: 'int' and '_MockObject' _button_mask = 0xff From 309d24896f9ac259dd2c63a810fb848b9b397650 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 28 Dec 2019 21:45:11 -0600 Subject: [PATCH 021/182] remove pylint directive not understood by 1.9.2 --- adafruit_seesaw/seesaw.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 6148a36..5824a7d 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -160,7 +160,6 @@ def sw_reset(self): .format(chip_id, _HW_ID_CODE)) pid = self.get_version() >> 16 - # pylint: disable=import-outside-toplevel if pid == _CRICKIT_PID: from adafruit_seesaw.crickit import Crickit_Pinmap self.pin_mapping = Crickit_Pinmap @@ -170,7 +169,6 @@ def sw_reset(self): else: from adafruit_seesaw.samd09 import SAMD09_Pinmap self.pin_mapping = SAMD09_Pinmap - # pylint: enable=import-outside-toplevel def get_options(self): """Retrieve the 'options' word from the SeeSaw board""" From 8f920354b0e80152544c2759fa59e8ed00b575f8 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 2 Jan 2020 10:23:44 -0600 Subject: [PATCH 022/182] digitalio: Enable Pull.DOWN mode --- adafruit_seesaw/digitalio.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_seesaw/digitalio.py b/adafruit_seesaw/digitalio.py index 764c259..f9c9f63 100644 --- a/adafruit_seesaw/digitalio.py +++ b/adafruit_seesaw/digitalio.py @@ -62,8 +62,8 @@ def switch_to_output(self, value=False, drive_mode=digitalio.DriveMode.PUSH_PULL def switch_to_input(self, pull=None): """Switch the pin to input mode""" if pull == digitalio.Pull.DOWN: - raise ValueError("Pull Down currently not supported") - if pull == digitalio.Pull.UP: + self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLDOWN) + elif pull == digitalio.Pull.UP: self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLUP) else: self._seesaw.pin_mode(self._pin, self._seesaw.INPUT) @@ -117,8 +117,8 @@ def pull(self, mode): if self._direction == digitalio.Direction.OUTPUT: raise AttributeError("cannot set pull on an output pin") if mode == digitalio.Pull.DOWN: - raise ValueError("Pull Down currently not supported") - if mode == digitalio.Pull.UP: + self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLDOWN) + elif mode == digitalio.Pull.UP: self._seesaw.pin_mode(self._pin, self._seesaw.INPUT_PULLUP) elif mode is None: self._seesaw.pin_mode(self._pin, self._seesaw.INPUT) From 20fb91a810d8044db1d0591efe7149fcbe9facd5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 2 Jan 2020 10:47:55 -0600 Subject: [PATCH 023/182] seesaw: Clear pull-ups when setting mode to INPUT .. pull-ups are enabled with INPUT_PULLUP, INPUT_PULLDOWN and would otherwise never be disabled --- adafruit_seesaw/seesaw.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 5824a7d..ff3bce3 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -277,6 +277,7 @@ def _pin_mode_bulk_x(self, capacity, offset, pins, mode): self.write(_GPIO_BASE, _GPIO_DIRSET_BULK, cmd) elif mode == self.INPUT: self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd) + self.write(_GPIO_BASE, _GPIO_PULLENCLR, cmd) elif mode == self.INPUT_PULLUP: self.write(_GPIO_BASE, _GPIO_DIRCLR_BULK, cmd) From 08c0f79902de5738ddfed782472ab451eacc8c9c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 2 Jan 2020 10:48:34 -0600 Subject: [PATCH 024/182] digitalio: Initialize direction to INPUT None is an invalid direction --- adafruit_seesaw/digitalio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/digitalio.py b/adafruit_seesaw/digitalio.py index f9c9f63..89cd64d 100644 --- a/adafruit_seesaw/digitalio.py +++ b/adafruit_seesaw/digitalio.py @@ -45,7 +45,7 @@ def __init__(self, seesaw, pin): self._seesaw = seesaw self._pin = pin self._drive_mode = digitalio.DriveMode.PUSH_PULL - self._direction = False + self._direction = digitalio.Direction.INPUT self._pull = None self._value = False From dc6f43c08ee146ee62ef278afbef60e30a5178ec Mon Sep 17 00:00:00 2001 From: dherrada Date: Sat, 4 Jan 2020 14:23:31 -0500 Subject: [PATCH 025/182] Moved repository from Travis to GitHub Actions --- .github/workflows/build.yml | 50 +++++++++++++++++++++ .github/workflows/release.yml | 81 +++++++++++++++++++++++++++++++++++ .gitignore | 1 - .travis.yml | 32 -------------- README.rst | 4 +- 5 files changed, 133 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml delete mode 100755 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..66ce4db --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Library version + run: git describe --dirty --always --tags + - name: PyLint + run: | + pylint $( find . -path './adafruit*.py' ) + ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Build docs + working-directory: docs + run: sphinx-build -E -W -b html . _build/html diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..18efb9c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Upload Release Assets + # the 'official' actions version does not yet support dynamically + # supplying asset names to upload. @csexton's version chosen based on + # discussion in the issue below, as its the simplest to implement and + # allows for selecting files with a pattern. + # https://github.com/actions/upload-release-asset/issues/4 + #uses: actions/upload-release-asset@v1.0.1 + uses: csexton/release-asset-action@master + with: + pattern: "bundles/*" + github-token: ${{ secrets.GITHUB_TOKEN }} + + upload-pypi: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Set up Python + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + env: + TWINE_USERNAME: ${{ secrets.pypi_username }} + TWINE_PASSWORD: ${{ secrets.pypi_password }} + run: | + python setup.py sdist + twine upload dist/* diff --git a/.gitignore b/.gitignore index cc1a9c8..1be1c4b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ __pycache__ _build *.pyc .env -build* bundles *.DS_Store .eggs diff --git a/.travis.yml b/.travis.yml deleted file mode 100755 index 093c6bf..0000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +0,0 @@ -dist: trusty -sudo: false -language: python -python: -- '3.6' -cache: - pip: true -deploy: -- provider: releases - api_key: "$GITHUB_TOKEN" - file_glob: true - file: "$TRAVIS_BUILD_DIR/bundles/*" - skip_cleanup: true - overwrite: true - on: - tags: true -- provider: pypi - user: adafruit-travis - on: - tags: true - password: - secure: oqlm4dJIzX2JH8Qbd+qU0g+M+1NSHD0f9pWQxvdhl+JlCtzRmBtyv6t24EN+SUGD3eKOK9A21/+QxsQJ2sB8/g8qh07OUNKw+erv9NqA2Wc0oHvOpwpN+TkS6hF0GI/Tn53hwm+qiTsXmBfbDoXDyu6Qe9rsht7Llv1wbHErCk7vkZ9zEL0zfhkgV5hzXPoRdwQclLeyleoJMyw0ZdfPqupMCGGAMPd6aTIYQfJ1PVmzYu9VqtK7yEB9lltc6U16dwp2huN2HBz5EzlRWszCli8mx1+MuZxNFlYkMo8vgWpSQmJpw22nSzI8ez57QibNGEm9u4Y9nb7PlzH9ZOeTVI7OZ9k3BPSN0db8WKGLz9VJxyTilqPNs737TCf36tdshPnuEtEDwk8YNReyK5uE5TnjnnXL2g3qSyhIniKLusY5d9cF3PEhwG6DcNqt39NrT6rG9PaeURYzKY19BgwhWD2CucEM6RDBRp+31citzM35NjET+5+xSOmDXdCdr+Ar+AWNxyfGn0N+Za/de8JyFjuk5TN4muB61eJPXPpinn8+egNyeiONPT96vJDVvFrEdG3bIEspYd6ZAMQ8Aou1Ii+CxOEXiY+57AK20LAieX8Nv2sTLLHo5wa7c4xghHVZdN187cesqm0LZtNYGhs/CeMP+9bC3bn7/IHGdcRZvg4= -install: -- pip install -r requirements.txt -- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme -- pip install --force-reinstall pylint==1.9.2 -script: -- pylint adafruit_seesaw/*.py -- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) -- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-seesaw --library_location - . -- cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/README.rst b/README.rst index 486be22..57085c6 100644 --- a/README.rst +++ b/README.rst @@ -10,8 +10,8 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord -.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_seesaw.svg?branch=master - :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_seesaw +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_seesaw/workflows/Build%20CI/badge.svg + :target: https://github.com/adafruit/Adafruit_CircuitPython_seesaw/actions :alt: Build Status CircuitPython module for use with the Adafruit ATSAMD09 seesaw. From dc01285aa45dd8260bb3ae35a657e4cdcbf325b8 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 8 Jan 2020 21:09:22 -0600 Subject: [PATCH 026/182] update pylint examples directive Signed-off-by: sommersoft --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66ce4db..11ce574 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) + ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Build docs From 5f9a2b1af8fa7f9055cdece880d97c26b38dc9b7 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 13 Feb 2020 09:39:51 -0800 Subject: [PATCH 027/182] Increase read delay to fix occasional bad reads --- adafruit_seesaw/seesaw.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index ff3bce3..26ff98f 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -204,18 +204,18 @@ def digital_read(self, pin): return self.digital_read_bulk_b((1 << (pin - 32))) != 0 return self.digital_read_bulk((1 << pin)) != 0 - def digital_read_bulk(self, pins): + 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) + self.read(_GPIO_BASE, _GPIO_BULK, buf, delay=delay) buf[0] = buf[0] & 0x3F ret = struct.unpack(">I", buf)[0] return ret & pins - def digital_read_bulk_b(self, pins): + def digital_read_bulk_b(self, pins, delay=0.008): """Get the values of all the pins on the 'B' port as a bitmask""" buf = bytearray(8) - self.read(_GPIO_BASE, _GPIO_BULK, buf) + self.read(_GPIO_BASE, _GPIO_BULK, buf, delay=delay) ret = struct.unpack(">I", buf[4:])[0] return ret & pins @@ -405,7 +405,7 @@ def read8(self, reg_base, reg): self.read(reg_base, reg, ret) return ret[0] - def read(self, reg_base, reg, buf, delay=.005): + def read(self, reg_base, reg, buf, delay=.008): """Read an arbitrary I2C register range on the device""" self.write(reg_base, reg) if self._drdy is not None: From 530fc6fd5f06224351d199ceecde8792b525e1cd Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 3 Mar 2020 00:28:48 -0600 Subject: [PATCH 028/182] build.yml: move pylint, black, and Sphinx installs to each repo; add description to 'actions-ci/install.sh' Signed-off-by: sommersoft --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11ce574..fff3aa9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,9 +34,13 @@ jobs: with: repository: adafruit/actions-ci-circuitpython-libs path: actions-ci - - name: Install deps + - name: Install dependencies + # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh + - name: Pip install pylint, black, & Sphinx + run: | + pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint From a113c9d11cdb1f8f580b9f2078c2953a75d7f8bc Mon Sep 17 00:00:00 2001 From: sommersoft Date: Thu, 5 Mar 2020 22:06:59 -0600 Subject: [PATCH 029/182] update pylintrc for black Signed-off-by: sommersoft --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 039eaec..d8f0ee8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -52,7 +52,7 @@ confidence= # 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 +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From f7274e2221d9ae4de52f9220b736f6d101ac30e1 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 13 Mar 2020 13:53:21 -0500 Subject: [PATCH 030/182] update code of conduct --- CODE_OF_CONDUCT.md | 125 ++++++++++++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 35 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 1617586..d79c514 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,74 +1,129 @@ -# Contributor Covenant Code of Conduct +# Adafruit Community Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and +contributors and leaders pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. +size, disability, ethnicity, gender identity and expression, level or type of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. ## Our Standards +We are committed to providing a friendly, safe and welcoming environment for +all. + Examples of behavior that contributes to creating a positive environment include: +* Be kind and courteous to others * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences +* Collaborating with other community members * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or -advances +* The use of sexualized language or imagery and sexual attention or advances +* The use of inappropriate images, including in a community member's avatar +* The use of inappropriate language, including in a community member's nickname +* Any spamming, flaming, baiting or other attention-stealing behavior +* Excessive or unwelcome helping; answering outside the scope of the question + asked * Trolling, insulting/derogatory comments, and personal or political attacks +* Promoting or spreading disinformation, lies, or conspiracy theories against + a person, group, organisation, project, or community * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +* Other conduct which could reasonably be considered inappropriate + +The goal of the standards and moderation guidelines outlined here is to build +and maintain a respectful community. We ask that you don’t just aim to be +"technically unimpeachable", but rather try to be your best self. + +We value many things beyond technical expertise, including collaboration and +supporting others within our community. Providing a positive experience for +other community members can have a much more significant impact than simply +providing the correct answer. ## Our Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable +Project leaders are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions +Project leaders have the right and responsibility to remove, edit, or +reject messages, comments, commits, code, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +permanently any community member for other behaviors that they deem +inappropriate, threatening, offensive, or harmful. -## Scope +## Moderation -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. +Instances of behaviors that violate the Adafruit Community Code of Conduct +may be reported by any member of the community. Community members are +encouraged to report these situations, including situations they witness +involving other community members. + +You may report in the following ways: + +In any situation, you may send an email to . -## Enforcement +On the Adafruit Discord, you may send an open message from any channel +to all Community Helpers by tagging @community helpers. You may also send an +open message from any channel, or a direct message to @kattni#1507, +@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, +@Mr. Certainly#0472 or @Andon#8175. -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at support@adafruit.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. +Email and direct message reports will be kept confidential. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +In situations on Discord where the issue is particularly egregious, possibly +illegal, requires immediate action, or violates the Discord terms of service, +you should also report the message directly to Discord. + +These are the steps for upholding our community’s standards of conduct. + +1. Any member of the community may report any situation that violates the +Adafruit Community Code of Conduct. All reports will be reviewed and +investigated. +2. If the behavior is an egregious violation, the community member who +committed the violation may be banned immediately, without warning. +3. Otherwise, moderators will first respond to such behavior with a warning. +4. Moderators follow a soft "three strikes" policy - the community member may +be given another chance, if they are receptive to the warning and change their +behavior. +5. If the community member is unreceptive or unreasonable when warned by a +moderator, or the warning goes unheeded, they may be banned for a first or +second offense. Repeated offenses will result in the community member being +banned. + +## Scope + +This Code of Conduct and the enforcement policies listed above apply to all +Adafruit Community venues. This includes but is not limited to any community +spaces (both public and private), the entire Adafruit Discord server, and +Adafruit GitHub repositories. Examples of Adafruit Community spaces include +but are not limited to meet-ups, audio chats on the Adafruit Discord, or +interaction at a conference. + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. As a community +member, you are representing our community, and are expected to behave +accordingly. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.4, available at +, +and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ +For other projects adopting the Adafruit Community Code of +Conduct, please contact the maintainers of those projects for enforcement. +If you wish to use this code of conduct for your own project, consider +explicitly mentioning your moderation policy or making a copy with your +own moderation policy so as to avoid confusion. From 56909af87d1f0ee62c1bc9d27401f0f9cbb80195 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 15 Mar 2020 11:49:22 -0500 Subject: [PATCH 031/182] update code of coduct: discord moderation contact section Signed-off-by: sommersoft --- CODE_OF_CONDUCT.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index d79c514..134d510 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -74,10 +74,10 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Helpers by tagging @community helpers. You may also send an -open message from any channel, or a direct message to @kattni#1507, -@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, -@Mr. Certainly#0472 or @Andon#8175. +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. From f2aa379ac181c882ecb2b730e7b72e5447771e87 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 16 Mar 2020 15:14:34 -0400 Subject: [PATCH 032/182] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_seesaw/analoginput.py | 2 + adafruit_seesaw/crickit.py | 43 +++++++-- adafruit_seesaw/digitalio.py | 2 + adafruit_seesaw/keypad.py | 10 +- adafruit_seesaw/neopixel.py | 24 ++++- adafruit_seesaw/pwmout.py | 4 +- adafruit_seesaw/robohat.py | 49 ++++++---- adafruit_seesaw/samd09.py | 11 ++- adafruit_seesaw/seesaw.py | 62 ++++++++---- adafruit_seesaw/tftshield18.py | 51 ++++++---- docs/conf.py | 126 +++++++++++++++---------- examples/seesaw_crickit_test.py | 21 ++--- examples/seesaw_joy_featherwing.py | 24 ++--- examples/seesaw_minitft_featherwing.py | 30 +++--- examples/seesaw_simpletest.py | 4 +- setup.py | 48 ++++------ 17 files changed, 323 insertions(+), 190 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_seesaw/analoginput.py b/adafruit_seesaw/analoginput.py index 55acb72..53eb2aa 100644 --- a/adafruit_seesaw/analoginput.py +++ b/adafruit_seesaw/analoginput.py @@ -29,6 +29,7 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" + class AnalogInput: """CircuitPython-compatible class for analog inputs @@ -37,6 +38,7 @@ class AnalogInput: :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device :param int pin: The pin number on the device """ + def __init__(self, seesaw, pin): self._seesaw = seesaw self._pin = pin diff --git a/adafruit_seesaw/crickit.py b/adafruit_seesaw/crickit.py index 55b8ba0..3089ab0 100644 --- a/adafruit_seesaw/crickit.py +++ b/adafruit_seesaw/crickit.py @@ -29,9 +29,11 @@ try: from micropython import const except ImportError: + def const(x): return x + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -75,15 +77,22 @@ def const(x): # PA pins are nn # PB pins are 32+nn + class Crickit_Pinmap: # seesaw firmware analog pin map: # analog[0]: 2 analog[1]: 3 analog[2]:40 analog[3]:41 # analog[4]:11 analog[5]:10 analog[6]: 9 analog[7]: 8 # no special remapping: same order as constants above - analog_pins = (_CRICKIT_SIGNAL1, _CRICKIT_SIGNAL2, - _CRICKIT_SIGNAL3, _CRICKIT_SIGNAL4, - _CRICKIT_SIGNAL5, _CRICKIT_SIGNAL6, - _CRICKIT_SIGNAL7, _CRICKIT_SIGNAL8) + analog_pins = ( + _CRICKIT_SIGNAL1, + _CRICKIT_SIGNAL2, + _CRICKIT_SIGNAL3, + _CRICKIT_SIGNAL4, + _CRICKIT_SIGNAL5, + _CRICKIT_SIGNAL6, + _CRICKIT_SIGNAL7, + _CRICKIT_SIGNAL8, + ) pwm_width = 16 @@ -91,12 +100,26 @@ class Crickit_Pinmap: # pwm[0]:14 pwm[1]:15 pwm[2]:16 pwm[3]:17 pwm[4]:18 pwm[5]:19 # pwm[6]:22 pwm[7]:23 pwm[8]:42 pwm[9]:43 pwm[10]:12 pwm[11]:13 # Note that servo pins are in reverse order (17-14), and motor pins are shuffled. - pwm_pins = (_CRICKIT_SERVO4, _CRICKIT_SERVO3, _CRICKIT_SERVO2, _CRICKIT_SERVO1, - _CRICKIT_MOTOR2B, _CRICKIT_MOTOR2A, - _CRICKIT_MOTOR1A, _CRICKIT_MOTOR1B, - _CRICKIT_DRIVE4, _CRICKIT_DRIVE3, - _CRICKIT_DRIVE2, _CRICKIT_DRIVE1) + pwm_pins = ( + _CRICKIT_SERVO4, + _CRICKIT_SERVO3, + _CRICKIT_SERVO2, + _CRICKIT_SERVO1, + _CRICKIT_MOTOR2B, + _CRICKIT_MOTOR2A, + _CRICKIT_MOTOR1A, + _CRICKIT_MOTOR1B, + _CRICKIT_DRIVE4, + _CRICKIT_DRIVE3, + _CRICKIT_DRIVE2, + _CRICKIT_DRIVE1, + ) # seesaw firmware touch pin map: # touch[0]: 4 touch[1]: 5 touch[2]: 6 touch[3]: 7 - touch_pins = (_CRICKIT_CAPTOUCH1, _CRICKIT_CAPTOUCH2, _CRICKIT_CAPTOUCH3, _CRICKIT_CAPTOUCH4) + touch_pins = ( + _CRICKIT_CAPTOUCH1, + _CRICKIT_CAPTOUCH2, + _CRICKIT_CAPTOUCH3, + _CRICKIT_CAPTOUCH4, + ) diff --git a/adafruit_seesaw/digitalio.py b/adafruit_seesaw/digitalio.py index 89cd64d..2a431b3 100644 --- a/adafruit_seesaw/digitalio.py +++ b/adafruit_seesaw/digitalio.py @@ -31,6 +31,7 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" + class DigitalIO: """CircuitPython-compatible class for digital I/O pins @@ -41,6 +42,7 @@ class DigitalIO: :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device :param int pin: The pin number on the device """ + def __init__(self, seesaw, pin): self._seesaw = seesaw self._pin = pin diff --git a/adafruit_seesaw/keypad.py b/adafruit_seesaw/keypad.py index 68e6f15..031e975 100644 --- a/adafruit_seesaw/keypad.py +++ b/adafruit_seesaw/keypad.py @@ -29,8 +29,11 @@ try: from micropython import const except ImportError: + def const(x): return x + + from adafruit_seesaw.seesaw import Seesaw __version__ = "0.0.0-auto.0" @@ -52,11 +55,15 @@ class KeyEvent: :param int num: The number of the key :param int edge: One of the EDGE propertes of `adafruit_seesaw.keypad.Keypad` """ + def __init__(self, num, edge): self.number = int(num) self.edge = int(edge) + + # pylint: enable=too-few-public-methods + class Keypad(Seesaw): """On compatible SeeSaw devices, reads from a keypad. @@ -102,6 +109,7 @@ def count(self): @count.setter def count(self, value): raise AttributeError("count is read only") + # pylint: enable=unused-argument, no-self-use def set_event(self, key, edge, enable): @@ -118,7 +126,7 @@ def set_event(self, key, edge, enable): cmd = bytearray(2) cmd[0] = key - cmd[1] = (1 << (edge+1)) | enable + cmd[1] = (1 << (edge + 1)) | enable self.write(_KEYPAD_BASE, _KEYPAD_EVENT, cmd) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 92ea493..fe017e1 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -33,9 +33,11 @@ try: from micropython import const except ImportError: + def const(x): return x + __version__ = "1.2.3" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -58,6 +60,7 @@ def const(x): GRBW = (1, 0, 2, 3) """Green Red Blue White""" + class NeoPixel: """Control NeoPixels connected to a seesaw @@ -70,7 +73,18 @@ class NeoPixel: :param tuple pixel_order: The layout of the pixels. Use one of the order constants such as RGBW. """ - def __init__(self, seesaw, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_order=None): + + def __init__( + self, + seesaw, + pin, + n, + *, + bpp=3, + brightness=1.0, + auto_write=True, + pixel_order=None + ): # TODO: brightness not yet implemented. self._seesaw = seesaw self._pin = pin @@ -82,7 +96,7 @@ def __init__(self, seesaw, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pi 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) @property @@ -109,9 +123,9 @@ def __setitem__(self, key, color): 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 + r = (color >> 16) & 0xFF + g = (color >> 8) & 0xFF + b = color & 0xFF else: if self._bpp == 3: r, g, b = color diff --git a/adafruit_seesaw/pwmout.py b/adafruit_seesaw/pwmout.py index 0eacf44..ed934c0 100644 --- a/adafruit_seesaw/pwmout.py +++ b/adafruit_seesaw/pwmout.py @@ -29,8 +29,10 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" + class PWMOut: """A single seesaw channel that matches the :py:class:`~pulseio.PWMOut` API.""" + def __init__(self, seesaw, pin): self._seesaw = seesaw self._pin = pin @@ -57,7 +59,7 @@ def duty_cycle(self): @duty_cycle.setter def duty_cycle(self, value): - if not 0 <= value <= 0xffff: + if not 0 <= value <= 0xFFFF: raise ValueError("Must be 0 to 65535") self._seesaw.analog_write(self._pin, value) self._dc = value diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py index 12985bf..0ff56a0 100644 --- a/adafruit_seesaw/robohat.py +++ b/adafruit_seesaw/robohat.py @@ -29,9 +29,11 @@ try: from micropython import const except ImportError: + def const(x): return x + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -40,20 +42,20 @@ def const(x): # The ordering here reflects the seesaw firmware (mm1_hat) pinmap for Robo HAT MM1, # not logical ordering of the HAT terminals. -_MM1_D0 = const(55) # (RX to RPI_TX) -_MM1_D1 = const(54) # (TX to RPI_RX) -_MM1_D2 = const(34) # ADC (GPS_TX) -_MM1_D3 = const(35) # ADC (GPS_RX) -_MM1_D4 = const(0) # (GPS_SDA) -_MM1_D5 = const(1) # (GPS_SCL) -_MM1_D6 = const(28) # (POWER_ENABLE) -_MM1_D7 = const(2) # (BATTERY) -_MM1_D8 = const(20) # (NEOPIXEL) -_MM1_D9 = const(43) # PWM (SPI_SCK) -_MM1_D10 = const(41) # PWM (SPI_SS) -_MM1_D11 = const(42) # PWM (SPI_MOSI) -_MM1_D12 = const(40) # PWM (SPI_MISO) -_MM1_D13 = const(21) # LED +_MM1_D0 = const(55) # (RX to RPI_TX) +_MM1_D1 = const(54) # (TX to RPI_RX) +_MM1_D2 = const(34) # ADC (GPS_TX) +_MM1_D3 = const(35) # ADC (GPS_RX) +_MM1_D4 = const(0) # (GPS_SDA) +_MM1_D5 = const(1) # (GPS_SCL) +_MM1_D6 = const(28) # (POWER_ENABLE) +_MM1_D7 = const(2) # (BATTERY) +_MM1_D8 = const(20) # (NEOPIXEL) +_MM1_D9 = const(43) # PWM (SPI_SCK) +_MM1_D10 = const(41) # PWM (SPI_SS) +_MM1_D11 = const(42) # PWM (SPI_MOSI) +_MM1_D12 = const(40) # PWM (SPI_MISO) +_MM1_D13 = const(21) # LED _MM1_D14 = const(3) # (POWER_OFF) _MM1_SERVO8 = const(8) @@ -81,11 +83,13 @@ def const(x): # PA pins are nn # PB pins are 32+nn + class MM1_Pinmap: """This class is automatically used by `adafruit_seesaw.seesaw.Seesaw` when a RoboHAT board is detected. It is also a reference for the capabilities of each pin.""" + # seesaw firmware (mm1_hat) analog pin map: # analog[0]:47 analog[1]:48 analog[2]: analog[3]: # analog[4]: analog[5]: analog[6]: analog[7]: @@ -101,9 +105,20 @@ class MM1_Pinmap: # pwm[6]:9 pwm[7]:8 pwm[8]:40 pwm[9]:41 pwm[10]:42 pwm[11]:43 # #: The pins capable of PWM output - pwm_pins = (_MM1_SERVO1, _MM1_SERVO2, _MM1_SERVO3, _MM1_SERVO4, - _MM1_SERVO5, _MM1_SERVO6, _MM1_SERVO7, _MM1_SERVO8, - _MM1_D12, _MM1_D10, _MM1_D11, _MM1_D9) + pwm_pins = ( + _MM1_SERVO1, + _MM1_SERVO2, + _MM1_SERVO3, + _MM1_SERVO4, + _MM1_SERVO5, + _MM1_SERVO6, + _MM1_SERVO7, + _MM1_SERVO8, + _MM1_D12, + _MM1_D10, + _MM1_D11, + _MM1_D9, + ) # seesaw firmware touch pin map: # touch[0]: 7 touch[1]: 6 touch[2]: 5 touch[3]: 4 diff --git a/adafruit_seesaw/samd09.py b/adafruit_seesaw/samd09.py index 67c7a03..4b81f72 100644 --- a/adafruit_seesaw/samd09.py +++ b/adafruit_seesaw/samd09.py @@ -29,9 +29,11 @@ try: from micropython import const except ImportError: + def const(x): return x + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" @@ -45,6 +47,7 @@ def const(x): _PWM_2_PIN = const(0x06) _PWM_3_PIN = const(0x07) + class SAMD09_Pinmap: """This class is automatically used by `adafruit_seesaw.seesaw.Seesaw` when a SAMD09 Breakout is detected. @@ -52,8 +55,12 @@ class SAMD09_Pinmap: It is also a reference for the capabilities of each pin.""" #: The pins capable of analog output - analog_pins = (_ADC_INPUT_0_PIN, _ADC_INPUT_1_PIN, - _ADC_INPUT_2_PIN, _ADC_INPUT_3_PIN) + analog_pins = ( + _ADC_INPUT_0_PIN, + _ADC_INPUT_1_PIN, + _ADC_INPUT_2_PIN, + _ADC_INPUT_3_PIN, + ) """The effective bit resolution of the PWM pins""" pwm_width = 8 diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 26ff98f..3db487f 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -55,9 +55,11 @@ try: from micropython import const except ImportError: + def const(x): return x + from adafruit_bus_device.i2c_device import I2CDevice __version__ = "0.0.0-auto.0" @@ -124,16 +126,18 @@ def const(x): _HW_ID_CODE = const(0x55) _EEPROM_I2C_ADDR = const(0x3F) -#TODO: update when we get real PID +# TODO: update when we get real PID _CRICKIT_PID = const(9999) _ROBOHATMM1_PID = const(9998) + class Seesaw: """Driver for Seesaw i2c generic conversion trip :param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to :param int addr: I2C address of the SeeSaw device :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output""" + INPUT = const(0x00) OUTPUT = const(0x01) INPUT_PULLUP = const(0x02) @@ -150,25 +154,33 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None): def sw_reset(self): """Trigger a software reset of the SeeSaw chip""" self.write8(_STATUS_BASE, _STATUS_SWRST, 0xFF) - time.sleep(.500) + time.sleep(0.500) chip_id = self.read8(_STATUS_BASE, _STATUS_HW_ID) if chip_id != _HW_ID_CODE: - raise RuntimeError("Seesaw hardware ID returned (0x{:x}) is not " - "correct! Expected 0x{:x}. Please check your wiring." - .format(chip_id, _HW_ID_CODE)) + raise RuntimeError( + "Seesaw hardware ID returned (0x{:x}) is not " + "correct! Expected 0x{:x}. Please check your wiring.".format( + chip_id, _HW_ID_CODE + ) + ) pid = self.get_version() >> 16 + # pylint: disable=import-outside-toplevel if pid == _CRICKIT_PID: from adafruit_seesaw.crickit import Crickit_Pinmap + self.pin_mapping = Crickit_Pinmap elif pid == _ROBOHATMM1_PID: from adafruit_seesaw.robohat import MM1_Pinmap + self.pin_mapping = MM1_Pinmap else: from adafruit_seesaw.samd09 import SAMD09_Pinmap + self.pin_mapping = SAMD09_Pinmap + # pylint: enable=import-outside-toplevel def get_options(self): """Retrieve the 'options' word from the SeeSaw board""" @@ -219,7 +231,6 @@ def digital_read_bulk_b(self, pins, delay=0.008): ret = struct.unpack(">I", buf[4:])[0] return ret & pins - def set_GPIO_interrupts(self, pins, enabled): """Enable or disable the GPIO interrupt""" cmd = struct.pack(">I", pins) @@ -234,9 +245,13 @@ def analog_read(self, pin): if pin not in self.pin_mapping.analog_pins: raise ValueError("Invalid ADC pin") - self.read(_ADC_BASE, _ADC_CHANNEL_OFFSET + self.pin_mapping.analog_pins.index(pin), buf) + self.read( + _ADC_BASE, + _ADC_CHANNEL_OFFSET + self.pin_mapping.analog_pins.index(pin), + buf, + ) ret = struct.unpack(">H", buf)[0] - time.sleep(.001) + time.sleep(0.001) return ret def touch_read(self, pin): @@ -246,7 +261,11 @@ def touch_read(self, pin): if pin not in self.pin_mapping.touch_pins: raise ValueError("Invalid touch pin") - self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET + self.pin_mapping.touch_pins.index(pin), buf) + self.read( + _TOUCH_BASE, + _TOUCH_CHANNEL_OFFSET + self.pin_mapping.touch_pins.index(pin), + buf, + ) ret = struct.unpack(">H", buf)[0] return ret @@ -254,16 +273,16 @@ def moisture_read(self): """Read the value of the moisture sensor""" buf = bytearray(2) - self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, .005) + self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, 0.005) ret = struct.unpack(">H", buf)[0] - time.sleep(.001) + time.sleep(0.001) # retry if reading was bad count = 0 while ret > 4095: - self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, .005) + self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, 0.005) ret = struct.unpack(">H", buf)[0] - time.sleep(.001) + time.sleep(0.001) count += 1 if count > 3: raise RuntimeError("Could not get a valid moisture reading.") @@ -308,7 +327,6 @@ def digital_write_bulk(self, pins, value): else: self.write(_GPIO_BASE, _GPIO_BULK_CLR, cmd) - def digital_write_bulk_b(self, pins, value): """Set the mode of pins on the 'B' port as a bitmask""" cmd = bytearray(8) @@ -324,7 +342,9 @@ def analog_write(self, pin, value): if self.pin_mapping.pwm_width == 16: if pin in self.pin_mapping.pwm_pins: pin_found = True - cmd = bytearray([self.pin_mapping.pwm_pins.index(pin), (value >> 8), value & 0xFF]) + cmd = bytearray( + [self.pin_mapping.pwm_pins.index(pin), (value >> 8), value & 0xFF] + ) else: if pin in self.pin_mapping.pwm_pins: pin_found = True @@ -333,12 +353,12 @@ def analog_write(self, pin, value): if pin_found is False: raise ValueError("Invalid PWM pin") self.write(_TIMER_BASE, _TIMER_PWM, cmd) - time.sleep(.001) + time.sleep(0.001) def get_temp(self): """Read the temperature""" buf = bytearray(4) - self.read(_STATUS_BASE, _STATUS_TEMP, buf, .005) + self.read(_STATUS_BASE, _STATUS_TEMP, buf, 0.005) buf[0] = buf[0] & 0x3F ret = struct.unpack(">I", buf)[0] return 0.00001525878 * ret @@ -346,7 +366,9 @@ 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]) + cmd = bytearray( + [self.pin_mapping.pwm_pins.index(pin), (freq >> 8), freq & 0xFF] + ) self.write(_TIMER_BASE, _TIMER_FREQ, cmd) else: raise ValueError("Invalid PWM pin") @@ -370,7 +392,7 @@ def set_pwm_freq(self, pin, freq): 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(.250) + time.sleep(0.250) self.i2c_device.device_address = addr self.sw_reset() @@ -405,7 +427,7 @@ def read8(self, reg_base, reg): self.read(reg_base, reg, ret) return ret[0] - def read(self, reg_base, reg, buf, delay=.008): + def read(self, reg_base, reg, buf, delay=0.008): """Read an arbitrary I2C register range on the device""" self.write(reg_base, reg) if self._drdy is not None: diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index b3d54f4..16b050d 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -28,11 +28,15 @@ from collections import namedtuple import board + try: from micropython import const except ImportError: + def const(x): return x + + from adafruit_seesaw.seesaw import Seesaw __version__ = "0.0.0-auto.0" @@ -55,26 +59,29 @@ def const(x): Buttons = namedtuple("Buttons", "right down left up select a b c") + class TFTShield18(Seesaw): _BACKLIGHT_ON = b"\xFF\xFF" _BACKLIGHT_OFF = b"\x00\x00" try: - _button_mask = ((1 << _BUTTON_RIGHT) | - (1 << _BUTTON_DOWN) | - (1 << _BUTTON_LEFT) | - (1 << _BUTTON_UP) | - (1 << _BUTTON_SELECT) | - (1 << _BUTTON_A) | - (1 << _BUTTON_B) | - (1 << _BUTTON_C)) + _button_mask = ( + (1 << _BUTTON_RIGHT) + | (1 << _BUTTON_DOWN) + | (1 << _BUTTON_LEFT) + | (1 << _BUTTON_UP) + | (1 << _BUTTON_SELECT) + | (1 << _BUTTON_A) + | (1 << _BUTTON_B) + | (1 << _BUTTON_C) + ) except TypeError: -# During Sphinx build, the following error occurs: -# File ".../tftshield18.py", line 60, in TFTShield18 -# (1 << _BUTTON_B) | -# TypeError: unsupported operand type(s) for <<: 'int' and '_MockObject' - _button_mask = 0xff + # During Sphinx build, the following error occurs: + # File ".../tftshield18.py", line 60, in TFTShield18 + # (1 << _BUTTON_B) | + # TypeError: unsupported operand type(s) for <<: 'int' and '_MockObject' + _button_mask = 0xFF def __init__(self, i2c_bus=board.I2C(), addr=0x2E): super(TFTShield18, self).__init__(i2c_bus, addr) @@ -111,6 +118,18 @@ def buttons(self): Return a set of buttons with current push values """ button_values = self.digital_read_bulk(self._button_mask) - return Buttons(*[not button_values & (1 << button) for button in - (_BUTTON_RIGHT, _BUTTON_DOWN, _BUTTON_LEFT, _BUTTON_UP, - _BUTTON_SELECT, _BUTTON_A, _BUTTON_B, _BUTTON_C)]) + return Buttons( + *[ + not button_values & (1 << button) + for button in ( + _BUTTON_RIGHT, + _BUTTON_DOWN, + _BUTTON_LEFT, + _BUTTON_UP, + _BUTTON_SELECT, + _BUTTON_A, + _BUTTON_B, + _BUTTON_C, + ) + ] + ) diff --git a/docs/conf.py b/docs/conf.py index dbd03c5..e2155eb 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,46 +11,57 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", ] # 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", "digitalio", "board"] -autodoc_default_flags = ['special-members', 'members'] +autodoc_default_flags = ["special-members", "members"] autodoc_default_options = { - 'member-order': 'bysource', - 'exclude-members': '__weakref__,__getnewargs__,__dict__,__module__,__init__', + "member-order": "bysource", + "exclude-members": "__weakref__,__getnewargs__,__dict__,__module__,__init__", } -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice": ( + "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + None, + ), + "Register": ( + "https://circuitpython.readthedocs.io/projects/register/en/latest/", + None, + ), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit SEESAW Library' -copyright = u'2017 Dean Miller' -author = u'Dean Miller' +project = u"Adafruit SEESAW Library" +copyright = u"2017 Dean Miller" +author = u"Dean Miller" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -61,7 +73,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -73,7 +85,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -87,59 +99,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitSEESAWLibrarydoc' +htmlhelp_basename = "AdafruitSEESAWLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitSEESAWLibrary.tex', u'Adafruit SEESAW Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitSEESAWLibrary.tex", + u"Adafruit SEESAW Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -147,8 +162,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'adafruitSEESAWlibrary', u'Adafruit SEESAW Library Documentation', - [author], 1) + ( + master_doc, + "adafruitSEESAWlibrary", + u"Adafruit SEESAW Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -157,7 +177,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitSEESAWLibrary', u'Adafruit SEESAW Library Documentation', - author, 'AdafruitSEESAWLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitSEESAWLibrary", + u"Adafruit SEESAW Library Documentation", + author, + "AdafruitSEESAWLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/seesaw_crickit_test.py b/examples/seesaw_crickit_test.py index 94887a4..782d2c4 100644 --- a/examples/seesaw_crickit_test.py +++ b/examples/seesaw_crickit_test.py @@ -4,8 +4,8 @@ from adafruit_seesaw.pwmout import PWMOut from adafruit_motor import servo -#from analogio import AnalogOut -#import board +# from analogio import AnalogOut +# import board i2c_bus = busio.I2C(SCL, SDA) ss = Seesaw(i2c_bus) @@ -53,8 +53,8 @@ counter = 0 -#analog_out = AnalogOut(board.A0) -#analog_out.value = 512 +# analog_out = AnalogOut(board.A0) +# analog_out.value = 512 while True: counter = (counter + 1) % 256 @@ -63,12 +63,11 @@ print("-------------------- analog -----------------------") str_out = "" for i in range(8): - val = ss.analog_read(CRCKit_adc[i]) * 3.3/1024 + val = ss.analog_read(CRCKit_adc[i]) * 3.3 / 1024 str_out = str_out + str(round(val, 2)) + "\t" print(str_out + "\n") - for i in range(4): val = ss.touch_read(i) cap_justtouched[i] = False @@ -116,7 +115,6 @@ else: print("Stopping speaker") - if test_servos: if counter % 32 == 0: print("-------------------- servos -----------------------") @@ -129,7 +127,6 @@ print("SER" + str(servonum) + " RIGHT") servos[servonum].angle = 180 - if test_drives: if counter % 32 == 0: print("-------------------- drives -----------------------") @@ -154,10 +151,10 @@ else: if motor1_dir: ss.analog_write(_CRCKIT_M1_A1, 0) - ss.analog_write(_CRCKIT_M1_A2, (255-counter) * 512) + 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_A1, (255 - counter) * 512) if counter == 255: print("-------------------- motor 1 -----------------------") motor1_dir = not motor1_dir @@ -172,10 +169,10 @@ else: if motor2_dir: ss.analog_write(_CRCKIT_M1_B1, 0) - ss.analog_write(_CRCKIT_M1_B2, (255-counter) * 512) + 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_B1, (255 - counter) * 512) if counter == 255: print("-------------------- motor 2 -----------------------") motor2_dir = not motor2_dir diff --git a/examples/seesaw_joy_featherwing.py b/examples/seesaw_joy_featherwing.py index 7eb1a36..0a516d4 100755 --- a/examples/seesaw_joy_featherwing.py +++ b/examples/seesaw_joy_featherwing.py @@ -8,16 +8,18 @@ # pylint: disable=bad-whitespace BUTTON_RIGHT = const(6) -BUTTON_DOWN = const(7) -BUTTON_LEFT = const(9) -BUTTON_UP = const(10) -BUTTON_SEL = const(14) +BUTTON_DOWN = const(7) +BUTTON_LEFT = const(9) +BUTTON_UP = const(10) +BUTTON_SEL = const(14) # pylint: enable=bad-whitespace -button_mask = const((1 << BUTTON_RIGHT) | - (1 << BUTTON_DOWN) | - (1 << BUTTON_LEFT) | - (1 << BUTTON_UP) | - (1 << BUTTON_SEL)) +button_mask = const( + (1 << BUTTON_RIGHT) + | (1 << BUTTON_DOWN) + | (1 << BUTTON_LEFT) + | (1 << BUTTON_UP) + | (1 << BUTTON_SEL) +) i2c_bus = busio.I2C(SCL, SDA) @@ -32,7 +34,7 @@ x = ss.analog_read(2) y = ss.analog_read(3) - if (abs(x - last_x) > 3) or (abs(y - last_y) > 3): + if (abs(x - last_x) > 3) or (abs(y - last_y) > 3): print(x, y) last_x = x last_y = y @@ -53,4 +55,4 @@ if not buttons & (1 << BUTTON_SEL): print("Button SEL pressed") - time.sleep(.01) + time.sleep(0.01) diff --git a/examples/seesaw_minitft_featherwing.py b/examples/seesaw_minitft_featherwing.py index 60a1da9..ecc47df 100644 --- a/examples/seesaw_minitft_featherwing.py +++ b/examples/seesaw_minitft_featherwing.py @@ -7,21 +7,23 @@ # pylint: disable=bad-whitespace BUTTON_RIGHT = const(7) -BUTTON_DOWN = const(4) -BUTTON_LEFT = const(3) -BUTTON_UP = const(2) -BUTTON_SEL = const(11) -BUTTON_A = const(10) -BUTTON_B = const(9) +BUTTON_DOWN = const(4) +BUTTON_LEFT = const(3) +BUTTON_UP = const(2) +BUTTON_SEL = const(11) +BUTTON_A = const(10) +BUTTON_B = const(9) # pylint: enable=bad-whitespace -button_mask = const((1 << BUTTON_RIGHT) | - (1 << BUTTON_DOWN) | - (1 << BUTTON_LEFT) | - (1 << BUTTON_UP) | - (1 << BUTTON_SEL) | - (1 << BUTTON_A) | - (1 << BUTTON_B)) +button_mask = const( + (1 << BUTTON_RIGHT) + | (1 << BUTTON_DOWN) + | (1 << BUTTON_LEFT) + | (1 << BUTTON_UP) + | (1 << BUTTON_SEL) + | (1 << BUTTON_A) + | (1 << BUTTON_B) +) i2c_bus = board.I2C() @@ -52,4 +54,4 @@ if not buttons & (1 << BUTTON_B): print("Button B pressed") - time.sleep(.01) + time.sleep(0.01) diff --git a/examples/seesaw_simpletest.py b/examples/seesaw_simpletest.py index da37053..7975bc7 100644 --- a/examples/seesaw_simpletest.py +++ b/examples/seesaw_simpletest.py @@ -15,7 +15,7 @@ ss.pin_mode(15, ss.OUTPUT) while True: - ss.digital_write(15, True) # turn the LED on (True is the voltage level) - time.sleep(1) # wait for a second + ss.digital_write(15, True) # turn the LED on (True is the voltage level) + time.sleep(1) # wait for a second ss.digital_write(15, False) # turn the LED off by making the voltage LOW time.sleep(1) diff --git a/setup.py b/setup.py index 2e453dc..fc2ca7c 100755 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -14,47 +15,38 @@ 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: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-seesaw', - + name="adafruit-circuitpython-seesaw", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for controlling a SeeSaw helper chip.', + setup_requires=["setuptools_scm"], + description="CircuitPython library for controlling a SeeSaw helper chip.", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_seesaw', - + url="https://github.com/adafruit/Adafruit_CircuitPython_seesaw", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"], - # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit seesaw hardware micropython circuitpython', - + 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'], + packages=["adafruit_seesaw"], ) From 3f06fad666d5f47b94555e21e320f3bd7c193685 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 7 Apr 2020 15:02:31 -0500 Subject: [PATCH 033/182] build.yml: add black formatting check Signed-off-by: sommersoft --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1dad804..b6977a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,9 @@ jobs: pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags + - name: Check formatting + run: | + black --check --target-version=py35 . - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) From 93d0abe34307deec1313de9f6564dddf8c1786c9 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 9 Apr 2020 15:10:29 -0400 Subject: [PATCH 034/182] Black reformatting with Python 3 target. --- docs/conf.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e2155eb..b1f4454 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,18 +50,18 @@ master_doc = "index" # General information about the project. -project = u"Adafruit SEESAW Library" -copyright = u"2017 Dean Miller" -author = u"Dean Miller" +project = "Adafruit SEESAW Library" +copyright = "2017 Dean Miller" +author = "Dean Miller" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u"1.0" +version = "1.0" # The full version, including alpha/beta/rc tags. -release = u"1.0" +release = "1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -151,7 +151,7 @@ ( master_doc, "AdafruitSEESAWLibrary.tex", - u"Adafruit SEESAW Library Documentation", + "Adafruit SEESAW Library Documentation", author, "manual", ), @@ -165,7 +165,7 @@ ( master_doc, "adafruitSEESAWlibrary", - u"Adafruit SEESAW Library Documentation", + "Adafruit SEESAW Library Documentation", [author], 1, ) @@ -180,7 +180,7 @@ ( master_doc, "AdafruitSEESAWLibrary", - u"Adafruit SEESAW Library Documentation", + "Adafruit SEESAW Library Documentation", author, "AdafruitSEESAWLibrary", "One line description of project.", From 65709c3cfd6b21e5a7060f32dc2224cf0942a103 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Apr 2020 21:53:20 -0400 Subject: [PATCH 035/182] Fix capitalization in conf.py --- docs/conf.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index b1f4454..290119c 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,7 +50,7 @@ master_doc = "index" # General information about the project. -project = "Adafruit SEESAW Library" +project = "Adafruit seesaw Library" copyright = "2017 Dean Miller" author = "Dean Miller" @@ -125,7 +125,7 @@ html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = "AdafruitSEESAWLibrarydoc" +htmlhelp_basename = "AdafruitseesawLibrarydoc" # -- Options for LaTeX output --------------------------------------------- @@ -150,8 +150,8 @@ latex_documents = [ ( master_doc, - "AdafruitSEESAWLibrary.tex", - "Adafruit SEESAW Library Documentation", + "Adafruitseesawibrary.tex", + "Adafruit seesaw Library Documentation", author, "manual", ), @@ -164,8 +164,8 @@ man_pages = [ ( master_doc, - "adafruitSEESAWlibrary", - "Adafruit SEESAW Library Documentation", + "adafruitseesawlibrary", + "Adafruit seesaw Library Documentation", [author], 1, ) From 88738da275a83acabb14b7140d1c79b33cdc7b02 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 8 Jul 2020 16:49:05 -0400 Subject: [PATCH 036/182] Fixed discord invite link --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 57085c6..26a3e43 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ Introduction :alt: Documentation Status .. image :: https://img.shields.io/discord/327254708534116352.svg - :target: https://discord.gg/nBQh6qu + :target: https://adafru.it/discord :alt: Discord .. image:: https://github.com/adafruit/Adafruit_CircuitPython_seesaw/workflows/Build%20CI/badge.svg From 62f609f39918dd79389ed5400e6758c7039aee00 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 23 Aug 2020 11:01:52 -0500 Subject: [PATCH 037/182] remove bad-whitespace pylint directive --- examples/seesaw_joy_featherwing.py | 2 -- examples/seesaw_minitft_featherwing.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/examples/seesaw_joy_featherwing.py b/examples/seesaw_joy_featherwing.py index 0a516d4..6eaa9d9 100755 --- a/examples/seesaw_joy_featherwing.py +++ b/examples/seesaw_joy_featherwing.py @@ -6,13 +6,11 @@ from adafruit_seesaw.seesaw import Seesaw -# pylint: disable=bad-whitespace BUTTON_RIGHT = const(6) BUTTON_DOWN = const(7) BUTTON_LEFT = const(9) BUTTON_UP = const(10) BUTTON_SEL = const(14) -# pylint: enable=bad-whitespace button_mask = const( (1 << BUTTON_RIGHT) | (1 << BUTTON_DOWN) diff --git a/examples/seesaw_minitft_featherwing.py b/examples/seesaw_minitft_featherwing.py index ecc47df..543cd73 100644 --- a/examples/seesaw_minitft_featherwing.py +++ b/examples/seesaw_minitft_featherwing.py @@ -5,7 +5,6 @@ from adafruit_seesaw.seesaw import Seesaw -# pylint: disable=bad-whitespace BUTTON_RIGHT = const(7) BUTTON_DOWN = const(4) BUTTON_LEFT = const(3) @@ -14,7 +13,6 @@ BUTTON_A = const(10) BUTTON_B = const(9) -# pylint: enable=bad-whitespace button_mask = const( (1 << BUTTON_RIGHT) | (1 << BUTTON_DOWN) From 52f624807167c54c0312bcf536091efb5ed42a92 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 24 Aug 2020 15:58:49 -0500 Subject: [PATCH 038/182] address super-with-arguments diagnostics --- adafruit_seesaw/keypad.py | 2 +- adafruit_seesaw/tftshield18.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_seesaw/keypad.py b/adafruit_seesaw/keypad.py index 031e975..4139cb0 100644 --- a/adafruit_seesaw/keypad.py +++ b/adafruit_seesaw/keypad.py @@ -81,7 +81,7 @@ class Keypad(Seesaw): EDGE_RISING = 3 def __init__(self, i2c_bus, addr=0x49, drdy=None): - super(Keypad, self).__init__(i2c_bus, addr, drdy) + super().__init__(i2c_bus, addr, drdy) self._interrupt_enabled = False @property diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 16b050d..6a38b40 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -84,7 +84,7 @@ class TFTShield18(Seesaw): _button_mask = 0xFF def __init__(self, i2c_bus=board.I2C(), addr=0x2E): - super(TFTShield18, self).__init__(i2c_bus, addr) + super().__init__(i2c_bus, addr) self.pin_mode(_TFTSHIELD_RESET_PIN, self.OUTPUT) self.pin_mode_bulk(self._button_mask, self.INPUT_PULLUP) From 432d3926bc8a14936d4037df327a51076400f36b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 24 Aug 2020 16:07:53 -0500 Subject: [PATCH 039/182] address wrong-import-order diagnostic --- examples/seesaw_crickit_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/seesaw_crickit_test.py b/examples/seesaw_crickit_test.py index 782d2c4..b323c07 100644 --- a/examples/seesaw_crickit_test.py +++ b/examples/seesaw_crickit_test.py @@ -1,8 +1,8 @@ from board import SCL, SDA import busio +from adafruit_motor import servo from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.pwmout import PWMOut -from adafruit_motor import servo # from analogio import AnalogOut # import board From 0f2258bf2120b9fe212e814bc94cb36d32ca1070 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 15:06:44 -0500 Subject: [PATCH 040/182] Added pre-commit and SPDX copyright Signed-off-by: dherrada --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++---- .github/workflows/release.yml | 4 ++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6977a9..59baa53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Build CI on: [pull_request, push] @@ -38,20 +42,36 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, black, & Sphinx + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - - name: Check formatting + - name: Pre-commit hooks run: | - black --check --target-version=py35 . + pre-commit run --all-files - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Archive bundles + uses: actions/upload-artifact@v2 + with: + name: bundles + path: ${{ github.workspace }}/bundles/ - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Build Python package + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + pip install --upgrade setuptools wheel twine readme_renderer testresources + python setup.py sdist + python setup.py bdist_wheel --universal + twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18efb9c..6d0015a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Release Actions on: From c449f07a1841c3a7e7e626219daea9f10b6b870b Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 16:06:47 -0500 Subject: [PATCH 041/182] Added pre-commit-config file Signed-off-by: dherrada --- .pre-commit-config.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aab5f1c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +repos: +- repo: https://github.com/python/black + rev: stable + hooks: + - id: black +- repo: https://github.com/fsfe/reuse-tool + rev: latest + hooks: + - id: reuse +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace From 391bd94b218c105d98360dbc2dc893c87f587a09 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 13 Jan 2021 14:32:47 -0500 Subject: [PATCH 042/182] Ran pre-commit, added licenses --- .gitignore | 4 + .pylintrc | 4 + .readthedocs.yml | 4 + CODE_OF_CONDUCT.md | 14 +- LICENSES/CC-BY-4.0.txt | 324 +++++++++++++++++++++++++ LICENSES/MIT.txt | 19 ++ LICENSES/Unlicense.txt | 20 ++ README.rst.license | 3 + adafruit_seesaw/analoginput.py | 26 +- adafruit_seesaw/crickit.py | 23 +- adafruit_seesaw/digitalio.py | 26 +- adafruit_seesaw/keypad.py | 39 +-- adafruit_seesaw/neopixel.py | 26 +- adafruit_seesaw/pwmout.py | 23 +- adafruit_seesaw/robohat.py | 23 +- adafruit_seesaw/samd09.py | 23 +- adafruit_seesaw/seesaw.py | 29 +-- adafruit_seesaw/tftshield18.py | 23 +- docs/_static/favicon.ico.license | 3 + docs/api.rst | 1 - docs/api.rst.license | 3 + docs/conf.py | 4 + docs/examples.rst.license | 3 + docs/index.rst.license | 3 + examples/seesaw_crickit_test.py | 3 + examples/seesaw_joy_featherwing.py | 3 + examples/seesaw_minitft_featherwing.py | 3 + examples/seesaw_simpletest.py | 3 + examples/seesaw_soil_simpletest.py | 3 + requirements.txt | 4 + setup.py | 4 + 31 files changed, 471 insertions(+), 222 deletions(-) create mode 100644 LICENSES/CC-BY-4.0.txt create mode 100644 LICENSES/MIT.txt create mode 100644 LICENSES/Unlicense.txt create mode 100644 README.rst.license create mode 100644 docs/_static/favicon.ico.license create mode 100644 docs/api.rst.license create mode 100644 docs/examples.rst.license create mode 100644 docs/index.rst.license diff --git a/.gitignore b/.gitignore index 1be1c4b..9647e71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + *.mpy .idea __pycache__ diff --git a/.pylintrc b/.pylintrc index d8f0ee8..5c31f66 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + [MASTER] # A comma-separated list of package or module names from where C extensions may diff --git a/.readthedocs.yml b/.readthedocs.yml index f4243ad..ffa84c4 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + python: version: 3 requirements_file: requirements.txt diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 134d510..8a55c07 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,3 +1,9 @@ + + # Adafruit Community Code of Conduct ## Our Pledge @@ -43,7 +49,7 @@ Examples of unacceptable behavior by participants include: The goal of the standards and moderation guidelines outlined here is to build and maintain a respectful community. We ask that you don’t just aim to be -"technically unimpeachable", but rather try to be your best self. +"technically unimpeachable", but rather try to be your best self. We value many things beyond technical expertise, including collaboration and supporting others within our community. Providing a positive experience for @@ -74,9 +80,9 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Moderators by tagging @community moderators. You may -also send an open message from any channel, or a direct message to -@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. diff --git a/LICENSES/CC-BY-4.0.txt b/LICENSES/CC-BY-4.0.txt new file mode 100644 index 0000000..3f92dfc --- /dev/null +++ b/LICENSES/CC-BY-4.0.txt @@ -0,0 +1,324 @@ +Creative Commons Attribution 4.0 International Creative Commons Corporation +("Creative Commons") is not a law firm and does not provide legal services +or legal advice. Distribution of Creative Commons public licenses does not +create a lawyer-client or other relationship. Creative Commons makes its licenses +and related information available on an "as-is" basis. Creative Commons gives +no warranties regarding its licenses, any material licensed under their terms +and conditions, or any related information. Creative Commons disclaims all +liability for damages resulting from their use to the fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and conditions +that creators and other rights holders may use to share original works of +authorship and other material subject to copyright and certain other rights +specified in the public license below. The following considerations are for +informational purposes only, are not exhaustive, and do not form part of our +licenses. + +Considerations for licensors: Our public licenses are intended for use by +those authorized to give the public permission to use material in ways otherwise +restricted by copyright and certain other rights. Our licenses are irrevocable. +Licensors should read and understand the terms and conditions of the license +they choose before applying it. Licensors should also secure all rights necessary +before applying our licenses so that the public can reuse the material as +expected. Licensors should clearly mark any material not subject to the license. +This includes other CC-licensed material, or material used under an exception +or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors + +Considerations for the public: By using one of our public licenses, a licensor +grants the public permission to use the licensed material under specified +terms and conditions. If the licensor's permission is not necessary for any +reason–for example, because of any applicable exception or limitation to copyright–then +that use is not regulated by the license. Our licenses grant only permissions +under copyright and certain other rights that a licensor has authority to +grant. Use of the licensed material may still be restricted for other reasons, +including because others have copyright or other rights in the material. A +licensor may make special requests, such as asking that all changes be marked +or described. Although not required by our licenses, you are encouraged to +respect those requests where reasonable. More considerations for the public +: wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution +4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree to +be bound by the terms and conditions of this Creative Commons Attribution +4.0 International Public License ("Public License"). To the extent this Public +License may be interpreted as a contract, You are granted the Licensed Rights +in consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the Licensor +receives from making the Licensed Material available under these terms and +conditions. + +Section 1 – Definitions. + +a. Adapted Material means material subject to Copyright and Similar Rights +that is derived from or based upon the Licensed Material and in which the +Licensed Material is translated, altered, arranged, transformed, or otherwise +modified in a manner requiring permission under the Copyright and Similar +Rights held by the Licensor. For purposes of this Public License, where the +Licensed Material is a musical work, performance, or sound recording, Adapted +Material is always produced where the Licensed Material is synched in timed +relation with a moving image. + +b. Adapter's License means the license You apply to Your Copyright and Similar +Rights in Your contributions to Adapted Material in accordance with the terms +and conditions of this Public License. + +c. Copyright and Similar Rights means copyright and/or similar rights closely +related to copyright including, without limitation, performance, broadcast, +sound recording, and Sui Generis Database Rights, without regard to how the +rights are labeled or categorized. For purposes of this Public License, the +rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. + +d. Effective Technological Measures means those measures that, in the absence +of proper authority, may not be circumvented under laws fulfilling obligations +under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, +and/or similar international agreements. + +e. Exceptions and Limitations means fair use, fair dealing, and/or any other +exception or limitation to Copyright and Similar Rights that applies to Your +use of the Licensed Material. + +f. Licensed Material means the artistic or literary work, database, or other +material to which the Licensor applied this Public License. + +g. Licensed Rights means the rights granted to You subject to the terms and +conditions of this Public License, which are limited to all Copyright and +Similar Rights that apply to Your use of the Licensed Material and that the +Licensor has authority to license. + +h. Licensor means the individual(s) or entity(ies) granting rights under this +Public License. + +i. Share means to provide material to the public by any means or process that +requires permission under the Licensed Rights, such as reproduction, public +display, public performance, distribution, dissemination, communication, or +importation, and to make material available to the public including in ways +that members of the public may access the material from a place and at a time +individually chosen by them. + +j. Sui Generis Database Rights means rights other than copyright resulting +from Directive 96/9/EC of the European Parliament and of the Council of 11 +March 1996 on the legal protection of databases, as amended and/or succeeded, +as well as other essentially equivalent rights anywhere in the world. + +k. You means the individual or entity exercising the Licensed Rights under +this Public License. Your has a corresponding meaning. + +Section 2 – Scope. + + a. License grant. + +1. Subject to the terms and conditions of this Public License, the Licensor +hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, +irrevocable license to exercise the Licensed Rights in the Licensed Material +to: + + A. reproduce and Share the Licensed Material, in whole or in part; and + + B. produce, reproduce, and Share Adapted Material. + +2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions +and Limitations apply to Your use, this Public License does not apply, and +You do not need to comply with its terms and conditions. + + 3. Term. The term of this Public License is specified in Section 6(a). + +4. Media and formats; technical modifications allowed. The Licensor authorizes +You to exercise the Licensed Rights in all media and formats whether now known +or hereafter created, and to make technical modifications necessary to do +so. The Licensor waives and/or agrees not to assert any right or authority +to forbid You from making technical modifications necessary to exercise the +Licensed Rights, including technical modifications necessary to circumvent +Effective Technological Measures. For purposes of this Public License, simply +making modifications authorized by this Section 2(a)(4) never produces Adapted +Material. + + 5. Downstream recipients. + +A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed +Material automatically receives an offer from the Licensor to exercise the +Licensed Rights under the terms and conditions of this Public License. + +B. No downstream restrictions. You may not offer or impose any additional +or different terms or conditions on, or apply any Effective Technological +Measures to, the Licensed Material if doing so restricts exercise of the Licensed +Rights by any recipient of the Licensed Material. + +6. No endorsement. Nothing in this Public License constitutes or may be construed +as permission to assert or imply that You are, or that Your use of the Licensed +Material is, connected with, or sponsored, endorsed, or granted official status +by, the Licensor or others designated to receive attribution as provided in +Section 3(a)(1)(A)(i). + + b. Other rights. + +1. Moral rights, such as the right of integrity, are not licensed under this +Public License, nor are publicity, privacy, and/or other similar personality +rights; however, to the extent possible, the Licensor waives and/or agrees +not to assert any such rights held by the Licensor to the limited extent necessary +to allow You to exercise the Licensed Rights, but not otherwise. + +2. Patent and trademark rights are not licensed under this Public License. + +3. To the extent possible, the Licensor waives any right to collect royalties +from You for the exercise of the Licensed Rights, whether directly or through +a collecting society under any voluntary or waivable statutory or compulsory +licensing scheme. In all other cases the Licensor expressly reserves any right +to collect such royalties. + +Section 3 – License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the following +conditions. + + a. Attribution. + +1. If You Share the Licensed Material (including in modified form), You must: + +A. retain the following if it is supplied by the Licensor with the Licensed +Material: + +i. identification of the creator(s) of the Licensed Material and any others +designated to receive attribution, in any reasonable manner requested by the +Licensor (including by pseudonym if designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of warranties; + +v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + +B. indicate if You modified the Licensed Material and retain an indication +of any previous modifications; and + +C. indicate the Licensed Material is licensed under this Public License, and +include the text of, or the URI or hyperlink to, this Public License. + +2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner +based on the medium, means, and context in which You Share the Licensed Material. +For example, it may be reasonable to satisfy the conditions by providing a +URI or hyperlink to a resource that includes the required information. + +3. If requested by the Licensor, You must remove any of the information required +by Section 3(a)(1)(A) to the extent reasonably practicable. + +4. If You Share Adapted Material You produce, the Adapter's License You apply +must not prevent recipients of the Adapted Material from complying with this +Public License. + +Section 4 – Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that apply to +Your use of the Licensed Material: + +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, +reuse, reproduce, and Share all or a substantial portion of the contents of +the database; + +b. if You include all or a substantial portion of the database contents in +a database in which You have Sui Generis Database Rights, then the database +in which You have Sui Generis Database Rights (but not its individual contents) +is Adapted Material; and + +c. You must comply with the conditions in Section 3(a) if You Share all or +a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not replace +Your obligations under this Public License where the Licensed Rights include +other Copyright and Similar Rights. + +Section 5 – Disclaimer of Warranties and Limitation of Liability. + +a. Unless otherwise separately undertaken by the Licensor, to the extent possible, +the Licensor offers the Licensed Material as-is and as-available, and makes +no representations or warranties of any kind concerning the Licensed Material, +whether express, implied, statutory, or other. This includes, without limitation, +warranties of title, merchantability, fitness for a particular purpose, non-infringement, +absence of latent or other defects, accuracy, or the presence or absence of +errors, whether or not known or discoverable. Where disclaimers of warranties +are not allowed in full or in part, this disclaimer may not apply to You. + +b. To the extent possible, in no event will the Licensor be liable to You +on any legal theory (including, without limitation, negligence) or otherwise +for any direct, special, indirect, incidental, consequential, punitive, exemplary, +or other losses, costs, expenses, or damages arising out of this Public License +or use of the Licensed Material, even if the Licensor has been advised of +the possibility of such losses, costs, expenses, or damages. Where a limitation +of liability is not allowed in full or in part, this limitation may not apply +to You. + +c. The disclaimer of warranties and limitation of liability provided above +shall be interpreted in a manner that, to the extent possible, most closely +approximates an absolute disclaimer and waiver of all liability. + +Section 6 – Term and Termination. + +a. This Public License applies for the term of the Copyright and Similar Rights +licensed here. However, if You fail to comply with this Public License, then +Your rights under this Public License terminate automatically. + +b. Where Your right to use the Licensed Material has terminated under Section +6(a), it reinstates: + +1. automatically as of the date the violation is cured, provided it is cured +within 30 days of Your discovery of the violation; or + + 2. upon express reinstatement by the Licensor. + +c. For the avoidance of doubt, this Section 6(b) does not affect any right +the Licensor may have to seek remedies for Your violations of this Public +License. + +d. For the avoidance of doubt, the Licensor may also offer the Licensed Material +under separate terms or conditions or stop distributing the Licensed Material +at any time; however, doing so will not terminate this Public License. + + e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. + +Section 7 – Other Terms and Conditions. + +a. The Licensor shall not be bound by any additional or different terms or +conditions communicated by You unless expressly agreed. + +b. Any arrangements, understandings, or agreements regarding the Licensed +Material not stated herein are separate from and independent of the terms +and conditions of this Public License. + +Section 8 – Interpretation. + +a. For the avoidance of doubt, this Public License does not, and shall not +be interpreted to, reduce, limit, restrict, or impose conditions on any use +of the Licensed Material that could lawfully be made without permission under +this Public License. + +b. To the extent possible, if any provision of this Public License is deemed +unenforceable, it shall be automatically reformed to the minimum extent necessary +to make it enforceable. If the provision cannot be reformed, it shall be severed +from this Public License without affecting the enforceability of the remaining +terms and conditions. + +c. No term or condition of this Public License will be waived and no failure +to comply consented to unless expressly agreed to by the Licensor. + +d. Nothing in this Public License constitutes or may be interpreted as a limitation +upon, or waiver of, any privileges and immunities that apply to the Licensor +or You, including from the legal processes of any jurisdiction or authority. + +Creative Commons is not a party to its public licenses. Notwithstanding, Creative +Commons may elect to apply one of its public licenses to material it publishes +and in those instances will be considered the "Licensor." The text of the +Creative Commons public licenses is dedicated to the public domain under the +CC0 Public Domain Dedication. Except for the limited purpose of indicating +that material is shared under a Creative Commons public license or as otherwise +permitted by the Creative Commons policies published at creativecommons.org/policies, +Creative Commons does not authorize the use of the trademark "Creative Commons" +or any other trademark or logo of Creative Commons without its prior written +consent including, without limitation, in connection with any unauthorized +modifications to any of its public licenses or any other arrangements, understandings, +or agreements concerning use of licensed material. For the avoidance of doubt, +this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..204b93d --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,19 @@ +MIT License Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 0000000..24a8f90 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,20 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute +this software, either in source code form or as a compiled binary, for any +purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and +to the detriment of our heirs and successors. We intend this dedication to +be an overt act of relinquishment in perpetuity of all present and future +rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH +THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, +please refer to diff --git a/README.rst.license b/README.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/README.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/adafruit_seesaw/analoginput.py b/adafruit_seesaw/analoginput.py index 53eb2aa..dd1ebd3 100644 --- a/adafruit_seesaw/analoginput.py +++ b/adafruit_seesaw/analoginput.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries # -# Copyright (c) 2017 Dean Miller for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + # pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ @@ -36,8 +19,7 @@ class AnalogInput: This class is intended to be a compatible subset of `analogio.AnalogIn` :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device - :param int pin: The pin number on the device -""" + :param int pin: The pin number on the device""" def __init__(self, seesaw, pin): self._seesaw = seesaw diff --git a/adafruit_seesaw/crickit.py b/adafruit_seesaw/crickit.py index 3089ab0..689b1ff 100644 --- a/adafruit_seesaw/crickit.py +++ b/adafruit_seesaw/crickit.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries # -# Copyright (c) 2017 Dean Miller for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + # pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods """ diff --git a/adafruit_seesaw/digitalio.py b/adafruit_seesaw/digitalio.py index 2a431b3..ca9a1f4 100644 --- a/adafruit_seesaw/digitalio.py +++ b/adafruit_seesaw/digitalio.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries # -# Copyright (c) 2017 Dean Miller for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + # pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ @@ -40,8 +23,7 @@ class DigitalIO: Due to technical limitations, PULL_DOWNs are not supported. :param ~adafruit_seesaw.seesaw.Seesaw seesaw: The device - :param int pin: The pin number on the device -""" + :param int pin: The pin number on the device""" def __init__(self, seesaw, pin): self._seesaw = seesaw diff --git a/adafruit_seesaw/keypad.py b/adafruit_seesaw/keypad.py index 4139cb0..4a3d6a3 100644 --- a/adafruit_seesaw/keypad.py +++ b/adafruit_seesaw/keypad.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries # -# Copyright (c) 2018 Dean Miller for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + # pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ @@ -52,8 +35,8 @@ def const(x): class KeyEvent: """Holds information about a key event in its properties - :param int num: The number of the key - :param int edge: One of the EDGE propertes of `adafruit_seesaw.keypad.Keypad` + :param int num: The number of the key + :param int edge: One of the EDGE propertes of `adafruit_seesaw.keypad.Keypad` """ def __init__(self, num, edge): @@ -67,9 +50,9 @@ def __init__(self, num, edge): class Keypad(Seesaw): """On compatible SeeSaw devices, reads from a keypad. - :param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to - :param int addr: I2C address of the SeeSaw device - :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output""" + :param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to + :param int addr: I2C address of the SeeSaw device + :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output""" #: Indicates that the key is currently pressed EDGE_HIGH = 0 @@ -115,9 +98,9 @@ def count(self, value): def set_event(self, key, edge, enable): """Control which kinds of events are set - :param int key: The key number - :param int edge: The type of event - :param bool enable: True to enable the event, False to disable it""" + :param int key: The key number + :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): raise ValueError("event enable must be True or False") diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index fe017e1..793b3b4 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries # -# Copyright (c) 2017 Dean Miller for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + # pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ @@ -71,8 +54,7 @@ class NeoPixel: :param float brightness: The brightness, from 0.0 to 1.0 :param bool auto_write: Automatically update the pixels when changed :param tuple pixel_order: The layout of the pixels. - Use one of the order constants such as RGBW. -""" + Use one of the order constants such as RGBW.""" def __init__( self, diff --git a/adafruit_seesaw/pwmout.py b/adafruit_seesaw/pwmout.py index ed934c0..0a148a6 100644 --- a/adafruit_seesaw/pwmout.py +++ b/adafruit_seesaw/pwmout.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries # -# Copyright (c) 2017 Dean Miller for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + # pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods """ diff --git a/adafruit_seesaw/robohat.py b/adafruit_seesaw/robohat.py index 0ff56a0..8bd14e9 100644 --- a/adafruit_seesaw/robohat.py +++ b/adafruit_seesaw/robohat.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2019 wallarug Robotics Masters # -# Copyright (c) 2019 wallarug for Robotics Masters -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + # pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods """ diff --git a/adafruit_seesaw/samd09.py b/adafruit_seesaw/samd09.py index 4b81f72..5c3ab18 100644 --- a/adafruit_seesaw/samd09.py +++ b/adafruit_seesaw/samd09.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries # -# Copyright (c) 2017 Dean Miller for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + # pylint: disable=missing-docstring,invalid-name,too-many-public-methods,too-few-public-methods """ diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 3db487f..09fbaec 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries # -# Copyright (c) 2017 Dean Miller for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + """ `adafruit_seesaw.seesaw` ==================================================== @@ -134,9 +117,9 @@ def const(x): class Seesaw: """Driver for Seesaw i2c generic conversion trip - :param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to - :param int addr: I2C address of the SeeSaw device - :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output""" + :param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to + :param int addr: I2C address of the SeeSaw device + :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output""" INPUT = const(0x00) OUTPUT = const(0x01) diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 6a38b40..830abd1 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2018 Dean Miller for Adafruit Industries # -# Copyright (c) 2018 Dean Miller for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + # pylint: disable=missing-docstring,invalid-name,too-many-public-methods """ diff --git a/docs/_static/favicon.ico.license b/docs/_static/favicon.ico.license new file mode 100644 index 0000000..86a3fbf --- /dev/null +++ b/docs/_static/favicon.ico.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries + +SPDX-License-Identifier: CC-BY-4.0 diff --git a/docs/api.rst b/docs/api.rst index d307888..0ffb57c 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -36,4 +36,3 @@ .. automodule:: adafruit_seesaw.tftshield18 :members: - diff --git a/docs/api.rst.license b/docs/api.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/api.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/conf.py b/docs/conf.py index 290119c..8932a71 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + import os import sys diff --git a/docs/examples.rst.license b/docs/examples.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/examples.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/index.rst.license b/docs/index.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/index.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/examples/seesaw_crickit_test.py b/examples/seesaw_crickit_test.py index b323c07..c454607 100644 --- a/examples/seesaw_crickit_test.py +++ b/examples/seesaw_crickit_test.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + from board import SCL, SDA import busio from adafruit_motor import servo diff --git a/examples/seesaw_joy_featherwing.py b/examples/seesaw_joy_featherwing.py index 6eaa9d9..1d79d0a 100755 --- a/examples/seesaw_joy_featherwing.py +++ b/examples/seesaw_joy_featherwing.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import time from board import SCL, SDA diff --git a/examples/seesaw_minitft_featherwing.py b/examples/seesaw_minitft_featherwing.py index 543cd73..e6f31a3 100644 --- a/examples/seesaw_minitft_featherwing.py +++ b/examples/seesaw_minitft_featherwing.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import time import board diff --git a/examples/seesaw_simpletest.py b/examples/seesaw_simpletest.py index 7975bc7..c831771 100644 --- a/examples/seesaw_simpletest.py +++ b/examples/seesaw_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + # Simple seesaw test using an LED attached to Pin 15. # # See the seesaw Learn Guide for wiring details: diff --git a/examples/seesaw_soil_simpletest.py b/examples/seesaw_soil_simpletest.py index 39c7626..af209a8 100644 --- a/examples/seesaw_soil_simpletest.py +++ b/examples/seesaw_soil_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import time from board import SCL, SDA diff --git a/requirements.txt b/requirements.txt index 465ff2f..f40b0b5 100755 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + adafruit-circuitpython-busdevice Adafruit-Blinka diff --git a/setup.py b/setup.py index fc2ca7c..bdaed56 100755 --- a/setup.py +++ b/setup.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + """A setuptools based setup module. See: From 043c1066d705ad210f376506c9757a634d964326 Mon Sep 17 00:00:00 2001 From: Dylan Herrada <33632497+dherrada@users.noreply.github.com> Date: Wed, 27 Jan 2021 19:05:17 -0500 Subject: [PATCH 043/182] Moved from pulseio.PWMOut to pwmio.PWMOut --- adafruit_seesaw/pwmout.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_seesaw/pwmout.py b/adafruit_seesaw/pwmout.py index 0a148a6..2c17aaa 100644 --- a/adafruit_seesaw/pwmout.py +++ b/adafruit_seesaw/pwmout.py @@ -14,7 +14,7 @@ class PWMOut: - """A single seesaw channel that matches the :py:class:`~pulseio.PWMOut` API.""" + """A single seesaw channel that matches the :py:class:`~pwmio.PWMOut` API.""" def __init__(self, seesaw, pin): self._seesaw = seesaw From 407abd05e3f4fe164cf964605532716a452cc756 Mon Sep 17 00:00:00 2001 From: Randall Bohn Date: Thu, 28 Jan 2021 20:05:15 -0700 Subject: [PATCH 044/182] Support boards that don't have a fixed I2C bus. --- adafruit_seesaw/tftshield18.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 830abd1..bc45c83 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -66,7 +66,12 @@ class TFTShield18(Seesaw): # TypeError: unsupported operand type(s) for <<: 'int' and '_MockObject' _button_mask = 0xFF - def __init__(self, i2c_bus=board.I2C(), addr=0x2E): + def __init__(self, i2c_bus=None, addr=0x2E): + if i2c_bus == None: + if hasattr(board, "I2C"): + i2c_bus = board.I2C + else: + print("Warning: board has no default I2C bus.") super().__init__(i2c_bus, addr) self.pin_mode(_TFTSHIELD_RESET_PIN, self.OUTPUT) self.pin_mode_bulk(self._button_mask, self.INPUT_PULLUP) From 9eb5d8f2e4d79561af5c0c74ce111dae21320c5b Mon Sep 17 00:00:00 2001 From: Randall Bohn Date: Thu, 28 Jan 2021 21:43:56 -0700 Subject: [PATCH 045/182] Raise ValueError if I2C bus is not provided. Based on guidance from jepler. --- adafruit_seesaw/tftshield18.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index bc45c83..6f3c05a 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -67,11 +67,11 @@ class TFTShield18(Seesaw): _button_mask = 0xFF def __init__(self, i2c_bus=None, addr=0x2E): - if i2c_bus == None: - if hasattr(board, "I2C"): - i2c_bus = board.I2C - else: - print("Warning: board has no default I2C bus.") + if i2c_bus is None: + try: + i2c_bus = board.I2C() + except AttributeError: + raise ValueError("Board has no default I2C bus.") super().__init__(i2c_bus, addr) self.pin_mode(_TFTSHIELD_RESET_PIN, self.OUTPUT) self.pin_mode_bulk(self._button_mask, self.INPUT_PULLUP) From b4e475fd63ae3ead6a4285d04696f713e03b812d Mon Sep 17 00:00:00 2001 From: Randall Bohn Date: Thu, 28 Jan 2021 21:51:16 -0700 Subject: [PATCH 046/182] Raise ValueError() from attributeError Suggested by pylint. TFTShield won't work without an i2c_bus, so fail with an informative message. --- adafruit_seesaw/tftshield18.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_seesaw/tftshield18.py b/adafruit_seesaw/tftshield18.py index 6f3c05a..494ed57 100755 --- a/adafruit_seesaw/tftshield18.py +++ b/adafruit_seesaw/tftshield18.py @@ -70,8 +70,8 @@ def __init__(self, i2c_bus=None, addr=0x2E): if i2c_bus is None: try: i2c_bus = board.I2C() - except AttributeError: - raise ValueError("Board has no default I2C bus.") + except AttributeError as attrError: + raise ValueError("Board has no default I2C bus.") from attrError super().__init__(i2c_bus, addr) self.pin_mode(_TFTSHIELD_RESET_PIN, self.OUTPUT) self.pin_mode_bulk(self._button_mask, self.INPUT_PULLUP) From 5b2112d2ca480a41653185cf4551d0bd496c9f3e Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Feb 2021 16:38:51 -0500 Subject: [PATCH 047/182] Hardcoded Black and REUSE versions Signed-off-by: dherrada --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aab5f1c..07f886c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,11 +4,11 @@ repos: - repo: https://github.com/python/black - rev: stable + rev: 20.8b1 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: latest + rev: v0.12.1 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks From f3b0a8b718f76dced024c30e4de3d97d4a4f1fb0 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 2 Mar 2021 16:46:17 -0500 Subject: [PATCH 048/182] Removed pylint process from github workflow Signed-off-by: dherrada --- .github/workflows/build.yml | 8 ++------ .pre-commit-config.yaml | 15 +++++++++++++++ .pylintrc | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59baa53..621d5ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,18 +42,14 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks run: | pre-commit run --all-files - - name: PyLint - run: | - pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Archive bundles diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 07f886c..354c761 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,18 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace +- repo: https://github.com/pycqa/pylint + rev: pylint-2.7.1 + hooks: + - id: pylint + name: pylint (library code) + types: [python] + exclude: "^(docs/|examples/|setup.py$)" +- repo: local + hooks: + - id: pylint_examples + name: pylint (examples code) + description: Run pylint rules on "examples/*.py" files + entry: /usr/bin/env bash -c + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + language: system diff --git a/.pylintrc b/.pylintrc index 5c31f66..9ed669e 100644 --- a/.pylintrc +++ b/.pylintrc @@ -250,7 +250,7 @@ ignore-comments=yes ignore-docstrings=yes # Ignore imports when computing similarities. -ignore-imports=no +ignore-imports=yes # Minimum lines number of a similarity. min-similarity-lines=4 From 1f295d0a9f983f536ff32732f7780d7e5d0c87ab Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 2 Mar 2021 17:17:50 -0500 Subject: [PATCH 049/182] Re-added pylint install to build.yml Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 621d5ef..3baf502 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (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 + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks From 9e06ac00fb27817b031b6b5acadd9542cab2989f Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 19 Mar 2021 13:46:46 -0400 Subject: [PATCH 050/182] "Increase duplicate code check threshold " --- .pylintrc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 9ed669e..0238b90 100644 --- a/.pylintrc +++ b/.pylintrc @@ -22,8 +22,7 @@ ignore-patterns= #init-hook= # Use multiple processes to speed up Pylint. -# jobs=1 -jobs=2 +jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. @@ -253,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 2ab7932ae24ab9bbc1090a245dc6e8a3ee4acf37 Mon Sep 17 00:00:00 2001 From: rianadon Date: Thu, 22 Apr 2021 23:18:34 -0700 Subject: [PATCH 051/182] Add method for reading GPIO Interrupt flag --- adafruit_seesaw/seesaw.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 09fbaec..0e5d022 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -222,6 +222,12 @@ def set_GPIO_interrupts(self, pins, enabled): else: self.write(_GPIO_BASE, _GPIO_INTENCLR, cmd) + def get_GPIO_interrupt_flag(self, delay=0.008): + """Read and clear GPIO interrupts that have fired""" + buf = bytearray(4) + self.read(_GPIO_BASE, _GPIO_INTFLAG, buf, delay=delay) + return struct.unpack(">I", buf)[0] + def analog_read(self, pin): """Read the value of an analog pin by number""" buf = bytearray(2) From 902665d19ba2e4a4bd0e6f4009e101e0a2c2bb5f Mon Sep 17 00:00:00 2001 From: John Furcean Date: Wed, 12 May 2021 12:10:48 -0400 Subject: [PATCH 052/182] add rotary encoder support --- adafruit_seesaw/seesaw.py | 32 ++++++++++++++++++++++++++++ examples/seesaw_rotary_simpletest.py | 32 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 examples/seesaw_rotary_simpletest.py diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 0e5d022..c4e0caf 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -61,6 +61,7 @@ def const(x): _EEPROM_BASE = const(0x0D) _NEOPIXEL_BASE = const(0x0E) _TOUCH_BASE = const(0x0F) +_ENCODER_BASE = const(0x11) _GPIO_DIRSET_BULK = const(0x02) _GPIO_DIRCLR_BULK = const(0x03) @@ -109,6 +110,12 @@ def const(x): _HW_ID_CODE = const(0x55) _EEPROM_I2C_ADDR = const(0x3F) +_ENCODER_STATUS = const(0x00) +_ENCODER_INTENSET = const(0x10) +_ENCODER_INTENCLR = const(0x20) +_ENCODER_POSITION = const(0x30) +_ENCODER_DELTA = const(0x40) + # TODO: update when we get real PID _CRICKIT_PID = const(9999) _ROBOHATMM1_PID = const(9998) @@ -362,6 +369,31 @@ def set_pwm_freq(self, pin, freq): else: raise ValueError("Invalid PWM pin") + def get_encoder_pos(self, encoder=0): + """Read the current position of the encoder""" + buf = bytearray(4) + self.read(_ENCODER_BASE, _ENCODER_POSITION + encoder, buf) + return struct.unpack(">i", buf)[0] + + def set_encoder_pos(self, pos, encoder=0): + """Set the current position of the encoder""" + cmd = struct.pack(">i", pos) + self.write(_ENCODER_BASE, _ENCODER_POSITION + encoder, cmd) + + def get_encoder_delta(self, encoder=0): + """Read the change in encoder position since it was last read""" + buf = bytearray(4) + self.read(_ENCODER_BASE, _ENCODER_DELTA + encoder, buf) + return struct.unpack(">i", buf)[0] + + def enable_encoder_interrupt(self, encoder=0): + """Enable the interrupt to fire when the encoder changes position""" + self.write8(_ENCODER_BASE, _ENCODER_INTENSET + encoder, 0x01) + + def disable_encoder_interrupt(self, encoder=0): + """Disable the interrupt from firing when the encoder changes""" + self.write8(_ENCODER_BASE, _ENCODER_INTENCLR + encoder, 0x01) + # def enable_sercom_data_rdy_interrupt(self, sercom): # # _sercom_inten.DATA_RDY = 1 diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py new file mode 100644 index 0000000..5eaac54 --- /dev/null +++ b/examples/seesaw_rotary_simpletest.py @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: 2021 John Furcean +# SPDX-License-Identifier: MIT + +import board +import busio +from adafruit_seesaw.seesaw import Seesaw +from adafruit_seesaw.digitalio import DigitalIO + +i2c_bus = busio.I2C(board.SCL, board.SDA) + +seesaw = Seesaw(i2c_bus, addr=0x36) + +button = DigitalIO(seesaw, 24) +button_held = False + +last_pos = seesaw.get_encoder_pos() + +while True: + + # read position of the rotary encoder + pos = seesaw.get_encoder_pos() + if pos != last_pos: + last_pos = pos + print(f"Position: {pos}") + + if not button.value and not button_held: + button_held = True + print("Button pressed") + + if button.value and button_held: + button_held = False + print("Button released") From d38cdea02ac690a2f5c88ed91dcbe63b886f9818 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Wed, 12 May 2021 13:16:21 -0400 Subject: [PATCH 053/182] Update names. --- adafruit_seesaw/seesaw.py | 10 +++++----- examples/seesaw_rotary_simpletest.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index c4e0caf..1e003a0 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -369,19 +369,19 @@ def set_pwm_freq(self, pin, freq): else: raise ValueError("Invalid PWM pin") - def get_encoder_pos(self, encoder=0): - """Read the current position of the encoder""" + def encoder_position(self, encoder=0): + """The current position of the encoder""" buf = bytearray(4) self.read(_ENCODER_BASE, _ENCODER_POSITION + encoder, buf) return struct.unpack(">i", buf)[0] - def set_encoder_pos(self, pos, encoder=0): + def set_encoder_position(self, pos, encoder=0): """Set the current position of the encoder""" cmd = struct.pack(">i", pos) self.write(_ENCODER_BASE, _ENCODER_POSITION + encoder, cmd) - def get_encoder_delta(self, encoder=0): - """Read the change in encoder position since it was last read""" + def encoder_delta(self, encoder=0): + """The change in encoder position since it was last read""" buf = bytearray(4) self.read(_ENCODER_BASE, _ENCODER_DELTA + encoder, buf) return struct.unpack(">i", buf)[0] diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index 5eaac54..65f6025 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -13,15 +13,15 @@ button = DigitalIO(seesaw, 24) button_held = False -last_pos = seesaw.get_encoder_pos() +last_position = seesaw.encoder_position() while True: # read position of the rotary encoder - pos = seesaw.get_encoder_pos() - if pos != last_pos: - last_pos = pos - print(f"Position: {pos}") + position = seesaw.encoder_position() + if position != last_position: + last_position = position + print(f"Position: {position}") if not button.value and not button_held: button_held = True From a8665714df8c11158a871170412f34c2bc233e77 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Wed, 12 May 2021 13:20:50 -0400 Subject: [PATCH 054/182] Update string format. --- examples/seesaw_rotary_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index 65f6025..3434ddc 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -21,7 +21,7 @@ position = seesaw.encoder_position() if position != last_position: last_position = position - print(f"Position: {position}") + print("Position: {}".format(position)) if not button.value and not button_held: button_held = True From 4d3f459da01f39bdfeeb1af6bc6f34d6eff690c4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 May 2021 12:35:44 -0500 Subject: [PATCH 055/182] Add IncrementalEncoder .. this wraps the core code in seesaw.py into a compatible subset of the core's rotaryio.IncrementalEncoder class. --- adafruit_seesaw/rotaryio.py | 35 ++++++++++++++++++++++++++++ examples/seesaw_rotary_simpletest.py | 6 +++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 adafruit_seesaw/rotaryio.py diff --git a/adafruit_seesaw/rotaryio.py b/adafruit_seesaw/rotaryio.py new file mode 100644 index 0000000..84e9ade --- /dev/null +++ b/adafruit_seesaw/rotaryio.py @@ -0,0 +1,35 @@ +# SPDX-FileCopyrightText: 2017 Dean Miller for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +# pylint: disable=missing-docstring,invalid-name,too-many-public-methods + + +""" +`adafruit_seesaw.digitalio` +==================================================== +""" + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" + + +class IncrementalEncoder: + """IncrementalEncoder determines the relative rotational position based + on two series of pulses.""" + + def __init__(self, seesaw, encoder=0): + """Create an IncrementalEncoder object associated with the given + eesaw device.""" + self._seesaw = seesaw + self._encoder = encoder + + @property + def position(self): + """The current position in terms of pulses. The number of pulses per + rotation is defined by the specific hardware.""" + return self._seesaw.encoder_position(self._encoder) + + @position.setter + def position(self, value): + self._seesaw.set_encoder_position(value, self._encoder) diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index 3434ddc..63d01c3 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -5,6 +5,7 @@ import busio from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.digitalio import DigitalIO +from adafruit_seesaw.rotaryio import IncrementalEncoder i2c_bus = busio.I2C(board.SCL, board.SDA) @@ -13,12 +14,13 @@ button = DigitalIO(seesaw, 24) button_held = False -last_position = seesaw.encoder_position() +encoder = IncrementalEncoder(seesaw) +last_position = None while True: # read position of the rotary encoder - position = seesaw.encoder_position() + position = encoder.position if position != last_position: last_position = position print("Position: {}".format(position)) From c20bb202c1779ee064f3dbfaba46507e5838fc08 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 May 2021 11:54:01 -0500 Subject: [PATCH 056/182] examples: Use board.I2C() --- examples/seesaw_crickit_test.py | 5 ++--- examples/seesaw_joy_featherwing.py | 5 ++--- examples/seesaw_rotary_simpletest.py | 3 +-- examples/seesaw_simpletest.py | 5 ++--- examples/seesaw_soil_simpletest.py | 5 ++--- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/examples/seesaw_crickit_test.py b/examples/seesaw_crickit_test.py index c454607..d77ff25 100644 --- a/examples/seesaw_crickit_test.py +++ b/examples/seesaw_crickit_test.py @@ -1,8 +1,7 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from board import SCL, SDA -import busio +import board from adafruit_motor import servo from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.pwmout import PWMOut @@ -10,7 +9,7 @@ # from analogio import AnalogOut # import board -i2c_bus = busio.I2C(SCL, SDA) +i2c_bus = board.I2C() ss = Seesaw(i2c_bus) pwm1 = PWMOut(ss, 17) pwm2 = PWMOut(ss, 16) diff --git a/examples/seesaw_joy_featherwing.py b/examples/seesaw_joy_featherwing.py index 1d79d0a..2512bf0 100755 --- a/examples/seesaw_joy_featherwing.py +++ b/examples/seesaw_joy_featherwing.py @@ -3,8 +3,7 @@ import time -from board import SCL, SDA -import busio +import board from micropython import const from adafruit_seesaw.seesaw import Seesaw @@ -22,7 +21,7 @@ | (1 << BUTTON_SEL) ) -i2c_bus = busio.I2C(SCL, SDA) +i2c_bus = board.I2C() ss = Seesaw(i2c_bus) diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index 3434ddc..443f4fe 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -2,11 +2,10 @@ # SPDX-License-Identifier: MIT import board -import busio from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.digitalio import DigitalIO -i2c_bus = busio.I2C(board.SCL, board.SDA) +i2c_bus = board.I2C() seesaw = Seesaw(i2c_bus, addr=0x36) diff --git a/examples/seesaw_simpletest.py b/examples/seesaw_simpletest.py index c831771..7b7d35c 100644 --- a/examples/seesaw_simpletest.py +++ b/examples/seesaw_simpletest.py @@ -7,11 +7,10 @@ # https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test import time -from board import SCL, SDA -import busio +import board from adafruit_seesaw.seesaw import Seesaw -i2c_bus = busio.I2C(SCL, SDA) +i2c_bus = board.I2C() ss = Seesaw(i2c_bus) diff --git a/examples/seesaw_soil_simpletest.py b/examples/seesaw_soil_simpletest.py index af209a8..9fccd66 100644 --- a/examples/seesaw_soil_simpletest.py +++ b/examples/seesaw_soil_simpletest.py @@ -3,12 +3,11 @@ import time -from board import SCL, SDA -import busio +import board from adafruit_seesaw.seesaw import Seesaw -i2c_bus = busio.I2C(SCL, SDA) +i2c_bus = board.I2C() ss = Seesaw(i2c_bus, addr=0x36) From 494266371315bcdc1e1c5296fa1272416fdef2ae Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 May 2021 12:41:32 -0500 Subject: [PATCH 057/182] Add product ID check to rotary simpletest --- examples/seesaw_rotary_simpletest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index 63d01c3..f08ca19 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -11,6 +11,11 @@ seesaw = Seesaw(i2c_bus, addr=0x36) +seesaw_product = (seesaw.get_product() >> 16) & 0xFFFF +print("Found product {}".format(seesaw_product)) +if seesaw_product != 4991: + print("Wrong firmware loaded? Expected 4991") + button = DigitalIO(seesaw, 24) button_held = False From 1294a38a1b366360a26b5fce450c6b6ac2f76d7c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 May 2021 14:10:47 -0500 Subject: [PATCH 058/182] Fix get_version(), lost in search&replace --- examples/seesaw_rotary_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index f08ca19..97f67f7 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -11,7 +11,7 @@ seesaw = Seesaw(i2c_bus, addr=0x36) -seesaw_product = (seesaw.get_product() >> 16) & 0xFFFF +seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF print("Found product {}".format(seesaw_product)) if seesaw_product != 4991: print("Wrong firmware loaded? Expected 4991") From ed09cb3ffae7f0f4c4bcc34fb08e46a918f0f0f1 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 12 May 2021 22:23:03 -0400 Subject: [PATCH 059/182] adding_example_to_API --- docs/examples.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/examples.rst b/docs/examples.rst index b2dd1fb..eb62afa 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -27,3 +27,8 @@ Here are some other examples using the Seesaw library .. literalinclude:: ../examples/seesaw_minitft_featherwing.py :caption: examples/seesaw_minitft_featherwing.py :linenos: + +.. literalinclude:: ../examples/seesaw_rotary_simpletest.py + :caption: examples/seesaw_rotary_simpletest.py + :linenos: + From 1fbc5debb65dfa9c0c957362bebb94f6dc30d6da Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 12 May 2021 22:29:57 -0400 Subject: [PATCH 060/182] corrrecting_extra_line --- docs/examples.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/examples.rst b/docs/examples.rst index eb62afa..9ae0cf4 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -31,4 +31,3 @@ Here are some other examples using the Seesaw library .. literalinclude:: ../examples/seesaw_rotary_simpletest.py :caption: examples/seesaw_rotary_simpletest.py :linenos: - From 365262c81986c69be7c6174f9426ac9dc4a3f7b8 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:32:42 -0400 Subject: [PATCH 061/182] Added pull request template Signed-off-by: dherrada --- .../adafruit_circuitpython_pr.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md new file mode 100644 index 0000000..71ef8f8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2021 Adafruit Industries +# +# SPDX-License-Identifier: MIT + +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 + +If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs + +Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code + +Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. From 92a40ccece3fb0839413d5ae6c99c0f63dadb404 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:35:18 -0400 Subject: [PATCH 062/182] Added help text and problem matcher Signed-off-by: dherrada --- .github/workflows/build.yml | 2 ++ .github/workflows/failure-help-text.yml | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .github/workflows/failure-help-text.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3baf502..0ab7182 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,3 +71,5 @@ jobs: python setup.py sdist python setup.py bdist_wheel --universal twine check dist/* + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/failure-help-text.yml b/.github/workflows/failure-help-text.yml new file mode 100644 index 0000000..0b1194f --- /dev/null +++ b/.github/workflows/failure-help-text.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Failure help text + +on: + workflow_run: + workflows: ["Build CI"] + types: + - completed + +jobs: + post-help: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} + steps: + - name: Post comment to help + uses: adafruit/circuitpython-action-library-ci-failed@v1 From 877dcf99a3b98060586d3605886d1de0ec637c21 Mon Sep 17 00:00:00 2001 From: James Carr Date: Sun, 23 May 2021 15:29:00 +0100 Subject: [PATCH 063/182] Correct __version__ in neopixel.py --- 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 793b3b4..5dbd58d 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -21,7 +21,7 @@ def const(x): return x -__version__ = "1.2.3" +__version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" _NEOPIXEL_BASE = const(0x0E) From 3c47a7323f81e961b06853814964d04db5b3817b Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 May 2021 09:54:31 -0400 Subject: [PATCH 064/182] Moved CI to Python 3.7 Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ab7182..c4c975d 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.6 + - name: Set up Python 3.7 uses: actions/setup-python@v1 with: - python-version: 3.6 + python-version: 3.7 - name: Versions run: | python3 --version From 83d6d7be7a24833d0b0d797a61e84615b3a00a78 Mon Sep 17 00:00:00 2001 From: John Furcean Date: Wed, 26 May 2021 09:56:41 -0400 Subject: [PATCH 065/182] fix docs --- adafruit_seesaw/rotaryio.py | 2 +- docs/api.rst | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/adafruit_seesaw/rotaryio.py b/adafruit_seesaw/rotaryio.py index 84e9ade..a698086 100644 --- a/adafruit_seesaw/rotaryio.py +++ b/adafruit_seesaw/rotaryio.py @@ -6,7 +6,7 @@ """ -`adafruit_seesaw.digitalio` +`adafruit_seesaw.rotaryio` ==================================================== """ diff --git a/docs/api.rst b/docs/api.rst index 0ffb57c..70ef344 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -2,7 +2,7 @@ .. If you created a package, create one automodule per module in the package. .. automodule:: adafruit_seesaw - :members: + :members: .. automodule:: adafruit_seesaw.seesaw :members: @@ -31,6 +31,9 @@ .. automodule:: adafruit_seesaw.robohat :members: +.. automodule:: adafruit_seesaw.rotaryio + :members: + .. automodule:: adafruit_seesaw.samd09 :members: From 8f80efbdc18c375bd832085697e37972f21b8472 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sat, 5 Jun 2021 15:15:22 -0400 Subject: [PATCH 066/182] adding_new_guides --- docs/index.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index 27840f3..c4be833 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,11 +23,35 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit seesaw + + Make it Move with Crickit + + Joy Featherwing + + Adafruit Mini TFT with Joystick Featherwing + + Adafruit I2C QT Rotary Encoder + + Adafruit STEMMA Soil Sensor - I2C Capacitive Moisture Sensor + + Discord and Slack Connected Smart Plant with Adafruit IO Triggers + .. toctree:: :caption: Related Products Adafruit ATSAMD09 Breakout with seesaw + Adafruit CRICKIT for Circuit Playground Express + + Adafruit Joy FeatherWing for all Feathers + + Adafruit Mini Color TFT with Joystick FeatherWing + + Adafruit I2C QT Rotary Encoder with NeoPixel + + Adafruit STEMMA Soil Sensor - I2C Capacitive Moisture Sensor + .. toctree:: :caption: Other Links From db8ed661f0cc4bf6728b6d921a83f474d1ed8bcd Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 7 Jun 2021 14:44:20 -0400 Subject: [PATCH 067/182] Moved default branch to main --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 26a3e43..e0635ae 100644 --- a/README.rst +++ b/README.rst @@ -61,7 +61,7 @@ Contributing ============ Contributions are welcome! Please read our `Code of Conduct -`_ +`_ before contributing to help this project stay welcoming. Documentation From 78a7a4c08087bb26d28b73153286793deda58679 Mon Sep 17 00:00:00 2001 From: John Furcean Date: Mon, 7 Jun 2021 15:09:55 -0400 Subject: [PATCH 068/182] fix brightness bug --- adafruit_seesaw/neopixel.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/adafruit_seesaw/neopixel.py b/adafruit_seesaw/neopixel.py index 5dbd58d..68189c8 100644 --- a/adafruit_seesaw/neopixel.py +++ b/adafruit_seesaw/neopixel.py @@ -80,6 +80,7 @@ def __init__( self._seesaw.write(_NEOPIXEL_BASE, _NEOPIXEL_PIN, cmd) 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): @@ -90,8 +91,16 @@ def brightness(self): def brightness(self, brightness): # pylint: disable=attribute-defined-outside-init self._brightness = min(max(brightness, 0.0), 1.0) - if self.auto_write: + + # 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 def deinit(self): pass @@ -114,6 +123,8 @@ def __setitem__(self, key, 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: From 538745f40f554b8916c26f1cee27db9cc4059f26 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 8 Jun 2021 10:57:31 -0400 Subject: [PATCH 069/182] Adding rotary QT NeoPixel example. --- examples/seesaw_rotary_neopixel.py | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 examples/seesaw_rotary_neopixel.py diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py new file mode 100644 index 0000000..b8790eb --- /dev/null +++ b/examples/seesaw_rotary_neopixel.py @@ -0,0 +1,47 @@ +"""I2C rotary encoder NeoPixel color picker and brightness setting example.""" +import board +from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio +try: + import _pixelbuf +except ImportError: + import adafruit_pypixelbuf as _pixelbuf + +# For use with the STEMMA connector on QT Py RP2040 +# import busio +# i2c = busio.I2C(board.SCL1, board.SDA1) +# seesaw = seesaw.Seesaw(i2c, 0x36) + +seesaw = seesaw.Seesaw(board.I2C(), 0x36) + +encoder = rotaryio.IncrementalEncoder(seesaw) +switch = digitalio.DigitalIO(seesaw, 24) + +pixel = neopixel.NeoPixel(seesaw, 6, 1) +pixel.brightness = 0.5 + +last_position = -1 +color = 0 # start at red + +while True: + position = encoder.position + + if position != last_position: + print(position) + + if switch.value: + # Change the LED color. + if position > last_position: # Advance forward through the colorwheel. + color += 1 + else: + color -= 1 # Advance backward through the colorwheel. + color = (color + 256) % 256 # wrap around to 0-256 + pixel.fill(_pixelbuf.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) + + last_position = position From 699487217ae9cbbd63564e729c39f3c5eb210539 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 8 Jun 2021 11:14:02 -0400 Subject: [PATCH 070/182] Add license. --- examples/seesaw_rotary_neopixel.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index b8790eb..eabeda0 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# SPDX-License-Identifier: MIT + """I2C rotary encoder NeoPixel color picker and brightness setting example.""" import board from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio From fa15b1ca7cb1b0b26f6366c3924bdb9d5ebe7c3b Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Tue, 8 Jun 2021 11:18:20 -0400 Subject: [PATCH 071/182] Blacken. --- examples/seesaw_rotary_neopixel.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index eabeda0..3d4ecb1 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -4,6 +4,7 @@ """I2C rotary encoder NeoPixel color picker and brightness setting example.""" import board from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio + try: import _pixelbuf except ImportError: From 8dc6366290e13d1c159fa97ca1116f46a58b099d Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 8 Jun 2021 12:53:33 -0400 Subject: [PATCH 072/182] adding_rotary_example_to_API --- docs/examples.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/examples.rst b/docs/examples.rst index 9ae0cf4..f5912d7 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -31,3 +31,7 @@ Here are some other examples using the Seesaw library .. literalinclude:: ../examples/seesaw_rotary_simpletest.py :caption: examples/seesaw_rotary_simpletest.py :linenos: + +.. literalinclude:: ../examples/seesaw_rotary_neopixel.py + :caption: examples/seesaw_rotary_neopixel.py + :linenos: From 33d1148949a9cea3eeb8ebc470781f88a84cf504 Mon Sep 17 00:00:00 2001 From: John Furcean Date: Thu, 10 Jun 2021 17:03:49 -0400 Subject: [PATCH 073/182] update examples --- examples/seesaw_rotary_neopixel.py | 5 ++++- examples/seesaw_rotary_simpletest.py | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index 3d4ecb1..b36d51b 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -18,6 +18,7 @@ seesaw = seesaw.Seesaw(board.I2C(), 0x36) encoder = rotaryio.IncrementalEncoder(seesaw) +seesaw.pin_mode(24, seesaw.INPUT_PULLUP) switch = digitalio.DigitalIO(seesaw, 24) pixel = neopixel.NeoPixel(seesaw, 6, 1) @@ -27,7 +28,9 @@ color = 0 # start at red while True: - position = encoder.position + + # negate the position to make clockwise rotation positive + position = -encoder.position if position != last_position: print(position) diff --git a/examples/seesaw_rotary_simpletest.py b/examples/seesaw_rotary_simpletest.py index c52cc5f..7f3bbbc 100644 --- a/examples/seesaw_rotary_simpletest.py +++ b/examples/seesaw_rotary_simpletest.py @@ -1,30 +1,35 @@ # SPDX-FileCopyrightText: 2021 John Furcean # SPDX-License-Identifier: MIT +"""I2C rotary encoder simple test example.""" + import board -from adafruit_seesaw.seesaw import Seesaw -from adafruit_seesaw.digitalio import DigitalIO -from adafruit_seesaw.rotaryio import IncrementalEncoder +from adafruit_seesaw import seesaw, rotaryio, digitalio -i2c_bus = board.I2C() +# For use with the STEMMA connector on QT Py RP2040 +# import busio +# i2c = busio.I2C(board.SCL1, board.SDA1) +# seesaw = seesaw.Seesaw(i2c, 0x36) -seesaw = Seesaw(i2c_bus, addr=0x36) +seesaw = seesaw.Seesaw(board.I2C(), addr=0x36) seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF print("Found product {}".format(seesaw_product)) if seesaw_product != 4991: print("Wrong firmware loaded? Expected 4991") -button = DigitalIO(seesaw, 24) +seesaw.pin_mode(24, seesaw.INPUT_PULLUP) +button = digitalio.DigitalIO(seesaw, 24) button_held = False -encoder = IncrementalEncoder(seesaw) +encoder = rotaryio.IncrementalEncoder(seesaw) last_position = None while True: - # read position of the rotary encoder - position = encoder.position + # negate the position to make clockwise rotation positive + position = -encoder.position + if position != last_position: last_position = position print("Position: {}".format(position)) From 1d781add1fd3a8d5f1cacc71a16112d9de3da92f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Aug 2021 10:47:06 -0500 Subject: [PATCH 074/182] use rainbowio for colorwheel --- examples/seesaw_rotary_neopixel.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index b36d51b..6dde5fc 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -3,12 +3,10 @@ """I2C rotary encoder NeoPixel color picker and brightness setting example.""" import board +from rainbowio import colorwheel from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio -try: - import _pixelbuf -except ImportError: - import adafruit_pypixelbuf as _pixelbuf + # For use with the STEMMA connector on QT Py RP2040 # import busio @@ -42,7 +40,7 @@ else: color -= 1 # Advance backward through the colorwheel. color = (color + 256) % 256 # wrap around to 0-256 - pixel.fill(_pixelbuf.colorwheel(color)) + pixel.fill(colorwheel(color)) else: # If the button is pressed... # ...change the brightness. From 4d82c8343659dfbbdb28d87148b1e7dbdf34f299 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 16 Aug 2021 10:51:58 -0500 Subject: [PATCH 075/182] run pre-commit --- examples/seesaw_rotary_neopixel.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/seesaw_rotary_neopixel.py b/examples/seesaw_rotary_neopixel.py index 6dde5fc..62e47bd 100644 --- a/examples/seesaw_rotary_neopixel.py +++ b/examples/seesaw_rotary_neopixel.py @@ -7,7 +7,6 @@ from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio - # For use with the STEMMA connector on QT Py RP2040 # import busio # i2c = busio.I2C(board.SCL1, board.SDA1) From 2eb9fc090e8c7333104e0df17f3ca553c6680bb0 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 23 Sep 2021 17:52:55 -0400 Subject: [PATCH 076/182] Globally disabled consider-using-f-string pylint check Signed-off-by: dherrada --- .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 354c761..8810708 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,5 +30,5 @@ repos: name: pylint (examples code) description: Run pylint rules on "examples/*.py" files entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] language: system From dab0f4af93a324ca704405343607cb0530f782c7 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sat, 9 Oct 2021 13:14:28 -0400 Subject: [PATCH 077/182] nu id code --- adafruit_seesaw/seesaw.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 1e003a0..bc84c2b 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -107,7 +107,8 @@ def const(x): _TOUCH_CHANNEL_OFFSET = const(0x10) -_HW_ID_CODE = const(0x55) +_SAMD09_HW_ID_CODE = const(0x55) +_ATTINY8X7_HW_ID_CODE = const(0x87) _EEPROM_I2C_ADDR = const(0x3F) _ENCODER_STATUS = const(0x00) @@ -148,11 +149,11 @@ def sw_reset(self): chip_id = self.read8(_STATUS_BASE, _STATUS_HW_ID) - if chip_id != _HW_ID_CODE: + if chip_id not in (_ATTINY8X7_HW_ID_CODE, _SAMD09_HW_ID_CODE): raise RuntimeError( "Seesaw hardware ID returned (0x{:x}) is not " - "correct! Expected 0x{:x}. Please check your wiring.".format( - chip_id, _HW_ID_CODE + "correct! Expected 0x{:x} or 0x{:x}. Please check your wiring.".format( + chip_id, _SAMD09_HW_ID_CODE, _ATTINY8X7_HW_ID_CODE ) ) From 0e3fd6dfa8711702569e4f5755f54fd4979fbb76 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sat, 9 Oct 2021 13:37:16 -0400 Subject: [PATCH 078/182] add another test --- examples/seesaw_digitalio_test.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/seesaw_digitalio_test.txt diff --git a/examples/seesaw_digitalio_test.txt b/examples/seesaw_digitalio_test.txt new file mode 100644 index 0000000..e648bb7 --- /dev/null +++ b/examples/seesaw_digitalio_test.txt @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +# Simple seesaw test using an LED attached to Pin 5 and a button on pin 2 +# +# See the seesaw Learn Guide for wiring details: +# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test + +import time +import board +from adafruit_seesaw.seesaw import Seesaw + +i2c_bus = board.I2C() +ss = Seesaw(i2c_bus) + +button_pin = 2 +led_pin = 5 + +ss.pin_mode(led_pin, ss.OUTPUT) +ss.pin_mode(button_pin, ss.INPUT_PULLUP) + +while True: + # simply set the LED to the same 'value' as the button pin + ss.digital_write(led_pin, ss.digital_read(button_pin)) + time.sleep(.1) \ No newline at end of file From 011fab0c02a8412b7fb190cefe97e5896f5df188 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sat, 9 Oct 2021 14:00:04 -0400 Subject: [PATCH 079/182] analog input --- adafruit_seesaw/attiny8x7.py | 46 ++++++++++++++++++++++++++++++++ adafruit_seesaw/seesaw.py | 17 ++++++++---- examples/seesaw_analogin_test.py | 24 +++++++++++++++++ 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 adafruit_seesaw/attiny8x7.py create mode 100644 examples/seesaw_analogin_test.py diff --git a/adafruit_seesaw/attiny8x7.py b/adafruit_seesaw/attiny8x7.py new file mode 100644 index 0000000..0afaf16 --- /dev/null +++ b/adafruit_seesaw/attiny8x7.py @@ -0,0 +1,46 @@ +# 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.attiny8x7` - Pin definition for Adafruit ATtiny8x7 Breakout with seesaw +================================================================================== +""" + +try: + from micropython import const +except ImportError: + + def const(x): + return x + + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" + + +_PWM_0_PIN = const(0x04) +_PWM_1_PIN = const(0x05) +_PWM_2_PIN = const(0x06) +_PWM_3_PIN = const(0x07) + + +class ATtiny8x7_Pinmap: + """This class is automatically used by `adafruit_seesaw.seesaw.Seesaw` when + a ATtiny8x7 Breakout 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, 6, 7, 18, 19, 20) + + """The effective bit resolution of the PWM pins""" + pwm_width = 8 + + """The pins capable of PWM output""" + pwm_pins = (_PWM_0_PIN, _PWM_1_PIN, _PWM_2_PIN, _PWM_3_PIN) + + """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 bc84c2b..ede5732 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -147,9 +147,9 @@ def sw_reset(self): self.write8(_STATUS_BASE, _STATUS_SWRST, 0xFF) time.sleep(0.500) - chip_id = self.read8(_STATUS_BASE, _STATUS_HW_ID) + self.chip_id = self.read8(_STATUS_BASE, _STATUS_HW_ID) - if chip_id not in (_ATTINY8X7_HW_ID_CODE, _SAMD09_HW_ID_CODE): + if self.chip_id not in (_ATTINY8X7_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( @@ -167,10 +167,12 @@ def sw_reset(self): from adafruit_seesaw.robohat import MM1_Pinmap self.pin_mapping = MM1_Pinmap - else: + elif self.chip_id == _SAMD09_HW_ID_CODE: from adafruit_seesaw.samd09 import SAMD09_Pinmap - self.pin_mapping = SAMD09_Pinmap + elif self.chip_id == _ATTINY8X7_HW_ID_CODE: + from adafruit_seesaw.attiny8x7 import ATtiny8x7_Pinmap + self.pin_mapping = ATtiny8x7_Pinmap # pylint: enable=import-outside-toplevel def get_options(self): @@ -242,9 +244,14 @@ def analog_read(self, pin): 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: + offset = self.pin_mapping.analog_pins.index(pin) + self.read( _ADC_BASE, - _ADC_CHANNEL_OFFSET + self.pin_mapping.analog_pins.index(pin), + _ADC_CHANNEL_OFFSET + offset, buf, ) ret = struct.unpack(">H", buf)[0] diff --git a/examples/seesaw_analogin_test.py b/examples/seesaw_analogin_test.py new file mode 100644 index 0000000..1a4a68c --- /dev/null +++ b/examples/seesaw_analogin_test.py @@ -0,0 +1,24 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +# Simple seesaw test reading analog value +# on SAMD09, analog in can be pins 2, 3, or 4 +# on Attiny8x7, analog in can be pins 0, 1, 2, 3, 6, 7, 18, 19, 20 +# +# See the seesaw Learn Guide for wiring details: +# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test + +import time +import board +from adafruit_seesaw.seesaw import Seesaw +from adafruit_seesaw.analoginput import AnalogInput + +i2c_bus = board.I2C() +ss = Seesaw(i2c_bus) + +analogin_pin = 2 +analog_in = AnalogInput(ss, analogin_pin) + +while True: + print(analog_in.value) + time.sleep(.1) From 213c7bc53e3ed3004f1a73fb1f931df6b9a7cfdc Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 10 Oct 2021 13:47:31 -0400 Subject: [PATCH 080/182] neotest --- examples/seesaw_neopixel_test.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/seesaw_neopixel_test.py diff --git a/examples/seesaw_neopixel_test.py b/examples/seesaw_neopixel_test.py new file mode 100644 index 0000000..f48581c --- /dev/null +++ b/examples/seesaw_neopixel_test.py @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +# Simple seesaw test writing NeoPixels +# Can use any valid GPIO pin, up to 60 pixels! +# +# See the seesaw Learn Guide for wiring details: +# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test + +import time +import board +from rainbowio import colorwheel +from adafruit_seesaw import seesaw, neopixel + +i2c_bus = board.I2C() +ss = seesaw.Seesaw(i2c_bus) + +NEOPIXEL_PIN = 6 # change to any pin +NEOPIXEL_NUM = 30 # no more than 60! +pixels = neopixel.NeoPixel(ss, NEOPIXEL_PIN, NEOPIXEL_NUM) +pixels.brightness = 0.3 # not so brite! + +color_offset = 0 # start at red + +# cycle through all colors along the strip +while True: + for i in range(NEOPIXEL_NUM): + rc_index = (i * 256 // NEOPIXEL_NUM) + color_offset + pixels[i] = colorwheel(rc_index & 255) + pixels.show() + color_offset += 1 + time.sleep(0.01) From 928559d1d3db3d8d7c503206bd8e84eec2b57720 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 10 Oct 2021 13:56:50 -0400 Subject: [PATCH 081/182] eep --- examples/seesaw_eeprom_test.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 examples/seesaw_eeprom_test.py diff --git a/examples/seesaw_eeprom_test.py b/examples/seesaw_eeprom_test.py new file mode 100644 index 0000000..cb2b1c4 --- /dev/null +++ b/examples/seesaw_eeprom_test.py @@ -0,0 +1,29 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +# Simple seesaw test reading and writing the internal EEPROM +# The ATtiny8xx series has a true 128 byte EEPROM, the SAMD09 mimics it in flash with 64 bytes +# THE LAST BYTE IS USED FOR I2C ADDRESS CHANGE! +# +# See the seesaw Learn Guide for wiring details: +# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test + +import time +import board +from adafruit_seesaw import seesaw + +i2c_bus = board.I2C() +ss = seesaw.Seesaw(i2c_bus) + +val = ss.eeprom_read8(0x02) # read from address 2 +print("Read 0x%02x from EEPROM address 0x02" % val) + +print("Incremening value") +ss.eeprom_write8(0x02, val + 1) + +val = ss.eeprom_read8(0x02) # read from address 2 +print("Second read 0x%02x from EEPROM address 0x02" % val) + +while True: + # Do not write EEPROM in a loop, it has 100k cycle life + time.sleep(1) From f6e2f6b269769aa8fe46e643f0fbb04cd98522fd Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 10 Oct 2021 14:14:34 -0400 Subject: [PATCH 082/182] pwm! --- adafruit_seesaw/attiny8x7.py | 10 ++-------- adafruit_seesaw/seesaw.py | 21 ++++++++++----------- examples/seesaw_pwmout_test.py | 25 +++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 examples/seesaw_pwmout_test.py diff --git a/adafruit_seesaw/attiny8x7.py b/adafruit_seesaw/attiny8x7.py index 0afaf16..38b059e 100644 --- a/adafruit_seesaw/attiny8x7.py +++ b/adafruit_seesaw/attiny8x7.py @@ -21,12 +21,6 @@ def const(x): __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" -_PWM_0_PIN = const(0x04) -_PWM_1_PIN = const(0x05) -_PWM_2_PIN = const(0x06) -_PWM_3_PIN = const(0x07) - - class ATtiny8x7_Pinmap: """This class is automatically used by `adafruit_seesaw.seesaw.Seesaw` when a ATtiny8x7 Breakout is detected. @@ -37,10 +31,10 @@ class ATtiny8x7_Pinmap: analog_pins = (0, 1, 2, 3, 6, 7, 18, 19, 20) """The effective bit resolution of the PWM pins""" - pwm_width = 8 + pwm_width = 16 # we dont actually use all 16 bits but whatever """The pins capable of PWM output""" - pwm_pins = (_PWM_0_PIN, _PWM_1_PIN, _PWM_2_PIN, _PWM_3_PIN) + pwm_pins = (0, 1, 9, 12, 13) """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 ede5732..f7fe2d7 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -342,20 +342,19 @@ def digital_write_bulk_b(self, pins, value): def analog_write(self, pin, value): """Set the value of an analog output by number""" - pin_found = False + 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: + offset = self.pin_mapping.pwm_pins.index(pin) + if self.pin_mapping.pwm_width == 16: - if pin in self.pin_mapping.pwm_pins: - pin_found = True - cmd = bytearray( - [self.pin_mapping.pwm_pins.index(pin), (value >> 8), value & 0xFF] - ) + cmd = bytearray([offset, (value >> 8), value & 0xFF]) else: - if pin in self.pin_mapping.pwm_pins: - pin_found = True - cmd = bytearray([self.pin_mapping.pwm_pins.index(pin), value]) + cmd = bytearray([offset, value]) - if pin_found is False: - raise ValueError("Invalid PWM pin") self.write(_TIMER_BASE, _TIMER_PWM, cmd) time.sleep(0.001) diff --git a/examples/seesaw_pwmout_test.py b/examples/seesaw_pwmout_test.py new file mode 100644 index 0000000..dbb2d6b --- /dev/null +++ b/examples/seesaw_pwmout_test.py @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + +# Simple seesaw test for writing PWM outputs +# On the SAMD09 breakout these are pins 5, 6, and 7 +# On the ATtiny8x7 breakout these are pins 0, 1, 9, 12, 13 +# +# See the seesaw Learn Guide for wiring details: +# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test + +import time +import board +from adafruit_seesaw import seesaw, pwmout + +i2c_bus = board.I2C() +ss = seesaw.Seesaw(i2c_bus) + +PWM_PIN = 9 # change to a valid PWM output! +pwm = pwmout.PWMOut(ss, PWM_PIN) + +while True: + # the API PWM range is 0 to 65535, but we increment by 256 since our + # resolution is often only 8 bits underneath + pwm.duty_cycle = (pwm.duty_cycle + 256) % 65536 + time.sleep(0.01) From a032f92c1151afaa8c983f4f1d3929d7fcfdc827 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 10 Oct 2021 14:18:25 -0400 Subject: [PATCH 083/182] allow optional reset https://github.com/adafruit/Adafruit_CircuitPython_seesaw/issues/79 --- adafruit_seesaw/seesaw.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index f7fe2d7..12edea3 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -127,25 +127,22 @@ class Seesaw: :param ~busio.I2C i2c_bus: Bus the SeeSaw is connected to :param int addr: I2C address of the SeeSaw device - :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output""" + :param ~digitalio.DigitalInOut drdy: Pin connected to SeeSaw's 'ready' output + :param bool reset: Whether to do a software reset on init""" INPUT = const(0x00) OUTPUT = const(0x01) INPUT_PULLUP = const(0x02) INPUT_PULLDOWN = const(0x03) - def __init__(self, i2c_bus, addr=0x49, drdy=None): + def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): self._drdy = drdy if drdy is not None: drdy.switch_to_input() self.i2c_device = I2CDevice(i2c_bus, addr) - self.sw_reset() - - def sw_reset(self): - """Trigger a software reset of the SeeSaw chip""" - self.write8(_STATUS_BASE, _STATUS_SWRST, 0xFF) - time.sleep(0.500) + if reset: + self.sw_reset() self.chip_id = self.read8(_STATUS_BASE, _STATUS_HW_ID) @@ -175,6 +172,12 @@ def sw_reset(self): self.pin_mapping = ATtiny8x7_Pinmap # pylint: enable=import-outside-toplevel + def sw_reset(self): + """Trigger a software reset of the SeeSaw chip""" + self.write8(_STATUS_BASE, _STATUS_SWRST, 0xFF) + time.sleep(0.500) + + def get_options(self): """Retrieve the 'options' word from the SeeSaw board""" buf = bytearray(4) From b083f1587cbe134ff907ba67502d033e7433e6a8 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 10 Oct 2021 18:41:56 -0400 Subject: [PATCH 084/182] objecty --- examples/seesaw_digitalio_test.txt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/seesaw_digitalio_test.txt b/examples/seesaw_digitalio_test.txt index e648bb7..4ebc6c2 100644 --- a/examples/seesaw_digitalio_test.txt +++ b/examples/seesaw_digitalio_test.txt @@ -8,7 +8,9 @@ import time import board +import digitalio from adafruit_seesaw.seesaw import Seesaw +from adafruit_seesaw.digitalio import DigitalIO i2c_bus = board.I2C() ss = Seesaw(i2c_bus) @@ -16,10 +18,14 @@ ss = Seesaw(i2c_bus) button_pin = 2 led_pin = 5 -ss.pin_mode(led_pin, ss.OUTPUT) -ss.pin_mode(button_pin, ss.INPUT_PULLUP) +button = DigitalIO(ss, button_pin) +button.direction = digitalio.Direction.INPUT +button.pull = digitalio.Pull.UP + +led = DigitalIO(ss, led_pin) +led.direction = digitalio.Direction.OUTPUT while True: # simply set the LED to the same 'value' as the button pin - ss.digital_write(led_pin, ss.digital_read(button_pin)) - time.sleep(.1) \ No newline at end of file + led.value = button.value + time.sleep(.1) From 839a8d3cd458d8ade6d3dbcd9dc3cb27d3e0d8f7 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 10 Oct 2021 18:42:24 -0400 Subject: [PATCH 085/182] blacken --- adafruit_seesaw/seesaw.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 12edea3..f1d129e 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -166,10 +166,12 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): self.pin_mapping = MM1_Pinmap elif self.chip_id == _SAMD09_HW_ID_CODE: from adafruit_seesaw.samd09 import SAMD09_Pinmap + self.pin_mapping = SAMD09_Pinmap elif self.chip_id == _ATTINY8X7_HW_ID_CODE: from adafruit_seesaw.attiny8x7 import ATtiny8x7_Pinmap - self.pin_mapping = ATtiny8x7_Pinmap + + self.pin_mapping = ATtiny8x7_Pinmap # pylint: enable=import-outside-toplevel def sw_reset(self): @@ -177,7 +179,6 @@ def sw_reset(self): self.write8(_STATUS_BASE, _STATUS_SWRST, 0xFF) time.sleep(0.500) - def get_options(self): """Retrieve the 'options' word from the SeeSaw board""" buf = bytearray(4) @@ -352,7 +353,7 @@ def analog_write(self, pin, value): offset = pin elif self.chip_id == _SAMD09_HW_ID_CODE: offset = self.pin_mapping.pwm_pins.index(pin) - + if self.pin_mapping.pwm_width == 16: cmd = bytearray([offset, (value >> 8), value & 0xFF]) else: From c3075da1a1bbaaa78b18ffea0df8ae7ab3f53869 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 10 Oct 2021 18:42:36 -0400 Subject: [PATCH 086/182] blacken2 --- examples/seesaw_analogin_test.py | 2 +- examples/seesaw_digitalio_test.txt | 2 +- examples/seesaw_eeprom_test.py | 4 ++-- examples/seesaw_neopixel_test.py | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/seesaw_analogin_test.py b/examples/seesaw_analogin_test.py index 1a4a68c..5d53173 100644 --- a/examples/seesaw_analogin_test.py +++ b/examples/seesaw_analogin_test.py @@ -21,4 +21,4 @@ while True: print(analog_in.value) - time.sleep(.1) + time.sleep(0.1) diff --git a/examples/seesaw_digitalio_test.txt b/examples/seesaw_digitalio_test.txt index 4ebc6c2..767b19b 100644 --- a/examples/seesaw_digitalio_test.txt +++ b/examples/seesaw_digitalio_test.txt @@ -28,4 +28,4 @@ led.direction = digitalio.Direction.OUTPUT while True: # simply set the LED to the same 'value' as the button pin led.value = button.value - time.sleep(.1) + time.sleep(0.1) diff --git a/examples/seesaw_eeprom_test.py b/examples/seesaw_eeprom_test.py index cb2b1c4..aee917f 100644 --- a/examples/seesaw_eeprom_test.py +++ b/examples/seesaw_eeprom_test.py @@ -15,13 +15,13 @@ i2c_bus = board.I2C() ss = seesaw.Seesaw(i2c_bus) -val = ss.eeprom_read8(0x02) # read from address 2 +val = ss.eeprom_read8(0x02) # read from address 2 print("Read 0x%02x from EEPROM address 0x02" % val) print("Incremening value") ss.eeprom_write8(0x02, val + 1) -val = ss.eeprom_read8(0x02) # read from address 2 +val = ss.eeprom_read8(0x02) # read from address 2 print("Second read 0x%02x from EEPROM address 0x02" % val) while True: diff --git a/examples/seesaw_neopixel_test.py b/examples/seesaw_neopixel_test.py index f48581c..f25e3ba 100644 --- a/examples/seesaw_neopixel_test.py +++ b/examples/seesaw_neopixel_test.py @@ -15,10 +15,10 @@ i2c_bus = board.I2C() ss = seesaw.Seesaw(i2c_bus) -NEOPIXEL_PIN = 6 # change to any pin -NEOPIXEL_NUM = 30 # no more than 60! +NEOPIXEL_PIN = 6 # change to any pin +NEOPIXEL_NUM = 30 # no more than 60! pixels = neopixel.NeoPixel(ss, NEOPIXEL_PIN, NEOPIXEL_NUM) -pixels.brightness = 0.3 # not so brite! +pixels.brightness = 0.3 # not so brite! color_offset = 0 # start at red From b526c09b0322a555e8b489c6633f2523c60a1683 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 10 Oct 2021 18:46:09 -0400 Subject: [PATCH 087/182] lint --- adafruit_seesaw/attiny8x7.py | 8 -------- adafruit_seesaw/seesaw.py | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/adafruit_seesaw/attiny8x7.py b/adafruit_seesaw/attiny8x7.py index 38b059e..a51e00c 100644 --- a/adafruit_seesaw/attiny8x7.py +++ b/adafruit_seesaw/attiny8x7.py @@ -9,14 +9,6 @@ ================================================================================== """ -try: - from micropython import const -except ImportError: - - def const(x): - return x - - __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_seesaw.git" diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index f1d129e..d42f746 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -150,7 +150,7 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True): raise RuntimeError( "Seesaw hardware ID returned (0x{:x}) is not " "correct! Expected 0x{:x} or 0x{:x}. Please check your wiring.".format( - chip_id, _SAMD09_HW_ID_CODE, _ATTINY8X7_HW_ID_CODE + self.chip_id, _SAMD09_HW_ID_CODE, _ATTINY8X7_HW_ID_CODE ) ) From cd50bd043d94524a8d926b1381e552f569606c05 Mon Sep 17 00:00:00 2001 From: lady ada Date: Mon, 11 Oct 2021 10:59:53 -0400 Subject: [PATCH 088/182] renamez --- examples/{seesaw_digitalio_test.txt => seesaw_digitalio_test.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{seesaw_digitalio_test.txt => seesaw_digitalio_test.py} (100%) diff --git a/examples/seesaw_digitalio_test.txt b/examples/seesaw_digitalio_test.py similarity index 100% rename from examples/seesaw_digitalio_test.txt rename to examples/seesaw_digitalio_test.py From 64e7c7f5dc9fa7aa3438107fdd8558a244cd1e20 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Wed, 13 Oct 2021 13:27:31 -0400 Subject: [PATCH 089/182] Adding ATtiny simpletest. --- examples/seesaw_attiny_simpletest.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/seesaw_attiny_simpletest.py diff --git a/examples/seesaw_attiny_simpletest.py b/examples/seesaw_attiny_simpletest.py new file mode 100644 index 0000000..5b9991e --- /dev/null +++ b/examples/seesaw_attiny_simpletest.py @@ -0,0 +1,18 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +Simple seesaw test for ATtiny8x7 breakout using built-in LED on pin 5. +""" +import time +import board +from adafruit_seesaw.seesaw import Seesaw + +ss = Seesaw(board.I2C()) + +ss.pin_mode(5, ss.OUTPUT) + +while True: + ss.digital_write(5, False) # Turn the LED on (the built-in LED is active low!) + time.sleep(1) # Wait for one second + ss.digital_write(5, True) # Turn the LED off + time.sleep(1) # Wait for one second From 39c33a9adf8366c0abb327fc7dbe4c808f7172d4 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Fri, 15 Oct 2021 12:26:59 -0400 Subject: [PATCH 090/182] Updating for ATtiny8x7 --- examples/seesaw_analogin_test.py | 6 +----- examples/seesaw_digitalio_test.py | 8 +++++--- examples/seesaw_eeprom_test.py | 20 +++++++++----------- examples/seesaw_neopixel_test.py | 20 +++++++++++--------- examples/seesaw_pwmout_test.py | 23 +++++++++++++++-------- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/examples/seesaw_analogin_test.py b/examples/seesaw_analogin_test.py index 5d53173..da2741d 100644 --- a/examples/seesaw_analogin_test.py +++ b/examples/seesaw_analogin_test.py @@ -4,17 +4,13 @@ # Simple seesaw test reading analog value # on SAMD09, analog in can be pins 2, 3, or 4 # on Attiny8x7, analog in can be pins 0, 1, 2, 3, 6, 7, 18, 19, 20 -# -# See the seesaw Learn Guide for wiring details: -# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test import time import board from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.analoginput import AnalogInput -i2c_bus = board.I2C() -ss = Seesaw(i2c_bus) +ss = Seesaw(board.I2C()) analogin_pin = 2 analog_in = AnalogInput(ss, analogin_pin) diff --git a/examples/seesaw_digitalio_test.py b/examples/seesaw_digitalio_test.py index 767b19b..2e197ec 100644 --- a/examples/seesaw_digitalio_test.py +++ b/examples/seesaw_digitalio_test.py @@ -3,8 +3,11 @@ # Simple seesaw test using an LED attached to Pin 5 and a button on pin 2 # -# See the seesaw Learn Guide for wiring details: +# See the seesaw Learn Guide for wiring details. +# For SAMD09: # https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test +# For ATtiny8x7: +# https://learn.adafruit.com/adafruit-attiny817-seesaw/digital-input import time import board @@ -12,8 +15,7 @@ from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.digitalio import DigitalIO -i2c_bus = board.I2C() -ss = Seesaw(i2c_bus) +ss = Seesaw(board.I2C()) button_pin = 2 led_pin = 5 diff --git a/examples/seesaw_eeprom_test.py b/examples/seesaw_eeprom_test.py index aee917f..7ff1eec 100644 --- a/examples/seesaw_eeprom_test.py +++ b/examples/seesaw_eeprom_test.py @@ -4,25 +4,23 @@ # Simple seesaw test reading and writing the internal EEPROM # The ATtiny8xx series has a true 128 byte EEPROM, the SAMD09 mimics it in flash with 64 bytes # THE LAST BYTE IS USED FOR I2C ADDRESS CHANGE! -# -# See the seesaw Learn Guide for wiring details: -# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test import time import board from adafruit_seesaw import seesaw -i2c_bus = board.I2C() -ss = seesaw.Seesaw(i2c_bus) +ss = seesaw.Seesaw(board.I2C()) -val = ss.eeprom_read8(0x02) # read from address 2 -print("Read 0x%02x from EEPROM address 0x02" % val) +write_value = 42 -print("Incremening value") -ss.eeprom_write8(0x02, val + 1) +value = ss.eeprom_read8(0x02) # Read from address 2 +print("Read 0x%02x from EEPROM address 0x02" % value) -val = ss.eeprom_read8(0x02) # read from address 2 -print("Second read 0x%02x from EEPROM address 0x02" % val) +ss.eeprom_write8(0x02, write_value) # Write value to address 2 +print("Writing value") + +value = ss.eeprom_read8(0x02) # Read from address 2 +print("Read 0x%02x from EEPROM address 0x02" % value) while True: # Do not write EEPROM in a loop, it has 100k cycle life diff --git a/examples/seesaw_neopixel_test.py b/examples/seesaw_neopixel_test.py index f25e3ba..43e654b 100644 --- a/examples/seesaw_neopixel_test.py +++ b/examples/seesaw_neopixel_test.py @@ -4,29 +4,31 @@ # Simple seesaw test writing NeoPixels # Can use any valid GPIO pin, up to 60 pixels! # -# See the seesaw Learn Guide for wiring details: +# See the seesaw Learn Guide for wiring details. +# For SAMD09: # https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test +# For ATtiny8x7: +# https://learn.adafruit.com/adafruit-attiny817-seesaw/neopixel import time import board from rainbowio import colorwheel from adafruit_seesaw import seesaw, neopixel -i2c_bus = board.I2C() -ss = seesaw.Seesaw(i2c_bus) +ss = seesaw.Seesaw(board.I2C()) + +NEOPIXEL_PIN = 19 # Can be any pin +NEOPIXEL_NUM = 12 # No more than 60 pixels! -NEOPIXEL_PIN = 6 # change to any pin -NEOPIXEL_NUM = 30 # no more than 60! pixels = neopixel.NeoPixel(ss, NEOPIXEL_PIN, NEOPIXEL_NUM) -pixels.brightness = 0.3 # not so brite! +pixels.brightness = 0.3 # Not so bright! -color_offset = 0 # start at red +color_offset = 0 # Start at red -# cycle through all colors along the strip +# Cycle through all colors along the ring while True: for i in range(NEOPIXEL_NUM): rc_index = (i * 256 // NEOPIXEL_NUM) + color_offset pixels[i] = colorwheel(rc_index & 255) - pixels.show() color_offset += 1 time.sleep(0.01) diff --git a/examples/seesaw_pwmout_test.py b/examples/seesaw_pwmout_test.py index dbb2d6b..06bcc0e 100644 --- a/examples/seesaw_pwmout_test.py +++ b/examples/seesaw_pwmout_test.py @@ -5,21 +5,28 @@ # On the SAMD09 breakout these are pins 5, 6, and 7 # On the ATtiny8x7 breakout these are pins 0, 1, 9, 12, 13 # -# See the seesaw Learn Guide for wiring details: +# See the seesaw Learn Guide for wiring details. +# For SAMD09: # https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test +# For ATtiny8x7: +# https://learn.adafruit.com/adafruit-attiny817-seesaw/pwmout import time import board from adafruit_seesaw import seesaw, pwmout -i2c_bus = board.I2C() -ss = seesaw.Seesaw(i2c_bus) +ss = seesaw.Seesaw(board.I2C()) -PWM_PIN = 9 # change to a valid PWM output! -pwm = pwmout.PWMOut(ss, PWM_PIN) +PWM_PIN = 12 # If desired, change to any valid PWM output! +led = pwmout.PWMOut(ss, PWM_PIN) +delay = 0.01 while True: - # the API PWM range is 0 to 65535, but we increment by 256 since our + # The API PWM range is 0 to 65535, but we increment by 256 since our # resolution is often only 8 bits underneath - pwm.duty_cycle = (pwm.duty_cycle + 256) % 65536 - time.sleep(0.01) + for cycle in range(0, 65535, 256): # + led.duty_cycle = cycle + time.sleep(delay) + for cycle in range(65534, 0, -256): + led.duty_cycle = cycle + time.sleep(delay) From b46e79da22e0c55cdc3edd5092e7148479350e43 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Fri, 15 Oct 2021 12:42:21 -0400 Subject: [PATCH 091/182] Update EEPROM example. --- examples/seesaw_eeprom_test.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/seesaw_eeprom_test.py b/examples/seesaw_eeprom_test.py index 7ff1eec..130a4bb 100644 --- a/examples/seesaw_eeprom_test.py +++ b/examples/seesaw_eeprom_test.py @@ -9,18 +9,17 @@ import board from adafruit_seesaw import seesaw -ss = seesaw.Seesaw(board.I2C()) - -write_value = 42 +i2c_bus = board.I2C() +ss = seesaw.Seesaw(i2c_bus) value = ss.eeprom_read8(0x02) # Read from address 2 print("Read 0x%02x from EEPROM address 0x02" % value) -ss.eeprom_write8(0x02, write_value) # Write value to address 2 -print("Writing value") +print("Incrementing value") +ss.eeprom_write8(0x02, (value + 1) % 0xFF) value = ss.eeprom_read8(0x02) # Read from address 2 -print("Read 0x%02x from EEPROM address 0x02" % value) +print("Second read 0x%02x from EEPROM address 0x02" % value) while True: # Do not write EEPROM in a loop, it has 100k cycle life From 67f9db57a76232d193de90b7bcaa03e6b8ff1749 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 25 Oct 2021 11:21:49 -0500 Subject: [PATCH 092/182] add docs link to readme --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index e0635ae..15a52e7 100644 --- a/README.rst +++ b/README.rst @@ -57,6 +57,11 @@ Usage Example See examples/seesaw_simpletest.py for usage example. +Documentation +============= + +API documentation for this library can be found on `Read the Docs `_. + Contributing ============ From 4c16020bd33314939c875c44bb4b5ee20daf8832 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Nov 2021 14:40:16 -0400 Subject: [PATCH 093/182] PATCH Pylint and readthedocs patch test Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- .pre-commit-config.yaml | 26 +++++++++++++++++--------- .pylintrc | 2 +- .readthedocs.yml | 2 +- docs/requirements.txt | 5 +++++ 5 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 docs/requirements.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4c975d..ca35544 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8810708..1b9fadc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,17 +18,25 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: pylint-2.7.1 + rev: v2.11.1 hooks: - id: pylint name: pylint (library code) types: [python] - exclude: "^(docs/|examples/|setup.py$)" -- repo: local - hooks: - - id: pylint_examples - name: pylint (examples code) + 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 - entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] - language: system + 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 diff --git a/.pylintrc b/.pylintrc index 0238b90..e78bad2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -252,7 +252,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=12 +min-similarity-lines=4 [BASIC] diff --git a/.readthedocs.yml b/.readthedocs.yml index ffa84c4..49dcab3 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -4,4 +4,4 @@ python: version: 3 -requirements_file: requirements.txt +requirements_file: docs/requirements.txt diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..88e6733 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +sphinx>=4.0.0 From 2df0ec7ced8a8e1ecb188d77eb7bdaf1dcfae7d1 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 5 Nov 2021 14:49:30 -0400 Subject: [PATCH 094/182] Disabled unspecified-encoding pylint check Signed-off-by: dherrada --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index e78bad2..cfd1c41 100644 --- a/.pylintrc +++ b/.pylintrc @@ -55,7 +55,7 @@ confidence= # 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 +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From f0c6f28e2bdf221c509a8df2e5d025264b251fbd Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 5 Nov 2021 17:38:33 -0400 Subject: [PATCH 095/182] Linted --- .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 1b9fadc..43d1385 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 + - --disable=consider-using-f-string,duplicate-code exclude: "^(docs/|examples/|tests/|setup.py$)" - id: pylint name: pylint (example code) From 0450119e163df782930a887022e197d6d25ca666 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 9 Nov 2021 13:31:14 -0500 Subject: [PATCH 096/182] 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 097/182] 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 098/182] 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 099/182] 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 100/182] 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 101/182] 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 102/182] 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 103/182] 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 104/182] 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 105/182] 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 106/182] 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 107/182] 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 108/182] 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 109/182] 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 110/182] 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 111/182] 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 112/182] 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 113/182] 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 114/182] 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 115/182] 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 116/182] 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 117/182] 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 118/182] 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 119/182] 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 120/182] 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 121/182] 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 122/182] 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 123/182] 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 124/182] 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 125/182] 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 126/182] 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 127/182] 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 128/182] 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 129/182] 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 130/182] 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 131/182] 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 132/182] 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 133/182] 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 134/182] 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 135/182] 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 136/182] 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 137/182] 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 138/182] 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 139/182] 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 140/182] 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 141/182] 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 142/182] 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 143/182] 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 144/182] 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 145/182] 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 146/182] 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 147/182] 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 148/182] 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 149/182] 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 150/182] 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 151/182] 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 152/182] 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 153/182] 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 154/182] 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 155/182] 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 156/182] 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 157/182] 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 158/182] 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 159/182] 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 160/182] 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 161/182] 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 162/182] 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 163/182] 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 164/182] 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 165/182] 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 166/182] 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 167/182] 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 168/182] "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 169/182] 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 170/182] 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 171/182] 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 172/182] 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 173/182] 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 174/182] 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 175/182] 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 176/182] 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 177/182] 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 178/182] 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 179/182] 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 180/182] 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 181/182] 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 182/182] 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"