From a8efc29aef70d5dea21c686e1271eb88fcb0a84a Mon Sep 17 00:00:00 2001 From: Paul Cutler Date: Fri, 3 Nov 2023 07:23:08 -0500 Subject: [PATCH 01/11] Update root_group for CP 9 compatibility --- examples/macropad_grid_layout.py | 2 +- examples/macropad_rainbow_keys.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/macropad_grid_layout.py b/examples/macropad_grid_layout.py index 6f8f917..ee8469a 100644 --- a/examples/macropad_grid_layout.py +++ b/examples/macropad_grid_layout.py @@ -14,7 +14,7 @@ macropad = MacroPad() main_group = displayio.Group() -macropad.display.show(main_group) +macropad.display.root_group = main_group title = label.Label( y=4, font=terminalio.FONT, diff --git a/examples/macropad_rainbow_keys.py b/examples/macropad_rainbow_keys.py index e3e2a1b..d13c8af 100644 --- a/examples/macropad_rainbow_keys.py +++ b/examples/macropad_rainbow_keys.py @@ -16,7 +16,7 @@ macropad = MacroPad() main_group = displayio.Group() -macropad.display.show(main_group) +macropad.display.root_group = main_group title = label.Label( y=4, font=terminalio.FONT, From 22a720a4c2768916ddef716198df46d9db06c990 Mon Sep 17 00:00:00 2001 From: Mitchell Haugen Date: Wed, 8 Nov 2023 23:22:16 -0800 Subject: [PATCH 02/11] Update font documentation for display_text() --- adafruit_macropad.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/adafruit_macropad.py b/adafruit_macropad.py index 4b697ee..354bca1 100755 --- a/adafruit_macropad.py +++ b/adafruit_macropad.py @@ -900,8 +900,9 @@ def display_text( :param int text_scale: Scale the size of the data lines. Scales the title as well. Defaults to 1. :param font: The font or the path to the custom font file to use to display the text. - Defaults to the built-in ``terminalio.FONT``. Custom font files must be - provided as a string, e.g. ``"/Arial12.bdf"``. + Defaults to the built-in ``terminalio.FONT``. The ``font`` argument must be of + a type that subclasses ``FontProtocol``. For more details, see: + https://docs.circuitpython.org/en/latest/shared-bindings/fontio/index.html The following example displays a title and lines of text indicating which key is pressed, the relative position of the rotary encoder, and whether the encoder switch is pressed. @@ -909,11 +910,14 @@ def display_text( .. code-block:: python + from adafruit_bitmap_font import bitmap_font from adafruit_macropad import MacroPad + from displayio import Bitmap macropad = MacroPad() - text_lines = macropad.display_text(title="MacroPad Info") + custom_font = bitmap_font.load_font("/Arial12.bdf", Bitmap) + text_lines = macropad.display_text(title="MacroPad Info", font=custom_font) while True: key_event = macropad.keys.events.get() From 8f5d3ee0ccaa77358d299a0988ce04ab987531a9 Mon Sep 17 00:00:00 2001 From: Mitchell Haugen Date: Wed, 8 Nov 2023 23:36:32 -0800 Subject: [PATCH 03/11] add param data type --- adafruit_macropad.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/adafruit_macropad.py b/adafruit_macropad.py index 354bca1..7b29bb7 100755 --- a/adafruit_macropad.py +++ b/adafruit_macropad.py @@ -899,9 +899,10 @@ def display_text( Defaults to 80. :param int text_scale: Scale the size of the data lines. Scales the title as well. Defaults to 1. - :param font: The font or the path to the custom font file to use to display the text. - Defaults to the built-in ``terminalio.FONT``. The ``font`` argument must be of - a type that subclasses ``FontProtocol``. For more details, see: + :param ~FontProtocol|None font: The font or the path to the custom font file to use to + display the text. Defaults to the built-in ``terminalio.FONT``. The ``font`` + argument must be of a type that subclasses ``FontProtocol``. For more details, + see: https://docs.circuitpython.org/en/latest/shared-bindings/fontio/index.html The following example displays a title and lines of text indicating which key is pressed, From 7805935b6d2dab4e2eda5d243e115d06b63b37b6 Mon Sep 17 00:00:00 2001 From: Mitchell Haugen Date: Wed, 8 Nov 2023 23:40:19 -0800 Subject: [PATCH 04/11] rewording --- adafruit_macropad.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/adafruit_macropad.py b/adafruit_macropad.py index 7b29bb7..bb36953 100755 --- a/adafruit_macropad.py +++ b/adafruit_macropad.py @@ -899,11 +899,9 @@ def display_text( Defaults to 80. :param int text_scale: Scale the size of the data lines. Scales the title as well. Defaults to 1. - :param ~FontProtocol|None font: The font or the path to the custom font file to use to - display the text. Defaults to the built-in ``terminalio.FONT``. The ``font`` - argument must be of a type that subclasses ``FontProtocol``. For more details, - see: - https://docs.circuitpython.org/en/latest/shared-bindings/fontio/index.html + :param ~FontProtocol|None font: The custom font to use to display the text. Defaults to the + built-in ``terminalio.FONT``. For more details, see: + https://docs.circuitpython.org/en/latest/shared-bindings/fontio/index.html The following example displays a title and lines of text indicating which key is pressed, the relative position of the rotary encoder, and whether the encoder switch is pressed. From 50725db0fb0de18baac5d0cd89e65f2a0b348e9c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 9 Nov 2023 14:06:00 -0500 Subject: [PATCH 05/11] Missed one .show(...) --- adafruit_macropad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_macropad.py b/adafruit_macropad.py index 4b697ee..e56153c 100755 --- a/adafruit_macropad.py +++ b/adafruit_macropad.py @@ -865,7 +865,7 @@ def display_image( if not position: position = (0, 0) group = displayio.Group(scale=1) - self.display.show(group) + self.display.root_group = group with open(file_name, "rb") as image_file: background = displayio.OnDiskBitmap(image_file) sprite = displayio.TileGrid( From f3aa11974eea1008de4c796b9c1926ff4844e3ef Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 4 Dec 2023 10:25:35 -0600 Subject: [PATCH 06/11] unpin sphinx and add sphinx-rtd-theme to docs reqs --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 4f3e4c2..e6ff49f 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,5 +3,6 @@ # # SPDX-License-Identifier: MIT -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme From 1b414331470475efb1a3a1d11c72f59321f98e00 Mon Sep 17 00:00:00 2001 From: Richard Terry Date: Sat, 10 Feb 2024 07:03:49 +0000 Subject: [PATCH 07/11] Add rotate() to change rotation after init --- adafruit_macropad.py | 94 ++++++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 33 deletions(-) diff --git a/adafruit_macropad.py b/adafruit_macropad.py index 6b355a1..c981432 100755 --- a/adafruit_macropad.py +++ b/adafruit_macropad.py @@ -246,43 +246,11 @@ def __init__( layout_class: type[KeyboardLayoutBase] = KeyboardLayoutUS, keycode_class: type[Keycode] = Keycode, ): - if rotation not in (0, 90, 180, 270): - raise ValueError("Only 90 degree rotations are supported.") - # Define LEDs: self._pixels = neopixel.NeoPixel(board.NEOPIXEL, 12) self._led = digitalio.DigitalInOut(board.LED) self._led.switch_to_output() - # Define key and pixel maps based on rotation: - self._rotated_pixels = None - self._key_pins = None - - def _keys_and_pixels( - order: Tuple[int, int, int, int, int, int, int, int, int, int, int, int] - ) -> None: - """ - Generate key and pixel maps based on a specified order. - :param order: Tuple containing the order of the keys and pixels. - """ - self._key_pins = [getattr(board, "KEY%d" % (num + 1)) for num in order] - self._rotated_pixels = _PixelMapLite(self._pixels, order=order) - - if rotation == 0: - _keys_and_pixels(order=ROTATED_KEYMAP_0) - - if rotation == 90: - _keys_and_pixels(order=ROTATED_KEYMAP_90) - - if rotation == 180: - _keys_and_pixels(order=ROTATED_KEYMAP_180) - - if rotation == 270: - _keys_and_pixels(order=ROTATED_KEYMAP_270) - - # Define keys: - self._keys = keypad.Keys(self._key_pins, value_when_pressed=False, pull=True) - # Define rotary encoder and encoder switch: self._encoder = rotaryio.IncrementalEncoder(board.ROTA, board.ROTB) self._encoder_switch = digitalio.DigitalInOut(board.BUTTON) @@ -292,10 +260,15 @@ def _keys_and_pixels( # Define display: if not isinstance(board.DISPLAY, type(None)): self.display = board.DISPLAY - self.display.rotation = rotation self.display.bus.send(_DISPLAY_WAKE_COMMAND, b"") self._display_sleep = False + # Define key and pixel maps based on rotation: + self._rotated_pixels = None + self._key_pins = None + self._keys = None + self.rotate(rotation) + # Define audio: self._speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE) self._speaker_enable.switch_to_output(value=False) @@ -328,6 +301,61 @@ def _keys_and_pixels( # No MIDI ports available. self._midi = None + def rotate(self, rotation): + """ + Set the display rotation + + :param int rotation: The rotational position of the MacroPad. Allows for rotating the MacroPad + in 90 degree increments to four different positions and rotates the keypad + layout and display orientation to match. Keypad layout is always left to + right, top to bottom, beginning with key number 0 in the top left, and + ending with key number 11 in the bottom right. Supports ``0``, ``90``, + ``180``, and ``270`` degree rotations. ``0`` is when the USB port is at + the top, ``90`` is when the USB port is to the left, ``180`` is when the + USB port is at the bottom, and ``270`` is when the USB port is to the + right. Defaults to ``0``. + """ + if rotation not in (0, 90, 180, 270): + raise ValueError("Only 90 degree rotations are supported.") + + self._rotation = rotation + + def _keys_and_pixels( + order: Tuple[int, int, int, int, int, int, int, int, int, int, int, int] + ) -> None: + """ + Generate key and pixel maps based on a specified order. + :param order: Tuple containing the order of the keys and pixels. + """ + self._key_pins = [getattr(board, "KEY%d" % (num + 1)) for num in order] + self._rotated_pixels = _PixelMapLite(self._pixels, order=order) + + if rotation == 0: + _keys_and_pixels(order=ROTATED_KEYMAP_0) + + if rotation == 90: + _keys_and_pixels(order=ROTATED_KEYMAP_90) + + if rotation == 180: + _keys_and_pixels(order=ROTATED_KEYMAP_180) + + if rotation == 270: + _keys_and_pixels(order=ROTATED_KEYMAP_270) + + # Define keys: + if self._keys is not None: + self._keys.deinit() + self._keys = keypad.Keys(self._key_pins, value_when_pressed=False, pull=True) + + self.display.rotation = rotation + + @property + def rotation(self) -> int: + """ + The current rotation + """ + return self._rotation + @property def display_sleep(self) -> bool: """The power saver mode of the display. Set it to put the display to From 43c0575863d11a8fa3776c21c7e10fb511fdc480 Mon Sep 17 00:00:00 2001 From: Richard Terry Date: Sat, 10 Feb 2024 16:23:00 +0000 Subject: [PATCH 08/11] Fix line length --- adafruit_macropad.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/adafruit_macropad.py b/adafruit_macropad.py index c981432..394aed3 100755 --- a/adafruit_macropad.py +++ b/adafruit_macropad.py @@ -305,15 +305,15 @@ def rotate(self, rotation): """ Set the display rotation - :param int rotation: The rotational position of the MacroPad. Allows for rotating the MacroPad - in 90 degree increments to four different positions and rotates the keypad - layout and display orientation to match. Keypad layout is always left to - right, top to bottom, beginning with key number 0 in the top left, and - ending with key number 11 in the bottom right. Supports ``0``, ``90``, - ``180``, and ``270`` degree rotations. ``0`` is when the USB port is at - the top, ``90`` is when the USB port is to the left, ``180`` is when the - USB port is at the bottom, and ``270`` is when the USB port is to the - right. Defaults to ``0``. + :param int rotation: The rotational position of the MacroPad. Allows for rotating the + MacroPad in 90 degree increments to four different positions and + rotates the keypad layout and display orientation to match. Keypad + layout is always left to right, top to bottom, beginning with key + number 0 in the top left, and ending with key number 11 in the bottom + right. Supports ``0``, ``90``, ``180``, and ``270`` degree rotations. + ``0`` is when the USB port is at the top, ``90`` is when the USB port + is to the left, ``180`` is when the USB port is at the bottom, and + ``270`` is when the USB port is to the right. Defaults to ``0``. """ if rotation not in (0, 90, 180, 270): raise ValueError("Only 90 degree rotations are supported.") From 6fb54713abe8f8a4773ecc9fc2cacd46d7618fcb Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 19 Feb 2024 19:20:32 -0600 Subject: [PATCH 09/11] add rotation setter --- adafruit_macropad.py | 4 ++++ 1 file changed, 4 insertions(+) mode change 100755 => 100644 adafruit_macropad.py diff --git a/adafruit_macropad.py b/adafruit_macropad.py old mode 100755 new mode 100644 index 394aed3..91954d5 --- a/adafruit_macropad.py +++ b/adafruit_macropad.py @@ -356,6 +356,10 @@ def rotation(self) -> int: """ return self._rotation + @rotation.setter + def rotation(self, new_rotation) -> None: + self.rotate(new_rotation) + @property def display_sleep(self) -> bool: """The power saver mode of the display. Set it to put the display to From 095dbc1d576ae3dbd81fad92897ea8389d62d6a3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 10/11] 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 4e66766..20488a9 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -129,7 +129,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 365bb827ed46fe8c6ee3276c385a57db7a53bebf Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 11/11] 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: