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
2 changes: 1 addition & 1 deletion ev3dev-lang
Submodule ev3dev-lang updated 1 files
+37 −10 spec.json
9 changes: 7 additions & 2 deletions ev3dev/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import fnmatch
import numbers
import array
import logging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how much does this add to startup time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No noticable difference as far as I can tell

import mmap
import ctypes
import re
Expand All @@ -53,6 +54,8 @@
from struct import pack, unpack
from subprocess import Popen, check_output, PIPE

log = logging.getLogger(__name__)

try:
# This is a linux-specific module.
# It is required by the Button() class, but failure to import it may be
Expand Down Expand Up @@ -195,7 +198,8 @@ def _get_attribute(self, attribute, name):
attribute.seek(0)
return attribute, attribute.read().strip().decode()
else:
raise Exception('Device is not connected')
log.info("%s: path %s, attribute %s" % (self, self._path, name))
raise Exception("%s is not connected" % self)

def _set_attribute(self, attribute, name, value):
"""Device attribute setter"""
Expand All @@ -208,7 +212,8 @@ def _set_attribute(self, attribute, name, value):
attribute.flush()
return attribute
else:
raise Exception('Device is not connected')
log.info("%s: path %s, attribute %s" % (self, self._path, name))
raise Exception("%s is not connected" % self)

def get_attr_int(self, attribute, name):
attribute, value = self._get_attribute(attribute, name)
Expand Down
20 changes: 10 additions & 10 deletions ev3dev/ev3.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class Leds(object):

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

red_left = Led(name_pattern='ev3:left:red:ev3dev')
red_right = Led(name_pattern='ev3:right:red:ev3dev')
green_left = Led(name_pattern='ev3:left:green:ev3dev')
green_right = Led(name_pattern='ev3:right:green:ev3dev')
red_left = Led(name_pattern='led0:red:brick-status')
red_right = Led(name_pattern='led1:red:brick-status')
green_left = Led(name_pattern='led0:green:brick-status')
green_right = Led(name_pattern='led1:green:brick-status')

LEFT = ( red_left, green_left, )
RIGHT = ( red_right, green_right, )
Expand Down Expand Up @@ -165,12 +165,12 @@ def on_backspace(state):


_buttons = {
'up': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 103},
'down': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 108},
'left': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 105},
'right': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 106},
'enter': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 28},
'backspace': {'name': '/dev/input/by-path/platform-gpio-keys.0-event', 'value': 14},
'up': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 103},
'down': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 108},
'left': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 105},
'right': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 106},
'enter': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 28},
'backspace': {'name': '/dev/input/by-path/platform-gpio_keys-event', 'value': 14},
}

@property
Expand Down
29 changes: 24 additions & 5 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
# fake-sys directory
The tests require the fake-sys directory which comes from
https://github.com/ddemidov/ev3dev-lang-fake-sys

If you have already cloned the ev3dev-lang-python repo but do not have the
`fake-sys` directory use `git submodule init` to get it. If you have not
already cloned the ev3dev-lang-python repo you can use the `--recursive` option
when you git clone. Example:

```
$ git clone --recursive https://github.com/rhempel/ev3dev-lang-python.git
```

# Running Tests
To run the tests do:
```
$ ./api_tests.py
```

# Misc
Commands used to copy the /sys/class node:

```sh
node=lego-sensor/sensor0
mkdir -p ./${node}
# Copy contents of special files, do not follow symlinks:
cp -P --copy-contents -r /sys/class/${node}/* ./${node}/
```
$ node=lego-sensor/sensor0
$ mkdir -p ./${node}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be at the bottom, because it's rarely needed. The important command is the one for running the tests.

$ cp -P --copy-contents -r /sys/class/${node}/* ./${node}/
```
2 changes: 1 addition & 1 deletion tests/api_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import unittest, sys, os

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