ink. Schalter ON/OFF/ON
This commit is contained in:
parent
e7e857d019
commit
ac75294295
1 changed files with 137 additions and 23 deletions
160
down.py
160
down.py
|
|
@ -9,6 +9,23 @@ import urllib.request
|
|||
|
||||
from zoneinfo import ZoneInfo
|
||||
from influxdb_client import InfluxDBClient
|
||||
from gpiozero import Button
|
||||
|
||||
# -------------------------------------------------
|
||||
# GPIO Schalter
|
||||
# -------------------------------------------------
|
||||
|
||||
SWITCH1 = Button(
|
||||
5,
|
||||
pull_up=True,
|
||||
bounce_time=0.1
|
||||
)
|
||||
|
||||
SWITCH2 = Button(
|
||||
21,
|
||||
pull_up=True,
|
||||
bounce_time=0.1
|
||||
)
|
||||
|
||||
# -------------------------------------------------
|
||||
# InfluxDB V2
|
||||
|
|
@ -347,8 +364,6 @@ def draw_graph(draw, values, x, y, w, h):
|
|||
if max_val <= 0:
|
||||
return
|
||||
|
||||
# Dezente Hilfslinien
|
||||
|
||||
draw.line(
|
||||
(x, y + h // 2, x + w, y + h // 2),
|
||||
fill=(40, 40, 40)
|
||||
|
|
@ -372,10 +387,10 @@ def draw_graph(draw, values, x, y, w, h):
|
|||
draw.line(points, fill="green", width=2)
|
||||
|
||||
# -------------------------------------------------
|
||||
# UI zeichnen
|
||||
# Dashboard 1
|
||||
# -------------------------------------------------
|
||||
|
||||
def draw_ui():
|
||||
def draw_dashboard_1():
|
||||
|
||||
down, up, down_prev, up_prev, ts = get_speedtest()
|
||||
|
||||
|
|
@ -435,23 +450,12 @@ def draw_ui():
|
|||
font=font_small_bold
|
||||
)
|
||||
|
||||
if ping >= 0:
|
||||
|
||||
draw.text(
|
||||
(10, 55),
|
||||
f"PING: {ping:.1f} ms",
|
||||
fill=ping_color,
|
||||
font=font_small_bold
|
||||
)
|
||||
|
||||
else:
|
||||
|
||||
draw.text(
|
||||
(10, 55),
|
||||
"PING: FEHLER",
|
||||
fill="red",
|
||||
font=font_small_bold
|
||||
)
|
||||
draw.text(
|
||||
(10, 55),
|
||||
f"PING: {ping:.1f} ms",
|
||||
fill=ping_color,
|
||||
font=font_small_bold
|
||||
)
|
||||
|
||||
draw.line(
|
||||
(10, 80, WIDTH - 10, 80),
|
||||
|
|
@ -538,6 +542,103 @@ def draw_ui():
|
|||
|
||||
return img
|
||||
|
||||
# -------------------------------------------------
|
||||
# Dashboard 2
|
||||
# -------------------------------------------------
|
||||
|
||||
def draw_dashboard_2():
|
||||
|
||||
img = Image.new("RGB", (WIDTH, HEIGHT), "black")
|
||||
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
draw.text(
|
||||
(20, 20),
|
||||
"SYSTEMSTATUS",
|
||||
fill="white",
|
||||
font=font_title
|
||||
)
|
||||
|
||||
draw.line(
|
||||
(20, 60, WIDTH - 20, 60),
|
||||
fill="white"
|
||||
)
|
||||
|
||||
draw.text(
|
||||
(20, 100),
|
||||
f"WLAN: {get_ip()}",
|
||||
fill="cyan",
|
||||
font=font_small
|
||||
)
|
||||
|
||||
draw.text(
|
||||
(20, 130),
|
||||
f"WAN: {get_wan_ip()}",
|
||||
fill="orange",
|
||||
font=font_small
|
||||
)
|
||||
|
||||
draw.text(
|
||||
(20, 190),
|
||||
time.strftime("%d.%m.%Y"),
|
||||
fill="white",
|
||||
font=font_small_bold
|
||||
)
|
||||
|
||||
draw.text(
|
||||
(20, 220),
|
||||
time.strftime("%H:%M:%S"),
|
||||
fill="green",
|
||||
font=font_download
|
||||
)
|
||||
|
||||
return img
|
||||
|
||||
# -------------------------------------------------
|
||||
# Dashboard 3
|
||||
# -------------------------------------------------
|
||||
|
||||
def draw_dashboard_3():
|
||||
|
||||
img = Image.new("RGB", (WIDTH, HEIGHT), "black")
|
||||
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
draw.text(
|
||||
(20, 20),
|
||||
"DASHBOARD 3",
|
||||
fill="white",
|
||||
font=font_title
|
||||
)
|
||||
|
||||
draw.line(
|
||||
(20, 60, WIDTH - 20, 60),
|
||||
fill="white"
|
||||
)
|
||||
|
||||
draw.text(
|
||||
(20, 100),
|
||||
"Bereit fuer weitere",
|
||||
fill="green",
|
||||
font=font_small
|
||||
)
|
||||
|
||||
draw.text(
|
||||
(20, 130),
|
||||
"Informationen",
|
||||
fill="green",
|
||||
font=font_small
|
||||
)
|
||||
|
||||
draw.text(
|
||||
(20, 200),
|
||||
"GPIO21 aktiv",
|
||||
fill="orange",
|
||||
font=font_small_bold
|
||||
)
|
||||
|
||||
return img
|
||||
|
||||
# -------------------------------------------------
|
||||
# Framebuffer schreiben
|
||||
# -------------------------------------------------
|
||||
|
|
@ -566,7 +667,20 @@ while True:
|
|||
|
||||
try:
|
||||
|
||||
img = draw_ui()
|
||||
# Dashboard 3
|
||||
if SWITCH2.is_pressed:
|
||||
|
||||
img = draw_dashboard_3()
|
||||
|
||||
# Dashboard 2
|
||||
elif SWITCH1.is_pressed:
|
||||
|
||||
img = draw_dashboard_2()
|
||||
|
||||
# Dashboard 1
|
||||
else:
|
||||
|
||||
img = draw_dashboard_1()
|
||||
|
||||
write_fb(img)
|
||||
|
||||
|
|
@ -574,4 +688,4 @@ while True:
|
|||
|
||||
print(traceback.format_exc())
|
||||
|
||||
time.sleep(60)
|
||||
time.sleep(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue