Skip to content

Commit

Permalink
refactor: make synchronous_clock enabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed Dec 20, 2023
1 parent 1dfbad4 commit 4fa9a94
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
21 changes: 11 additions & 10 deletions headless_kivy_pi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'),
Expand All @@ -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
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 4fa9a94

Please sign in to comment.