shutdown.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import hyperion, time, subprocess
  2. def setPixel(x,y,rgb):
  3. global imageData, width
  4. offset = y*width*3 + x*3
  5. if offset+2 < len(imageData):
  6. imageData[offset] = rgb[0]
  7. imageData[offset+1] = rgb[1]
  8. imageData[offset+2] = rgb[2]
  9. # Initialize the led data and args
  10. sleepTime = float(hyperion.args.get('speed', 1.0))*0.5
  11. alarmColor = hyperion.args.get('alarm-color', (255,0,0))
  12. postColor = hyperion.args.get('post-color', (255,174,11))
  13. off = bool(hyperion.args.get('shutdown-enabled', False))
  14. initialBlink = bool(hyperion.args.get('initial-blink', True))
  15. setPostColor = bool(hyperion.args.get('set-post-color', True))
  16. width = 12
  17. height = 10
  18. imageData = bytearray(height * width * (0,0,0))
  19. # Start the write data loop
  20. if initialBlink:
  21. for i in range(6):
  22. if hyperion.abort():
  23. off = False
  24. break
  25. if i % 2:
  26. hyperion.setColor(alarmColor[0], alarmColor[1], alarmColor[2])
  27. else:
  28. hyperion.setColor(0, 0, 0)
  29. time.sleep(sleepTime)
  30. for y in range(height,0,-1):
  31. if hyperion.abort():
  32. off = False
  33. break
  34. for x in range(width):
  35. setPixel(x, y-1, alarmColor)
  36. hyperion.setImage(width, height, imageData)
  37. time.sleep(sleepTime)
  38. time.sleep(1)
  39. if setPostColor:
  40. for y in range(height):
  41. for x in range(width):
  42. setPixel(x, y, postColor)
  43. hyperion.setImage(width, height, imageData)
  44. time.sleep(2)
  45. if off and not hyperion.abort():
  46. subprocess.call("halt")