Skip to content

Commit 06ae05f

Browse files
authored
Stretch fixes (#366)
* list the device name in 'Device not connected' Exception * api_test.py must use python3 * Update README for tests * Update to latest ev3dev-lang to pick up stretch fixes * Update tests/README * Update tests/README
1 parent 22d493e commit 06ae05f

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

ev3dev-lang

ev3dev/core.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import fnmatch
4343
import numbers
4444
import array
45+
import logging
4546
import mmap
4647
import ctypes
4748
import re
@@ -54,6 +55,8 @@
5455
from struct import pack, unpack
5556
from subprocess import Popen, check_output, PIPE
5657

58+
log = logging.getLogger(__name__)
59+
5760
try:
5861
# This is a linux-specific module.
5962
# It is required by the Button() class, but failure to import it may be
@@ -196,7 +199,8 @@ def _get_attribute(self, attribute, name):
196199
attribute.seek(0)
197200
return attribute, attribute.read().strip().decode()
198201
else:
199-
raise Exception('Device is not connected')
202+
log.info("%s: path %s, attribute %s" % (self, self._path, name))
203+
raise Exception("%s is not connected" % self)
200204

201205
def _set_attribute(self, attribute, name, value):
202206
"""Device attribute setter"""
@@ -213,7 +217,8 @@ def _set_attribute(self, attribute, name, value):
213217
self._raise_friendly_access_error(ex, name)
214218
return attribute
215219
else:
216-
raise Exception('Device is not connected')
220+
log.info("%s: path %s, attribute %s" % (self, self._path, name))
221+
raise Exception("%s is not connected" % self)
217222

218223
def _raise_friendly_access_error(self, driver_error, attribute):
219224
if not isinstance(driver_error, OSError):

ev3dev/ev3.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class Leds(object):
4747

4848
# ~autogen led-colors platforms.ev3.led>currentClass
4949

50-
red_left = Led(name_pattern='ev3:left:red:ev3dev')
51-
red_right = Led(name_pattern='ev3:right:red:ev3dev')
52-
green_left = Led(name_pattern='ev3:left:green:ev3dev')
53-
green_right = Led(name_pattern='ev3:right:green:ev3dev')
50+
red_left = Led(name_pattern='led0:red:brick-status')
51+
red_right = Led(name_pattern='led1:red:brick-status')
52+
green_left = Led(name_pattern='led0:green:brick-status')
53+
green_right = Led(name_pattern='led1:green:brick-status')
5454

5555
LEFT = ( red_left, green_left, )
5656
RIGHT = ( red_right, green_right, )
@@ -165,12 +165,12 @@ def on_backspace(state):
165165

166166

167167
_buttons = {
168-
'up': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 103},
169-
'down': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 108},
170-
'left': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 105},
171-
'right': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 106},
172-
'enter': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 28},
173-
'backspace': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 14},
168+
'up': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 103},
169+
'down': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 108},
170+
'left': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 105},
171+
'right': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 106},
172+
'enter': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 28},
173+
'backspace': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 14},
174174
}
175175

176176
@property

tests/README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
1+
# fake-sys directory
2+
The tests require the fake-sys directory which comes from
3+
https://github.com/ddemidov/ev3dev-lang-fake-sys
4+
5+
If you have already cloned the ev3dev-lang-python repo but do not have the
6+
`fake-sys` directory use `git submodule init` to get it. If you have not
7+
already cloned the ev3dev-lang-python repo you can use the `--recursive` option
8+
when you git clone. Example:
9+
10+
```
11+
$ git clone --recursive https://github.com/rhempel/ev3dev-lang-python.git
12+
```
13+
14+
# Running Tests
15+
To run the tests do:
16+
```
17+
$ ./api_tests.py
18+
```
19+
20+
# Misc
121
Commands used to copy the /sys/class node:
222

3-
```sh
4-
node=lego-sensor/sensor0
5-
mkdir -p ./${node}
6-
# Copy contents of special files, do not follow symlinks:
7-
cp -P --copy-contents -r /sys/class/${node}/* ./${node}/
23+
```
24+
$ node=lego-sensor/sensor0
25+
$ mkdir -p ./${node}
26+
$ cp -P --copy-contents -r /sys/class/${node}/* ./${node}/
827
```

tests/api_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
import unittest, sys, os
33

44
FAKE_SYS = os.path.join(os.path.dirname(__file__), 'fake-sys')

0 commit comments

Comments
 (0)