Skip to content

Commit 3581dd7

Browse files
committed
Use numpy for rev D
1 parent 49154d8 commit 3581dd7

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

library/lcd/lcd_comm_rev_d.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
# You should have received a copy of the GNU General Public License
1717
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1818

19-
import struct
2019
from enum import Enum
2120

2221
from serial.tools.list_ports import comports
2322

2423
from library.lcd.lcd_comm import *
24+
from library.lcd.serialize import image_to_RGB565, chunked
2525
from library.log import logger
2626

2727

@@ -175,31 +175,12 @@ def DisplayPILImage(
175175
# Prepare bitmap data transmission
176176
self.SendCommand(Command.INTOPICMODE)
177177

178-
pix = image.load()
179-
line = bytes([80])
178+
rgb565be = image_to_RGB565(image, "big")
180179

181180
# Lock queue mutex then queue all the requests for the image data
182181
with self.update_queue_mutex:
183-
for h in range(image_height):
184-
for w in range(image_width):
185-
R = pix[w, h][0] >> 3
186-
G = pix[w, h][1] >> 2
187-
B = pix[w, h][2] >> 3
188-
189-
# Color information is 0bRRRRRGGGGGGBBBBB
190-
# Revision A: Encode in Little-Endian (native x86/ARM encoding)
191-
# Revition B: Encode in Big-Endian
192-
rgb = (R << 11) | (G << 5) | B
193-
line += struct.pack('>H', rgb)
194-
195-
# Send image data by multiple of 64 bytes + 1 command byte
196-
if len(line) >= 65:
197-
self.SendLine(line[0:64])
198-
line = bytes([80]) + line[64:]
199-
200-
# Write last line if needed
201-
if len(line) > 0:
202-
self.SendLine(line)
182+
for chunk in chunked(rgb565be, 63):
183+
self.SendLine(b"\x50" + chunk)
203184

204185
# Indicate the complete bitmap has been transmitted
205186
self.SendCommand(Command.OUTPICMODE)

0 commit comments

Comments
 (0)