Add Pico display rendering abstraction
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
class Display:
|
||||
def __init__(self, driver=None):
|
||||
self.driver = driver
|
||||
self.commands = []
|
||||
|
||||
def clear(self):
|
||||
self.commands.append(("clear",))
|
||||
|
||||
def text(self, x, y, value, size=1):
|
||||
self.commands.append(("text", x, y, str(value), size))
|
||||
|
||||
def rect(self, x, y, w, h, filled=False):
|
||||
self.commands.append(("rect", x, y, w, h, filled))
|
||||
|
||||
def flush(self):
|
||||
if not self.driver:
|
||||
return
|
||||
|
||||
for command in self.commands:
|
||||
name = command[0]
|
||||
|
||||
if name == "clear":
|
||||
self.driver.clear()
|
||||
elif name == "text":
|
||||
_, x, y, value, size = command
|
||||
self.driver.text(x, y, value, size)
|
||||
elif name == "rect":
|
||||
_, x, y, w, h, filled = command
|
||||
self.driver.rect(x, y, w, h, filled)
|
||||
|
||||
self.commands = []
|
||||
|
||||
Reference in New Issue
Block a user