oszi_grid.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. # -*- coding: UTF-8 -*-
  2. import os
  3. import fcntl
  4. import time
  5. import socket
  6. import struct
  7. import random
  8. from optparse import OptionParser
  9. parser = OptionParser()
  10. parser.add_option("-r", "--recive", dest="recive",
  11. help="set recive ip like --recive 10.")
  12. parser.add_option("-s", "--sendto", dest="sendto",
  13. help="set sender ip like --sendto 2.255.255.255")
  14. parser.add_option("-t", "--test", dest="testuniv",
  15. help="set test univers like --test [0-16]")
  16. parser.add_option("", "--inmap", dest="inmap",
  17. help="set test univers like --test [0-16]")
  18. #parser.add_option("-q", "--quiet",
  19. # action="store_false", dest="verbose", default=True,
  20. # help="don't print status messages to stdout")
  21. (options, args) = parser.parse_args()
  22. print("option",options)
  23. print(options.sendto)
  24. x=0
  25. y=0
  26. running = True
  27. import pygame
  28. import pygame.gfxdraw
  29. pygame.init()
  30. screen = pygame.display.set_mode((780, 610))
  31. pygame.display.set_caption("pygame: DMX OSZI 2.01")
  32. pygame.mouse.set_visible(1)
  33. pygame.key.set_repeat(1, 30)
  34. clock = pygame.time.Clock()
  35. pygame.init()
  36. import copy
  37. import _thread as thread
  38. import sys
  39. font = pygame.font.SysFont("FreeSans", 12) #,color=(255,0,0))
  40. class Trans():
  41. def __init__(self,y=150):
  42. self.y = 150
  43. self.s = 0.25
  44. def get_y(self,y):
  45. return int((y*self.s)+(self.y*self.s))*-1
  46. T = Trans()
  47. class OSZI():
  48. def __init__(self):
  49. self._x=0
  50. self.sdata={}
  51. self.lz = time.time()
  52. self.c=0
  53. def draw(self,screen,data):#,c,x,y,T):
  54. x=int(self._x)
  55. if time.time() > self.lz:
  56. self.lz = time.time()+6
  57. self._x=0
  58. x=0
  59. rec = pygame.Rect(x+1,T.get_y(10),30,245) # clear balken
  60. pygame.draw.rect(screen,(10,10,0),rec)
  61. T.y=-260
  62. c=0
  63. for d in data:
  64. y=d
  65. pygame.gfxdraw.pixel(screen,x,T.get_y(255),(255,0,0))
  66. pygame.gfxdraw.pixel(screen,x,T.get_y(0),(10,10,25))
  67. rec = pygame.Rect(x+4,T.get_y(0),20,-80) # clear balken
  68. pygame.draw.rect(screen,(c,210,110),rec)
  69. rec = pygame.Rect(x+2,T.get_y(0),30,-80) # clear balken
  70. pygame.draw.rect(screen,(c,10,110),rec)
  71. text = font.render( str(y), True, (0,0,0))
  72. pygame.draw.circle(screen,(255,155,0),(x,T.get_y(y)),2)
  73. c+=50
  74. if c >255:
  75. c=255
  76. T.y-=275
  77. #_x+=3.5*2
  78. self._x+=1.5*2
  79. def read_event():
  80. running = True
  81. for event in pygame.event.get():
  82. if event.type == pygame.QUIT:
  83. running = False
  84. if event.type == pygame.KEYDOWN:
  85. print(event.type)
  86. if event.key == pygame.K_ESCAPE:
  87. pygame.event.post(pygame.event.Event(pygame.QUIT))
  88. return running
  89. class GRID():
  90. def __init__(self):
  91. self.grid_timer = time.time()
  92. def draw(self,xsdata):
  93. grid_timer = self.grid_timer
  94. if grid_timer > time.time():
  95. return
  96. grid_timer=time.time()+.0215
  97. for d in xsdata:
  98. xx=sdata[d]
  99. univ = xx["head"][6] //256 #/ 255
  100. if xx["host"].startswith('2.0.0.'):
  101. if univ == 0:
  102. rx=308
  103. ry=10
  104. rec = pygame.Rect(rx,ry,600,600) # clear balken
  105. pygame.draw.rect(screen,(20,20,20),rec)
  106. text = font.render( str(univ).rjust(3," "), True, (255,255,255))
  107. screen.blit(text, ( rx-10, ry ) )
  108. line = []
  109. for i,dmx in enumerate(xx["dmx"]):
  110. text = font.render( str(dmx).rjust(3," "), True, (255,255,255))
  111. screen.blit(text, ( rx+10, ry+10 ) )
  112. rx+=29
  113. if (i+1) % 20 == 0:
  114. rx=308
  115. ry+=11
  116. elif univ == 1:
  117. rx=8
  118. ry=310
  119. rec = pygame.Rect(rx,ry,600,600) # clear balken
  120. pygame.draw.rect(screen,(10,30,10),rec)
  121. text = font.render( str(univ).rjust(3," "), True, (255,255,255))
  122. screen.blit(text, ( rx-10, ry ) )
  123. line = []
  124. for i,dmx in enumerate(xx["dmx"]):
  125. text = font.render( str(dmx).rjust(3," "), True, (255,200,255))
  126. screen.blit(text, ( rx+10, ry+10 ) )
  127. rx+=29
  128. if (i+1) % 20 == 0:
  129. rx=8
  130. ry+=11
  131. _ips = {}
  132. def print_ips(sdata):
  133. if int(time.time()*10) % 20 == 0:
  134. for k in sdata:
  135. if k in _ips:
  136. _ips[k] += 1
  137. else:
  138. _ips[k] = 0
  139. print(k.ljust(15," "),_ips[k])
  140. print()
  141. grid_a = GRID()
  142. oszi_a = OSZI()
  143. import artnet_read
  144. e = artnet_read.ArtNetRead()
  145. thread.start_new_thread(e.loop,())
  146. while running:
  147. clock.tick(15)
  148. #clock.tick(225)
  149. #print(dir(e),e)
  150. #exit()
  151. sdata = e.get()
  152. xsdata = copy.deepcopy(sdata)
  153. print_ips(sdata)
  154. data = artnet_read.get_value(sdata,univ=1,dmx=[21,142,261,263])
  155. running = read_event()
  156. oszi_a.draw(screen,data) #,c,x,y,T)
  157. grid_a.draw(xsdata)
  158. pygame.display.flip()