Mercurial > code > home > repos > light9
annotate light8/ExternalInput.py @ 158:5c7ac46e33d3
more disabling of stuff that make no sense at certain times and some
more disabling of stuff that make no sense at certain times and some
bug fixes. still haven't fixed the scale problem
author | dmcc |
---|---|
date | Mon, 07 Jul 2003 07:39:40 +0000 |
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 |