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.

discobert.py 4.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import subprocess
  2. import sys, inspect, os
  3. import wiringpi
  4. import time
  5. from time import sleep
  6. import lirc
  7. import mpd
  8. from pyudmx import pyudmx
  9. # GPIO
  10. pin_kugel = 2
  11. pin_sun = 4
  12. pin_pir = 0
  13. dmxScenes = {
  14. "fadecolors":[255,255,255,255,255,192],
  15. "plain-red":[255,255,0,0,0,0],
  16. "strobe":[190,255,255,255,0,0],
  17. "nini":[120,0,255,255,0,224],
  18. "black":[0,0,0,0,0,0]
  19. }
  20. dmxUserScenes = [
  21. [255,255,255,255,255,192],
  22. [255,255,0,0,0,0],
  23. [255,0,255,0,0,0],
  24. [255,0,0,255,0,0],
  25. [255,0,180,180,0,0],
  26. [190,255,255,255,0,0],
  27. [120,0,255,255,0,224]
  28. ]
  29. def setDmxScene(scene):
  30. cv = [0 for v in range(0, 512)]
  31. errorcode = [240,255,0,0,0,0]
  32. for index, val in enumerate(dmxScenes.get(scene,errorcode)):
  33. cv[index] = val
  34. dev.send_multi_value(1, cv)
  35. def setUserDmxScene(scene):
  36. cv = [0 for v in range(0, 512)]
  37. for index, val in enumerate(dmxUserScenes[scene]):
  38. cv[index] = val
  39. dev.send_multi_value(1, cv)
  40. def setKugel(state):
  41. if state == 'on':
  42. wiringpi.digitalWrite(pin_kugel, 0)
  43. if state == 'off':
  44. wiringpi.digitalWrite(pin_kugel, 1)
  45. def setSun(state):
  46. if state == 'off':
  47. wiringpi.digitalWrite(pin_sun, 0)
  48. if state == 'on':
  49. wiringpi.digitalWrite(pin_sun, 1)
  50. def startMusic(playlist):
  51. client.clear() # clear playlist
  52. client.add(playlist) # add file/directory to playlist
  53. client.shuffle() # shuffle playlist
  54. client.repeat(1) # set playback mode repeat
  55. client.setvol(80)# set volume
  56. client.play() # play
  57. def stopMusic():
  58. client.stop()
  59. def setDiscoMode():
  60. setSun('off')
  61. sleep(0.3)
  62. setKugel('on')
  63. setDmxScene('fadecolors')
  64. def setWorkingMode():
  65. setSun('on')
  66. sleep(0.3)
  67. setKugel('off')
  68. setDmxScene('black')
  69. def setOff():
  70. setSun('off')
  71. sleep(0.3)
  72. setKugel('off')
  73. setDmxScene('black')
  74. def bootstrap():
  75. wiringpi.wiringPiSetup()
  76. wiringpi.pinMode(pin_kugel, 1) # set Relay Disokugel mode to OUTPUT
  77. wiringpi.pinMode(pin_sun, 1) # set Relay Sun mode to OUTPUT # TODO: Set pin!
  78. wiringpi.pinMode(pin_pir, 0) # set PIR Sensor mode to INPUT
  79. bootstrap()
  80. dev = pyudmx.uDMXDevice()
  81. dev.open()
  82. #connect to MPD
  83. client = mpd.MPDClient()
  84. client.connect("localhost", 6600)
  85. pirstate = wiringpi.digitalRead(6)
  86. defaultscene = 1
  87. lastUsed = time.time()
  88. inUse = True
  89. inUseBefore = False
  90. timeout = 2 * 60
  91. dmxScene = 0
  92. lirc.init("disco", "./lircrc", blocking=False)
  93. # Main event loop ...
  94. while True:
  95. sleep(0.2)
  96. pirstate = wiringpi.digitalRead(pin_pir)
  97. #print('pirstate: ', pirstate)
  98. if pirstate == 1:
  99. lastUsed = time.time()
  100. inUse = True
  101. else:
  102. if(time.time() > lastUsed + timeout):
  103. inUse = False
  104. remotesignal = lirc.nextcode()
  105. if remotesignal:
  106. lastUsed = time.time() # user is active!
  107. for code in remotesignal:
  108. print('received code:', code)
  109. if(code == "mode_disco"):
  110. setDiscoMode()
  111. if(code == "mode_work"):
  112. setWorkingMode()
  113. if(code == "mode_off"):
  114. setOff()
  115. if(code == "mode_dmx_next"):
  116. print("dmxScene", dmxScene)
  117. setUserDmxScene(dmxScene)
  118. if dmxScene < len(dmxUserScenes)-1:
  119. dmxScene += 1
  120. else:
  121. dmxScene = 0
  122. if(code == "mode_music_play_1"):
  123. startMusic('1')
  124. if(code == "mode_music_play_2"):
  125. startMusic('2')
  126. if(code == "mode_music_play_3"):
  127. startMusic('3')
  128. if(code == "mode_music_play_4"):
  129. startMusic('4')
  130. if(code == "mode_music_play_5"):
  131. startMusic('5')
  132. if(code == "mode_play_fm4"):
  133. startMusic('http://185.85.28.144:8000/')
  134. if(code == "mode_music_stop"):
  135. stopMusic()
  136. if(inUseBefore != inUse):
  137. print("State change inUse:", inUseBefore, inUse)
  138. if (inUse):
  139. setDiscoMode()
  140. else:
  141. setOff()
  142. inUseBefore = inUse
  143. lirc.deinit() # Clean up lirc
  144. dev.close()