Added new Candle effect - like those fake flickering led candles (#317)

* Added new Candle effect - like those fake flickering led candles

* Candle work...
code cleanups
parameter changes
schema file
english labels

* renamed a title

* candle effect german localisation

* fix typo in police.py
This commit is contained in:
penfold42 2016-12-09 23:21:32 +11:00 committed by brindosch
parent 0d114ca728
commit 33f5530a1c
6 changed files with 161 additions and 1 deletions

View File

@ -321,6 +321,7 @@
"edt_conf_effp_disable_itemtitle" : "Effekt",
"edt_conf_log_heading_title" : "Protokoll",
"edt_conf_log_level_title" : "Protokollstufe",
"edt_eff_candle_header_title" : "Kerze",
"edt_eff_police_header_title" : "Polizei",
"edt_eff_fade_header_title" : "Farbübergang",
"edt_eff_rainbowmood_header_title" : "Regenbogen",
@ -347,6 +348,9 @@
"edt_eff_fadetime_title" : "Übergangszeit",
"edt_eff_colorstart_title" : "Farbe Start",
"edt_eff_colorend_title" : "Farbe Ende",
"edt_eff_colorshift_title" : "Farbverschiebung",
"edt_eff_whichleds_title" : "Welche LEDs",
"edt_eff_ledlist_title" : "LED Liste",
"edt_eff_speed_title" : "Geschwindigkeit",
"edt_eff_fadefactor_title" : "Verblass Faktor",
"edt_eff_showseconds_title" : "Zeige Sekunden",

View File

@ -321,6 +321,7 @@
"edt_conf_effp_disable_itemtitle" : "Effect",
"edt_conf_log_heading_title" : "Logging",
"edt_conf_log_level_title" : "Log-Level",
"edt_eff_candle_header_title" : "Candle",
"edt_eff_police_header_title" : "Police",
"edt_eff_fade_header_title" : "Fade",
"edt_eff_rainbowmood_header_title" : "Rainbow Mood",
@ -347,6 +348,9 @@
"edt_eff_fadetime_title" : "Fade time",
"edt_eff_colorstart_title" : "Color start",
"edt_eff_colorend_title" : "Color end",
"edt_eff_colorshift_title" : "Color Shift",
"edt_eff_whichleds_title" : "Which Leds",
"edt_eff_ledlist_title" : "Led List",
"edt_eff_speed_title" : "Speed",
"edt_eff_fadefactor_title" : "Fade factor",
"edt_eff_showseconds_title" : "Show seconds",

11
effects/candle.json Normal file
View File

@ -0,0 +1,11 @@
{
"name" : "Candle",
"script" : "candle.py",
"args" :
{
"sleepTime" : 0.15,
"brightness" : 0.50,
"color" : [ 255, 138, 0 ],
"candles" : "all"
}
}

81
effects/candle.py Normal file
View File

@ -0,0 +1,81 @@
# Candleflicker effect by penfold42
# Algorithm courtesy of
# https://cpldcpu.com/2013/12/08/hacking-a-candleflicker-led/
# candles can be :
# a single led number, a list of candle numbers
# "all" to flicker all the leds randomly
# "all-together" to flicker all the leds in unison
import hyperion
import time
import colorsys
import random
# Get parameters
color = hyperion.args.get('color', (255,138,0))
colorShift = hyperion.args.get('colorShift', 0.01)
brightness = float(hyperion.args.get('brightness', 0.5))
sleepTime = float(hyperion.args.get('sleepTime', 0.14))
candles = hyperion.args.get('candles', "all")
ledlist = hyperion.args.get('ledlist', "1")
candlelist = ()
if (candles == "list") and (type(ledlist) is str):
for s in ledlist.split(','):
i = int(s)
if (i<hyperion.ledCount):
candlelist += (i,)
elif (candles == "list") and (type(ledlist) is list):
for s in (ledlist):
i = int(s)
if (i<hyperion.ledCount):
candlelist += (i,)
else:
candlelist = range(hyperion.ledCount)
# Convert rgb color to hsv
hsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color [2]/255.0)
def CandleRgb():
hue = random.uniform(hsv[0]-colorShift, hsv[0]+colorShift) % 1.0
RAND=random.randint(0,15)
while ((RAND & 0x0c)==0):
RAND=random.randint(0,15)
val = ( min(RAND, 15)/15.0001 ) * brightness
frgb = colorsys.hsv_to_rgb(hue, hsv[1], val);
return (int(255*frgb[0]), int(255*frgb[1]), int(255*frgb[2]))
ledData = bytearray(hyperion.ledCount * (0,0,0) )
while not hyperion.abort():
if (candles == "all-together"):
rgb = CandleRgb()
for lednum in candlelist:
ledData[3*lednum+0] = rgb[0]
ledData[3*lednum+1] = rgb[1]
ledData[3*lednum+2] = rgb[2]
elif (candles == "all"):
for lednum in candlelist:
rgb = CandleRgb()
ledData[3*lednum+0] = rgb[0]
ledData[3*lednum+1] = rgb[1]
ledData[3*lednum+2] = rgb[2]
else:
for lednum in candlelist:
rgb = CandleRgb()
ledData[3*lednum+0] = rgb[0]
ledData[3*lednum+1] = rgb[1]
ledData[3*lednum+2] = rgb[2]
hyperion.setColor (ledData)
time.sleep(sleepTime)

View File

@ -9,7 +9,7 @@ reverse = bool(hyperion.args.get('reverse', False))
# Check parameters
rotationTime = max(0.1, rotationTime)
colorsCoun t = min(hyperion.ledCount/2, colorsCount)
colorsCount = min(hyperion.ledCount/2, colorsCount)
# Initialize the led data
hsv1 = colorsys.rgb_to_hsv(colorOne[0]/255.0, colorOne[1]/255.0, colorOne[2]/255.0)

View File

@ -0,0 +1,60 @@
{
"type":"object",
"script" : "candle.py",
"title":"edt_eff_candle_header_title",
"required":true,
"properties":{
"candles": {
"type": "string",
"title":"edt_eff_whichleds_title",
"enum" : ["all","all-together","list"],
"default" : "all",
"propertyOrder" : 1
},
"ledlist": {
"type": "string",
"title":"edt_eff_ledlist_title",
"default" : "1,11,21",
"propertyOrder" : 2
},
"color": {
"type": "array",
"title":"edt_eff_color_title",
"format":"colorpicker",
"default": [255,138,0],
"items" : {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"minItems": 3,
"maxItems": 3,
"propertyOrder" : 3
},
"colorShift": {
"type": "number",
"title":"edt_eff_colorshift_title",
"default": 0.01,
"minimum" : 0.00,
"maximum": 1,
"propertyOrder" : 4
},
"brightness": {
"type": "number",
"title":"edt_eff_brightness_title",
"default": 0.5,
"minimum" : 0.01,
"maximum": 1,
"propertyOrder" : 5
},
"sleepTime": {
"type": "number",
"title":"edt_eff_sleeptime_title",
"default": 0.15,
"minimum" : 0.01,
"maximum": 1,
"propertyOrder" : 6
}
},
"additionalProperties": false
}