Mercurial > code > home > repos > light9
annotate light8/potserver.py @ 2405:69ca2b2fc133
overcomplicated attempt at persisting the pane layout in the rdf graph
this was hard because we have to somehow wait for the graph to load before config'ing the panes
author | drewp@bigasterisk.com |
---|---|
date | Fri, 17 May 2024 16:58:26 -0700 |
parents | d8e2492e2947 |
children |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 | |
91
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
3 import socket,time |
0 | 4 |
5 from io import * | |
6 | |
7 pots = SerialPots() | |
8 pots.golive() | |
9 | |
91
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
10 laste="" |
106
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
11 lastlevs=(0,0,0,0) |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
12 dirs=[0,0,0,0] |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
13 samples=nsends=noises=0 |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
14 watch=0 |
0 | 15 while 1: |
106
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
16 if samples > 30: |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
17 fps=1.0*samples/(time.time()-watch) |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
18 watch=time.time() |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
19 print "S"*nsends+"n"*noises+" "*(samples-nsends-noises),"%.1f Hz"%fps |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
20 samples=nsends=noises=0 |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
21 samples+=1 |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
22 l=pots.getlevels() |
91
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
23 |
106
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
24 # no change at all? |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
25 if l==lastlevs: |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
26 time.sleep(.01) |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
27 continue |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
28 |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
29 report=0 # we only will report if a dimmer moves twice in the same direction |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
30 for i in range(0,4): |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
31 change = l[i]-lastlevs[i] |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
32 if change!=0: |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
33 thisdir = (change>0)-(change<0) |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
34 if thisdir==dirs[i]: |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
35 # a dimmer is moving in a constant direction |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
36 report=1 |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
37 dirs[i]=thisdir |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
38 |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
39 if report==0: |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
40 noises+=1 |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
41 continue |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
42 |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
43 lastlevs = l |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
44 nsends+=1 |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
45 |
0 | 46 try: |
47 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
106
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
48 #s.setblocking(1) |
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
49 ret=s.connect_ex(("10.1.0.32", socket.getservbyname('rlslider','tcp'))) |
91
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
50 # print ret |
0 | 51 s.send("%d %d %d %d\n" % l) |
52 s.close() | |
53 except Exception,e: | |
91
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
54 print str(e) |
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
55 s=socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
56 if ret==111: |
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
57 print time.ctime(),"waiting for server" |
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
58 time.sleep(3) |
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
59 else: |
106
d8e2492e2947
results of 7.20 show, potserver and tracks finally in CVS
dmcc
parents:
91
diff
changeset
|
60 print time.ctime(),e |
0 | 61 |
62 | |
91
7f273883de60
messed with the server a lot. it works, though doesnt do persistent conenctions
drewp
parents:
88
diff
changeset
|
63 |