Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from __future__ import division
  3. import threading
  4. import random
  5. import usbdmx
  6. import time
  7. import sys
  8. import datetime
  9.  
  10. dmxkill=[0]*512
  11.  
  12. def default():
  13. print "Used default configuration"
  14. interfaces = usbdmx.scan()
  15. if not interfaces:
  16. print "No interfaces found."
  17. sys.exit()
  18. global dmx
  19. dmx = interfaces[0]
  20. dmx.open()
  21. dmx.mode(6)
  22.  
  23. def fade(channel, fromvalue, tovalue, duration): ### THIS IS loopwrapper()
  24. global dmxkill
  25. dmxkill[channel]=1
  26. value=fademeta(channel, fromvalue, tovalue, duration)
  27. return channel, value
  28.  
  29. def fademeta(channel, fromvalue, tovalue, duration): ### THIS IS loop()
  30. print dmxkill[channel]
  31. global dmxkill
  32. dmxkill[channel]=0
  33. value = fromvalue
  34. if fromvalue > tovalue:
  35. difference = fromvalue-tovalue
  36. else:
  37. difference = tovalue-fromvalue
  38.  
  39. frametime=duration/difference
  40. dmx.set_dmx(channel, fromvalue)
  41. #print(value)
  42. time.sleep(frametime)
  43. while value <> tovalue:
  44. #print dmxkill[channel]
  45. if dmxkill[channel]==1:
  46. print "Dead."
  47. if fromvalue > tovalue:
  48. value-=1
  49. dmx.set_dmx(channel, value)
  50. #print(value)
  51. time.sleep(frametime)
  52. else:
  53. value+=1
  54. dmx.set_dmx(channel, value)
  55. #print(value)
  56. time.sleep(frametime)
  57. return value
  58.  
  59. def fadet(channel, fromvalue, tovalue, duration): ### THIS IS loopwrapperwrapper()
  60. t = threading.Thread(target=fade, args=(channel, fromvalue, tovalue, duration))
  61. t.start()
  62. return channel, tovalue
  63.  
  64. def flicker(channel, low, high, speed, duration):
  65. frame=duration*speed
  66. randomlast=random.randint(int(low),int(high))
  67. for i in range(frame):
  68. if i==frame:
  69. dmx.set_dmx(channel, randomlast)
  70. return channel, randomlast
  71. else:
  72. randomnow=random.randint(int(low),int(high))
  73. dmx.set_dmx(channel, randomnow)
  74. time.sleep(duration/speed/duration)
  75.  
  76. def flickert_dont_use(channel, low, high, speed, duration, randomlast):
  77. frame=duration*speed
  78. for i in range(frame):
  79. if i==frame-1:
  80. dmx.set_dmx(channel, randomlast)
  81. else:
  82. randomnow=random.randint(int(low),int(high))
  83. dmx.set_dmx(channel, randomnow)
  84. time.sleep(duration/speed/duration)
  85.  
  86.  
  87. def flickert(channel, low, high, speed, duration):
  88. randomlast=random.randint(int(low),int(high))
  89. t = threading.Thread(target=flickert_dont_use, args=(channel, low, high, speed, duration, randomlast))
  90. t.start()
  91. return channel, randomlast
  92. def setval(channel, value):
  93. dmx.set_dmx(channel, value)
  94. return channel, value
  95. def setvalt(channel, value):
  96. t = threading.Thread(target=setval, args=(channel, value))
  97. t.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement