Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Module interface
InfraredSensor
RemoteControl
Led
Leds
PowerSupply
Button
Sound
Expand Down Expand Up @@ -109,6 +110,9 @@ Other
.. autoclass:: Led
:members:

.. autoclass:: Leds
:members:

.. autoclass:: PowerSupply
:members:

Expand Down
38 changes: 30 additions & 8 deletions ev3dev/brickpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,43 @@ class Leds(object):
blue_one = Led(name='brickpi1:blue:ev3dev')
blue_two = Led(name='brickpi2:blue:ev3dev')

@staticmethod
def mix_colors(blue):
Leds.blue_one.brightness_pct = blue
Leds.blue_two.brightness_pct = blue
BLUE_ONE = (blue_one, )
BLUE_TWO = (blue_two, )

BLUE = (1, )

@staticmethod
def set_blue(pct):
Leds.mix_colors(blue=1 * pct)
def set_color(group, color, pct=1):
"""
Sets brigthness of leds in the given group to the values specified in
color tuple. When percentage is specified, brightness of each led is
reduced proportionally.

Example::

Leds.set_color(LEFT, AMBER)
"""
for l, v in zip(group, color):
l.brightness_pct = v * pct

@staticmethod
def blue_on():
Leds.set_blue(1)
def set(group, **kwargs):
"""
Set attributes for each led in group.

Example::

Leds.set(LEFT, brightness_pct=0.5, trigger='timer')
"""
for led in group:
for k in kwargs:
setattr(led, k, kwargs[k])

@staticmethod
def all_off():
"""
Turn all leds off
"""
Leds.blue_one.brightness = 0
Leds.blue_two.brightness = 0

Expand Down
66 changes: 29 additions & 37 deletions ev3dev/ev3.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,55 +52,47 @@ class Leds(object):
green_left = Led(name='ev3-left1:green:ev3dev')
green_right = Led(name='ev3-right1:green:ev3dev')

@staticmethod
def mix_colors(red, green):
Leds.red_left.brightness_pct = red
Leds.red_right.brightness_pct = red
Leds.green_left.brightness_pct = green
Leds.green_right.brightness_pct = green
LEFT = (red_left, green_left, )
RIGHT = (red_right, green_right, )

@staticmethod
def set_red(pct):
Leds.mix_colors(red=1 * pct, green=0 * pct)
RED = (1, 0, )
GREEN = (0, 1, )
AMBER = (1, 1, )
ORANGE = (1, 0.5, )
YELLOW = (0.5, 1, )

@staticmethod
def red_on():
Leds.set_red(1)

@staticmethod
def set_green(pct):
Leds.mix_colors(red=0 * pct, green=1 * pct)

@staticmethod
def green_on():
Leds.set_green(1)

@staticmethod
def set_amber(pct):
Leds.mix_colors(red=1 * pct, green=1 * pct)
def set_color(group, color, pct=1):
"""
Sets brigthness of leds in the given group to the values specified in
color tuple. When percentage is specified, brightness of each led is
reduced proportionally.

@staticmethod
def amber_on():
Leds.set_amber(1)
Example::

@staticmethod
def set_orange(pct):
Leds.mix_colors(red=1 * pct, green=0.5 * pct)
Leds.set_color(LEFT, AMBER)
"""
for l, v in zip(group, color):
l.brightness_pct = v * pct

@staticmethod
def orange_on():
Leds.set_orange(1)
def set(group, **kwargs):
"""
Set attributes for each led in group.

@staticmethod
def set_yellow(pct):
Leds.mix_colors(red=0.5 * pct, green=1 * pct)
Example::

@staticmethod
def yellow_on():
Leds.set_yellow(1)
Leds.set(LEFT, brightness_pct=0.5, trigger='timer')
"""
for led in group:
for k in kwargs:
setattr(led, k, kwargs[k])

@staticmethod
def all_off():
"""
Turn all leds off
"""
Leds.red_left.brightness = 0
Leds.red_right.brightness = 0
Leds.green_left.brightness = 0
Expand Down
60 changes: 38 additions & 22 deletions templates/led-colors.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,50 @@
assign instanceName = instance.name | downcase | underscore_spaces %}
{{instanceName}} = Led(name='{{instance.systemName}}'){%
endfor %}

@staticmethod
def mix_colors({%
for group in currentClass.groups%}{{ group.name | downcase | underscore_spaces }}{%
unless forloop.last %}, {% endunless %}{%
endfor %}):{%
for group in currentClass.groups %}{%
assign groupName = group.name | downcase | underscore_spaces %}{%
for instance in group.entries %}{%
assign instanceName = instance | downcase | underscore_spaces %}
Leds.{{instanceName}}.brightness_pct = {{groupName}}{%
endfor %}{%
{% for group in currentClass.groups %}{%
assign groupName = group.name | upcase | underscore_spaces %}
{{ groupName }} = ({% for e in group.entries %}{%
assign instance = e | downcase | underscore_spaces
%}{{ instance }}, {%
endfor %}){%
endfor %}
{% for color in currentClass.colors %}{%
assign colorName = color.name | downcase | underscore_spaces %}
assign colorName = color.name | upcase | underscore_spaces %}
{{ colorName }} = ({% for v in color.value %}{{ v }}, {%endfor %}){%
endfor %}

@staticmethod
def set_{{ colorName }}(pct):
Leds.mix_colors({%
for group in color.groups %}{{ group.name | downcase | underscore_spaces }}={{ group.value }} * pct{%
unless forloop.last %}, {% endunless %}{%
endfor %})
def set_color(group, color, pct=1):
"""
Sets brigthness of leds in the given group to the values specified in
color tuple. When percentage is specified, brightness of each led is
reduced proportionally.

Example::

Leds.set_color(LEFT, AMBER)
"""
for l, v in zip(group, color):
l.brightness_pct = v * pct

@staticmethod
def {{ colorName }}_on():
Leds.set_{{ colorName }}(1)
{% endfor %}
def set(group, **kwargs):
"""
Set attributes for each led in group.

Example::

Leds.set(LEFT, brightness_pct=0.5, trigger='timer')
"""
for led in group:
for k in kwargs:
setattr(led, k, kwargs[k])

@staticmethod
def all_off():{%
def all_off():
"""
Turn all leds off
"""{%
for instance in currentClass.instances %}{%
assign instanceName = instance.name | downcase | underscore_spaces %}
Leds.{{instanceName}}.brightness = 0{%
Expand Down