Skip to content

Updated examples to work with smaller screen better #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions examples/ra8875_bmptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
display.init()
display.fill(WHITE)

def convert_555_to_565(rgb):
return (rgb & 0x7FE0) << 1 | 0x20 | rgb & 0x001F

class BMP(object):
def __init__(self, filename):
self.filename = filename
Expand All @@ -35,7 +38,8 @@ def __init__(self, filename):
self.data_size = 0
self.bpp = 0
self.width = 0
self.height=0
self.height = 0
self.read_header()

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

def draw(self, disp, x=0, y=0):
self.read_header()
print("{:d}x{:d} image".format(self.width, self.height))
print("{:d}-bit encoding detected".format(self.bpp))
line = 0
Expand All @@ -72,12 +75,15 @@ def draw(self, disp, x=0, y=0):
if (line_size-i) < self.bpp//8:
break
if self.bpp == 16:
color = line_data[i] << 8 | line_data[i+1]
if self.bpp == 24:
color = color565(line_data[i], line_data[i+1], line_data[i+2])
color = convert_555_to_565(line_data[i] | line_data[i+1] << 8)
if self.bpp == 24 or self.bpp == 32:
color = color565(line_data[i+2], line_data[i+1], line_data[i])
current_line_data = current_line_data + struct.pack(">H", color)
disp.setxy(x, self.height - line + y)
disp.push_pixels(current_line_data)
disp.set_window(0, 0, disp.width, disp.height)

BMP("/ra8875_blinka.bmp").draw(display, 287, 127)
bitmap = BMP("/ra8875_blinka.bmp")
x_position = (display.width // 2) - (bitmap.width // 2)
y_position = (display.height // 2) - (bitmap.height // 2)
bitmap.draw(display, x_position, y_position)
6 changes: 4 additions & 2 deletions examples/ra8875_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
display.curve(50, 100, 80, 40, 2, BLACK)
display.fill_curve(50, 100, 78, 38, 2, WHITE)

display.txt_set_cursor(240, 240)
display.txt_set_cursor(display.width // 2 - 200, display.height // 2 - 20)
print(display.width)
print(display.height)
display.txt_trans(WHITE)
display.txt_size(2)
testvar = 99
Expand All @@ -77,7 +79,7 @@
coords = display.touch_read()
display.fill_circle(int(coords[0]/x_scale), int(coords[1]/y_scale), 4, MAGENTA)
display.txt_color(WHITE, BLACK)
display.txt_set_cursor(240, 240)
display.txt_set_cursor(display.width // 2 - 220, display.height // 2 - 20)
display.txt_size(2)
display.txt_write("Position (" + str(int(coords[0]/x_scale)) + ", " +
str(int(coords[1]/y_scale)) + ")")