Gamme support
This commit is contained in:
parent
810453fc8c
commit
c00415aa7b
34
main.py
34
main.py
@ -10,6 +10,7 @@ import time
|
|||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
import logging
|
import logging
|
||||||
|
import math
|
||||||
|
|
||||||
logging.basicConfig(filename='pixelserver.log',level=config.LogLevel)
|
logging.basicConfig(filename='pixelserver.log',level=config.LogLevel)
|
||||||
|
|
||||||
@ -78,6 +79,7 @@ class SerialWriter(threading.Thread):
|
|||||||
self.cv = threading.Condition()
|
self.cv = threading.Condition()
|
||||||
self.datasource = datasource
|
self.datasource = datasource
|
||||||
self.datasource.addListener(self.cv)
|
self.datasource.addListener(self.cv)
|
||||||
|
self.updateGamma = False
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
should_connect = True
|
should_connect = True
|
||||||
@ -92,6 +94,22 @@ class SerialWriter(threading.Thread):
|
|||||||
with self.cv:
|
with self.cv:
|
||||||
self.cv.wait(timeout = 1/30)
|
self.cv.wait(timeout = 1/30)
|
||||||
data = self.datasource.getData()
|
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(b"\01")
|
||||||
ser.write(data)
|
ser.write(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -106,6 +124,14 @@ class SerialWriter(threading.Thread):
|
|||||||
self.cv.notify_all()
|
self.cv.notify_all()
|
||||||
super().join()
|
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):
|
class WatchDog(threading.Thread):
|
||||||
def __init__(self, check, action):
|
def __init__(self, check, action):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
@ -274,6 +300,8 @@ class AppRunner(threading.Thread):
|
|||||||
if self.app == None:
|
if self.app == None:
|
||||||
return ""
|
return ""
|
||||||
return self.app.getLog()
|
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():
|
def index():
|
||||||
return bottle.static_file("index.html", root='html')
|
return bottle.static_file("index.html", root='html')
|
||||||
#return open("html/index.html").read()
|
#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)
|
run(host=config.WebHost, port=config.WebPort)
|
||||||
running = False
|
running = False
|
||||||
|
Loading…
Reference in New Issue
Block a user