color_bits_inverted: bool = False,
highlight_color: int = 0x000000,
refresh_display_command: Union[int, ReadableBuffer],
- refresh_time: float = 40.0,
+ refresh_time: float = 40,
busy_pin: Optional[microcontroller.Pin] = None,
busy_state: bool = True,
seconds_per_frame: float = 180,
if rotation % 90 != 0:
raise ValueError("Display rotation must be in 90 degree increments")
+ self._refreshing = False
color_depth = 1
core_grayscale = True
self._color_bits_inverted = color_bits_inverted
self._refresh_time_ms = refresh_time * 1000
self._busy_state = busy_state
- self._refreshing = False
self._milliseconds_per_frame = seconds_per_frame * 1000
self._chip_select = (
CHIP_SELECT_TOGGLE_EVERY_BYTE
self._start_sequence = start_sequence
self._start_up_time = start_up_time
self._stop_sequence = stop_sequence
- self._refesh_sequence = refresh_sequence
+ self._refresh_sequence = refresh_sequence
self._busy = None
self._two_byte_sequence_length = two_byte_sequence_length
if busy_pin is not None:
self._busy = DigitalInOut(busy_pin)
self._busy.switch_to_input()
+ self._ticks_disabled = False
+
# Clear the color memory if it isn't in use
if highlight_color == 0x00 and write_color_ram_command != NO_COMMAND:
"""TODO: Clear"""
def _refresh(self) -> bool:
if self._refreshing and self._busy is not None:
if self._busy.value != self._busy_state:
+ self._ticks_disabled = True
self._refreshing = False
self._send_command_sequence(False, self._stop_sequence)
else:
self._start_refresh()
for area in areas_to_refresh:
self._refresh_area(area)
- self._core.finish_refresh()
+ self._finish_refresh()
return True
"""Release the display and free its resources"""
if self._refreshing:
self._wait_for_busy()
+ self._ticks_disabled = True
self._refreshing = False
# Run stop sequence but don't wait for busy because busy is set when sleeping
self._send_command_sequence(False, self._stop_sequence)
def _background(self) -> None:
"""Run background refresh tasks."""
+
+ # Wait until initialized
+ if not hasattr(self, "_core"):
+ return
+
+ if self._ticks_disabled:
+ return
+
if self._refreshing:
refresh_done = False
if self._busy is not None:
time.monotonic() * 1000 - self._core.last_refresh
> self._refresh_time
)
+
if refresh_done:
+ self._ticks_disabled = True
self._refreshing = False
- self._finish_refresh()
# Run stop sequence but don't wait for busy because busy is set when sleeping
self._send_command_sequence(False, self._stop_sequence)
def _refresh_area(self, area: Area) -> bool:
"""Redraw the area."""
# pylint: disable=too-many-locals, too-many-branches
-
clipped = Area()
# Clip the area to the display by overlapping the areas.
# If there is no overlap then we're done.
self._core.send(
DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, bytes([command])
)
- self._core.send(
- DISPLAY_DATA,
- CHIP_SELECT_UNTOUCHED,
- data,
- )
+ if data_size > 0:
+ self._core.send(
+ DISPLAY_DATA,
+ CHIP_SELECT_UNTOUCHED,
+ bytes(data),
+ )
self._core.end_transaction()
delay_time_ms = 0
if delay:
def _finish_refresh(self) -> None:
# Actually refresh the display now that all pixel RAM has been updated
- self._send_command_sequence(False, self._refesh_sequence)
+ self._send_command_sequence(False, self._refresh_sequence)
+ self._ticks_disabled = False
self._refreshing = True
self._core.finish_refresh()
def _wait_for_busy(self) -> None:
if self._busy is not None:
- while self._busy.value != self._busy_state:
+ while self._busy.value == self._busy_state:
time.sleep(0.001)
def _clean_area(self) -> bool: