Merge remote-tracking branch 'tvdzwan/master'

Former-commit-id: c10089870868d7019404f566c0105b9d7a8f5b49
This commit is contained in:
redpanther
2016-01-21 23:30:10 +01:00
13 changed files with 259 additions and 141 deletions

View File

@@ -0,0 +1,12 @@
{
"name" : "Police Lights Single",
"script" : "police.py",
"args" :
{
"rotation-time" : 1.5,
"color_one" : [ 255, 0, 0 ],
"color_two" : [ 0, 0, 255 ],
"colors_count" : 10,
"reverse" : false
}
}

View File

@@ -0,0 +1,11 @@
{
"name" : "Police Lights Solid",
"script" : "police.py",
"args" :
{
"rotation-time" : 1.0,
"color_one" : [ 255, 0, 0 ],
"color_two" : [ 0, 0, 255 ],
"reverse" : false
}
}

46
effects/police.py Normal file
View File

@@ -0,0 +1,46 @@
import hyperion
import time
import colorsys
# Get the parameters
rotationTime = float(hyperion.args.get('rotation-time', 2.0))
colorOne = hyperion.args.get('color_one', (255,0,0))
colorTwo = hyperion.args.get('color_two', (0,0,255))
colorsCount = hyperion.args.get('colors_count', hyperion.ledCount/2)
reverse = bool(hyperion.args.get('reverse', False))
# Check parameters
rotationTime = max(0.1, rotationTime)
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)
hsv2 = colorsys.rgb_to_hsv(colorTwo[0]/255.0, colorTwo[1]/255.0, colorTwo[2]/255.0)
colorBlack = (0,0,0)
ledData = bytearray()
for i in range(hyperion.ledCount):
if i <= colorsCount:
rgb = colorsys.hsv_to_rgb(hsv1[0], hsv1[1], hsv1[2])
elif (i >= hyperion.ledCount/2-1) & (i < (hyperion.ledCount/2) + colorsCount):
rgb = colorsys.hsv_to_rgb(hsv2[0], hsv2[1], hsv2[2])
else:
rgb = colorBlack
ledData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])))
# Calculate the sleep time and rotation increment
increment = 3
sleepTime = rotationTime / hyperion.ledCount
while sleepTime < 0.05:
increment *= 2
sleepTime *= 2
increment %= hyperion.ledCount
# Switch direction if needed
if reverse:
increment = -increment
# Start the write data loop
while not hyperion.abort():
hyperion.setColor(ledData)
ledData = ledData[-increment:] + ledData[:-increment]
time.sleep(sleepTime)