renaming folders and files to python format

This commit is contained in:
dezeyer
2019-05-11 14:28:42 +00:00
parent ade378d128
commit 798775805c
19 changed files with 509 additions and 268 deletions
@@ -0,0 +1,49 @@
"""
Convert the effectController function outputs to json format
"""
def responseHandler(effectController,rgbStripController,data):
if "startEffect" in data:
enabledRGBStrips = []
for rgbStrip in rgbStripController.getRGBStrips():
for rgbStripJsonArray in data['startEffect']['rgbStrips']:
if rgbStrip.STRIP_UID in rgbStripJsonArray[0] and rgbStripJsonArray[1]:
enabledRGBStrips.append(rgbStrip)
effectController.startEffect(effectController.getEffects()[data['startEffect']['effect']],enabledRGBStrips,data['startEffect']['params'])
if "moveRGBStripToEffectThread" in data:
for rgbStrip in rgbStripController.getRGBStrips():
if rgbStrip.STRIP_UID in data['moveRGBStripToEffectThread']['rgbStrip']:
effectController.moveRGBStripToEffectThread( \
rgbStrip, \
effectController.getEffectThreads()[data['moveRGBStripToEffectThread']['effectThread']] \
)
if "effectThreadChangeEffectParam" in data:
effectController.updateEffectParameters(\
effectController.getEffectThreads()[data['effectThreadChangeEffectParam']['effectThread']], \
data['effectThreadChangeEffectParam']['params']
)
return 'ok'
# return json of all configured effects (except offEffect) with their paramDescriptions
def getEffects(effectController):
result = {}
for x, effect in enumerate(effectController.getEffects()):
effectParams = {}
for y, effectParam in enumerate(effect.effectParameters):
effectParams[y] = {'index': y,'type': effectParam.type, 'name': effectParam.name, 'desc': effectParam.desc, 'options': effectParam.options}
result[x] = {'index': x, 'name': effect.name, 'desc': effect.desc, 'effectParams': effectParams}
return result
# return json of all running effectThreads with their active rgbStrips and params
def getEffectThreads(effectController):
result = {}
for x, effectThread in enumerate(effectController.getEffectThreads()):
effectRGBStrips = {}
for effectRGBStrip in effectController.getEffectRGBStrips(effectThread):
effectRGBStrips[effectRGBStrip.STRIP_UID] = {'index': effectRGBStrip.STRIP_UID, 'name': effectRGBStrip.STRIP_NAME}
effectParams = {}
for z, effectParam in enumerate(effectThread.effectParameters):
effectParams[z] = {'index': z,'type': effectParam.type, 'name': effectParam.name, 'desc': effectParam.desc, 'options': effectParam.options, 'values': effectThread.effectParameterValues[z]}
result[x] = {'index': x, 'name': effectThread.name, 'desc': effectThread.desc,'activeRGBStips': effectRGBStrips, 'dump': str(effectThread), 'effectParams': effectParams}
return result
@@ -0,0 +1,14 @@
"""
Convert the rgbStripController function outputs to json format
"""
# get the color values of a single led in json format
def getRGBData(rgbStrip,led = 0):
return {'led': led, 'red': rgbStrip.getData()[0][led], 'green': rgbStrip.getData()[1][led], 'blue': rgbStrip.getData()[2][led]}
# return json of all configured rgbStrips
def getRGBStrips(rgbStripController):
result = {}
for rgbStrip in rgbStripController.getRGBStrips():
result[rgbStrip.STRIP_UID] = {'index': rgbStrip.STRIP_UID, 'name': rgbStrip.STRIP_NAME}
return result
+2 -9
View File
@@ -18,7 +18,6 @@ class ThreadedUDPServer(threading.Thread):
self.start()
self.udpClientGuardian = self.UDPClientGuardian()
self.udpClientGuardian.start()
UDPClients
def run(self):
@@ -86,13 +85,6 @@ class UDPClient():
self.lastping = time()
def handle(self, request):
clientdata = request[0].decode()
self.socket = request[1]
#print(time(),"{} wrote:".format(self.client_address))
#print(time(),"clientdata -> ", clientdata)
# socket.sendto(bytes("pong","utf-8"),self.client_address)
# Client Types:
# CLIENT_TYPE_CONTROLLER = 0
# CLIENT_TYPE_STRIPE = 1
@@ -104,8 +96,9 @@ class UDPClient():
# s:ping
# UDP
self.socket = request[1]
try:
data = clientdata.split(':')
data = request[0].decode().split(':')
#print(data)
# r:1:srg strip name
if data[0] == "r" and int(data[1]) == CLIENT_TYPE_STRIPE and data[2] != None and self.registered is False:
+8 -25
View File
@@ -22,8 +22,8 @@ class ThreadedWebSocketServer(Thread):
import json
from rgbUtils import effectControllerJsonHelper
from rgbUtils import rgbStripControllerJsonHelper
from BackendProvider.Helper import effectControllerJsonHelper
from BackendProvider.Helper import rgbStripControllerJsonHelper
import traceback
import logging
@@ -63,12 +63,6 @@ class HTTPWebSocketsHandler(WebSocket):
ledcount=1
if "led_count" in data:
ledcount = int(data["led_count"])
self.nojson=0
if "nojson" in data:
self.nojson = int(data["nojson"])
self.nosend=0
if "nosend" in data:
self.nosend = int(data["nosend"])
# registers the strip with websocket object and name. the onRGBStripValueUpdate(rgbStrip) is called by
# by the rgbStrip when an effectThread updates it
@@ -87,13 +81,9 @@ class HTTPWebSocketsHandler(WebSocket):
})
)
return
# the stripe should usualy not send any data, i do not know why it should...
elif self.client_type is CLIENT_TYPE_STRIPE:
if self.nosend == 1:
respdata = "d"
for i in range(self.rgbStrip.STRIP_LENGHT):
respdata += ":" + str(i) + ":"+str(self.rgbStrip.red[i])+":"+str(self.rgbStrip.green[i])+":"+str(self.rgbStrip.blue[i])
self.sendMessage(respdata)
return
# audio recorder responses are handled by the effectControllerJsonHandler
elif self.client_type is CLIENT_TYPE_RECORDER:
@@ -139,15 +129,8 @@ class HTTPWebSocketsHandler(WebSocket):
# when a rgbStrip value is changed, send json data to client
def onRGBStripValueUpdate(self,rgbStrip):
if self.nosend == 0:
if self.nojson == 0:
self.sendMessage(
json.dumps({
'data': rgbStripControllerJsonHelper.getRGBData(rgbStrip)
})
)
if self.nojson == 1:
respdata = "d"
for i in range(rgbStrip.STRIP_LENGHT):
respdata += ":" + str(i) + ":"+str(rgbStrip.red[i])+":"+str(rgbStrip.green[i])+":"+str(rgbStrip.blue[i])
self.sendMessage(respdata)
self.sendMessage(
json.dumps({
'data': rgbStripControllerJsonHelper.getRGBData(rgbStrip)
})
)