Skip to content

Commit 9f3e443

Browse files
committed
pydisplay: Package troubleshooting.
Signed-off-by: Brad Barnett <[email protected]>
1 parent d36eaf4 commit 9f3e443

File tree

16 files changed

+25
-650
lines changed

16 files changed

+25
-650
lines changed

micropython/pydisplay/displaysys/displaysys-pgdisplay/displaysys/pgdisplay.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
pass
1616

1717

18-
def poll() -> Optional[pg.event.Event | False]:
18+
def poll():
1919
"""
2020
Polls for an event and returns the event type and data.
2121
@@ -24,22 +24,6 @@ def poll() -> Optional[pg.event.Event | False]:
2424
"""
2525
return pg.event.poll()
2626

27-
def peek(eventtype: Optional[Union[int, Sequence[int]]] = None, pump: bool = True) -> bool:
28-
"""
29-
Check the event queue for messages. Returns True if there are any events of the given type waiting on the queue.
30-
If a sequence of event types is passed, this will return True if any of those events are on the queue.
31-
32-
If pump is True (the default), then pygame.event.pump() will be called.
33-
34-
Args:
35-
eventtype (Optional[Union[int, Sequence[int]]]): The event type(s) to check. Defaults to None.
36-
pump (bool): Whether to call pygame.event.pump(). Defaults to True.
37-
38-
Returns:
39-
bool: True if there are any events of the given type waiting on the queue.
40-
"""
41-
return pg.event.peek(eventtype, pump)
42-
4327

4428
class PGDisplay(DisplayDriver):
4529
"""
@@ -262,7 +246,7 @@ def render(self, renderRect: Optional[pg.Rect] = None) -> None:
262246
bfaRect = pg.Rect(0, tfa + vsa, width, bfa)
263247
self._window.blit(buffer, bfaRect, bfaRect)
264248

265-
def show(self) -> None:
249+
def show(self, param=None) -> None:
266250
"""
267251
Show the display.
268252
"""

micropython/pydisplay/displaysys/displaysys-pgdisplay/examples/board_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Board configuration for PyGame.
33
"""
44

5-
from displaysys.pgdisplay import PGDisplay as DTDisplay, poll, peek
5+
from displaysys.pgdisplay import PGDisplay as DTDisplay, poll
66
from eventsys import devices
77
import sys
88

@@ -26,7 +26,6 @@
2626
type=devices.types.QUEUE,
2727
read=poll,
2828
data=display_drv,
29-
read2=peek,
3029
# data2=events.filter,
3130
)
3231

micropython/pydisplay/displaysys/displaysys-sdldisplay/displaysys/sdldisplay/__init__.py

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from displaysys import DisplayDriver, color_rgb
1010
from eventsys import events
1111
from sys import implementation
12+
from micropython import schedule
1213
from ._sdl2_lib import (
1314
SDL_Init,
1415
SDL_Quit,
@@ -41,8 +42,6 @@
4142
SDL_INIT_EVERYTHING,
4243
SDL_Rect,
4344
SDL_PollEvent,
44-
SDL_PeepEvents,
45-
SDL_PumpEvents,
4645
SDL_GetKeyName,
4746
SDL_Event,
4847
SDL_QUIT,
@@ -55,9 +54,6 @@
5554
SDL_MOUSEWHEEL,
5655
SDL_KEYDOWN,
5756
SDL_KEYUP,
58-
SDL_PEEKEVENT,
59-
SDL_FIRSTEVENT,
60-
SDL_LASTEVENT,
6157
)
6258

6359
try:
@@ -72,6 +68,20 @@
7268
else:
7369
is_cpython = False
7470

71+
try:
72+
from time import ticks_ms, ticks_add
73+
except ImportError:
74+
from adafruit_ticks import ticks_ms, ticks_add
75+
76+
77+
def scheduler(param):
78+
func, next_run, interval = param
79+
if (current_time := ticks_ms()) >= next_run:
80+
interval = func(interval)
81+
next_run = ticks_add(current_time, interval)
82+
if interval > 0:
83+
schedule(scheduler, (func, next_run, interval))
84+
7585

7686
_event = SDL_Event()
7787

@@ -93,33 +103,6 @@ def poll() -> Optional[events]:
93103
return _convert(SDL_Event(_event))
94104
return None
95105

96-
def peek(eventtype: Optional[Union[int, Sequence[int]]] = None, pump: bool = True) -> bool:
97-
"""
98-
Check the event queue for messages. Returns True if there are any events of the given type waiting on the queue.
99-
If a sequence of event types is passed, this will return True if any of those events are on the queue.
100-
101-
If pump is True (the default), then pygame.event.pump() will be called.
102-
103-
Args:
104-
eventtype (Optional[Union[int, Sequence[int]]]): The event type(s) to check. Defaults to None.
105-
pump (bool): Whether to call pygame.event.pump(). Defaults to True.
106-
107-
Returns:
108-
bool: True if there are any events of the given type waiting on the queue.
109-
"""
110-
global _event
111-
_event = SDL_Event()
112-
if pump:
113-
SDL_PumpEvents()
114-
num_matching = SDL_PeepEvents(_event, 1, SDL_PEEKEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT)
115-
if num_matching == 0:
116-
return False
117-
if eventtype is None:
118-
return True
119-
if isinstance(eventtype, int):
120-
return _event.type == eventtype
121-
return _event.type in eventtype
122-
123106
def _convert(e):
124107
# Convert an SDL event to a Pygame event
125108
if e.type == SDL_MOUSEMOTION:
@@ -169,7 +152,6 @@ def _convert(e):
169152
evt = events.Unknown(e.type)
170153
return evt
171154

172-
173155
def retcheck(retvalue):
174156
# Check the return value of an SDL function and raise an exception if it's not 0
175157
if retvalue:
@@ -395,6 +377,7 @@ def _rotation_helper(self, value):
395377
value (int): The new rotation value.
396378
"""
397379

380+
print("here")
398381
if (angle := (value % 360) - (self._rotation % 360)) != 0:
399382
if implementation.name == "cpython":
400383
tempBuffer = SDL_CreateTexture(

micropython/pydisplay/displaysys/displaysys-sdldisplay/displaysys/sdldisplay/_sdl2_lib/_constants.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@
7979
SDL_BUTTON_MMASK = const(1 << 1) # Middle mouse button
8080
SDL_BUTTON_RMASK = const(1 << 2) # Right mouse button
8181

82-
# Event constants
83-
SDL_PEEKEVENT = const(0x1)
84-
SDL_FIRSTEVENT = const(0x2)
85-
SDL_LASTEVENT = const(0x3)
8682

8783
###############################################################################
8884
# SDL2 Pixel Formats #

micropython/pydisplay/displaysys/displaysys-sdldisplay/displaysys/sdldisplay/_sdl2_lib/_cpython.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,6 @@ class Wheel(ctypes.Structure):
140140
_libSDL2.SDL_PollEvent.restype = ctypes.c_int
141141
SDL_PollEvent = _libSDL2.SDL_PollEvent
142142

143-
_libSDL2.SDL_PeepEvents.argtypes = [ctypes.POINTER(SDL_CommonEvent), ctypes.c_int, ctypes.c_int, ctypes.c_uint, ctypes.c_uint]
144-
_libSDL2.SDL_PeepEvents.restype = ctypes.c_int
145-
SDL_PeepEvents = _libSDL2.SDL_PeepEvents
146-
147-
_libSDL2.SDL_PumpEvents.argtypes = []
148-
_libSDL2.SDL_PumpEvents.restype = None
149-
SDL_PumpEvents = _libSDL2.SDL_PumpEvents
150-
151143
# SDL key functions
152144
_libSDL2.SDL_GetKeyName.argtypes = [ctypes.c_int]
153145
_libSDL2.SDL_GetKeyName.restype = ctypes.c_char_p

micropython/pydisplay/displaysys/displaysys-sdldisplay/displaysys/sdldisplay/_sdl2_lib/_micropython.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ def SDL_Point(x=0, y=0):
120120
SDL_Quit = _libSDL2.func("v", "SDL_Quit", "")
121121
SDL_GetError = _libSDL2.func("s", "SDL_GetError", "")
122122
SDL_PollEvent = _libSDL2.func("i", "SDL_PollEvent", "P")
123-
SDL_PeepEvents = _libSDL2.func("i", "SDL_PeepEvents", "Piiii")
124-
SDL_PumpEvents = _libSDL2.func("v", "SDL_PumpEvents", "")
125123

126124
# SDL key functions
127125
SDL_GetKeyName = _libSDL2.func("s", "SDL_GetKeyName", "i")

micropython/pydisplay/displaysys/displaysys-sdldisplay/examples/board_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Combination board configuration for desktop, pyscript and jupyter notebook platforms.
33
"""
44

5-
from displaysys.sdldisplay import SDLDisplay as DTDisplay, poll, peek
5+
from displaysys.sdldisplay import SDLDisplay as DTDisplay, poll
66
from eventsys import devices
77
import sys
88

@@ -25,7 +25,6 @@
2525
type=devices.types.QUEUE,
2626
read=poll,
2727
data=display_drv,
28-
read2=peek,
2928
# data2=events.filter,
3029
)
3130

micropython/pydisplay/displaysys/displaysys/displaysys/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ def __init__(self, auto_refresh=False):
118118
try:
119119
from multimer import get_timer
120120

121-
self._timer = get_timer(self.show)
121+
self._timer = get_timer(self.show, period=33)
122122
except ImportError:
123123
raise ImportError("timer is required for auto_refresh")
124124
else:
125125
self._timer = None
126126
self.init()
127127
gc.collect()
128-
print(f"{self.__class__.__name__} initialized.")
129-
print(f"{self.__class__.__name__} requires_byteswap = {self.requires_byteswap}")
128+
print(f"{self.__class__.__name__}: initialized.")
129+
print(f"{self.__class__.__name__}: requires_byteswap = {self.requires_byteswap}")
130130

131131
def __del__(self):
132132
self.deinit()
@@ -171,6 +171,7 @@ def rotation(self, value) -> None:
171171

172172
print(f"{self.__class__.__name__}.rotation(): Setting rotation to {value}")
173173
self._rotation_helper(value)
174+
print("done setting rotation")
174175

175176
self._rotation = value
176177

micropython/pydisplay/eventsys/eventsys/devices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def peek(self) -> bool:
439439
bool: True if there is an event in the queue that matches the filter in self._data, otherwise False.
440440
Note: self._data defaults to events.filter but may be set to a different list.
441441
"""
442-
return self._read2(self._data2)
442+
raise NotImplementedError("QueueDevice.peek() not implemented")
443443

444444

445445
class TouchDevice(Device):

0 commit comments

Comments
 (0)