vpu2_live.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. import math
  2. import random
  3. import time
  4. import os
  5. HOME = os.getenv('HOME')
  6. from optparse import OptionParser
  7. ...
  8. parser = OptionParser()
  9. parser.add_option("-m", "--mode", dest="mode",
  10. help="pixel mode") #, metavar="FILE")
  11. parser.add_option("-X", "--XX", dest="XX", #default=1,
  12. help="x-split") #, metavar="FILE")
  13. parser.add_option("-x", "--xx", dest="xsplit", #default=1,
  14. help="x-split") #, metavar="FILE")
  15. parser.add_option("-y", "--yy", dest="ysplit",#default=1,
  16. help="y-split") #, metavar="FILE")
  17. #parser.add_option("-f", "--file", dest="filename",
  18. # help="write report to FILE", metavar="FILE")
  19. #parser.add_option("-q", "--quiet",
  20. # action="store_false", dest="verbose", default=True,
  21. # help="don't print status messages to stdout")
  22. (options, args) = parser.parse_args()
  23. START = time.time()
  24. # ===== ARTNET DMX =========
  25. import memcache
  26. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  27. def read_index():
  28. ips=mc.get("index")#cmd)
  29. if ips is None:
  30. ips = {}
  31. #for k,v in ips.items():
  32. # print(k,v)
  33. return ips
  34. def select_ip(ips, univ=2): # artnet univ
  35. _univ = ":{}".format(univ)
  36. for ip in ips: #high priority
  37. if "2.0.0" in ip and _univ in ip:
  38. return ip
  39. for ip in ips:
  40. if "ltp-out" in ip and _univ in ip:
  41. return ip
  42. FUNC = 0
  43. def read_dmx(ip):
  44. global frame
  45. r = ""
  46. if ip:
  47. #t = int(math.sin(time.time() - s)*10)
  48. r = mc.get(ip) #"2.0.0.13:2")
  49. frame += 1
  50. rr = [0]*512
  51. for i,v in enumerate(r):
  52. try: #cleanup ltp-out to int
  53. v = int(v)
  54. rr[i] = v
  55. except:pass
  56. r = rr
  57. if not r:
  58. c = 0
  59. #time.sleep(0.1)
  60. r = [0] *512
  61. for i in range(12*8+1):
  62. dmx = i*4
  63. #print(dmx)
  64. r[dmx:dmx+4] = [255,10,10,40]
  65. return r
  66. # ===== ARTNET DMX =========
  67. p = 16
  68. block = [p,p]
  69. _x = 8
  70. _y = 8
  71. #HD = "0"
  72. if options.mode:
  73. try:
  74. HD = options.mode
  75. p,_x,_y = HD.split(",")
  76. _x = int(_x)
  77. _y = int(_y)
  78. p = int(p)
  79. block = [p,p]
  80. except Exception as e:
  81. print( "Exc",options.mode,e)
  82. HD_x = 2
  83. HD_y = 2
  84. print( [options.xsplit])
  85. print( [options.ysplit])
  86. try:
  87. if options.xsplit:
  88. HD_x = int(options.xsplit)
  89. if options.ysplit:
  90. HD_y = int(options.ysplit)
  91. except Exception as e:
  92. print( "Exc",options.mode,e)
  93. print("HD",HD_x,HD_y)
  94. print("xy",_x,_y)
  95. print("++++++++++++++++++", p,_x,_y)
  96. _x2 = _x
  97. try:
  98. if options.XX:
  99. _x2 = int(options.XX)
  100. except Exception as e:
  101. print( "Exc",options.mode,e)
  102. print("_x2 , -X",_x2)
  103. # ===== GUI =========
  104. import pygame
  105. import pygame.gfxdraw
  106. import pygame.font
  107. os.environ['SDL_VIDEO_WINDOW_POS'] = '%i,%i' % (200,164)
  108. os.environ['SDL_VIDEO_CENTERED'] = '0'
  109. pg = pygame
  110. pygame.init()
  111. pygame.mixer.quit()
  112. f = pygame.font.get_fonts()
  113. for i in f:
  114. if "mono" in i.lower():
  115. print(i)
  116. font = pygame.font.SysFont("freemonobold",22)
  117. font10 = pygame.font.SysFont("freemonobold",10)
  118. font12 = pygame.font.SysFont("freemonobold",12)
  119. font15 = pygame.font.SysFont("freemonobold",15)
  120. #font = pygame.font.SysFont(None,30)
  121. fr = font.render("hallo" ,1, (200,0,255))
  122. main_size=(600,500)
  123. try:
  124. wx = 100+block[0] * _x
  125. wy = 100+block[1] * _y
  126. main_size=(wx,wy)
  127. except Exception as e:
  128. print("Exception:",e)
  129. #main_size=(280,200)
  130. window = pygame.display.set_mode(main_size,pg.RESIZABLE)#,32)#,pygame.FULLSCREEN) #x left->right ,y top-> bottom
  131. pg.display.set_caption('LibreLight LED-SCREEN')
  132. class Fix():
  133. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  134. #print("Fix",_id)
  135. self._id = _id
  136. self.dmx = (_id-1) * ch +1 #dmx
  137. self.univ = univ
  138. self.ch = ch
  139. self.pos = pos
  140. self.rgb = [0,0,0]
  141. self.block = block #[10,10]
  142. self.x = pos[0]
  143. self.y = pos[1]
  144. self.strobo = time.time()
  145. self.bmp = 250
  146. self.sub_fix = []
  147. sub_block =[block[0]/HD_x,block[1]/HD_y]
  148. if _id <= 0: #exit
  149. return
  150. spalte = (_id-1)%_y +1
  151. zeile = int((_id-1)/_x2) #+1
  152. #zeile = zeile*_x*HD_x*HD_y
  153. add_row = _x*HD_x*HD_y
  154. #zeile 1
  155. sid = (_id-1)*2 + zeile*HD_x*_x2
  156. #for i in range(1,HD_x):
  157. sid = sid+1
  158. #sid = zeile
  159. sub_pos= [pos[0]*block[0],pos[1]*block[1]]
  160. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  161. self.sub_fix.append(sub_fix)
  162. sid = sid+1
  163. #sid = zeile
  164. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]]
  165. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  166. self.sub_fix.append(sub_fix)
  167. #zeile 2
  168. sid = (_id-1)*2+1 + _x2*HD_x + zeile*HD_x*_x2 # int(add_row)
  169. #sid = sid+1
  170. #sid = HD_x
  171. sub_pos= [pos[0]*block[0],pos[1]*block[1]+block[1]/2]
  172. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  173. self.sub_fix.append(sub_fix)
  174. #sid = sid+1
  175. sid = sid+1
  176. sub_pos= [pos[0]*block[0]+block[0]/2,pos[1]*block[1]+block[1]/2]
  177. sub_fix = SubFix(sid,sub_pos,sub_block,univ,dmx,ch)
  178. self.sub_fix.append(sub_fix)
  179. def calc(self,data):
  180. _rgb = [0,255,0]
  181. return _rgb
  182. def sub_calc(self,data):
  183. _rgb = [0,255,0]
  184. for sub_fix in self.sub_fix:
  185. sub_fix.block = self.block[:]
  186. _rgb = sub_fix.calc(data)
  187. return _rgb
  188. def POS(self,x=0,y=0,a=0,b=0):
  189. A = (self.pos[0])*self.block[0]
  190. B = (self.pos[1])*self.block[1]
  191. C = self.block[0]-a
  192. D = self.block[1]-b
  193. return [x+A,y+B,C,D]
  194. def subPOS(self,x=0,y=0,a=0,b=0):
  195. __out = []
  196. for sub_fix in self.sub_fix:
  197. __out.append( sub_fix.POS(x,y,a,b) )
  198. return __out
  199. class SubFix():
  200. def __init__(self,_id,pos,block=[16,16],univ=0,dmx=0,ch=4):
  201. #print("Fix",_id)
  202. self._id = _id
  203. self.dmx = (_id-1) * ch +1 #dmx
  204. self.univ = univ
  205. self.ch = ch
  206. self.pos = pos
  207. self.rgb = [0,0,40]
  208. self.block = block #[10,10]
  209. self.x = pos[0]
  210. self.y = pos[1]
  211. self.strobo = time.time()
  212. self.bmp = 250
  213. def calc(self,data):
  214. #return [130,30,20]
  215. dmx_sub = [30]*10
  216. #print(dmx_sub)
  217. dmx = self.dmx -1
  218. _dmx_sub = []
  219. if self.dmx >= 0:
  220. dmx = rDMX(self.univ,self.dmx)-1
  221. if dmx+self.ch < len(data):
  222. _dmx_sub = data[dmx:dmx+self.ch]
  223. if _dmx_sub:
  224. dmx_sub = _dmx_sub
  225. #print(dmx_sub)
  226. dim = dmx_sub[0]/255
  227. #print("dmx",dmx,dmx_sub)
  228. r = dmx_sub[1]*dim
  229. g = dmx_sub[2]*dim
  230. b = dmx_sub[3]*dim
  231. r = int(r)
  232. g = int(g)
  233. b = int(b)
  234. self.rgb = [r,g,b]
  235. return self.rgb
  236. def POS(self,x=0,y=0,a=0,b=0):
  237. A = (self.pos[0]) #+self.block[0]
  238. B = (self.pos[1]) #+self.block[1]
  239. C = self.block[0]-a
  240. D = self.block[1]-b
  241. if NR:
  242. C-=1
  243. D-=1
  244. return [int(x+A),int(y+B),int(C),int(D)]
  245. class POINTER():
  246. def __init__(self):
  247. self.pos = [0,0,0,0]
  248. self.on = 0
  249. self.rgb = [0,100,10]
  250. self._x = 0
  251. self._y = 0
  252. self.x = 0
  253. self.y = 0
  254. self.fix = Fix(0 ,[999,999],[16,16],0,0,0)
  255. def row_move(self,x,y):
  256. self._x = x
  257. self._y = y
  258. def move(self,pos):
  259. self.pos = pos
  260. self.on = 1
  261. def cross(self,x,y):
  262. self.x = x
  263. self.y = y
  264. def draw(self):
  265. if self.on:
  266. pygame.draw.rect(window,self.rgb,self.pos)
  267. #pygame.draw.line(window,self.rgb, (self.pos[0],self.pos[1]) , (self.pos[0]+100,self.pos[1]) )
  268. # mouse grid posision
  269. fr = font15.render("{}/{}".format(self.fix.x+1,self.fix.y) ,1, (200,200,200))
  270. _nr = self.fix.y * _x + self.fix.x +1
  271. #fr = font15.render("{:02} {}/{}".format(_nr, self.fix.x+1,self.fix.y+1 ) ,1, (200,200,200))
  272. fr = font15.render("{:02}".format(_nr ) ,1, (200,200,200))
  273. window.blit(fr,(self.pos[0]+2,self.pos[1]+2 ))
  274. window.blit(fr,(200,25))
  275. # fix pos
  276. txt=str(self.pos)
  277. fr = font15.render(txt ,1, (200,200,200))
  278. #window.blit(fr,(self.pos[0]+2,self.pos[1]+2 ))
  279. window.blit(fr,(200,10))
  280. # univers
  281. #fr = font15.render("{:02}:{:03}".format(self.fix.univ,self.fix.dmx) ,1, (200,200,200))
  282. #window.blit(fr,(300,10))
  283. # pointer
  284. fr = font15.render("X:{:03}".format(self._x) ,1, (200,200,200))
  285. window.blit(fr,(10,30))
  286. fr = font15.render("Y:{:03}".format(self._y) ,1, (200,200,200))
  287. window.blit(fr,(10,40))
  288. # crosshair
  289. self.rgb = [0,0,200]
  290. pygame.draw.line(window,self.rgb, (self.x-p,self.y) , (self.x-2,self.y) )
  291. pygame.draw.line(window,self.rgb, (self.x,self.y-p) , (self.x,self.y-2) )
  292. self.rgb = [0,200,0]
  293. pygame.draw.line(window,self.rgb, (self.x+2,self.y) , (self.x+p,self.y) )
  294. pygame.draw.line(window,self.rgb, (self.x,self.y+2) , (self.x,self.y+p) )
  295. self.rgb = [200,0,0]
  296. pointer = POINTER()
  297. NR = 0
  298. running = True
  299. def event():
  300. global NR,running
  301. for event in pygame.event.get():
  302. #print(event.dict)
  303. _button = None
  304. if "button" in event.dict:
  305. _button = event.dict["button"]
  306. _state = None
  307. if "state" in event.dict:
  308. _state = event.state
  309. _key = None
  310. if "key" in event.dict:
  311. _key = event.key
  312. _pos = None
  313. if "pos" in event.dict:
  314. _pos = event.pos
  315. _type = None
  316. if "type" in event.dict:
  317. _type = event.type
  318. _type = event.type
  319. _mod = None
  320. if "mod" in event.dict:
  321. _mod = event.mod
  322. print( " ")
  323. print( "{:.02f}".format( time.time() - START ))
  324. print("button -",_button,end="\t| ")
  325. #print("state -",_state)
  326. print("pos -",_pos)
  327. print("type -",_type, end="\t| ")
  328. print("key -",_key)
  329. print("mod -",_mod)
  330. try:
  331. if _type == 5:
  332. if _button == 1:
  333. NR += 1
  334. if NR > 1:
  335. NR = 0
  336. if _button == 3:
  337. NR -= 1
  338. if NR < 0:
  339. NR = 1
  340. if _pos:
  341. posA = _pos
  342. fix = find_pix(_pos[0]-40,_pos[1]-60)
  343. if fix:
  344. pos = fix.POS(40,60)
  345. rgb = [0,0,0]
  346. pointer.move(pos)
  347. pointer.fix = fix
  348. else:
  349. pointer.on = 0
  350. pointer.row_move(_pos[0],_pos[1])
  351. pointer.cross(_pos[0],_pos[1])
  352. if event.type == pygame.VIDEORESIZE:
  353. window = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
  354. except Exception as e:
  355. print(e)
  356. if event.type==pygame.QUIT:
  357. running=False
  358. fps = 0
  359. frame = 0
  360. frame_t = time.time()
  361. IP = "yyy"
  362. def draw_overlay():
  363. global fps
  364. fr = font.render("FPS:{}".format(fps) ,1, (200,0,255))
  365. window.blit(fr,(10,10))
  366. fr = font.render("ip:{}".format(IP) ,1, (200,0,255))
  367. window.blit(fr,(80,10))
  368. def calc_fps():
  369. global fps,frame,frame_t
  370. t = time.time()
  371. if frame_t+1 < t:
  372. fps = frame #frame_t- t #frame
  373. frame = 1
  374. frame_t = time.time()
  375. # ===== GUI =========
  376. #def draw_circle(surface, x, y, radius, color):
  377. def draw_circle(surface,color, pos, radius):
  378. x,y=pos
  379. pygame.gfxdraw.aacircle(surface, int(x), int(y), radius-1, color)
  380. pygame.gfxdraw.filled_circle(surface, int(x), int(y), radius-1, color)
  381. def rDMX(univ,dmx):
  382. return univ*512+dmx
  383. grid_file = "/tmp/vpu_grid.csv"
  384. grid_file = HOME+"/LibreLight/vpu_grid_hd.csv"
  385. def generate_grid():
  386. log = open(grid_file,"w")
  387. head = "i,univ,dmx,x,y,ch\n"
  388. head = "i,univ,dmx,ch\n"
  389. head = "univ,dmx,x,y,ch\n"
  390. head = "nr,id,info\n"
  391. print("csv:",head)
  392. log.write(head)
  393. dmx = 1-1
  394. ch = 4
  395. y=0
  396. x=0
  397. for i in range((_y)*(_x)):
  398. if x > _x and i%_x == 0:
  399. print("--> -->")
  400. x=0
  401. y+=1
  402. _univ = int(dmx/512)
  403. _dmx = dmx - (_univ)*512
  404. pos=[x,y]
  405. line="{},{},{},{},{},{}\n".format(i+1,_univ,_dmx+1,pos[0],pos[1],ch)
  406. line="{},{},{},{},{}\n".format(_univ,_dmx+1,x,y,ch)
  407. line="{},{},x\n".format(i+1,i+1)
  408. print("wcsv:",[line])
  409. log.write(line)
  410. dmx += ch
  411. x+=1
  412. log.close()
  413. return GRID
  414. def init_grid():
  415. try:
  416. log = open(grid_file,"r")
  417. except:
  418. generate_grid()
  419. log = open(grid_file,"r")
  420. lines = log.readlines()
  421. GRID = []
  422. y=0
  423. x=0
  424. print("CSV header",[lines[0]])
  425. for i,line in enumerate(lines[1:]): #exclude first line
  426. #print("rcsv",[line])
  427. line = line.strip()
  428. line = line.split(",") # csv
  429. if i >= _x and i%_x == 0:
  430. x=0
  431. y+=1
  432. if y > _y:
  433. break
  434. #i = int(line[0])
  435. _id = int(line[1])
  436. #univ = int(line[0])
  437. #dmx = int(line[1])
  438. #x = int(line[3])
  439. #y = int(line[4])
  440. #ch = int(line[4])
  441. pos = [x,y]
  442. f = Fix(_id,pos,block) #pos,univ,dmx,ch)
  443. #f.x = x
  444. #f.y = y
  445. #f.block = block
  446. GRID.append(f)
  447. x+=1
  448. #print("y, _y",y,_y)
  449. return GRID
  450. def find_pix(x,y):
  451. global GRID
  452. for fix in GRID:
  453. X = 0
  454. Y = 0
  455. pos = fix.POS()
  456. if x > pos[0] and x < pos[0]+pos[2]:
  457. X = 1
  458. if y > pos[1] and y < pos[1]+pos[3]:
  459. Y = 1
  460. if X and Y:
  461. print(pos,x,y)
  462. print("find",X,Y)
  463. return fix
  464. def draw_gobo(window,FUNC,spos,srgb):
  465. #print(fix.dmx,rgb,pos)
  466. #pygame.draw.circle(window,rgb,(pos[0]+int(pos[2]/2),pos[1]+int(pos[3]/2)),int(pos[3]/2))
  467. if FUNC > 10 and FUNC <= 20: # big dot
  468. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  469. elif FUNC > 20 and FUNC <= 30:#small dot
  470. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  471. elif FUNC > 30 and FUNC <= 40:#donut
  472. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  473. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  474. elif FUNC > 40 and FUNC <= 50: # rec with hole
  475. pygame.draw.rect(window,srgb,spos)
  476. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  477. elif FUNC > 50 and FUNC <= 60: # rec with big hole
  478. pygame.draw.rect(window,srgb,spos)
  479. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  480. elif FUNC > 60 and FUNC <= 70: # rec with donat
  481. pygame.draw.rect(window,srgb,spos)
  482. draw_circle(window,[0,0,0],(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/2))
  483. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  484. elif FUNC > 70 and FUNC <= 80: # rec boarder
  485. pygame.draw.rect(window,srgb,[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  486. elif FUNC > 80 and FUNC <= 90: # rec big boarder
  487. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  488. elif FUNC > 90 and FUNC <= 100: # rec thin line
  489. pygame.draw.rect(window,srgb,spos)
  490. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  491. elif FUNC > 100 and FUNC <= 110: # rec big line
  492. pygame.draw.rect(window,srgb,spos)
  493. pygame.draw.rect(window,[0,0,0],[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  494. elif FUNC > 110 and FUNC <= 120: # rec with dot
  495. pygame.draw.rect(window,srgb,spos)
  496. pygame.draw.rect(window,[0,0,0],[spos[0]+1,spos[1]+1,spos[2]-2,spos[3]-2])
  497. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  498. elif FUNC > 120 and FUNC <= 130: # rec inline
  499. pygame.draw.rect(window,srgb,[spos[0]+2,spos[1]+2,spos[2]-4,spos[3]-4])
  500. pygame.draw.rect(window,[0,0,0],[spos[0]+3,spos[1]+3,spos[2]-6,spos[3]-6])
  501. elif FUNC > 130 and FUNC <= 140: # 3 dot (heart)
  502. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)+2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  503. draw_circle(window,srgb,(spos[0]+int(spos[2]/2)-2,spos[1]+int(spos[3]/2)),int(spos[3]/3.5))
  504. draw_circle(window,srgb,(spos[0]+int(spos[2]/2),spos[1]+int(spos[3]/2)+2),int(spos[3]/3.5))
  505. else:
  506. pygame.draw.rect(window,srgb,spos)
  507. GRID = []
  508. NR = 0
  509. START_UNIV=2
  510. def main():
  511. global IP,GRID,FUNC
  512. counter = time.time()
  513. GRID = init_grid() #init_gird()
  514. print("GRID LEN:",len(GRID))
  515. s=time.time()
  516. print("run")
  517. r = ""
  518. IP = "xx"
  519. while running:
  520. pygame.display.flip()
  521. event()
  522. window.fill((0,0,0))
  523. calc_fps()
  524. draw_overlay()
  525. ips = read_index()
  526. ip = select_ip(ips,univ=START_UNIV)
  527. IP = ip
  528. #print("IP",ip)
  529. data = read_dmx(ip)
  530. ip = select_ip(ips,univ=START_UNIV+1)
  531. data3 = read_dmx(ip)
  532. data.extend(data3)
  533. ip = select_ip(ips,univ=START_UNIV+2)
  534. data3 = read_dmx(ip)
  535. data.extend(data3)
  536. #ip = select_ip(ips,univ=START_UNIV+4)
  537. #data3 = read_dmx(ip)
  538. #data.extend(data3)
  539. # GRID loop
  540. try:
  541. ddd = 1023 #univ 3 512
  542. FUNC = data[ddd]
  543. #print("FUNC", FUNC )#:ddd+512])
  544. #FUNC = 15
  545. except Exception as e:
  546. print("EXC FUNC",e)
  547. i = 0
  548. dmx = 1
  549. h = 1
  550. v = 1
  551. for fix in GRID:
  552. pos = fix.POS(40,60)
  553. rgb = fix.rgb
  554. if 1:
  555. # draw row/col grid number
  556. if fix.pos[0] == 0:
  557. fr = font12.render("{}".format(fix.pos[1]+1) ,1, (200,200,200))
  558. window.blit(fr,(10,pos[1]+3 ))
  559. if fix.pos[1] == 0:
  560. fr = font12.render("{}".format(fix.pos[0]+1) ,1, (200,200,200))
  561. window.blit(fr,(pos[0]+2,35 ))
  562. pygame.draw.rect(window,rgb,pos)
  563. # DRAW SUB-FIXTURE
  564. j = 0
  565. for subfix in fix.sub_fix:#calc(data):
  566. subfix.calc(data)
  567. #fix = subfix
  568. spos = subfix.POS(40,60)
  569. srgb = subfix.rgb
  570. draw_gobo(window,FUNC,spos=spos,srgb=srgb)
  571. # draw row/col grid number
  572. if subfix.pos[0] == 0:
  573. fr = font12.render("{}".format(v ) ,1, (200,200,200))
  574. window.blit(fr,(25,spos[1] ))
  575. v += 1
  576. if subfix.pos[1] == 0:
  577. fr = font12.render("{}".format(1) ,1, (200,200,200))
  578. fr = font12.render("{}".format(h ) ,1, (200,200,200))
  579. h+=1
  580. window.blit(fr,(spos[0],50 ))
  581. if p >= 40:
  582. if NR:
  583. #fr = font15.render("{:02}".format(j+1) ,1, (0,200,255))
  584. fr = font15.render("{:02}".format(subfix._id) ,1, (250,200,5))
  585. window.blit(fr,(spos[0]+2,spos[1]+10))
  586. j += 1
  587. i += 1
  588. # DRAW FIX NUMBER on TOP
  589. i=0
  590. for fix in GRID:
  591. pos = fix.POS(40,60)
  592. rgb = fix.rgb
  593. if NR:
  594. pygame.draw.rect(window,[0,0,0],[pos[0]+2,pos[1]+2,12,9])
  595. #if NR == 1:
  596. # fr = font15.render("{:02}".format(i+1) ,1, (200,0,255))
  597. # window.blit(fr,(pos[0]+2,pos[1]+2))
  598. #elif NR == 2:
  599. if NR:# == 2:
  600. if counter +5 < time.time():
  601. counter = time.time()
  602. try:
  603. GRID = init_grid() #init_gird()
  604. except Exception as e:
  605. print("Except: grid re init",e)
  606. if fix._id != i+1:
  607. fr = font15.render("{:02}".format(fix._id) ,1, (255,255,0))
  608. else:
  609. fr = font15.render("{:02}".format(fix._id) ,1, (100,100,255))
  610. window.blit(fr,(pos[0]+2,pos[1]+2))
  611. i += 1
  612. #color=window.get_at((70, 70))
  613. #print("pix",color)
  614. #surface.set_at((x, y), color)
  615. #from pygame import gfxdraw
  616. #gfxdraw.pixel(surface, x, y, color)
  617. pointer.draw()
  618. pygame.display.flip()
  619. pg.time.wait(30)
  620. if __name__ == "__main__":
  621. main()