Mercurial > code > home > repos > light9
comparison light8/potserver.py @ 0:45b12307c695
Initial revision
author | drewp |
---|---|
date | Wed, 03 Jul 2002 09:37:57 +0000 |
parents | |
children | 238fbd5266ea |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:45b12307c695 |
---|---|
1 #!/usr/bin/python | |
2 | |
3 import socket,time | |
4 | |
5 from io import * | |
6 | |
7 pots = SerialPots() | |
8 pots.golive() | |
9 | |
10 laste="" | |
11 lastlevs=(0,0,0,0) | |
12 dirs=[0,0,0,0] | |
13 samples=nsends=noises=0 | |
14 watch=0 | |
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() | |
23 | |
24 # no change at all? | |
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 | |
46 try: | |
47 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
48 #s.setblocking(1) | |
49 ret=s.connect_ex(("10.1.0.32", socket.getservbyname('rlslider','tcp'))) | |
50 # print ret | |
51 s.send("%d %d %d %d\n" % l) | |
52 s.close() | |
53 except Exception,e: | |
54 print str(e) | |
55 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
56 if ret==111: | |
57 print time.ctime(),"waiting for server" | |
58 time.sleep(3) | |
59 else: | |
60 print time.ctime(),e | |
61 | |
62 | |
63 |