Skip to content

Commit

Permalink
Displaycore fix (#161)
Browse files Browse the repository at this point in the history
Split st7789 drawing methods into separate displaycore module.

BREAKING: This change slightly modifies some method signatures in the display module (Some args are now keyword-only args), as well as heavily modifies some private methods from the st7789 module. Hopefully, neither of these changes will actually cause problems, in practice.

st7789.py will now be purely a driver for the display. Ideally, new drivers will be able to be created in the future, and can use the same displaycore.py base for all their graphics functions.

This resolves #146


* Split st7789.py, create displaycore.py

* Clean up displaycore and st7789

* Reorganize and tidy display methods

* Small fixes

* Improve tiny buf speed + anim improvements
  • Loading branch information
echo-lalia authored Sep 26, 2024
1 parent 11ec322 commit aa48645
Show file tree
Hide file tree
Showing 4 changed files with 772 additions and 754 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ignore = [
"INP001", # File is part of an implicit namespace package. (Just a bit unnecessary)
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF005", # collection-literal-concatenation
"FBT001", # A function taking a sinlge bool value is very common.

# MH uses commented out code in the build process:
"ERA", # Found commented-out code
Expand Down
36 changes: 22 additions & 14 deletions src/launcher/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _CONSTANTS: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_MH_DISPLAY_WIDTH = const(320)
_MH_DISPLAY_HEIGHT = const(240)
_MH_DISPLAY_BACKLIGHT = const(42)
_MH_DISPLAY_WIDTH = const(240)
_MH_DISPLAY_HEIGHT = const(135)
_MH_DISPLAY_BACKLIGHT = const(38)

_DISPLAY_WIDTH_HALF = const(_MH_DISPLAY_WIDTH//2)

Expand Down Expand Up @@ -87,6 +87,7 @@


_SCROLL_ANIMATION_TIME = const(400)
_SCROLL_ANIMATION_QUICK = const(250)


_ASCII_MAX = const(128)
Expand Down Expand Up @@ -492,6 +493,7 @@ def __init__(self):
self.x = _DISPLAY_WIDTH_HALF
self.prev_x = 0
self.scroll_start_ms = time.ticks_ms()
self.anim = _SCROLL_ANIMATION_TIME
self.force_update()

# buffer for storing one custom icon
Expand Down Expand Up @@ -531,7 +533,7 @@ def _animate_scroll(self) -> int:
fac = time.ticks_diff(
time.ticks_ms(),
self.scroll_start_ms,
) / _SCROLL_ANIMATION_TIME
) / self.anim_time

if fac >= 1:
self.direction = 0
Expand All @@ -548,6 +550,9 @@ def start_scroll(self, direction=0):
"""Initialize the scrolling animation."""
if self.next_icon != self.drawn_icon:
self.force_update()
self.anim_time = _SCROLL_ANIMATION_QUICK
else:
self.anim_time = _SCROLL_ANIMATION_TIME

draw_scrollbar()
draw_app_name()
Expand Down Expand Up @@ -799,19 +804,19 @@ def main_loop():
new_keys = KB.get_new_keys()

# mh_if CARDPUTER:
# # Cardputer should use extended movement keys in the launcher
# KB.ext_dir_keys(new_keys)
# Cardputer should use extended movement keys in the launcher
KB.ext_dir_keys(new_keys)
# mh_end_if

# mh_if touchscreen:
# add swipes to direcitonal input
touch_events = KB.get_touch_events()
for event in touch_events:
if hasattr(event, 'direction'):
if event.direction == 'RIGHT':
new_keys.append('LEFT')
elif event.direction == 'LEFT':
new_keys.append('RIGHT')
# # add swipes to direcitonal input
# touch_events = KB.get_touch_events()
# for event in touch_events:
# if hasattr(event, 'direction'):
# if event.direction == 'RIGHT':
# new_keys.append('LEFT')
# elif event.direction == 'LEFT':
# new_keys.append('RIGHT')
# mh_end_if

if new_keys:
Expand Down Expand Up @@ -919,6 +924,9 @@ def main_loop():
if SYNCING_CLOCK:
try_sync_clock()

# short sleep makes the animation look a little less flickery
time.sleep_ms(5)


# run the main loop!
main_loop()
Loading

0 comments on commit aa48645

Please sign in to comment.