26
26
"""
27
27
28
28
import gc
29
+ from time import sleep
29
30
import terminalio
30
- import displayio
31
31
from adafruit_bitmap_font import bitmap_font
32
32
from adafruit_display_text .label import Label
33
33
from adafruit_matrixportal .network import Network
34
- from adafruit_matrixportal .matrix import Matrix
34
+ from adafruit_matrixportal .graphics import Graphics
35
35
36
36
__version__ = "0.0.0-auto.0"
37
37
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal.git"
@@ -79,8 +79,10 @@ def __init__(
79
79
):
80
80
81
81
self ._debug = debug
82
- matrix = Matrix (bit_depth = bit_depth , width = 64 , height = 32 )
83
- self .display = matrix .display
82
+ self ._graphics = Graphics (
83
+ default_bg = default_bg , bit_depth = bit_depth , width = 64 , height = 32 , debug = debug
84
+ )
85
+ self .display = self ._graphics .display
84
86
85
87
self ._network = Network (
86
88
status_neopixel = status_neopixel ,
@@ -98,20 +100,7 @@ def __init__(
98
100
99
101
self ._regexp_path = regexp_path
100
102
101
- if self ._debug :
102
- print ("Init display" )
103
- self .splash = displayio .Group (max_size = 15 )
104
-
105
- if self ._debug :
106
- print ("Init background" )
107
- self ._bg_group = displayio .Group (max_size = 1 )
108
- self ._bg_file = None
109
- self ._default_bg = default_bg
110
- self .splash .append (self ._bg_group )
111
-
112
- # set the default background
113
- self .set_background (self ._default_bg )
114
- self .display .show (self .splash )
103
+ self .splash = self ._graphics .splash
115
104
116
105
# Add any JSON translators
117
106
if json_transform :
@@ -200,39 +189,7 @@ def set_background(self, file_or_color, position=None):
200
189
:param file_or_color: The filename of the chosen background image, or a hex color.
201
190
202
191
"""
203
- print ("Set background to " , file_or_color )
204
- while self ._bg_group :
205
- self ._bg_group .pop ()
206
-
207
- if not position :
208
- position = (0 , 0 ) # default in top corner
209
-
210
- if not file_or_color :
211
- return # we're done, no background desired
212
- if self ._bg_file :
213
- self ._bg_file .close ()
214
- if isinstance (file_or_color , str ): # its a filenme:
215
- self ._bg_file = open (file_or_color , "rb" )
216
- background = displayio .OnDiskBitmap (self ._bg_file )
217
- self ._bg_sprite = displayio .TileGrid (
218
- background ,
219
- pixel_shader = displayio .ColorConverter (),
220
- x = position [0 ],
221
- y = position [1 ],
222
- )
223
- elif isinstance (file_or_color , int ):
224
- # Make a background color fill
225
- color_bitmap = displayio .Bitmap (self .display .width , self .display .height , 1 )
226
- color_palette = displayio .Palette (1 )
227
- color_palette [0 ] = file_or_color
228
- self ._bg_sprite = displayio .TileGrid (
229
- color_bitmap , pixel_shader = color_palette , x = position [0 ], y = position [1 ],
230
- )
231
- else :
232
- raise RuntimeError ("Unknown type of background" )
233
- self ._bg_group .append (self ._bg_sprite )
234
- self .display .refresh ()
235
- gc .collect ()
192
+ self ._graphics .set_background (file_or_color , position )
236
193
237
194
def preload_font (self , glyphs = None ):
238
195
# pylint: disable=line-too-long
@@ -307,25 +264,77 @@ def _get_next_scrollable_text_index(self):
307
264
if index == self ._scrolling_index :
308
265
return None
309
266
267
+ def push_to_io (self , feed_key , data ):
268
+ """Push data to an adafruit.io feed
269
+
270
+ :param str feed_key: Name of feed key to push data to.
271
+ :param data: data to send to feed
272
+
273
+ """
274
+
275
+ self ._network .push_to_io (feed_key , data )
276
+
277
+ def get_io_data (self , feed_key ):
278
+ """Return all values from the Adafruit IO Feed Data that matches the feed key
279
+
280
+ :param str feed_key: Name of feed key to receive data from.
281
+
282
+ """
283
+
284
+ return self ._network .get_io_data (feed_key )
285
+
286
+ def get_io_feed (self , feed_key , detailed = False ):
287
+ """Return the Adafruit IO Feed that matches the feed key
288
+
289
+ :param str feed_key: Name of feed key to match.
290
+ :param bool detailed: Whether to return additional detailed information
291
+
292
+ """
293
+ return self ._network .get_io_feed (feed_key , detailed )
294
+
295
+ def get_io_group (self , group_key ):
296
+ """Return the Adafruit IO Group that matches the group key
297
+
298
+ :param str group_key: Name of group key to match.
299
+
300
+ """
301
+ return self ._network .get_io_group (group_key )
302
+
310
303
def scroll (self ):
311
- """Scroll any text that needs scrolling. We also want to queue up
312
- multiple lines one after another. To get simultaneous lines, we can
313
- simply use a line break."""
304
+ """Scroll any text that needs scrolling by a single frame. We also
305
+ we want to queue up multiple lines one after another. To get
306
+ simultaneous lines, we can simply use a line break.
307
+ """
314
308
315
309
if self ._scrolling_index is None : # Not initialized yet
316
310
next_index = self ._get_next_scrollable_text_index ()
317
311
if next_index is None :
318
312
return
319
313
self ._scrolling_index = next_index
320
314
321
- # set line to label with self._scrolling_index
322
-
323
315
self ._text [self ._scrolling_index ].x = self ._text [self ._scrolling_index ].x - 1
324
316
line_width = self ._text [self ._scrolling_index ].bounding_box [2 ]
325
317
if self ._text [self ._scrolling_index ].x < - line_width :
326
318
# Find the next line
327
319
self ._scrolling_index = self ._get_next_scrollable_text_index ()
328
- self ._text [self ._scrolling_index ].x = self .display .width
320
+ self ._text [self ._scrolling_index ].x = self ._graphics .display .width
321
+
322
+ def scroll_text (self , frame_delay = 0.02 ):
323
+ """Scroll the entire text all the way across. We also
324
+ we want to queue up multiple lines one after another. To get
325
+ simultaneous lines, we can simply use a line break.
326
+ """
327
+ if self ._scrolling_index is None : # Not initialized yet
328
+ next_index = self ._get_next_scrollable_text_index ()
329
+ if next_index is None :
330
+ return
331
+ self ._scrolling_index = next_index
332
+
333
+ self ._text [self ._scrolling_index ].x = self ._graphics .display .width
334
+ line_width = self ._text [self ._scrolling_index ].bounding_box [2 ]
335
+ for _ in range (self ._graphics .display .width + line_width + 1 ):
336
+ self .scroll ()
337
+ sleep (frame_delay )
329
338
330
339
def fetch (self , refresh_url = None , timeout = 10 ):
331
340
"""Fetch data from the url we initialized with, perfom any parsing,
0 commit comments