|
2 | 2 | assign instanceName = instance.name | downcase | underscore_spaces %} |
3 | 3 | {{instanceName}} = Led(name='{{instance.systemName}}'){% |
4 | 4 | endfor %} |
5 | | - |
6 | | - @staticmethod |
7 | | - def mix_colors({% |
8 | | -for group in currentClass.groups%}{{ group.name | downcase | underscore_spaces }}{% |
9 | | - unless forloop.last %}, {% endunless %}{% |
10 | | -endfor %}):{% |
11 | | -for group in currentClass.groups %}{% |
12 | | - assign groupName = group.name | downcase | underscore_spaces %}{% |
13 | | - for instance in group.entries %}{% |
14 | | - assign instanceName = instance | downcase | underscore_spaces %} |
15 | | - Leds.{{instanceName}}.brightness_pct = {{groupName}}{% |
16 | | - endfor %}{% |
| 5 | +{% for group in currentClass.groups %}{% |
| 6 | + assign groupName = group.name | upcase | underscore_spaces %} |
| 7 | + {{ groupName }} = ({% for e in group.entries %}{% |
| 8 | + assign instance = e | downcase | underscore_spaces |
| 9 | +%}{{ instance }}, {% |
| 10 | + endfor %}){% |
17 | 11 | endfor %} |
18 | 12 | {% for color in currentClass.colors %}{% |
19 | | - assign colorName = color.name | downcase | underscore_spaces %} |
| 13 | + assign colorName = color.name | upcase | underscore_spaces %} |
| 14 | + {{ colorName }} = ({% for v in color.value %}{{ v }}, {%endfor %}){% |
| 15 | +endfor %} |
| 16 | + |
20 | 17 | @staticmethod |
21 | | - def set_{{ colorName }}(pct): |
22 | | - Leds.mix_colors({% |
23 | | - for group in color.groups %}{{ group.name | downcase | underscore_spaces }}={{ group.value }} * pct{% |
24 | | - unless forloop.last %}, {% endunless %}{% |
25 | | - endfor %}) |
| 18 | + def set_color(group, color, pct=1): |
| 19 | + """ |
| 20 | + Sets brigthness of leds in the given group to the values specified in |
| 21 | + color tuple. When percentage is specified, brightness of each led is |
| 22 | + reduced proportionally. |
| 23 | + |
| 24 | + Example:: |
| 25 | + |
| 26 | + Leds.set_color(LEFT, AMBER) |
| 27 | + """ |
| 28 | + for l, v in zip(group, color): |
| 29 | + l.brightness_pct = v * pct |
26 | 30 |
|
27 | 31 | @staticmethod |
28 | | - def {{ colorName }}_on(): |
29 | | - Leds.set_{{ colorName }}(1) |
30 | | -{% endfor %} |
| 32 | + def set(group, **kwargs): |
| 33 | + """ |
| 34 | + Set attributes for each led in group. |
| 35 | + |
| 36 | + Example:: |
| 37 | + |
| 38 | + Leds.set(LEFT, brightness_pct=0.5, trigger='timer') |
| 39 | + """ |
| 40 | + for led in group: |
| 41 | + for k in kwargs: |
| 42 | + setattr(led, k, kwargs[k]) |
| 43 | + |
31 | 44 | @staticmethod |
32 | | - def all_off():{% |
| 45 | + def all_off(): |
| 46 | + """ |
| 47 | + Turn all leds off |
| 48 | + """{% |
33 | 49 | for instance in currentClass.instances %}{% |
34 | 50 | assign instanceName = instance.name | downcase | underscore_spaces %} |
35 | 51 | Leds.{{instanceName}}.brightness = 0{% |
|
0 commit comments