allow args. README.
This commit is contained in:
parent
529262ea4d
commit
f10caa3918
7 changed files with 71 additions and 16 deletions
11
README.md
11
README.md
|
|
@ -137,3 +137,14 @@ Ist das Geflacker dann weg?
|
||||||
- gpio-slowdown auf 4
|
- gpio-slowdown auf 4
|
||||||
- nach dem stop (ctrl-c) und start 10 sekunden warten
|
- nach dem stop (ctrl-c) und start 10 sekunden warten
|
||||||
- mit "gunicorn -w 1 -k gthread main:app" laufen lassen
|
- mit "gunicorn -w 1 -k gthread main:app" laufen lassen
|
||||||
|
|
||||||
|
# Szenen
|
||||||
|
|
||||||
|
curl "http://localhost:8000/start/color?red=255&green=255&blue=255"
|
||||||
|
curl http://localhost:8000/start/bitcoin
|
||||||
|
curl http://localhost:8000/start/clock
|
||||||
|
curl http://localhost:8000/start/colorclock
|
||||||
|
curl http://localhost:8000/start/helloworld
|
||||||
|
curl http://localhost:8000/stop
|
||||||
|
curl http://localhost:8000/reset
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,10 @@ class MyMatrix:
|
||||||
#self.matrix_height = options.rows
|
#self.matrix_height = options.rows
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf", 18)
|
#self.font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf", 18)
|
||||||
self.large_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf", 32)
|
self.font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 18)
|
||||||
|
self.large_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 32)
|
||||||
|
#self.large_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight.ttf", 32)
|
||||||
except IOError:
|
except IOError:
|
||||||
self.font = ImageFont.load_default()
|
self.font = ImageFont.load_default()
|
||||||
self.large_font = ImageFont.load_default()
|
self.large_font = ImageFont.load_default()
|
||||||
|
|
|
||||||
11
main.py
11
main.py
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from flask import Flask, jsonify
|
from flask import Flask, jsonify, request
|
||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import importlib
|
import importlib
|
||||||
|
|
@ -38,7 +38,7 @@ def run_animation(name):
|
||||||
print(f"Animation {name} stopped")
|
print(f"Animation {name} stopped")
|
||||||
|
|
||||||
# Utility to start a new animation
|
# Utility to start a new animation
|
||||||
def start_animation(scene_name):
|
def start_animation(scene_name, args):
|
||||||
global animation_thread, stop_event
|
global animation_thread, stop_event
|
||||||
if scene_name not in scenes:
|
if scene_name not in scenes:
|
||||||
print(f"Scene '{scene_name}' not found!")
|
print(f"Scene '{scene_name}' not found!")
|
||||||
|
|
@ -51,12 +51,12 @@ def start_animation(scene_name):
|
||||||
|
|
||||||
# Reset stop event and start new thread
|
# Reset stop event and start new thread
|
||||||
stop_event.clear()
|
stop_event.clear()
|
||||||
animation_thread = Thread(target=scenes[scene_name].start, args=(stop_event,), daemon=True)
|
animation_thread = Thread(target=scenes[scene_name].start, args=(stop_event, args), daemon=True)
|
||||||
animation_thread.start()
|
animation_thread.start()
|
||||||
|
|
||||||
@app.route("/start/<animation_name>")
|
@app.route("/start/<animation_name>")
|
||||||
def start(animation_name):
|
def start(animation_name):
|
||||||
start_animation(animation_name)
|
start_animation(animation_name, args=request.args)
|
||||||
return jsonify({"status": "started", "animation": animation_name})
|
return jsonify({"status": "started", "animation": animation_name})
|
||||||
|
|
||||||
@app.route("/reset")
|
@app.route("/reset")
|
||||||
|
|
@ -66,10 +66,13 @@ def reset():
|
||||||
|
|
||||||
@app.route("/stop")
|
@app.route("/stop")
|
||||||
def stop():
|
def stop():
|
||||||
|
# Stop running thread
|
||||||
global animation_thread, stop_event
|
global animation_thread, stop_event
|
||||||
if animation_thread and animation_thread.is_alive():
|
if animation_thread and animation_thread.is_alive():
|
||||||
stop_event.set()
|
stop_event.set()
|
||||||
animation_thread.join()
|
animation_thread.join()
|
||||||
|
# Clear the display
|
||||||
|
lib.display.matrix.matrix.Clear()
|
||||||
return jsonify({"status": "stopped"})
|
return jsonify({"status": "stopped"})
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
from lib import display
|
import lib.display
|
||||||
|
|
||||||
# Replace with your free Finnhub API key
|
# Replace with your free Finnhub API key
|
||||||
API_KEY = "d3t8099r01qigeg1s7cgd3t8099r01qigeg1s7d0"
|
API_KEY = "d3t8099r01qigeg1s7cgd3t8099r01qigeg1s7d0"
|
||||||
|
|
@ -12,14 +12,18 @@ finnhub_client = finnhub.Client(api_key="d3t8099r01qigeg1s7cgd3t8099r01qigeg1s7d
|
||||||
def get_bitcoin_price():
|
def get_bitcoin_price():
|
||||||
symbol = "BINANCE:BTCEUR"
|
symbol = "BINANCE:BTCEUR"
|
||||||
data = finnhub_client.quote(symbol)
|
data = finnhub_client.quote(symbol)
|
||||||
|
#print("getting finnhub")
|
||||||
return data['c']
|
return data['c']
|
||||||
|
|
||||||
def start(image_buffer, stop_event, text="Hello World!"):
|
def start(stop_event, args):
|
||||||
last_price = None
|
last_price = None
|
||||||
trend = None
|
trend = None
|
||||||
while not stop_event.is_set():
|
image_buffer = lib.display.matrix.buffer()
|
||||||
image_buffer = Image.new("RGB", (128, 64))
|
|
||||||
draw = ImageDraw.Draw(image_buffer)
|
draw = ImageDraw.Draw(image_buffer)
|
||||||
|
symbol = '⏶'
|
||||||
|
while not stop_event.is_set():
|
||||||
|
# All to black
|
||||||
|
draw.rectangle( ((0,0),(lib.display.matrix.width-1,lib.display.matrix.height-1)), fill=(0,0,0) )
|
||||||
|
|
||||||
price = get_bitcoin_price()
|
price = get_bitcoin_price()
|
||||||
|
|
||||||
|
|
@ -27,16 +31,19 @@ def start(image_buffer, stop_event, text="Hello World!"):
|
||||||
if last_price:
|
if last_price:
|
||||||
if price > last_price:
|
if price > last_price:
|
||||||
trend = 1
|
trend = 1
|
||||||
|
symbol = "🡅"
|
||||||
elif price < last_price:
|
elif price < last_price:
|
||||||
trend = -1
|
trend = -1
|
||||||
|
symbol = "🡇"
|
||||||
|
|
||||||
display.triangle(draw, 0, 0, trend, width=16, height=32)
|
#display.triangle(draw, 0, 0, trend, width=16, height=32)
|
||||||
|
print(symbol)
|
||||||
|
|
||||||
text = f"BTC: {price:.0f}€"
|
text = f"{symbol} BTC: {price:.0f}€"
|
||||||
|
|
||||||
draw.text((20, 0), text, fill=(255, 255, 255), font=display.font)
|
draw.text((20, 0), text, fill=(255, 255, 255), font=lib.display.matrix.large_font)
|
||||||
|
|
||||||
display.do(image_buffer)
|
lib.display.matrix.show(image_buffer)
|
||||||
|
|
||||||
last_price = price
|
last_price = price
|
||||||
# Alle 10 Sekunden einen neuen Kurs holen. Jede Sekunde auf "stop" horchen.
|
# Alle 10 Sekunden einen neuen Kurs holen. Jede Sekunde auf "stop" horchen.
|
||||||
|
|
@ -45,3 +52,4 @@ def start(image_buffer, stop_event, text="Hello World!"):
|
||||||
return
|
return
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import datetime
|
||||||
import locale
|
import locale
|
||||||
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
|
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
|
||||||
|
|
||||||
def start(stop_event, text="Hello World!"):
|
def start(stop_event, args):
|
||||||
image_buffer = lib.display.matrix.buffer()
|
image_buffer = lib.display.matrix.buffer()
|
||||||
draw = ImageDraw.Draw(image_buffer)
|
draw = ImageDraw.Draw(image_buffer)
|
||||||
while not stop_event.is_set():
|
while not stop_event.is_set():
|
||||||
|
|
|
||||||
31
scenes/color.py
Normal file
31
scenes/color.py
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import io
|
||||||
|
from time import sleep
|
||||||
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
import lib.display
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
import locale
|
||||||
|
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
|
||||||
|
|
||||||
|
def start(stop_event, args):
|
||||||
|
image_buffer = lib.display.matrix.buffer()
|
||||||
|
draw = ImageDraw.Draw(image_buffer)
|
||||||
|
|
||||||
|
#print(int(args.get('red', 0)))
|
||||||
|
|
||||||
|
# All to color
|
||||||
|
draw.rectangle(
|
||||||
|
( (0,0), (lib.display.matrix.width-1,lib.display.matrix.height-1) ),
|
||||||
|
fill=(
|
||||||
|
int(args.get('red', 0)),
|
||||||
|
int(args.get('green', 0)),
|
||||||
|
int(args.get('blue', 0))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
lib.display.matrix.show(image_buffer)
|
||||||
|
|
||||||
|
while not stop_event.is_set():
|
||||||
|
sleep(0.5)
|
||||||
|
|
||||||
|
|
@ -9,7 +9,7 @@ import datetime
|
||||||
import locale
|
import locale
|
||||||
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
|
locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
|
||||||
|
|
||||||
def start(stop_event, text="Hello World!"):
|
def start(stop_event, args):
|
||||||
while not stop_event.is_set():
|
while not stop_event.is_set():
|
||||||
image_buffer = lib.display.matrix.buffer()
|
image_buffer = lib.display.matrix.buffer()
|
||||||
draw = ImageDraw.Draw(image_buffer)
|
draw = ImageDraw.Draw(image_buffer)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue