repo: archive legacy pico dashboard
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
class Buzzer:
|
||||
def __init__(self, pin=None):
|
||||
self.pin = pin
|
||||
self.enabled = False
|
||||
self.pattern = None
|
||||
|
||||
def on(self):
|
||||
self.enabled = True
|
||||
if self.pin:
|
||||
self.pin.value(1)
|
||||
|
||||
def off(self):
|
||||
self.enabled = False
|
||||
self.pattern = None
|
||||
if self.pin:
|
||||
self.pin.value(0)
|
||||
|
||||
def set_pattern(self, pattern):
|
||||
self.pattern = pattern
|
||||
self.enabled = pattern is not None
|
||||
|
||||
def update_from_alarm_view(self, alarm_view):
|
||||
if alarm_view.should_buzz():
|
||||
self.set_pattern("critical")
|
||||
else:
|
||||
self.off()
|
||||
@@ -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 = []
|
||||
@@ -0,0 +1,21 @@
|
||||
class TouchEvent:
|
||||
def __init__(self, x, y, pressed=True):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.pressed = pressed
|
||||
|
||||
|
||||
class TouchController:
|
||||
def __init__(self, touch_device=None):
|
||||
self.touch_device = touch_device
|
||||
|
||||
def read_event(self):
|
||||
if not self.touch_device:
|
||||
return None
|
||||
|
||||
point = self.touch_device.read()
|
||||
|
||||
if not point:
|
||||
return None
|
||||
|
||||
return TouchEvent(point["x"], point["y"], point.get("pressed", True))
|
||||
Reference in New Issue
Block a user