Gamme support

This commit is contained in:
Andreas 2018-10-21 15:03:56 +02:00
parent 810453fc8c
commit c00415aa7b

36
main.py
View File

@ -10,6 +10,7 @@ import time
import sys
import signal
import logging
import math
logging.basicConfig(filename='pixelserver.log',level=config.LogLevel)
@ -78,7 +79,8 @@ class SerialWriter(threading.Thread):
self.cv = threading.Condition()
self.datasource = datasource
self.datasource.addListener(self.cv)
self.updateGamma = False
def run(self):
should_connect = True
ser = None
@ -92,6 +94,22 @@ class SerialWriter(threading.Thread):
with self.cv:
self.cv.wait(timeout = 1/30)
data = self.datasource.getData()
with self.cv:
if self.updateGamma:
buf = bytearray("\x00")*3*256
r = self.r
g = self.g
b = self.b
for i in range(256):
gr = int(math.pow(i/255, r)*255)
gg = int(math.pow(i/255, g)*255)
gb = int(math.pow(i/255, b)*255)
buf[i] =gr
buf[i+255] = gg
buf[i+511] = gb
ser.write(b"\x02")
ser.write(buf)
self.updateGamma = False
ser.write(b"\01")
ser.write(data)
except Exception as e:
@ -106,6 +124,14 @@ class SerialWriter(threading.Thread):
self.cv.notify_all()
super().join()
def setGamma(self, r, g, b):
with self.cv:
self.r = r
self.g = g
self.b = b
self.updateGamma = True
self.cv.notify_all()
class WatchDog(threading.Thread):
def __init__(self, check, action):
super().__init__()
@ -274,6 +300,8 @@ class AppRunner(threading.Thread):
if self.app == None:
return ""
return self.app.getLog()
def setGamma(self, r, g, b):
self.serial.setGamma(r, g, b)
@ -339,6 +367,12 @@ def apps_running():
def index():
return bottle.static_file("index.html", root='html')
#return open("html/index.html").read()
@route("/setgamma/<r>/<g>/<b>")
def setGamma(r, g, b):
r = float(r)
g = float(g)
b = float(b)
runner.setGamma(r, g, b)
run(host=config.WebHost, port=config.WebPort)
running = False