X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka_Displayio.git/blobdiff_plain/7cb15fbccca19f31b6024ee4493844bc68392426..996c02e4f83c0034202ea81767a96fb42d75df09:/displayio/__init__.py diff --git a/displayio/__init__.py b/displayio/__init__.py index c0d35a3..fad38f0 100644 --- a/displayio/__init__.py +++ b/displayio/__init__.py @@ -17,9 +17,11 @@ displayio for Blinka """ import threading +import time from typing import Union import fourwire +import i2cdisplaybus from busdisplay import BusDisplay from busdisplay._displaybus import _DisplayBus from epaperdisplay import EPaperDisplay @@ -36,6 +38,7 @@ from ._constants import CIRCUITPY_DISPLAY_LIMIT # when compatibility is removed from core displayio Display = BusDisplay FourWire = fourwire.FourWire +I2CDisplay = i2cdisplaybus.I2CDisplayBus __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_Blinka_displayio.git" @@ -45,11 +48,15 @@ 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: @@ -83,7 +90,8 @@ 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 @@ -94,6 +102,7 @@ def _start_background(): def _stop_background(): if background_thread.is_alive(): + background_thread_stop_event.set() # Stop the thread background_thread.join()