From 2555c5071053c5f5112893d7bc11a525e234c0f3 Mon Sep 17 00:00:00 2001 From: redpanther Date: Sat, 23 Jan 2016 13:09:23 +0100 Subject: [PATCH] add shutdown effect: system shutdown is disabled by default. enable it in json (set false to true) the shutdown is abortable. simply select another effect before shutdown time reached this effect is made for linux and did not workl on windows without modifications Former-commit-id: 32f92246fbc87de576e4b1059dd319646917ec74 --- effects/shutdown.json | 11 ++++++++++ effects/shutdown.py | 51 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 effects/shutdown.json create mode 100644 effects/shutdown.py diff --git a/effects/shutdown.json b/effects/shutdown.json new file mode 100644 index 00000000..7e09a13b --- /dev/null +++ b/effects/shutdown.json @@ -0,0 +1,11 @@ +{ + "name" : "System Shutdown", + "script" : "shutdown.py", + "args" : + { + "speed" : 1.2, + "alarm-color" : [255,0,0], + "post-color" : [255,174,11], + "shutdown-enabled" : false + } +} diff --git a/effects/shutdown.py b/effects/shutdown.py new file mode 100644 index 00000000..469443d0 --- /dev/null +++ b/effects/shutdown.py @@ -0,0 +1,51 @@ +import hyperion, time, colorsys, random, subprocess + +def setPixel(x,y,rgb): + global imageData, width + offset = y*width*3 + x*3 + if offset+2 < len(imageData): + imageData[offset] = rgb[0] + imageData[offset+1] = rgb[1] + imageData[offset+2] = rgb[2] + +# Initialize the led data and args +sleepTime = float(hyperion.args.get('speed', 1.0))*0.5 +alarmColor = hyperion.args.get('alarm-color', (255,0,0)) +postColor = hyperion.args.get('post-color', (255,174,11)) +off = bool(hyperion.args.get('shutdown-enabled', False)) +width = 12 +height = 10 + +imageData = bytearray(height * width * (0,0,0)) +imageDataBlack = bytearray(height * width * (0,0,0)) +imageDataRed = bytearray(height * width * alarmColor) + +# Start the write data loop +for i in range(6): + if hyperion.abort(): + off = False + break + if i % 2: + hyperion.setImage(width, height, imageDataRed) + else: + hyperion.setImage(width, height, imageDataBlack) + time.sleep(sleepTime) + +for y in range(height,0,-1): + if hyperion.abort(): + off = False + break + for x in range(width): + setPixel(x, y-1, alarmColor) + hyperion.setImage(width, height, imageData) + time.sleep(sleepTime) +time.sleep(1) + +for y in range(height): + for x in range(width): + setPixel(x, y, postColor) +hyperion.setImage(width, height, imageData) +time.sleep(2) + +if off and not hyperion.abort(): + subprocess.call("halt")