Mercurial > code > home > repos > light9
comparison light8/potserver.py @ 106:d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
author | dmcc |
---|---|
date | Sun, 21 Jul 2002 04:38:19 +0000 |
parents | 7f273883de60 |
children |
comparison
equal
deleted
inserted
replaced
105:616f8af19462 | 106:d8e2492e2947 |
---|---|
6 | 6 |
7 pots = SerialPots() | 7 pots = SerialPots() |
8 pots.golive() | 8 pots.golive() |
9 | 9 |
10 laste="" | 10 laste="" |
11 lastlevs=(0,0,0,0) | |
12 dirs=[0,0,0,0] | |
13 samples=nsends=noises=0 | |
14 watch=0 | |
11 while 1: | 15 while 1: |
16 if samples > 30: | |
17 fps=1.0*samples/(time.time()-watch) | |
18 watch=time.time() | |
19 print "S"*nsends+"n"*noises+" "*(samples-nsends-noises),"%.1f Hz"%fps | |
20 samples=nsends=noises=0 | |
21 samples+=1 | |
22 l=pots.getlevels() | |
12 | 23 |
13 l=pots.getlevels() | 24 # no change at all? |
14 | 25 if l==lastlevs: |
26 time.sleep(.01) | |
27 continue | |
28 | |
29 report=0 # we only will report if a dimmer moves twice in the same direction | |
30 for i in range(0,4): | |
31 change = l[i]-lastlevs[i] | |
32 if change!=0: | |
33 thisdir = (change>0)-(change<0) | |
34 if thisdir==dirs[i]: | |
35 # a dimmer is moving in a constant direction | |
36 report=1 | |
37 dirs[i]=thisdir | |
38 | |
39 if report==0: | |
40 noises+=1 | |
41 continue | |
42 | |
43 lastlevs = l | |
44 nsends+=1 | |
45 | |
15 try: | 46 try: |
16 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 47 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
17 s.setblocking(1) | 48 #s.setblocking(1) |
18 ret=s.connect_ex(("dash", socket.getservbyname('rlslider','tcp'))) | 49 ret=s.connect_ex(("10.1.0.32", socket.getservbyname('rlslider','tcp'))) |
19 # print ret | 50 # print ret |
20 s.send("%d %d %d %d\n" % l) | 51 s.send("%d %d %d %d\n" % l) |
21 s.close() | 52 s.close() |
22 except Exception,e: | 53 except Exception,e: |
23 print str(e) | 54 print str(e) |
24 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) | 55 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
25 if ret==111: | 56 if ret==111: |
26 print time.ctime(),"waiting for server" | 57 print time.ctime(),"waiting for server" |
27 time.sleep(3) | 58 time.sleep(3) |
28 else: | 59 else: |
29 print time.ctime(),"connected" | 60 print time.ctime(),e |
30 | 61 |
31 | 62 |
32 | 63 |