Skip to content

Commit 0de3c0c

Browse files
authored
Merge pull request #6 from makermelissa/master
Updated examples to work with smaller screen better
2 parents e2b8b20 + 89ec2b0 commit 0de3c0c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

examples/ra8875_bmptest.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
display.init()
2828
display.fill(WHITE)
2929

30+
def convert_555_to_565(rgb):
31+
return (rgb & 0x7FE0) << 1 | 0x20 | rgb & 0x001F
32+
3033
class BMP(object):
3134
def __init__(self, filename):
3235
self.filename = filename
@@ -35,7 +38,8 @@ def __init__(self, filename):
3538
self.data_size = 0
3639
self.bpp = 0
3740
self.width = 0
38-
self.height=0
41+
self.height = 0
42+
self.read_header()
3943

4044
def read_header(self):
4145
if self.colors:
@@ -54,7 +58,6 @@ def read_header(self):
5458
self.colors = int.from_bytes(f.read(4), 'little')
5559

5660
def draw(self, disp, x=0, y=0):
57-
self.read_header()
5861
print("{:d}x{:d} image".format(self.width, self.height))
5962
print("{:d}-bit encoding detected".format(self.bpp))
6063
line = 0
@@ -72,12 +75,15 @@ def draw(self, disp, x=0, y=0):
7275
if (line_size-i) < self.bpp//8:
7376
break
7477
if self.bpp == 16:
75-
color = line_data[i] << 8 | line_data[i+1]
76-
if self.bpp == 24:
77-
color = color565(line_data[i], line_data[i+1], line_data[i+2])
78+
color = convert_555_to_565(line_data[i] | line_data[i+1] << 8)
79+
if self.bpp == 24 or self.bpp == 32:
80+
color = color565(line_data[i+2], line_data[i+1], line_data[i])
7881
current_line_data = current_line_data + struct.pack(">H", color)
7982
disp.setxy(x, self.height - line + y)
8083
disp.push_pixels(current_line_data)
8184
disp.set_window(0, 0, disp.width, disp.height)
8285

83-
BMP("/ra8875_blinka.bmp").draw(display, 287, 127)
86+
bitmap = BMP("/ra8875_blinka.bmp")
87+
x_position = (display.width // 2) - (bitmap.width // 2)
88+
y_position = (display.height // 2) - (bitmap.height // 2)
89+
bitmap.draw(display, x_position, y_position)

examples/ra8875_simpletest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
display.curve(50, 100, 80, 40, 2, BLACK)
6060
display.fill_curve(50, 100, 78, 38, 2, WHITE)
6161

62-
display.txt_set_cursor(240, 240)
62+
display.txt_set_cursor(display.width // 2 - 200, display.height // 2 - 20)
63+
print(display.width)
64+
print(display.height)
6365
display.txt_trans(WHITE)
6466
display.txt_size(2)
6567
testvar = 99
@@ -77,7 +79,7 @@
7779
coords = display.touch_read()
7880
display.fill_circle(int(coords[0]/x_scale), int(coords[1]/y_scale), 4, MAGENTA)
7981
display.txt_color(WHITE, BLACK)
80-
display.txt_set_cursor(240, 240)
82+
display.txt_set_cursor(display.width // 2 - 220, display.height // 2 - 20)
8183
display.txt_size(2)
8284
display.txt_write("Position (" + str(int(coords[0]/x_scale)) + ", " +
8385
str(int(coords[1]/y_scale)) + ")")

0 commit comments

Comments
 (0)