def _refresh_area(self, area) -> bool:
"""Loop through dirty areas and redraw that area."""
- # pylint: disable=too-many-locals
+ # pylint: disable=too-many-locals, too-many-branches
clipped = Area()
# Clip the area to the display by overlapping the areas.
buffer = memoryview(bytearray([0] * (buffer_size * 4)))
mask = memoryview(bytearray([0] * mask_length))
self._core.fill_area(subrectangle, mask, buffer)
+
+ # Can't acquire display bus; skip the rest of the data.
+ if not self._core.bus_free():
+ return False
+
self._core.begin_transaction()
self._send_pixels(buffer[:subrectangle_size_bytes])
self._core.end_transaction()
if bus:
if isinstance(bus, (FourWire, I2CDisplay, ParallelBus)):
self._bus_reset = bus.reset
+ self._bus_free = bus._free
self._begin_transaction = bus._begin_transaction
self._send = bus._send
self._end_transaction = bus._end_transaction
"""
Send the data to the current bus
"""
- print(len(data))
- if isinstance(data, memoryview):
- data = data.tobytes()
- print(data)
self._send(data_type, chip_select, data)
+ def bus_free(self) -> bool:
+ """
+ Check if the bus is free
+ """
+ return self._bus_free()
+
def begin_transaction(self) -> bool:
"""
Begin Bus Transaction
else:
self._spi.write(data)
+ def _free(self) -> bool:
+ """Attempt to free the bus and return False if busy"""
+ if not self._spi.try_lock():
+ return False
+ self._spi.unlock()
+ return True
+
def _begin_transaction(self) -> bool:
"""Begin the SPI transaction by locking, configuring, and setting Chip Select"""
if not self._spi.try_lock():
time.sleep(0.0001)
self._reset.value = True
- def _begin_transaction(self) -> bool:
- """Lock the bus before sending data."""
- return self._i2c.try_lock()
-
def send(self, command: int, data: ReadableBuffer) -> None:
"""
Sends the given command value followed by the full set of data. Display state,
) from error
raise error
+ def _free(self) -> bool:
+ """Attempt to free the bus and return False if busy"""
+ if not self._i2c.try_lock():
+ return False
+ self._i2c.unlock()
+ return True
+
+ def _begin_transaction(self) -> bool:
+ """Lock the bus before sending data."""
+ return self._i2c.try_lock()
+
def _end_transaction(self) -> None:
"""Release the bus after sending data."""
self._i2c.unlock()
) -> None:
pass
+ def _free(self) -> bool:
+ """Attempt to free the bus and return False if busy"""
+
def _begin_transaction(self) -> bool:
- # pylint: disable=no-self-use
- return True
+ pass
def _end_transaction(self) -> None:
pass