You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
2.7 KiB

  1. import subprocess
  2. import sys, inspect, os
  3. import wiringpi
  4. from time import sleep
  5. #from multiprocessing import Process
  6. #import lirc
  7. from pyudmx import pyudmx
  8. # def send_dmx(dev, red, green, blue, dimmer):
  9. # """
  10. # Send a set of RGB values to the light
  11. # """
  12. # cv = [0 for v in range(0, 512)]
  13. # cv[0] = dimmer
  14. # cv[1] = red
  15. # cv[2] = green
  16. # cv[3] = blue
  17. # sent = dev.send_multi_value(1, cv)
  18. # return sent
  19. #
  20. # GPIO
  21. pin_kugel = 2
  22. pin_sun = 4
  23. pin_pir = 0
  24. def setDmxScene(scene):
  25. cv = [0 for v in range(0, 512)]
  26. scenes = {
  27. "fadecolors":[255,255,255,255,255,192],
  28. "plain-red":[255,255,0,0,0,0],
  29. "strobe":[190,255,255,255,0,0],
  30. "nini":[120,0,255,255,0,224],
  31. "black":[0,0,0,0,0,0]
  32. }
  33. errorcode = [240,255,0,0,0,0]
  34. for index, val in enumerate(scenes.get(scene,errorcode)):
  35. cv[index] = val
  36. dev.send_multi_value(1, cv)
  37. def setKugel(state):
  38. if state == 'on':
  39. wiringpi.digitalWrite(pin_kugel, 0)
  40. if state == 'off':
  41. wiringpi.digitalWrite(pin_kugel, 1)
  42. def setSun(state):
  43. if state == 'off':
  44. wiringpi.digitalWrite(pin_sun, 0)
  45. if state == 'on':
  46. wiringpi.digitalWrite(pin_sun, 1)
  47. def setMusic(action, scene):
  48. if action == "play":
  49. if not scene:
  50. scene = defaulscene
  51. musicdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/music/" + scene
  52. for (path, dirnames, filenames) in os.walk(musicdir):
  53. #folders.extend(os.path.join(path, name) for name in dirnames)
  54. for name in filenames:
  55. file = os.path.join(path, name)
  56. #os.system("mpg123 " + "'" + file + "'")
  57. #os.system("")
  58. subprocess.run(["mpg123", file])
  59. def bootstrap():
  60. wiringpi.wiringPiSetup()
  61. wiringpi.pinMode(pin_kugel, 1) # set Relay Disokugel mode to OUTPUT
  62. wiringpi.pinMode(pin_sun, 1) # set Relay Sun mode to OUTPUT # TODO: Set pin!
  63. wiringpi.pinMode(pin_pir, 0) # set PIR Sensor mode to INPUT
  64. setSun('off')
  65. setKugel('off')
  66. bootstrap()
  67. dev = pyudmx.uDMXDevice()
  68. dev.open()
  69. pirstate = wiringpi.digitalRead(6)
  70. defaultscene = 1
  71. while True:
  72. # if PIR-State changes
  73. if wiringpi.digitalRead(pin_pir) != pirstate:
  74. pirstate = wiringpi.digitalRead(pin_pir)
  75. print('pirstate: ', pirstate)
  76. if pirstate == 1:
  77. setSun('off')
  78. setKugel('on')
  79. setDmxScene('fadecolors')
  80. sleep(1)
  81. sleep(1)
  82. # setMusic('play', '1')
  83. sleep(20)
  84. else:
  85. setSun('on')
  86. setDmxScene('black')
  87. sleep(1)
  88. setKugel('off')
  89. sleep(1)
  90. dev.close()