Skip to content

Commit 79d0c47

Browse files
committed
Updated README and added text_scale
1 parent b571dfb commit 79d0c47

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

README.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Introduction
1717
:target: https://github.com/psf/black
1818
:alt: Code Style: Black
1919

20-
Helper library for the Adafruit RGB Matrix Shield + Metro M4 Airlift Lite.
20+
CircuitPython helper for Adafruit MatrixPortal M4, Adafruit RGB Matrix Shield + Metro M4 Airlift Lite,
21+
and Adafruit RGB Matrix FeatherWings
2122

2223

2324
Dependencies

adafruit_matrixportal/matrixportal.py

+31-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import gc
2929
from time import sleep
3030
import terminalio
31+
from displayio import Group
3132
from adafruit_bitmap_font import bitmap_font
3233
from adafruit_display_text.label import Label
3334
from adafruit_matrixportal.network import Network
@@ -124,6 +125,7 @@ def __init__(
124125
self._text_maxlen = []
125126
self._text_transform = []
126127
self._text_scrolling = []
128+
self._text_scale = []
127129
self._scrolling_index = None
128130
self._text_font = terminalio.FONT
129131

@@ -138,6 +140,7 @@ def add_text(
138140
text_wrap=False,
139141
text_maxlen=0,
140142
text_transform=None,
143+
text_scale=1,
141144
scrolling=False,
142145
):
143146
"""
@@ -153,6 +156,7 @@ def add_text(
153156
``False``, no wrapping.
154157
:param text_maxlen: The max length of the text for text wrapping. Defaults to 0.
155158
:param text_transform: A function that will be called on the text before display
159+
:param int text_scale: The factor to scale the default size of the text by
156160
:param bool scrolling: If true, text is placed offscreen and the scroll() function is used
157161
to scroll text on a pixel-by-pixel basis. Multiple text labels with
158162
the scrolling set to True will be cycled through.
@@ -169,6 +173,9 @@ def add_text(
169173
text_maxlen = 0
170174
if not text_transform:
171175
text_transform = None
176+
if not isinstance(text_scale, (int, float)) or text_scale < 1:
177+
text_scale = 1
178+
text_scale = round(text_scale)
172179
if scrolling:
173180
text_position = (self.display.width, text_position[1])
174181

@@ -182,6 +189,7 @@ def add_text(
182189
self._text_wrap.append(text_wrap)
183190
self._text_maxlen.append(text_maxlen)
184191
self._text_transform.append(text_transform)
192+
self._text_scale.append(text_scale)
185193
self._text_scrolling.append(scrolling)
186194

187195
if scrolling and self._scrolling_index is None: # Not initialized yet
@@ -242,7 +250,10 @@ def set_text_color(self, color, index=0):
242250
if self._text[index]:
243251
color = self.html_color_convert(color)
244252
self._text_color[index] = color
245-
self._text[index].color = color
253+
if isinstance(self._text[index], Group):
254+
self._text[index][0].color = color
255+
else:
256+
self._text[index].color = color
246257

247258
def set_text(self, val, index=0):
248259
"""Display text, with indexing into our list of text boxes.
@@ -261,12 +272,18 @@ def set_text(self, val, index=0):
261272
index_in_splash = None
262273
if self._text[index] is not None:
263274
print("Replacing text area with :", string)
264-
index_in_splash = self.splash.index(self._text[index])
265275
if len(string) > 0:
266-
self._text[index] = Label(self._text_font, text=string)
267-
self._text[index].color = self._text_color[index]
268-
self._text[index].x = self._text_position[index][0]
269-
self._text[index].y = self._text_position[index][1]
276+
label = Label(self._text_font, text=string)
277+
label.color = self._text_color[index]
278+
if self._text_scale[index] > 1:
279+
self._text[index] = Group(max_size=1, scale=self._text_scale[index])
280+
self._text[index].x = self._text_position[index][0]
281+
self._text[index].y = self._text_position[index][1]
282+
self._text[index].append(label)
283+
else:
284+
label.x = self._text_position[index][0]
285+
label.y = self._text_position[index][1]
286+
self._text[index] = label
270287
elif index_in_splash is not None:
271288
self._text[index] = None
272289

@@ -315,6 +332,14 @@ def get_io_data(self, feed_key):
315332

316333
return self.network.get_io_data(feed_key)
317334

335+
def get_io_last_data(self, feed_key):
336+
"""Return last value from Adafruit IO Feed Data that matches the feed key
337+
338+
:param str feed_key: Name of feed key to receive data from.
339+
340+
"""
341+
return self.network.get_io_last_data(feed_key)
342+
318343
def get_io_feed(self, feed_key, detailed=False):
319344
"""Return the Adafruit IO Feed that matches the feed key
320345

docs/index.rst

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26+
* Adafruit MatrixPortal M4 <https://learn.adafruit.com/adafruit-matrixportal-m4>
27+
2628
.. toctree::
2729
:caption: Related Products
2830

29-
* Adafruit Matrix Portal <https://www.adafruit.com/product/4745>
31+
* Adafruit MatrixPortal M4 <https://www.adafruit.com/product/4745>
3032
* Adafruit Metro M4 Express AirLift <https://www.adafruit.com/product/4000>
3133
* Adafruit RGB Matrix Shield <https://www.adafruit.com/product/2601>
34+
* Adafruit RGB Matrix Featherwing for M0/M4 <https://www.adafruit.com/product/3036>
35+
* Adafruit RGB Matrix FeatherWing for nrf52840 <https://www.adafruit.com/product/4702>
3236
* 64x32 RGB LED Matrix <https://www.adafruit.com/product/2278>
37+
* 16x32 RGB LED Matrix <https://www.adafruit.com/product/420>
38+
* 64x64 2.5mm pitch RGB LED Matrix <https://www.adafruit.com/product/3649>
39+
* 64x64 3mm pitch RGB LED Matrix <https://www.adafruit.com/product/4732>
3340

3441
.. toctree::
3542
:caption: Other Links

0 commit comments

Comments
 (0)