added stop_effect, get_effects
fixed some wrong calculations from hsv to pwm added lots of todo descriptions changed find_stripe from requiring a json to sid directly
This commit is contained in:
@@ -25,7 +25,6 @@ import time
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import spectra
|
import spectra
|
||||||
|
|
||||||
from zeroconf import Zeroconf, ServiceInfo
|
from zeroconf import Zeroconf, ServiceInfo
|
||||||
|
|
||||||
from ledd import controller, VERSION
|
from ledd import controller, VERSION
|
||||||
@@ -149,30 +148,72 @@ class Daemon:
|
|||||||
@ledd_protocol(protocol)
|
@ledd_protocol(protocol)
|
||||||
def start_effect(self, req_json):
|
def start_effect(self, req_json):
|
||||||
"""
|
"""
|
||||||
|
Part of the Color API. Used to start a specific effect.
|
||||||
|
Required JSON parameters: stripe IDs: sids; effect id: eid, effect options: eopt
|
||||||
:param req_json: dict of request json
|
:param req_json: dict of request json
|
||||||
"""
|
"""
|
||||||
|
log.debug("recieved action: %s", req_json['action'])
|
||||||
|
|
||||||
|
stripes = []
|
||||||
|
|
||||||
|
if "sids" in req_json:
|
||||||
|
for sid in req_json['sids']:
|
||||||
|
found_s = self.find_stripe(sid)
|
||||||
|
|
||||||
|
if found_s is not None:
|
||||||
|
stripes.append(found_s)
|
||||||
|
|
||||||
|
if len(stripes) > 0:
|
||||||
|
# TODO: add anything required to start effect with req_json['eid']
|
||||||
|
# on stripes[] with options in req_json['eopt']
|
||||||
effect = EffectStack()
|
effect = EffectStack()
|
||||||
self.effects.append(effect)
|
self.effects.append(effect)
|
||||||
effect.stripes.append(self.controllers[1].stripes[0])
|
effect.stripes.append(self.controllers[0].stripes[0])
|
||||||
effect.start()
|
effect.start()
|
||||||
|
|
||||||
# asyncio.ensure_future(asyncio.get_event_loop().run_in_executor(self.executor, effect.execute))
|
# asyncio.ensure_future(asyncio.get_event_loop().run_in_executor(self.executor, effect.execute))
|
||||||
|
|
||||||
log.debug("recieved action: %s", req_json['action'])
|
rjson = {
|
||||||
|
'success': True,
|
||||||
|
'eident': None, # unique effect identifier that identifies excatly this effect started on this set of
|
||||||
|
# stripes, used to stop them later and to give informations about running effects
|
||||||
|
'ref': req_json['ref']
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.dumps(rjson)
|
||||||
|
else:
|
||||||
|
rjson = {
|
||||||
|
'success': False,
|
||||||
|
'message': "No stripe with this id found",
|
||||||
|
'ref': req_json['ref']
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.dumps(rjson)
|
||||||
|
|
||||||
@ledd_protocol(protocol)
|
@ledd_protocol(protocol)
|
||||||
def start_effect(self, req_json):
|
def stop_effect(self, req_json):
|
||||||
"""
|
"""
|
||||||
|
Part of the Color API. Used to stop a specific effect.
|
||||||
|
Required JSON parameters: effect identifier: eident
|
||||||
:param req_json: dict of request json
|
:param req_json: dict of request json
|
||||||
"""
|
"""
|
||||||
effect = BaseEffect(Stripe(),self.loop)
|
|
||||||
self.effects.append(effect)
|
|
||||||
asyncio.ensure_future(asyncio.get_event_loop().run_in_executor(self.executor, effect.execute))
|
|
||||||
|
|
||||||
log.debug("recieved action: %s", req_json['action'])
|
log.debug("recieved action: %s", req_json['action'])
|
||||||
|
|
||||||
|
# TODO: add stop effect by eident logic
|
||||||
|
|
||||||
|
@ledd_protocol(protocol)
|
||||||
|
def get_effects(self, req_json):
|
||||||
|
"""
|
||||||
|
Part of the Color API. Used to show all available and running effects.
|
||||||
|
Required JSON parameters: -
|
||||||
|
:param req_json: dict of request json
|
||||||
|
"""
|
||||||
|
log.debug("recieved action: %s", req_json['action'])
|
||||||
|
|
||||||
|
# TODO: list all effects here and on which stripes they run atm
|
||||||
|
# TODO: all effects get runtime only ids, "eid"'s. They are shown here for the client to start effects.
|
||||||
|
# TODO: All options that an effect may have need to be transmitted here too with "eopt".
|
||||||
|
|
||||||
@ledd_protocol(protocol)
|
@ledd_protocol(protocol)
|
||||||
def set_color(self, req_json):
|
def set_color(self, req_json):
|
||||||
"""
|
"""
|
||||||
@@ -184,7 +225,7 @@ class Daemon:
|
|||||||
|
|
||||||
if "stripes" in req_json:
|
if "stripes" in req_json:
|
||||||
for stripe in req_json['stripes']:
|
for stripe in req_json['stripes']:
|
||||||
found_s = self.find_stripe(stripe)
|
found_s = self.find_stripe(stripe['sid'])
|
||||||
|
|
||||||
if found_s is None:
|
if found_s is None:
|
||||||
log.warning("Stripe not found: id=%s", stripe['sid'])
|
log.warning("Stripe not found: id=%s", stripe['sid'])
|
||||||
@@ -192,7 +233,7 @@ class Daemon:
|
|||||||
|
|
||||||
found_s.set_color(spectra.hsv(stripe['hsv']['h'], stripe['hsv']['s'], stripe['hsv']['v']))
|
found_s.set_color(spectra.hsv(stripe['hsv']['h'], stripe['hsv']['s'], stripe['hsv']['v']))
|
||||||
|
|
||||||
def find_stripe(self, jstripe):
|
def find_stripe(self, sid):
|
||||||
"""
|
"""
|
||||||
Finds a given stripeid in the currently known controllers
|
Finds a given stripeid in the currently known controllers
|
||||||
:param jstripe: json containing sid
|
:param jstripe: json containing sid
|
||||||
@@ -201,7 +242,7 @@ class Daemon:
|
|||||||
"""
|
"""
|
||||||
for c in self.controllers:
|
for c in self.controllers:
|
||||||
for s in c.stripes:
|
for s in c.stripes:
|
||||||
if s.id == jstripe['sid']:
|
if s.id == sid:
|
||||||
return s
|
return s
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@@ -251,7 +292,7 @@ class Daemon:
|
|||||||
|
|
||||||
if "stripes" in req_json:
|
if "stripes" in req_json:
|
||||||
for stripe in req_json['stripes']:
|
for stripe in req_json['stripes']:
|
||||||
found_s = self.find_stripe(stripe)
|
found_s = self.find_stripe(stripe['sid'])
|
||||||
|
|
||||||
if found_s is None:
|
if found_s is None:
|
||||||
log.warning("Stripe not found: id=%s", stripe['sid'])
|
log.warning("Stripe not found: id=%s", stripe['sid'])
|
||||||
|
@@ -27,7 +27,7 @@ class FadeEffect(GeneratorEffect):
|
|||||||
description = "Fades through the HSV color wheel"
|
description = "Fades through the HSV color wheel"
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
scale = spectra.scale([spectra.hsv(0.0, 1.0, 1.0), spectra.hsv(360, 1.0, 1.0)]).domain([0, 20000])
|
scale = spectra.scale([spectra.hsv(0.0, 1.0, 1.0), spectra.hsv(360.0, 1.0, 1.0)]).domain([0, 20000])
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
|
@@ -57,7 +57,7 @@ class Stripe:
|
|||||||
def set_color(self, c):
|
def set_color(self, c):
|
||||||
self._color = c
|
self._color = c
|
||||||
for channel, gamma_correct, value in zip(self.channels, self.gamma_correct, c.clamped_rgb):
|
for channel, gamma_correct, value in zip(self.channels, self.gamma_correct, c.clamped_rgb):
|
||||||
self.controller.set_channel(channel, value * 255)
|
self.controller.set_channel(channel, value)
|
||||||
|
|
||||||
def get_color(self):
|
def get_color(self):
|
||||||
return self._color
|
return self._color
|
||||||
|
Reference in New Issue
Block a user