From 6fa31413553f5d57a736c3cfe7b1e5a9fab14309 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 9 Apr 2019 22:27:41 -0700 Subject: [PATCH 01/13] Added MiniTFT with Joystick FeatherWing --- README.rst | 1 + adafruit_featherwing/minitft_featherwing.py | 133 ++++++++++++++++++++ docs/api.rst | 3 + docs/conf.py | 2 +- docs/examples.rst | 4 + examples/featherwing_minitft_simpletest.py | 35 ++++++ 6 files changed, 177 insertions(+), 1 deletion(-) create mode 100755 adafruit_featherwing/minitft_featherwing.py create mode 100755 examples/featherwing_minitft_simpletest.py diff --git a/README.rst b/README.rst index 74f7bac..1aadd9b 100644 --- a/README.rst +++ b/README.rst @@ -28,6 +28,7 @@ These drivers depends on: * `DotStar `_ * `NeoPixel `_ * `DS3231 `_ +* `ST7735R `_ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py new file mode 100755 index 0000000..fe2e14e --- /dev/null +++ b/adafruit_featherwing/minitft_featherwing.py @@ -0,0 +1,133 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Melissa LeBlanc-Williams for Adafruit Industries LLC +# +# 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. +""" +`adafruit_featherwing.minitft_featherwing` +==================================================== + +Helper for using the `Mini Color TFT with Joystick FeatherWing +`_. + +* Author(s): Melissa LeBlanc-Williams +""" + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" + +import time +import board +import displayio +from micropython import const +from adafruit_seesaw.seesaw import Seesaw +from adafruit_st7735r import ST7735R + +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) + +class MiniTFTFeatherWing: + """Class representing an `Mini Color TFT with Joystick FeatherWing + `_. + + Automatically uses the feather's I2C bus.""" + def __init__(self, address=0x5E, i2c=None, spi=None): + if i2c is None: + i2c = board.I2C() + if spi is None: + spi = board.SPI() + self._ss = Seesaw(i2c, address) + self._button_mask = const((1 << BUTTON_RIGHT) | + (1 << BUTTON_DOWN) | + (1 << BUTTON_LEFT) | + (1 << BUTTON_UP) | + (1 << BUTTON_SEL) | + (1 << BUTTON_A) | + (1 << BUTTON_B)) + self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP) + displayio.release_displays() + display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5) + self._ss.pin_mode(8, self._ss.OUTPUT) + self._ss.digital_write(8, True) # Reset the Display via Seesaw + self._display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True) + + @property + def _buttons(self): + return self._ss.digital_read_bulk(self._button_mask) + + @property + def display(self): + """ + Returns the display object for doing fun displayio stuff on + """ + return self._display + + @property + def right(self): + """ + Checks and returns if right is currently being pressed + """ + return not self._buttons & (1 << BUTTON_RIGHT) + + @property + def left(self): + """ + Checks and returns if left is currently being pressed + """ + return not self._buttons & (1 << BUTTON_LEFT) + + @property + def up(self): + """ + Checks and returns if up is currently being pressed + """ + return not self._buttons & (1 << BUTTON_UP) + + @property + def down(self): + """ + Checks and returns if down is currently being pressed + """ + return not self._buttons & (1 << BUTTON_DOWN) + + @property + def button_a(self): + """ + Checks and returns if button A is currently being pressed + """ + return not self._buttons & (1 << BUTTON_A) + + @property + def button_b(self): + """ + Checks and returns if button B is currently being pressed + """ + return not self._buttons & (1 << BUTTON_B) + + @property + def select(self): + """ + Checks and returns if select is currently being pressed + """ + return not self._buttons & (1 << BUTTON_SEL) diff --git a/docs/api.rst b/docs/api.rst index 5927698..3d0c389 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -24,3 +24,6 @@ .. automodule:: adafruit_featherwing.matrix_featherwing :members: + +.. automodule:: adafruit_featherwing.minitft_featherwing + :members: diff --git a/docs/conf.py b/docs/conf.py index 20b5b08..208aba4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,7 +18,7 @@ # 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 = ["board", "busio"] +autodoc_mock_imports = ["board", "busio", "displayio"] intersphinx_mapping = { 'python': ('https://docs.python.org/3.4', None), diff --git a/docs/examples.rst b/docs/examples.rst index 285a02c..dec7d88 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -39,6 +39,10 @@ Ensure your device works with this simple test. :caption: examples/featherwing_matrix_simpletest.py :linenos: +.. literalinclude:: ../examples/featherwing_minitft_simpletest.py + :caption: examples/featherwing_minitft_simpletest.py + :linenos: + Other Examples --------------- diff --git a/examples/featherwing_minitft_simpletest.py b/examples/featherwing_minitft_simpletest.py new file mode 100755 index 0000000..9d72b62 --- /dev/null +++ b/examples/featherwing_minitft_simpletest.py @@ -0,0 +1,35 @@ +""" +This example display a CircuitPython console and +print which button that is being pressed if any + +Note: This relies on displayio which is only widely +available on CircuitPython 4.0 Beta 5 and later +""" +import time +from adafruit_featherwing import minitft_featherwing + +minitft = minitft_featherwing.MiniTFTFeatherWing() + +while True: + if minitft.right: + print("Button RIGHT!") + + if minitft.down: + print("Button DOWN!") + + if minitft.left: + print("Button LEFT!") + + if minitft.up: + print("Button UP!") + + if minitft.select: + print("Button SELECT!") + + if minitft.button_a: + print("Button A!") + + if minitft.button_b: + print("Button B!") + + time.sleep(.01) From 4982ad071111811719ccb9eaa8c179243d83f858 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 9 Apr 2019 22:33:33 -0700 Subject: [PATCH 02/13] Linting --- adafruit_featherwing/minitft_featherwing.py | 20 ++++++++++---------- examples/featherwing_minitft_simpletest.py | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index fe2e14e..26e2ef4 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -32,15 +32,14 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" -import time import board -import displayio from micropython import const from adafruit_seesaw.seesaw import Seesaw +import displayio from adafruit_st7735r import ST7735R BUTTON_RIGHT = const(7) -BUTTON_DOWN = const(4) +BUTTON_DOWN = const(4) BUTTON_LEFT = const(3) BUTTON_UP = const(2) BUTTON_SEL = const(11) @@ -70,11 +69,12 @@ def __init__(self, address=0x5E, i2c=None, spi=None): display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5) self._ss.pin_mode(8, self._ss.OUTPUT) self._ss.digital_write(8, True) # Reset the Display via Seesaw - self._display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True) + self._display = ST7735R(display_bus, width=160, height=80, colstart=24, + rotation=270, bgr=True) @property def _buttons(self): - return self._ss.digital_read_bulk(self._button_mask) + return self._ss.digital_read_bulk(self._button_mask) @property def display(self): @@ -84,28 +84,28 @@ def display(self): return self._display @property - def right(self): + def button_right(self): """ Checks and returns if right is currently being pressed """ return not self._buttons & (1 << BUTTON_RIGHT) @property - def left(self): + def button_left(self): """ Checks and returns if left is currently being pressed """ return not self._buttons & (1 << BUTTON_LEFT) @property - def up(self): + def button_up(self): """ Checks and returns if up is currently being pressed """ return not self._buttons & (1 << BUTTON_UP) @property - def down(self): + def button_down(self): """ Checks and returns if down is currently being pressed """ @@ -126,7 +126,7 @@ def button_b(self): return not self._buttons & (1 << BUTTON_B) @property - def select(self): + def button_select(self): """ Checks and returns if select is currently being pressed """ diff --git a/examples/featherwing_minitft_simpletest.py b/examples/featherwing_minitft_simpletest.py index 9d72b62..f4e79b4 100755 --- a/examples/featherwing_minitft_simpletest.py +++ b/examples/featherwing_minitft_simpletest.py @@ -11,19 +11,19 @@ minitft = minitft_featherwing.MiniTFTFeatherWing() while True: - if minitft.right: + if minitft.button_right: print("Button RIGHT!") - if minitft.down: + if minitft.button_down: print("Button DOWN!") - if minitft.left: + if minitft.button_left: print("Button LEFT!") - if minitft.up: + if minitft.button_up: print("Button UP!") - if minitft.select: + if minitft.button_select: print("Button SELECT!") if minitft.button_a: From b0747f58a42151958869183ab71a95270e656330 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 9 Apr 2019 22:46:44 -0700 Subject: [PATCH 03/13] Added requirements --- requirements.txt | 1 + setup.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a0f7a50..6dbce5c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ adafruit-circuitpython-dotstar adafruit-circuitpython-neopixel adafruit-circuitpython-ds3231 adafruit-circuitpython-gps +adafruit-circuitpython-st7735r diff --git a/setup.py b/setup.py index 643597f..9ab0e60 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,8 @@ 'adafruit-circuitpython-register', 'adafruit-circuitpython-ina219', 'adafruit-circuitpython-seesaw', 'adafruit-circuitpython-ht16k33', 'adafruit-circuitpython-dotstar', 'adafruit-circuitpython-neopixel', - 'adafruit-circuitpython-ds3231', 'adafruit-circuitpython-gps'], + 'adafruit-circuitpython-ds3231', 'adafruit-circuitpython-gps', + 'adafruit-circuitpython-st7735r'], # Choose your license license='MIT', From b3f356d8e6f86cd07d973428f3373e906bcd8269 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 9 Apr 2019 22:50:31 -0700 Subject: [PATCH 04/13] Trying automock instead --- docs/conf.py | 2 +- requirements.txt | 1 - setup.py | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 208aba4..5c833dc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,7 +18,7 @@ # 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 = ["board", "busio", "displayio"] +autodoc_mock_imports = ["board", "busio", "displayio", "adafruit_st7735r"] intersphinx_mapping = { 'python': ('https://docs.python.org/3.4', None), diff --git a/requirements.txt b/requirements.txt index 6dbce5c..a0f7a50 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,3 @@ adafruit-circuitpython-dotstar adafruit-circuitpython-neopixel adafruit-circuitpython-ds3231 adafruit-circuitpython-gps -adafruit-circuitpython-st7735r diff --git a/setup.py b/setup.py index 9ab0e60..643597f 100644 --- a/setup.py +++ b/setup.py @@ -39,8 +39,7 @@ 'adafruit-circuitpython-register', 'adafruit-circuitpython-ina219', 'adafruit-circuitpython-seesaw', 'adafruit-circuitpython-ht16k33', 'adafruit-circuitpython-dotstar', 'adafruit-circuitpython-neopixel', - 'adafruit-circuitpython-ds3231', 'adafruit-circuitpython-gps', - 'adafruit-circuitpython-st7735r'], + 'adafruit-circuitpython-ds3231', 'adafruit-circuitpython-gps'], # Choose your license license='MIT', From 32fe548f2d5ff6bcc187532b24b98c52060fec55 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Tue, 9 Apr 2019 23:05:06 -0700 Subject: [PATCH 05/13] Added missing word to example description --- examples/featherwing_minitft_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/featherwing_minitft_simpletest.py b/examples/featherwing_minitft_simpletest.py index f4e79b4..c8194db 100755 --- a/examples/featherwing_minitft_simpletest.py +++ b/examples/featherwing_minitft_simpletest.py @@ -1,5 +1,5 @@ """ -This example display a CircuitPython console and +This example will display a CircuitPython console and print which button that is being pressed if any Note: This relies on displayio which is only widely From 5b78b06a779ad8697803040d40ab62ddd2219139 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 10 Apr 2019 21:55:25 -0700 Subject: [PATCH 06/13] Added backlight and deshipus suggested changes --- adafruit_featherwing/minitft_featherwing.py | 90 ++++++++------------- examples/featherwing_minitft_simpletest.py | 23 +++--- 2 files changed, 44 insertions(+), 69 deletions(-) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index 26e2ef4..a5caa6f 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -32,10 +32,12 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" +from collections import namedtuple import board +import displayio from micropython import const from adafruit_seesaw.seesaw import Seesaw -import displayio +from adafruit_seesaw.pwmout import PWMOut from adafruit_st7735r import ST7735R BUTTON_RIGHT = const(7) @@ -57,13 +59,8 @@ def __init__(self, address=0x5E, i2c=None, spi=None): if spi is None: spi = board.SPI() self._ss = Seesaw(i2c, address) - self._button_mask = const((1 << BUTTON_RIGHT) | - (1 << BUTTON_DOWN) | - (1 << BUTTON_LEFT) | - (1 << BUTTON_UP) | - (1 << BUTTON_SEL) | - (1 << BUTTON_A) | - (1 << BUTTON_B)) + self._backlight = PWMOut(self._ss, 5) + self._backlight.duty_cycle = 0 self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP) displayio.release_displays() display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5) @@ -73,61 +70,40 @@ def __init__(self, address=0x5E, i2c=None, spi=None): rotation=270, bgr=True) @property - def _buttons(self): - return self._ss.digital_read_bulk(self._button_mask) + def _button_mask(self): + return ((1 << BUTTON_RIGHT) | + (1 << BUTTON_DOWN) | + (1 << BUTTON_LEFT) | + (1 << BUTTON_UP) | + (1 << BUTTON_SEL) | + (1 << BUTTON_A) | + (1 << BUTTON_B)) @property - def display(self): + def backlight(self): """ - Returns the display object for doing fun displayio stuff on + Return the current backlight duty cycle value """ - return self._display + return self._backlight.duty_cycle / 255 - @property - def button_right(self): - """ - Checks and returns if right is currently being pressed - """ - return not self._buttons & (1 << BUTTON_RIGHT) - - @property - def button_left(self): + @backlight.setter + def backlight(self, brightness): """ - Checks and returns if left is currently being pressed + Set the backlight duty cycle """ - return not self._buttons & (1 << BUTTON_LEFT) + self._backlight.duty_cycle = int(255 * min(max(1 - brightness, 0.0), 1.0)) @property - def button_up(self): - """ - Checks and returns if up is currently being pressed - """ - return not self._buttons & (1 << BUTTON_UP) - - @property - def button_down(self): - """ - Checks and returns if down is currently being pressed - """ - return not self._buttons & (1 << BUTTON_DOWN) - - @property - def button_a(self): - """ - Checks and returns if button A is currently being pressed - """ - return not self._buttons & (1 << BUTTON_A) - - @property - def button_b(self): - """ - Checks and returns if button B is currently being pressed - """ - return not self._buttons & (1 << BUTTON_B) - - @property - def button_select(self): - """ - Checks and returns if select is currently being pressed - """ - return not self._buttons & (1 << BUTTON_SEL) + def buttons(self): + """ + Return a set of buttons with current push values + """ + Buttons = namedtuple("Buttons", "up down left right a b select") + button_values = self._ss.digital_read_bulk(self._button_mask) + return Buttons(up=(not button_values & (1 << BUTTON_UP)), + down=(not button_values & (1 << BUTTON_DOWN)), + left=(not button_values & (1 << BUTTON_LEFT)), + right=(not button_values & (1 << BUTTON_RIGHT)), + a=(not button_values & (1 << BUTTON_A)), + b=(not button_values & (1 << BUTTON_B)), + select=(not button_values & (1 << BUTTON_SEL))) diff --git a/examples/featherwing_minitft_simpletest.py b/examples/featherwing_minitft_simpletest.py index c8194db..1eb2b1f 100755 --- a/examples/featherwing_minitft_simpletest.py +++ b/examples/featherwing_minitft_simpletest.py @@ -1,9 +1,6 @@ """ -This example will display a CircuitPython console and +This example display a CircuitPython console and print which button that is being pressed if any - -Note: This relies on displayio which is only widely -available on CircuitPython 4.0 Beta 5 and later """ import time from adafruit_featherwing import minitft_featherwing @@ -11,25 +8,27 @@ minitft = minitft_featherwing.MiniTFTFeatherWing() while True: - if minitft.button_right: + buttons = minitft.buttons + + if buttons.right: print("Button RIGHT!") - if minitft.button_down: + if buttons.down: print("Button DOWN!") - if minitft.button_left: + if buttons.left: print("Button LEFT!") - if minitft.button_up: + if buttons.up: print("Button UP!") - if minitft.button_select: + if buttons.select: print("Button SELECT!") - if minitft.button_a: + if buttons.a: print("Button A!") - if minitft.button_b: + if buttons.b: print("Button B!") - time.sleep(.01) + time.sleep(.001) From dcbecccb80e76f0bd6102206205e5028f35b61f6 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 10 Apr 2019 22:00:37 -0700 Subject: [PATCH 07/13] Linting --- adafruit_featherwing/minitft_featherwing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index a5caa6f..45df08a 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -34,10 +34,10 @@ from collections import namedtuple import board -import displayio from micropython import const from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.pwmout import PWMOut +import displayio from adafruit_st7735r import ST7735R BUTTON_RIGHT = const(7) @@ -98,9 +98,9 @@ def buttons(self): """ Return a set of buttons with current push values """ - Buttons = namedtuple("Buttons", "up down left right a b select") + buttons = namedtuple("Buttons", "up down left right a b select") button_values = self._ss.digital_read_bulk(self._button_mask) - return Buttons(up=(not button_values & (1 << BUTTON_UP)), + return buttons(up=(not button_values & (1 << BUTTON_UP)), down=(not button_values & (1 << BUTTON_DOWN)), left=(not button_values & (1 << BUTTON_LEFT)), right=(not button_values & (1 << BUTTON_RIGHT)), From 61bb72168cc55fc28060113b12ead214c01fb148 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 10 Apr 2019 22:06:02 -0700 Subject: [PATCH 08/13] display attribute exposed --- adafruit_featherwing/minitft_featherwing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index 45df08a..41418a2 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -66,8 +66,8 @@ def __init__(self, address=0x5E, i2c=None, spi=None): display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5) self._ss.pin_mode(8, self._ss.OUTPUT) self._ss.digital_write(8, True) # Reset the Display via Seesaw - self._display = ST7735R(display_bus, width=160, height=80, colstart=24, - rotation=270, bgr=True) + self.display = ST7735R(display_bus, width=160, height=80, colstart=24, + rotation=270, bgr=True) @property def _button_mask(self): From 829f6ab9e57cf8473bf30a0801ccad64e011c5e3 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 11 Apr 2019 17:43:09 -0700 Subject: [PATCH 09/13] Added deshipu's suggestions --- adafruit_featherwing/minitft_featherwing.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index 41418a2..575bdb5 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -48,6 +48,8 @@ BUTTON_A = const(10) BUTTON_B = const(9) +Buttons = namedtuple("Buttons", "up down left right a b select") + class MiniTFTFeatherWing: """Class representing an `Mini Color TFT with Joystick FeatherWing `_. @@ -98,9 +100,8 @@ def buttons(self): """ Return a set of buttons with current push values """ - buttons = namedtuple("Buttons", "up down left right a b select") button_values = self._ss.digital_read_bulk(self._button_mask) - return buttons(up=(not button_values & (1 << BUTTON_UP)), + return Buttons(up=(not button_values & (1 << BUTTON_UP)), down=(not button_values & (1 << BUTTON_DOWN)), left=(not button_values & (1 << BUTTON_LEFT)), right=(not button_values & (1 << BUTTON_RIGHT)), From 7cd63911b6868a58313998eef613a2ecf1045314 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 11 Apr 2019 17:43:55 -0700 Subject: [PATCH 10/13] saved file before committing this time --- adafruit_featherwing/minitft_featherwing.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index 575bdb5..0948354 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -101,10 +101,6 @@ def buttons(self): Return a set of buttons with current push values """ button_values = self._ss.digital_read_bulk(self._button_mask) - return Buttons(up=(not button_values & (1 << BUTTON_UP)), - down=(not button_values & (1 << BUTTON_DOWN)), - left=(not button_values & (1 << BUTTON_LEFT)), - right=(not button_values & (1 << BUTTON_RIGHT)), - a=(not button_values & (1 << BUTTON_A)), - b=(not button_values & (1 << BUTTON_B)), - select=(not button_values & (1 << BUTTON_SEL))) + return Buttons(*[not button_values & (1 << button) for button in + (BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, + BUTTON_A, BUTTON_B, BUTTON_SEL)]) From e186a71bb33b1fdaff0edd941185ceda35086221 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 11 Apr 2019 17:46:23 -0700 Subject: [PATCH 11/13] linting --- adafruit_featherwing/minitft_featherwing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index 0948354..3c8dd49 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -103,4 +103,4 @@ def buttons(self): button_values = self._ss.digital_read_bulk(self._button_mask) return Buttons(*[not button_values & (1 << button) for button in (BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, - BUTTON_A, BUTTON_B, BUTTON_SEL)]) + BUTTON_A, BUTTON_B, BUTTON_SEL)]) From eed9b5c688db869586a3ef9e0b17c545afa07401 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 11 Apr 2019 17:49:16 -0700 Subject: [PATCH 12/13] more linting --- adafruit_featherwing/minitft_featherwing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index 3c8dd49..4c1bed1 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -102,5 +102,5 @@ def buttons(self): """ button_values = self._ss.digital_read_bulk(self._button_mask) return Buttons(*[not button_values & (1 << button) for button in - (BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, - BUTTON_A, BUTTON_B, BUTTON_SEL)]) + (BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, + BUTTON_A, BUTTON_B, BUTTON_SEL)]) From 2842b798b2ccad59fa09feece26ea928d524a3c1 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 12 Apr 2019 12:20:02 -0700 Subject: [PATCH 13/13] Button Mask not a property anymore --- adafruit_featherwing/minitft_featherwing.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index 4c1bed1..786b7cb 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -55,6 +55,15 @@ class MiniTFTFeatherWing: `_. Automatically uses the feather's I2C bus.""" + + _button_mask = ((1 << BUTTON_RIGHT) | + (1 << BUTTON_DOWN) | + (1 << BUTTON_LEFT) | + (1 << BUTTON_UP) | + (1 << BUTTON_SEL) | + (1 << BUTTON_A) | + (1 << BUTTON_B)) + def __init__(self, address=0x5E, i2c=None, spi=None): if i2c is None: i2c = board.I2C() @@ -71,16 +80,6 @@ def __init__(self, address=0x5E, i2c=None, spi=None): self.display = ST7735R(display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True) - @property - def _button_mask(self): - return ((1 << BUTTON_RIGHT) | - (1 << BUTTON_DOWN) | - (1 << BUTTON_LEFT) | - (1 << BUTTON_UP) | - (1 << BUTTON_SEL) | - (1 << BUTTON_A) | - (1 << BUTTON_B)) - @property def backlight(self): """