Skip to content

Commit 09e612e

Browse files
committed
Move code not dependent on spec.json out of template
1 parent 5442a28 commit 09e612e

File tree

2 files changed

+2
-58
lines changed

2 files changed

+2
-58
lines changed

ev3dev.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,8 @@ class Button(object):
17221722
in /include/uapi/linux/input.h for details.
17231723
"""
17241724

1725+
#~autogen
1726+
17251727
KEY_MAX = 0x2FF
17261728
KEY_BUF_LEN = int((KEY_MAX + 7) / 8)
17271729
EVIOCGKEY = (2 << (14 + 8 + 8) | KEY_BUF_LEN << (8 + 8) | ord('E') << 8 | 0x18)
@@ -1779,7 +1781,6 @@ def these(self,buttons={}):
17791781
return False
17801782
return True
17811783

1782-
#~autogen
17831784
if current_platform() == 'ev3':
17841785
#~autogen button-property platforms.ev3.button>currentClass
17851786
_buttons = {

templates/button-class.liquid

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,3 @@ class {{ class_name }}({{ base_class }}):
1313
to be able to read the button state buffer. See Linux kernel source
1414
in /include/uapi/linux/input.h for details.
1515
"""
16-
17-
KEY_MAX = 0x2FF
18-
KEY_BUF_LEN = int((KEY_MAX + 7) / 8)
19-
EVIOCGKEY = (2 << (14 + 8 + 8) | KEY_BUF_LEN << (8 + 8) | ord('E') << 8 | 0x18)
20-
21-
def __init__(self):
22-
self.buffer_cache = {}
23-
self.filehandle_cache = {}
24-
for b in self._buttons:
25-
self._button_file( self._buttons[b]['name'] )
26-
self._button_buffer( self._buttons[b]['name'] )
27-
28-
def _button_file(self, name):
29-
if name not in self.filehandle_cache:
30-
f = open( name, 'r' )
31-
self.filehandle_cache[name] = f
32-
else:
33-
f = self.filehandle_cache[name]
34-
return f
35-
36-
def _button_buffer(self, name):
37-
if name not in self.buffer_cache:
38-
self.buffer_cache[name] = array.array( 'B', [0] * self.KEY_BUF_LEN )
39-
return self.buffer_cache[name]
40-
41-
def read_buttons(self):
42-
for b in self.buffer_cache:
43-
fcntl.ioctl(self.filehandle_cache[b], self.EVIOCGKEY, self.buffer_cache[b])
44-
45-
def check_buttons(self):
46-
pressed = []
47-
self.read_buttons()
48-
for k,v in self._buttons.items():
49-
buf = self.buffer_cache[v['name']]
50-
bit = v['value']
51-
if not bool(buf[int(bit / 8)] & 1 << bit % 8):
52-
pressed += [k]
53-
return pressed
54-
55-
@property
56-
def any(self):
57-
return bool(len(self.check_buttons()) != 0)
58-
59-
@property
60-
def which(self):
61-
return self.check_buttons()
62-
63-
def these(self,buttons={}):
64-
if len(buttons) == 0:
65-
return False
66-
s = self.check_buttons()
67-
if len(s) == 0:
68-
return False
69-
for b in buttons:
70-
if b not in s:
71-
return False
72-
return True

0 commit comments

Comments
 (0)