diff --git a/CHANGELOG.md b/CHANGELOG.md index c345e7b..32f9015 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Version 0.5.9 + +- refactor: make `synchronous_clock` enabled by default + ## Version 0.5.8 - refactor: avoid unnecessary scheduled calls of `render_on_display` diff --git a/headless_kivy_pi/__init__.py b/headless_kivy_pi/__init__.py index 08a6c1f..9030b65 100644 --- a/headless_kivy_pi/__init__.py +++ b/headless_kivy_pi/__init__.py @@ -18,7 +18,7 @@ import time from distutils.util import strtobool from pathlib import Path -from queue import Queue +from queue import Empty, Queue from threading import Thread from typing import TYPE_CHECKING, ClassVar @@ -71,7 +71,7 @@ MAX_FPS = int(os.environ.get('HEADLESS_KIVY_PI_MAX_FPS', '32')) WIDTH = int(os.environ.get('HEADLESS_KIVY_PI_WIDTH', '240')) HEIGHT = int(os.environ.get('HEADLESS_KIVY_PI_HEIGHT', '240')) -BAUDRATE = int(os.environ.get('HEADLESS_KIVY_PI_BAUDRATE', '70000000')) +BAUDRATE = int(os.environ.get('HEADLESS_KIVY_PI_BAUDRATE', '60000000')) DEBUG_MODE = ( strtobool( os.environ.get('HEADLESS_KIVY_PI_DEBUG', 'False' if IS_RPI else 'True'), @@ -86,7 +86,7 @@ ) SYNCHRONOUS_CLOCK = ( strtobool( - os.environ.get('HEADLESS_KIVY_PI_SYNCHRONOUS_CLOCK', 'True'), + os.environ.get('HEADLESS_KIVY_PI_SYNCHRONOUS_CLOCK', 'False'), ) == 1 ) @@ -213,7 +213,6 @@ def setup_headless(config: SetupHeadlessConfig | None = None) -> None: width=width, y_offset=80, x_offset=0, - rotation=180, cs=cs_pin, dc=dc_pin, rst=reset_pin, @@ -472,9 +471,6 @@ def render_on_display(self: HeadlessWidget, *_: Any) -> None: # noqa: ANN401 self.skipped_frames += 1 return - if self.debug_mode: - self.rendered_frames += 1 - data = np.frombuffer(self.texture.pixels, dtype=np.uint8).reshape( HeadlessWidget.width, HeadlessWidget.height, @@ -494,6 +490,9 @@ def render_on_display(self: HeadlessWidget, *_: Any) -> None: # noqa: ANN401 # Considering the content has not changed, this frame can safely be ignored return + if self.debug_mode: + self.rendered_frames += 1 + HeadlessWidget.should_ignore_hash = False self.last_change = time.time() @@ -503,14 +502,16 @@ def render_on_display(self: HeadlessWidget, *_: Any) -> None: # noqa: ANN401 self.activate_high_fps_mode() # Render the current frame on the display asynchronously + try: + last_thread = self.pending_render_threads.get(False) + except Empty: + last_thread = None thread = Thread( target=self.transfer_to_display, args=( data, data_hash, - self.pending_render_threads.get() - if self.pending_render_threads.qsize() > 0 - else None, + last_thread, ), ) self.pending_render_threads.put(thread) diff --git a/pyproject.toml b/pyproject.toml index 00aafd1..92dd00f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "headless-kivy-pi" -version = "0.5.8" +version = "0.5.9" description = "Headless renderer for Kivy framework on Raspberry Pi" authors = ["Sassan Haradji "] license = "Apache-2.0"