front_idill/extern/fajran-tuiojs/connector/stomp/tuio-gateway.py
changeset 25 a7b0e40bcab0
equal deleted inserted replaced
24:2bdf5d51d434 25:a7b0e40bcab0
       
     1 import tuio
       
     2 import stomp
       
     3 
       
     4 s = stomp.Connection()
       
     5 s.start()
       
     6 s.connect()
       
     7 
       
     8 cnt = 0
       
     9 
       
    10 current = []
       
    11 ld = {}
       
    12 
       
    13 t = tuio.Tracking()
       
    14 try:
       
    15 	while True:
       
    16 		t.update()
       
    17 
       
    18 		active = []
       
    19 		for c in t.cursors():
       
    20 			active.append(c.sessionid)
       
    21 
       
    22 		tbr = []
       
    23 		for c in current:
       
    24 			if c not in active:
       
    25 				tbr.append(c)
       
    26 
       
    27 		tba = []
       
    28 		for c in active:
       
    29 			if c not in current:
       
    30 				tba.append(c)
       
    31 
       
    32 		current = active
       
    33 
       
    34 		for c in tbr:
       
    35 			d = ld[c]
       
    36 			# cursor removed = 5
       
    37 			s.send("5 %d %d %f %f 0" % (c, c, d[1], d[2]), destination="/topic/home")
       
    38 			ld.pop(c)
       
    39 
       
    40 		# for c in tba:
       
    41 		# 	s.send("C N %d" % c, destination="/topic/home")
       
    42 
       
    43 		for c in t.cursors():
       
    44 			data = (c.sessionid, c.sessionid, c.xpos, c.ypos)
       
    45 			if not ld.get(c.sessionid, None) == data:
       
    46 				if c.sessionid in tba:
       
    47 					# cursor new = 3
       
    48 					msg = "3 %d %d %f %f 0" % data
       
    49 				else:
       
    50 					# cursor update = 4
       
    51 					msg = "4 %d %d %f %f 0" % data
       
    52 				s.send(msg, destination="/topic/home")
       
    53 				ld[c.sessionid] = data
       
    54 				cnt += 1
       
    55 
       
    56 except KeyboardInterrupt:
       
    57 	t.stop()
       
    58