console.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 lib.chat as chat
  22. import lib.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. class Main():
  41. def __init__(self):
  42. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=12)
  43. #artnet = ANN.ArtNetNode(to="127.0.0.1",port=6555,univ=0)
  44. #artnet = ANN.ArtNetNode(to="2.0.0.255",univ=0)
  45. #artnet = ANN.ArtNetNode(to="10.10.10.255",univ=1)
  46. self.artnet = ANN.ArtNetNode(to="10.10.10.255",univ=0)
  47. self.fx = {} # key is dmx address
  48. def loop(self):
  49. #dmx[205] = 255 #205 BLUE
  50. self.artnet.dmx= dmx #[0]*512
  51. self.artnet.send()
  52. while 1:
  53. #artnet._test_frame()
  54. self.artnet.next()
  55. time.sleep(0.01)
  56. main = Main()
  57. #thread.start_new_thread(artnet_loop,())
  58. thread.start_new_thread(main.loop,())
  59. def split_cmd(data):
  60. if "cmd" in data:
  61. cmd = data["cmd"]
  62. print("cmd",cmd)
  63. if "," in cmd:
  64. cmds = cmd.split(",")
  65. else:
  66. cmds = [cmd]
  67. return cmds
  68. def CB(data):
  69. print("CB",data)
  70. cmds = split_cmd(data)
  71. for xcmd in cmds:
  72. if xcmd.startswith("d"):
  73. xxcmd=xcmd[1:].split(":")
  74. print("DMX:",xxcmd)
  75. l = xxcmd
  76. try:
  77. k=int(l[0])-1
  78. v=int(l[1])
  79. if v > 255:
  80. v = 255
  81. if len(dmx) > k:
  82. dmx[k] = v
  83. except Exception as e:
  84. print("EXCEPTION IN DMX",e)
  85. chat.cmd(CB) # server listener
  86. input("END")