use bytes and memoryview

pull/70/head
surdouski 2024-08-06 11:51:44 -04:00
rodzic 28486ef3f6
commit ce9bfc6009
1 zmienionych plików z 18 dodań i 45 usunięć

Wyświetl plik

@ -61,43 +61,17 @@ _DARK_GREY = 0x80 # gray
_BLACK = 0x00 # Blackest
# Pulled from demo code in the waveshare link at the top
_LUT = [
b"\x01", b"\x0A", b"\x1B", b"\x0F", b"\x03", b"\x01", b"\x01",
b"\x05", b"\x0A", b"\x01", b"\x0A", b"\x01", b"\x01", b"\x01",
b"\x05", b"\x08", b"\x03", b"\x02", b"\x04", b"\x01", b"\x01",
b"\x01", b"\x04", b"\x04", b"\x02", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x0A", b"\x1B", b"\x0F", b"\x03", b"\x01", b"\x01",
b"\x05", b"\x4A", b"\x01", b"\x8A", b"\x01", b"\x01", b"\x01",
b"\x05", b"\x48", b"\x03", b"\x82", b"\x84", b"\x01", b"\x01",
b"\x01", b"\x84", b"\x84", b"\x82", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x0A", b"\x1B", b"\x8F", b"\x03", b"\x01", b"\x01",
b"\x05", b"\x4A", b"\x01", b"\x8A", b"\x01", b"\x01", b"\x01",
b"\x05", b"\x48", b"\x83", b"\x82", b"\x04", b"\x01", b"\x01",
b"\x01", b"\x04", b"\x04", b"\x02", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x8A", b"\x1B", b"\x8F", b"\x03", b"\x01", b"\x01",
b"\x05", b"\x4A", b"\x01", b"\x8A", b"\x01", b"\x01", b"\x01",
b"\x05", b"\x48", b"\x83", b"\x02", b"\x04", b"\x01", b"\x01",
b"\x01", b"\x04", b"\x04", b"\x02", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x8A", b"\x9B", b"\x8F", b"\x03", b"\x01", b"\x01",
b"\x05", b"\x4A", b"\x01", b"\x8A", b"\x01", b"\x01", b"\x01",
b"\x05", b"\x48", b"\x03", b"\x42", b"\x04", b"\x01", b"\x01",
b"\x01", b"\x04", b"\x04", b"\x42", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x01", b"\x00", b"\x00", b"\x00", b"\x00", b"\x01", b"\x01",
b"\x00", b"\x00", b"\x00", b"\x00", b"\x00", b"\x00", b"\x00",
b"\x00", b"\x00", b"\x00", b"\x00", b"\x00", b"\x00", b"\x00",
b"\x02", b"\x00", b"\x00", b"\x07", b"\x17", b"\x41", b"\xA8",
b"\x32", b"\x30"
]
_LUT = b"\x01\n\x1b\x0f\x03\x01\x01\x05\n\x01\n\x01\x01\x01\x05\x08\x03\x02\x04\x01\x01\
\x01\x04\x04\x02\x00\x01\x01\x01\x00\x00\x00\x00\x01\x01\x01\x00\x00\x00\x00\x01\x01\x01\
\n\x1b\x0f\x03\x01\x01\x05J\x01\x8a\x01\x01\x01\x05H\x03\x82\x84\x01\x01\x01\x84\x84\x82\
\x00\x01\x01\x01\x00\x00\x00\x00\x01\x01\x01\x00\x00\x00\x00\x01\x01\x01\n\x1b\x8f\x03\
\x01\x01\x05J\x01\x8a\x01\x01\x01\x05H\x83\x82\x04\x01\x01\x01\x04\x04\x02\x00\x01\x01\
\x01\x00\x00\x00\x00\x01\x01\x01\x00\x00\x00\x00\x01\x01\x01\x8a\x1b\x8f\x03\x01\x01\x05J\
\x01\x8a\x01\x01\x01\x05H\x83\x02\x04\x01\x01\x01\x04\x04\x02\x00\x01\x01\x01\x00\x00\x00\
\x00\x01\x01\x01\x00\x00\x00\x00\x01\x01\x01\x8a\x9b\x8f\x03\x01\x01\x05J\x01\x8a\x01\x01\
\x01\x05H\x03B\x04\x01\x01\x01\x04\x04B\x00\x01\x01\x01\x00\x00\x00\x00\x01\x01\x01\x00\
\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\
\x07\x17A\xa820"
# Framebuf mapping is pixel 0 is in LS 2 bits
@ -220,23 +194,22 @@ class EPD(framebuf.FrameBuffer):
self.wait_until_ready()
def set_grey(self):
lut_mv = memoryview(_LUT)
self._command(b"\x32")
for i in range(0, 227):
self._data(_LUT[i])
self._data(bytes(lut_mv[0:227]))
self._command(b"\x3F")
self._data(_LUT[227])
self._data(bytes(lut_mv[227:228]))
self._command(b"\x03")
self._data(_LUT[228])
self._data(bytes(lut_mv[228:229]))
self._command(b"\x04")
self._data(_LUT[229])
self._data(_LUT[230])
self._data(_LUT[231])
self._data(bytes(lut_mv[229:232]))
self._command(b"\x2C")
self._data(_LUT[232])
self._data(bytes(lut_mv[232:233]))
def wait_until_ready(self):
while not self.ready():