Initial commit

This commit is contained in:
deckensteuerung 2018-08-19 20:47:08 +02:00
commit bd84098ff4
4 changed files with 156 additions and 0 deletions

61
apps/idle.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python3
import sys
import os
import numpy as np
Nx = int(sys.argv[1])
Ny = int(sys.argv[2])
param = sys.argv[3]
buffer = bytearray(b" "*(3*Nx*Ny))
Lx = 32 #128 #Physikalische Laenge des Gebietes in x-Richtung
Ly =32 #128#Physikalische Laenge des Gebietes in y-Richtung
x, y = np.meshgrid(np.arange(Nx)* Lx/Nx, np.arange(Ny)* Ly/Ny) #x-Array
kx, ky = np.meshgrid(np.fft.fftfreq(Nx,Lx/(Nx*2.0*np.pi)), np.fft.fftfreq(Ny,Ly/(Ny*2.0*np.pi)))
ksq = kx*kx + ky*ky
c = 0.0+(np.random.random((Ny,Nx))-0.5)*0.1
#eps=0.3
#delta=0.0
eps = 0.1
delta = 1.0
t = 0.0
dt = 0.01
T_End = 300000
N_t = int(T_End / dt)
plotEveryNth = 100
ck = np.fft.fft2(c) #FFT(c)
# Lineare Terme
def rhs_lin(ksq):
result=eps-(1.0-ksq)**2
return result
Eu=1.0/(1.0-dt*rhs_lin(ksq))
i = 0
def lerp_sat(a, t, b):
v = (1-t)*a+t*b
v = int(v)
if v < 0:
v = 0
if v > 255:
v = 255
return v
while True:
i+= 1
ck=Eu*(ck+dt*(delta*np.fft.fft2(np.fft.ifft2(ck)**2)-np.fft.fft2(np.fft.ifft2(ck)**3)))
c=np.fft.ifft2(ck)
if(i % plotEveryNth == 0):
myc = c.real
myc = (myc-np.min(myc))/(np.max(myc)-np.min(myc))
for px in range(Nx):
for py in range(Ny):
idx = 3*(px+Nx*py)
buffer[idx+0] = lerp_sat(0xff, myc[py,px], 0x00)
buffer[idx+1] = lerp_sat(0x00, myc[py,px], 0xff)
buffer[idx+2] = 0
os.write(1, buffer)

2
apps/play_youtube.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
youtube-dl --no-progress --output - https://www.youtube.com/watch?v=${3} -f best | ffmpeg -re -i - -pix_fmt rgb24 -vf "transpose=1,scale=${1}x${2}" -sws_flags bicubic -sws_dither bayer -vcodec rawvideo -f image2pipe -

12
config.py Normal file
View File

@ -0,0 +1,12 @@
#width
ScreenX = 24
#height
ScreenY = 40
# first app is always running in IDLE
Apps = [
{"name": "pixelflut", "cmd": "apps/idle.py", "permanent": True},
{"name": "framebuffer", "cmd": "apps/framebuffercp"},
{"name": "play_youtube", "cmd": "apps/play_youtube.sh"}
]

81
main.py Normal file
View File

@ -0,0 +1,81 @@
import config
import subprocess
import os
import serial
import threading
import json
from bottle import route, run
class AppRunner(threading.Thread):
def __init__(self):
super().__init__()
self.currentApp = -1
self.requestedApp = 0
self.app = None
self.lock = threading.Lock()
self.param = ""
def requestApp(self, app, param=""):
with self.lock:
self.requestedApp = app
self.param = param
def updateApp(self):
if self.app != None:
self.app.terminate()
args = [os.getcwd()+"/"+config.Apps[self.requestedApp]["cmd"], str(config.ScreenX), str(config.ScreenY), self.param]
self.app = subprocess.Popen(args, stdout=subprocess.PIPE)
def run(self):
ser = serial.Serial("/dev/ttyACM0")
while True:
with self.lock:
if self.app == None or self.app.poll() != None:
self.requestedApp = 0
if self.currentApp != self.requestedApp:
self.currentApp = self.requestedApp
self.updateApp()
d = self.app.stdout
oshandle = d.fileno()
data = os.read(oshandle, config.ScreenX*config.ScreenY*3)
# data = d.raw.read(config.ScreenX*config.ScreenY*3)
ser.write(b"\01")
ser.write(data)
runner = AppRunner()
runner.start()
@route("/apps/list")
def apps_list():
s = []
for app in config.Apps:
s.append(app["name"])
return json.dumps(s)
@route("/apps/start/<name>")
def apps_start(name):
for i in range(len(config.Apps)):
if config.Apps[i]["name"] == name:
runner.requestApp(i)
return "ok"
return "not_found"
@route("/apps/start/<name>/<param>")
def apps_start(name, param):
for i in range(len(config.Apps)):
if config.Apps[i]["name"] == name:
runner.requestApp(i, param)
return "ok"
return "not_found"
@route("/apps/running")
def apps_running():
i = runner.currentApp
return config.Apps[i]["name"]
run(host="localhost", port=8000)