X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/blobdiff_plain/cfee25c8ae316776ce54589eae64409ea41bc42b..HEAD:/displayio/__init__.py diff --git a/displayio/__init__.py b/displayio/__init__.py index 55bb1d5..e42d24a 100644 --- a/displayio/__init__.py +++ b/displayio/__init__.py @@ -17,22 +17,19 @@ displayio for Blinka """ import threading +import time from typing import Union -from ._fourwire import FourWire -from ._i2cdisplay import I2CDisplay + from ._bitmap import Bitmap from ._colorspace import Colorspace from ._colorconverter import ColorConverter -from ._display import Display -from ._epaperdisplay import EPaperDisplay from ._group import Group from ._ondiskbitmap import OnDiskBitmap from ._palette import Palette -from ._shape import Shape from ._tilegrid import TileGrid -from ._displaybus import _DisplayBus from ._constants import CIRCUITPY_DISPLAY_LIMIT + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git" @@ -41,12 +38,16 @@ displays = [] display_buses = [] -def _background(): +def _background(stop_event): """Main thread function to loop through all displays and update them""" - while True: + while not stop_event.is_set(): for display in displays: display._background() # pylint: disable=protected-access + # relax system when _background does nothing + # and we are in a while True loop consuming lots of CPU + time.sleep(0.0) + def release_displays() -> None: """Releases any actively used displays so their busses and pins can be used again. @@ -63,14 +64,16 @@ def release_displays() -> None: display_buses.clear() -def allocate_display(new_display: Union[Display, EPaperDisplay]) -> None: +def allocate_display( + new_display: Union["busdisplay.BusDisplay", "epaperdisplay.EPaperDisplay"] +) -> None: """Add a display to the displays pool and return the new display""" if len(displays) >= CIRCUITPY_DISPLAY_LIMIT: raise RuntimeError("Too many displays") displays.append(new_display) -def allocate_display_bus(new_display_bus: _DisplayBus) -> None: +def allocate_display_bus(new_display_bus: "busdisplay._displaybus._DisplayBus") -> None: """Add a display bus to the display_buses pool and return the new display bus""" if len(display_buses) >= CIRCUITPY_DISPLAY_LIMIT: raise RuntimeError( @@ -79,7 +82,10 @@ def allocate_display_bus(new_display_bus: _DisplayBus) -> None: display_buses.append(new_display_bus) -background_thread = threading.Thread(target=_background, daemon=True) +background_thread_stop_event = threading.Event() +background_thread = threading.Thread( + target=_background, args=(background_thread_stop_event,), daemon=True +) # Start the background thread @@ -90,6 +96,7 @@ def _start_background(): def _stop_background(): if background_thread.is_alive(): + background_thread_stop_event.set() # Stop the thread background_thread.join()