|
30 | 30 | import os.path |
31 | 31 | import fnmatch |
32 | 32 | import numbers |
| 33 | +import platform |
| 34 | + |
| 35 | +#------------------------------------------------------------------------------ |
| 36 | +# Guess platform we are running on |
| 37 | +def current_platform(): |
| 38 | + machine = platform.machine() |
| 39 | + if machine == 'armv5tejl': |
| 40 | + return 'ev3' |
| 41 | + elif machine == 'armv6l': |
| 42 | + return 'brickpi' |
| 43 | + else: |
| 44 | + return 'unsupported' |
33 | 45 |
|
34 | 46 | #------------------------------------------------------------------------------ |
35 | 47 | # Define the base class from which all other ev3dev classes are defined. |
@@ -1586,6 +1598,124 @@ def delay_off(self, value): |
1586 | 1598 | self.set_attr_int( 'delay_off', value ) |
1587 | 1599 |
|
1588 | 1600 |
|
| 1601 | +#~autogen |
| 1602 | + |
| 1603 | + @property |
| 1604 | + def brightness_pct(self): |
| 1605 | + """ |
| 1606 | + Returns led brightness as a fraction of max_brightness |
| 1607 | + """ |
| 1608 | + return float(self.brightness) / self.max_brightness |
| 1609 | + |
| 1610 | + @brightness_pct.setter |
| 1611 | + def brightness_pct(self, value): |
| 1612 | + self.brightness = value * self.max_brightness |
| 1613 | + |
| 1614 | +if current_platform() == 'ev3': |
| 1615 | +#~autogen python_led-colors platforms.ev3.led>currentClass |
| 1616 | + |
| 1617 | + Led.red_left = Led(name='ev3-left0:red:ev3dev') |
| 1618 | + Led.red_right = Led(name='ev3-right0:red:ev3dev') |
| 1619 | + Led.green_left = Led(name='ev3-left1:green:ev3dev') |
| 1620 | + Led.green_right = Led(name='ev3-right1:green:ev3dev') |
| 1621 | + |
| 1622 | + @staticmethod |
| 1623 | + def Led_mix_colors(red, green): |
| 1624 | + Led.red_left.brightness_pct = red |
| 1625 | + Led.red_right.brightness_pct = red |
| 1626 | + Led.green_left.brightness_pct = green |
| 1627 | + Led.green_right.brightness_pct = green |
| 1628 | + Led.mix_colors = Led_mix_colors |
| 1629 | + |
| 1630 | + @staticmethod |
| 1631 | + def Led_set_red(pct): |
| 1632 | + Led.mix_colors(red=1*pct, green=0*pct) |
| 1633 | + Led.set_red = Led_set_red |
| 1634 | + |
| 1635 | + @staticmethod |
| 1636 | + def Led_red_on(): |
| 1637 | + Led.set_red(1) |
| 1638 | + Led.red_on = Led_red_on |
| 1639 | + |
| 1640 | + @staticmethod |
| 1641 | + def Led_set_green(pct): |
| 1642 | + Led.mix_colors(red=0*pct, green=1*pct) |
| 1643 | + Led.set_green = Led_set_green |
| 1644 | + |
| 1645 | + @staticmethod |
| 1646 | + def Led_green_on(): |
| 1647 | + Led.set_green(1) |
| 1648 | + Led.green_on = Led_green_on |
| 1649 | + |
| 1650 | + @staticmethod |
| 1651 | + def Led_set_amber(pct): |
| 1652 | + Led.mix_colors(red=1*pct, green=1*pct) |
| 1653 | + Led.set_amber = Led_set_amber |
| 1654 | + |
| 1655 | + @staticmethod |
| 1656 | + def Led_amber_on(): |
| 1657 | + Led.set_amber(1) |
| 1658 | + Led.amber_on = Led_amber_on |
| 1659 | + |
| 1660 | + @staticmethod |
| 1661 | + def Led_set_orange(pct): |
| 1662 | + Led.mix_colors(red=1*pct, green=0.5*pct) |
| 1663 | + Led.set_orange = Led_set_orange |
| 1664 | + |
| 1665 | + @staticmethod |
| 1666 | + def Led_orange_on(): |
| 1667 | + Led.set_orange(1) |
| 1668 | + Led.orange_on = Led_orange_on |
| 1669 | + |
| 1670 | + @staticmethod |
| 1671 | + def Led_set_yellow(pct): |
| 1672 | + Led.mix_colors(red=0.5*pct, green=1*pct) |
| 1673 | + Led.set_yellow = Led_set_yellow |
| 1674 | + |
| 1675 | + @staticmethod |
| 1676 | + def Led_yellow_on(): |
| 1677 | + Led.set_yellow(1) |
| 1678 | + Led.yellow_on = Led_yellow_on |
| 1679 | + |
| 1680 | + @staticmethod |
| 1681 | + def Led_all_off(): |
| 1682 | + Led.red_left.brightness = 0 |
| 1683 | + Led.red_right.brightness = 0 |
| 1684 | + Led.green_left.brightness = 0 |
| 1685 | + Led.green_right.brightness = 0 |
| 1686 | + Led.all_off = Led_all_off |
| 1687 | + |
| 1688 | + |
| 1689 | +#~autogen |
| 1690 | +elif current_platform() == 'brickpi': |
| 1691 | +#~autogen python_led-colors platforms.brickpi.led>currentClass |
| 1692 | + |
| 1693 | + Led.blue_one = Led(name='brickpi1:blue:ev3dev') |
| 1694 | + Led.blue_two = Led(name='brickpi2:blue:ev3dev') |
| 1695 | + |
| 1696 | + @staticmethod |
| 1697 | + def Led_mix_colors(blue): |
| 1698 | + Led.blue_one.brightness_pct = blue |
| 1699 | + Led.blue_two.brightness_pct = blue |
| 1700 | + Led.mix_colors = Led_mix_colors |
| 1701 | + |
| 1702 | + @staticmethod |
| 1703 | + def Led_set_blue(pct): |
| 1704 | + Led.mix_colors(blue=1*pct) |
| 1705 | + Led.set_blue = Led_set_blue |
| 1706 | + |
| 1707 | + @staticmethod |
| 1708 | + def Led_blue_on(): |
| 1709 | + Led.set_blue(1) |
| 1710 | + Led.blue_on = Led_blue_on |
| 1711 | + |
| 1712 | + @staticmethod |
| 1713 | + def Led_all_off(): |
| 1714 | + Led.blue_one.brightness = 0 |
| 1715 | + Led.blue_two.brightness = 0 |
| 1716 | + Led.all_off = Led_all_off |
| 1717 | + |
| 1718 | + |
1589 | 1719 | #~autogen |
1590 | 1720 | #~autogen python_generic-class classes.powerSupply>currentClass |
1591 | 1721 |
|
|
0 commit comments