console.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #! /usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. This file is part of grandPA.
  5. grandPA is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. grandPA is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with grandPA. If not, see <http://www.gnu.org/licenses/>.
  15. (c) 2012 micha.rathfelder@gmail.com
  16. """
  17. import time
  18. import socket
  19. import struct
  20. import random
  21. import chat
  22. import ArtNetNode as ANN
  23. import _thread as thread
  24. #thread.start_new_thread
  25. idmx = [0]*512 # incremental dmx
  26. dmx = [0]*512 # absolute dmx data
  27. def artnet_loop():
  28. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=12)
  29. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=0)
  30. artnet = ANN.ArtNetNode(to="10.10.10.255",univ=0)
  31. #artnet = ANN.ArtNetNode(to="2.0.0.255",univ=0)
  32. #artnet = ANN.ArtNetNode(to="10.10.10.255",univ=1)
  33. dmx[205] = 255 #205 BLUE
  34. artnet.dmx= dmx #[0]*512
  35. artnet.send()
  36. while 1:
  37. #artnet._test_frame()
  38. artnet.next()
  39. time.sleep(0.01)
  40. thread.start_new_thread(artnet_loop,())
  41. def CB(data):
  42. print("CB",data)
  43. if "cmd" in data:
  44. cmd = data["cmd"]
  45. print("cmd",cmd)
  46. if "," in cmd:
  47. cmds = cmd.split(",")
  48. else:
  49. cmds = [cmd]
  50. for xcmd in cmds:
  51. if xcmd.startswith("d"):
  52. xxcmd=xcmd[1:].split(":")
  53. print("DMX:",xxcmd)
  54. l = xxcmd
  55. try:
  56. k=int(l[0])-1
  57. v=int(l[1])
  58. if v > 255:
  59. v = 255
  60. if len(dmx) > k:
  61. dmx[k] = v
  62. except Exception as e:
  63. print("EXCEPTION IN DMX",e)
  64. chat.cmd(CB)
  65. input("END")