comparison bin/gyrocontroller @ 253:a92b6d1ac072

SubClient created, keyboardcomposer and gyrocontroller use it now Plus some minor cleanups in keyboardcomposer and gyrocontroller
author David McClosky <dmcc@bigasterisk.com>
date Wed, 15 Jun 2005 04:28:16 +0000
parents 89cd37c4314b
children 1546c423b467
comparison
equal deleted inserted replaced
252:40e7d08e0123 253:a92b6d1ac072
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # vi: syntax=python 2 # vi: syntax=python
3 3
4 from __future__ import division
5 import run_local 4 import run_local
6 from light9.Submaster import combine_subdict 5 from light9.Submaster import combine_subdict
7 from light9 import dmxclient, showconfig 6 from light9.subclient import SubClient
8 7
9 class circcycle: 8 class circcycle:
10 """Like itertools.cycle, but with a prev() method too. You lose 9 """Like itertools.cycle, but with a prev() method too. You lose
11 all iterator benefits by using this, since it will store the whole 10 all iterator benefits by using this, since it will store the whole
12 sequence/iterator in memory. Also, do not run this on an infinite 11 sequence/iterator in memory. Also, do not run this on an infinite
25 def prev(self): 24 def prev(self):
26 ret = self.sequence[self.index] 25 ret = self.sequence[self.index]
27 self._change_index(-1) 26 self._change_index(-1)
28 return ret 27 return ret
29 28
30 class AbstractSimpleController: 29 class AbstractSimpleController(SubClient):
31 """Simple controller with minimal input and output: 30 """Simple controller with minimal input and output:
32 31
33 Input is 4 directions and 3 buttons. 32 Input is 4 directions and 3 buttons.
34 Output is an integer and a color and maybe more. 33 Output is an integer and a color and maybe more.
35 34
36 Left + B1/right + B1: prev/next sub 35 Left + B1/right + B1: prev/next sub
37 Y-axis + B2: set current level 36 Y-axis + B2: set current level
38 B3: toggle keep/solo mode 37 B3: toggle keep/solo mode
39 Double-B3: clear kept levels""" 38 Double-B3: clear kept levels"""
40 def __init__(self, subnames): 39 def __init__(self, subnames):
40 SubClient.__init__(self)
41 self.subnames = subnames 41 self.subnames = subnames
42 self.refresh() 42 self.refresh()
43 def refresh(self): 43 def refresh(self):
44 # reload subs from disk 44 # reload subs from disk
45 self.submasters = Submasters() 45 self.submasters = Submasters()
58 def prev(self): 58 def prev(self):
59 if self.keep_solo_mode == 'keep': 59 if self.keep_solo_mode == 'keep':
60 self.kept_levels[self.current_sub] = self.current_level 60 self.kept_levels[self.current_sub] = self.current_level
61 61
62 self.current_sub = self.submasters.get_sub_by_name(self.all_subs.prev()) 62 self.current_sub = self.submasters.get_sub_by_name(self.all_subs.prev())
63
63 def get_levels_as_sub(self): 64 def get_levels_as_sub(self):
64 if self.keep_solo_mode == 'keep': 65 if self.keep_solo_mode == 'keep':
65 # send all levels in self.kept_levels 66 # send all levels in self.kept_levels
66 levels = combine_subdict(self.kept_levels) 67 levelsub = combine_subdict(self.kept_levels)
67 else: 68 else:
68 levels = {self.current_sub : self.current_level} 69 levelsub = self.current_sub * self.current_level
69 70
70 return levels 71 return levelsub
71 def get_dmx_list(self):
72 maxes = self.get_levels_as_sub()
73 return maxes.get_dmx_list()
74 def send_levels(self):
75 levels = self.get_dmx_list()
76 dmxclient.outputlevels(levels)
77 72
78 if __name__ == "__main__": 73 if __name__ == "__main__":
79 if 0: 74 if 0:
80 x = range(20) 75 x = range(20)
81 for z in circcycle(x): 76 for z in circcycle(x):