kopia lustrzana https://github.com/micropython/micropython
drivers/display/lcd160cr: Fix get_line method and enhance screen_dump.
The docs are updated and describe the new behaviour of these methods.pull/3090/merge
rodzic
e4a53570d0
commit
f351c6db5e
|
@ -150,11 +150,19 @@ The following methods manipulate individual pixels on the display.
|
||||||
|
|
||||||
.. method:: LCD160CR.get_line(x, y, buf)
|
.. method:: LCD160CR.get_line(x, y, buf)
|
||||||
|
|
||||||
Get a line of pixels into the given buffer.
|
Low-level method to get a line of pixels into the given buffer.
|
||||||
|
To read `n` pixels `buf` should be `2*n+1` bytes in length. The first byte
|
||||||
|
is a dummy byte and should be ignored, and subsequent bytes represent the
|
||||||
|
pixels in the line starting at coordinate `(x, y)`.
|
||||||
|
|
||||||
.. method:: LCD160CR.screen_dump(buf)
|
.. method:: LCD160CR.screen_dump(buf, x=0, y=0, w=None, h=None)
|
||||||
|
|
||||||
Dump the entire screen to the given buffer.
|
Dump the contents of the screen to the given buffer. The parameters `x` and `y`
|
||||||
|
specify the starting coordinate, and `w` and `h` the size of the region. If `w`
|
||||||
|
or `h` are `None` then they will take on their maximum values, set by the size
|
||||||
|
of the screen minus the given `x` and `y` values. `buf` should be large enough
|
||||||
|
to hold `2*w*h` bytes. If it's smaller then only the initial horizontal lines
|
||||||
|
will be stored.
|
||||||
|
|
||||||
.. method:: LCD160CR.screen_load(buf)
|
.. method:: LCD160CR.screen_load(buf)
|
||||||
|
|
||||||
|
|
|
@ -257,6 +257,7 @@ class LCD160CR:
|
||||||
def get_line(self, x, y, buf):
|
def get_line(self, x, y, buf):
|
||||||
l = len(buf) // 2
|
l = len(buf) // 2
|
||||||
self._fcmd2b('<BBBBB', 0x10, l, x, y)
|
self._fcmd2b('<BBBBB', 0x10, l, x, y)
|
||||||
|
l *= 2
|
||||||
t = 1000
|
t = 1000
|
||||||
while t:
|
while t:
|
||||||
self.i2c.readfrom_into(self.i2c_addr, self.buf1)
|
self.i2c.readfrom_into(self.i2c_addr, self.buf1)
|
||||||
|
@ -267,21 +268,28 @@ class LCD160CR:
|
||||||
sleep_ms(1)
|
sleep_ms(1)
|
||||||
raise OSError(uerrno.ETIMEDOUT)
|
raise OSError(uerrno.ETIMEDOUT)
|
||||||
|
|
||||||
def screen_dump(self, buf):
|
def screen_dump(self, buf, x=0, y=0, w=None, h=None):
|
||||||
line = bytearray(self.w + 1)
|
if w is None:
|
||||||
h = len(buf) // (2 * self.w)
|
w = self.w - x
|
||||||
if h > self.h:
|
if h is None:
|
||||||
h = self.h
|
h = self.h - y
|
||||||
for i in range(h):
|
if w <= 127:
|
||||||
ix = i * self.w * 2
|
line = bytearray(2 * w + 1)
|
||||||
self.get_line(0, i, line)
|
line2 = None
|
||||||
for j in range(1, len(line)):
|
else:
|
||||||
buf[ix] = line[j]
|
# split line if more than 254 bytes needed
|
||||||
ix += 1
|
buflen = (w + 1) // 2
|
||||||
self.get_line(self.w // 2, i, line)
|
line = bytearray(2 * buflen + 1)
|
||||||
for j in range(1, len(line)):
|
line2 = memoryview(line)[:2 * (w - buflen) + 1]
|
||||||
buf[ix] = line[j]
|
for i in range(min(len(buf) // (2 * w), h)):
|
||||||
ix += 1
|
ix = i * w * 2
|
||||||
|
self.get_line(x, y + i, line)
|
||||||
|
buf[ix:ix + len(line) - 1] = memoryview(line)[1:]
|
||||||
|
ix += len(line) - 1
|
||||||
|
if line2:
|
||||||
|
self.get_line(x + buflen, y + i, line2)
|
||||||
|
buf[ix:ix + len(line2) - 1] = memoryview(line2)[1:]
|
||||||
|
ix += len(line2) - 1
|
||||||
|
|
||||||
def screen_load(self, buf):
|
def screen_load(self, buf):
|
||||||
l = self.w * self.h * 2+2
|
l = self.w * self.h * 2+2
|
||||||
|
|
Ładowanie…
Reference in New Issue