Mercurial > code > home > repos > light9
annotate light8/ExternalInput.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 | d6c48d2d3bd6 |
children |
rev | line source |
---|---|
90
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
1 import thread, SocketServer, socket |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
2 |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
3 |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
4 currentlevels = [0,0,0,0] |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
5 |
0 | 6 |
7 class NetSliderHandler(SocketServer.StreamRequestHandler): | |
8 def handle(self): | |
9 data = self.rfile.readline(1000) | |
93
d6c48d2d3bd6
shrunk the useful range of the slider so there won't be any noise at the ends
drewp
parents:
90
diff
changeset
|
10 currentlevels[:] = [round(self.bounds(float(x)/255),3) for x in list(data.split())] |
d6c48d2d3bd6
shrunk the useful range of the slider so there won't be any noise at the ends
drewp
parents:
90
diff
changeset
|
11 def bounds(self,x): |
d6c48d2d3bd6
shrunk the useful range of the slider so there won't be any noise at the ends
drewp
parents:
90
diff
changeset
|
12 # the last .1 both ways shall not do anything |
d6c48d2d3bd6
shrunk the useful range of the slider so there won't be any noise at the ends
drewp
parents:
90
diff
changeset
|
13 x=x*1.1-.05 |
d6c48d2d3bd6
shrunk the useful range of the slider so there won't be any noise at the ends
drewp
parents:
90
diff
changeset
|
14 x=min(1,max(0,x)) |
d6c48d2d3bd6
shrunk the useful range of the slider so there won't be any noise at the ends
drewp
parents:
90
diff
changeset
|
15 return x |
0 | 16 |
90
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
17 def start_server(levelstorage=0): |
0 | 18 server = SocketServer.TCPServer( |
19 ('', socket.getservbyname('rlslider', 'tcp')), | |
20 NetSliderHandler) | |
21 server.serve_forever() | |
22 | |
23 class ExternalSliders: | |
24 def __init__(self, level_storage=[]): | |
25 self.level_storage = level_storage | |
26 self.spawn_server() | |
27 def test(self): | |
28 'Store fake inputs to test operations' | |
29 pass | |
30 def spawn_server(self): | |
31 pass | |
32 # thread.start_new_thread(start_server, (self.update)) | |
33 def update(self, *args): | |
34 self.level_storage[:] = args | |
35 def get_levels(self): | |
90
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
36 return currentlevels |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
37 # import math, time |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
38 # return [max(0, math.sin(time.time() + i)) for i in range(4)] # bogus |
0 | 39 |
40 # return self.level_storage |