Skip to content

Commit 66d2cc3

Browse files
committed
Fix the LCD example
1 parent b02ff65 commit 66d2cc3

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

examples/mcu/stm32f411_i2c_lcd.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,32 @@ def render(self):
8080
print('LCD quit')
8181
pygame.quit()
8282

83-
def send(self, data):
84-
self.buf.append(data)
85-
86-
if len(self.buf) == 4:
87-
up = self.buf[0] & 0xf0
88-
lo = self.buf[3] & 0xf0
89-
cmd = up | (lo >> 4)
90-
91-
if self.buf[0] & 0x1:
92-
if self.cur_col < 16 and self.cur_row < 2:
93-
self.data[self.cur_row][self.cur_col] = cmd
94-
self.cur_col += 1
95-
self.pixels = LCD.make_screen(self.data)
96-
97-
elif cmd == 0x1:
98-
self.data = [[ord(' ') for _ in range(self.cols)] for _ in range(self.rows)]
99-
self.pixels = LCD.make_screen(self.data)
100-
101-
elif up == 0x80:
102-
self.cur_row, self.cur_col = 0, lo >> 4
103-
104-
elif up == 0xc0:
105-
self.cur_row, self.cur_col = 1, lo >> 4
106-
107-
self.buf = []
83+
def send(self, buf):
84+
for data in buf:
85+
self.buf.append(data)
86+
87+
if len(self.buf) == 4:
88+
up = self.buf[0] & 0xf0
89+
lo = self.buf[3] & 0xf0
90+
cmd = up | (lo >> 4)
91+
92+
if self.buf[0] & 0x1:
93+
if self.cur_col < 16 and self.cur_row < 2:
94+
self.data[self.cur_row][self.cur_col] = cmd
95+
self.cur_col += 1
96+
self.pixels = LCD.make_screen(self.data)
97+
98+
elif cmd == 0x1:
99+
self.data = [[ord(' ') for _ in range(self.cols)] for _ in range(self.rows)]
100+
self.pixels = LCD.make_screen(self.data)
101+
102+
elif up == 0x80:
103+
self.cur_row, self.cur_col = 0, lo >> 4
104+
105+
elif up == 0xc0:
106+
self.cur_row, self.cur_col = 1, lo >> 4
107+
108+
self.buf = []
108109

109110
def run(self):
110111
threading.Thread(target=self.render).start()

0 commit comments

Comments
 (0)