|
30 | 30 | import os |
31 | 31 | import fnmatch |
32 | 32 | import numbers |
33 | | -import platform |
34 | 33 | import fcntl |
35 | 34 | import array |
36 | 35 | import mmap |
|
42 | 41 | from subprocess import Popen |
43 | 42 |
|
44 | 43 |
|
45 | | -# ----------------------------------------------------------------------------- |
46 | | -# Guess platform we are running on |
47 | | -def current_platform(): |
48 | | - machine = platform.machine() |
49 | | - if machine == 'armv5tejl': |
50 | | - return 'ev3' |
51 | | - elif machine == 'armv6l': |
52 | | - return 'brickpi' |
53 | | - else: |
54 | | - return 'unsupported' |
55 | | - |
56 | | - |
57 | 44 | # ----------------------------------------------------------------------------- |
58 | 45 | # Attribute reader/writer with cached file access |
59 | 46 | class FileCache(object): |
@@ -1700,112 +1687,6 @@ def brightness_pct(self): |
1700 | 1687 | def brightness_pct(self, value): |
1701 | 1688 | self.brightness = value * self.max_brightness |
1702 | 1689 |
|
1703 | | -if current_platform() == 'ev3': |
1704 | | -# ~autogen led-colors platforms.ev3.led>currentClass |
1705 | | - |
1706 | | - Led.red_left = Led(name='ev3-left0:red:ev3dev') |
1707 | | - Led.red_right = Led(name='ev3-right0:red:ev3dev') |
1708 | | - Led.green_left = Led(name='ev3-left1:green:ev3dev') |
1709 | | - Led.green_right = Led(name='ev3-right1:green:ev3dev') |
1710 | | - |
1711 | | - @staticmethod |
1712 | | - def _Led_mix_colors(red, green): |
1713 | | - Led.red_left.brightness_pct = red |
1714 | | - Led.red_right.brightness_pct = red |
1715 | | - Led.green_left.brightness_pct = green |
1716 | | - Led.green_right.brightness_pct = green |
1717 | | - Led.mix_colors = _Led_mix_colors |
1718 | | - |
1719 | | - @staticmethod |
1720 | | - def _Led_set_red(pct): |
1721 | | - Led.mix_colors(red=1*pct, green=0*pct) |
1722 | | - Led.set_red = _Led_set_red |
1723 | | - |
1724 | | - @staticmethod |
1725 | | - def _Led_red_on(): |
1726 | | - Led.set_red(1) |
1727 | | - Led.red_on = _Led_red_on |
1728 | | - |
1729 | | - @staticmethod |
1730 | | - def _Led_set_green(pct): |
1731 | | - Led.mix_colors(red=0*pct, green=1*pct) |
1732 | | - Led.set_green = _Led_set_green |
1733 | | - |
1734 | | - @staticmethod |
1735 | | - def _Led_green_on(): |
1736 | | - Led.set_green(1) |
1737 | | - Led.green_on = _Led_green_on |
1738 | | - |
1739 | | - @staticmethod |
1740 | | - def _Led_set_amber(pct): |
1741 | | - Led.mix_colors(red=1*pct, green=1*pct) |
1742 | | - Led.set_amber = _Led_set_amber |
1743 | | - |
1744 | | - @staticmethod |
1745 | | - def _Led_amber_on(): |
1746 | | - Led.set_amber(1) |
1747 | | - Led.amber_on = _Led_amber_on |
1748 | | - |
1749 | | - @staticmethod |
1750 | | - def _Led_set_orange(pct): |
1751 | | - Led.mix_colors(red=1*pct, green=0.5*pct) |
1752 | | - Led.set_orange = _Led_set_orange |
1753 | | - |
1754 | | - @staticmethod |
1755 | | - def _Led_orange_on(): |
1756 | | - Led.set_orange(1) |
1757 | | - Led.orange_on = _Led_orange_on |
1758 | | - |
1759 | | - @staticmethod |
1760 | | - def _Led_set_yellow(pct): |
1761 | | - Led.mix_colors(red=0.5*pct, green=1*pct) |
1762 | | - Led.set_yellow = _Led_set_yellow |
1763 | | - |
1764 | | - @staticmethod |
1765 | | - def _Led_yellow_on(): |
1766 | | - Led.set_yellow(1) |
1767 | | - Led.yellow_on = _Led_yellow_on |
1768 | | - |
1769 | | - @staticmethod |
1770 | | - def _Led_all_off(): |
1771 | | - Led.red_left.brightness = 0 |
1772 | | - Led.red_right.brightness = 0 |
1773 | | - Led.green_left.brightness = 0 |
1774 | | - Led.green_right.brightness = 0 |
1775 | | - Led.all_off = _Led_all_off |
1776 | | - |
1777 | | - |
1778 | | -# ~autogen |
1779 | | -elif current_platform() == 'brickpi': |
1780 | | -# ~autogen led-colors platforms.brickpi.led>currentClass |
1781 | | - |
1782 | | - Led.blue_one = Led(name='brickpi1:blue:ev3dev') |
1783 | | - Led.blue_two = Led(name='brickpi2:blue:ev3dev') |
1784 | | - |
1785 | | - @staticmethod |
1786 | | - def _Led_mix_colors(blue): |
1787 | | - Led.blue_one.brightness_pct = blue |
1788 | | - Led.blue_two.brightness_pct = blue |
1789 | | - Led.mix_colors = _Led_mix_colors |
1790 | | - |
1791 | | - @staticmethod |
1792 | | - def _Led_set_blue(pct): |
1793 | | - Led.mix_colors(blue=1*pct) |
1794 | | - Led.set_blue = _Led_set_blue |
1795 | | - |
1796 | | - @staticmethod |
1797 | | - def _Led_blue_on(): |
1798 | | - Led.set_blue(1) |
1799 | | - Led.blue_on = _Led_blue_on |
1800 | | - |
1801 | | - @staticmethod |
1802 | | - def _Led_all_off(): |
1803 | | - Led.blue_one.brightness = 0 |
1804 | | - Led.blue_two.brightness = 0 |
1805 | | - Led.all_off = _Led_all_off |
1806 | | - |
1807 | | - |
1808 | | -# ~autogen |
1809 | 1690 |
|
1810 | 1691 | class ButtonBase(object): |
1811 | 1692 | """ |
@@ -1847,26 +1728,23 @@ def process(self): |
1847 | 1728 | self.on_change([(button, button in new_state) for button in state_diff]) |
1848 | 1729 |
|
1849 | 1730 |
|
1850 | | -# ~autogen button-class classes.button>currentClass |
1851 | | -class Button(ButtonBase): |
| 1731 | +class ButtonEVIO(ButtonBase): |
1852 | 1732 |
|
1853 | 1733 | """ |
1854 | | - Provides a generic button reading mechanism that can be adapted |
1855 | | - to platform specific implementations. Each platform's specific |
1856 | | - button capabilites are enumerated in the 'platforms' section |
1857 | | - of this specification |
| 1734 | + Provides a generic button reading mechanism that works with event interface |
| 1735 | + and may be adapted to platform specific implementations. |
1858 | 1736 |
|
1859 | 1737 | This implementation depends on the availability of the EVIOCGKEY ioctl |
1860 | 1738 | to be able to read the button state buffer. See Linux kernel source |
1861 | 1739 | in /include/uapi/linux/input.h for details. |
1862 | 1740 | """ |
1863 | 1741 |
|
1864 | | -# ~autogen |
1865 | | - |
1866 | 1742 | KEY_MAX = 0x2FF |
1867 | 1743 | KEY_BUF_LEN = int((KEY_MAX + 7) / 8) |
1868 | 1744 | EVIOCGKEY = (2 << (14 + 8 + 8) | KEY_BUF_LEN << (8 + 8) | ord('E') << 8 | 0x18) |
1869 | 1745 |
|
| 1746 | + _buttons = {} |
| 1747 | + |
1870 | 1748 | def __init__(self): |
1871 | 1749 | self._file_cache = FileCache() |
1872 | 1750 | self._buffer_cache = {} |
@@ -1895,51 +1773,7 @@ def buttons_pressed(self): |
1895 | 1773 | pressed += [k] |
1896 | 1774 | return pressed |
1897 | 1775 |
|
1898 | | - if current_platform() == 'ev3': |
1899 | | -# ~autogen button-property platforms.ev3.button>currentClass |
1900 | | - |
1901 | | - on_up = None |
1902 | | - on_down = None |
1903 | | - on_left = None |
1904 | | - on_right = None |
1905 | | - on_enter = None |
1906 | | - on_backspace = None |
1907 | | - |
1908 | | - _buttons = { |
1909 | | - 'up': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 103}, |
1910 | | - 'down': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 108}, |
1911 | | - 'left': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 105}, |
1912 | | - 'right': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 106}, |
1913 | | - 'enter': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 28}, |
1914 | | - 'backspace': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 14}, |
1915 | | - } |
1916 | | - |
1917 | | - @property |
1918 | | - def up(self): |
1919 | | - return 'up' in self.buttons_pressed |
1920 | 1776 |
|
1921 | | - @property |
1922 | | - def down(self): |
1923 | | - return 'down' in self.buttons_pressed |
1924 | | - |
1925 | | - @property |
1926 | | - def left(self): |
1927 | | - return 'left' in self.buttons_pressed |
1928 | | - |
1929 | | - @property |
1930 | | - def right(self): |
1931 | | - return 'right' in self.buttons_pressed |
1932 | | - |
1933 | | - @property |
1934 | | - def enter(self): |
1935 | | - return 'enter' in self.buttons_pressed |
1936 | | - |
1937 | | - @property |
1938 | | - def backspace(self): |
1939 | | - return 'backspace' in self.buttons_pressed |
1940 | | - |
1941 | | - |
1942 | | -# ~autogen |
1943 | 1777 | # ~autogen remote-control classes.infraredSensor.remoteControl>currentClass |
1944 | 1778 | class RemoteControl(ButtonBase): |
1945 | 1779 | """ |
|
0 commit comments