From 186b53dea8e24e9fa1b6498d0a26371d80bcd871 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Fri, 8 Sep 2017 11:16:03 +0000 Subject: [PATCH 1/6] list the device name in 'Device not connected' Exception --- ev3dev/core.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ev3dev/core.py b/ev3dev/core.py index 8747923..0dd29ca 100644 --- a/ev3dev/core.py +++ b/ev3dev/core.py @@ -42,6 +42,7 @@ import fnmatch import numbers import array +import logging import mmap import ctypes import re @@ -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 @@ -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""" @@ -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) From beb2c2de142a335fb21fd55309bfc9411bf4f1c9 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Fri, 8 Sep 2017 20:40:33 -0400 Subject: [PATCH 2/6] api_test.py must use python3 --- tests/api_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api_tests.py b/tests/api_tests.py index 6edb48e..7476352 100755 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -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') From 1ccce2163013d234b8027af3c274bc39a0a5b4c3 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Fri, 8 Sep 2017 20:41:01 -0400 Subject: [PATCH 3/6] Update README for tests --- tests/README.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/README.md b/tests/README.md index b8f0017..04ca3b9 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,8 +1,20 @@ +If you do not have the `fake-sys` directory it means you did not use the +`--recursive` option when you git cloned the ev3dev-lang-python repo. +Example: + +``` +$ git clone --recursive https://github.com/rhempel/ev3dev-lang-python.git +``` + 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} +$ cp -P --copy-contents -r /sys/class/${node}/* ./${node}/ +``` + +To run the tests do: +``` +$ ./api_tests.py ``` From 77f3fd6846d2a89b22f3d6c3c4103829625a8131 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 20 Sep 2017 14:34:43 -0400 Subject: [PATCH 4/6] Update to latest ev3dev-lang to pick up stretch fixes --- ev3dev-lang | 2 +- ev3dev/ev3.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ev3dev-lang b/ev3dev-lang index 008804f..0169750 160000 --- a/ev3dev-lang +++ b/ev3dev-lang @@ -1 +1 @@ -Subproject commit 008804f5c28acd225f1b43057be2060d9965b2c1 +Subproject commit 0169750bf9aeefac423c38929287b4ad9ef7abd4 diff --git a/ev3dev/ev3.py b/ev3dev/ev3.py index 725f713..c9ec23f 100644 --- a/ev3dev/ev3.py +++ b/ev3dev/ev3.py @@ -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, ) @@ -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 From 68381178a27ce4f442bf52e1e028e7802d98226e Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 20 Sep 2017 17:20:09 -0400 Subject: [PATCH 5/6] Update tests/README --- tests/README.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/README.md b/tests/README.md index 04ca3b9..0e7c47f 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,11 +1,23 @@ -If you do not have the `fake-sys` directory it means you did not use the -`--recursive` option when you git cloned the ev3dev-lang-python repo. -Example: +# 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 closed 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: ``` @@ -13,8 +25,3 @@ $ node=lego-sensor/sensor0 $ mkdir -p ./${node} $ cp -P --copy-contents -r /sys/class/${node}/* ./${node}/ ``` - -To run the tests do: -``` -$ ./api_tests.py -``` From 2d3f934355a3a9327731a0532fc8caa461882fb3 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 20 Sep 2017 17:27:20 -0400 Subject: [PATCH 6/6] Update tests/README --- tests/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 0e7c47f..0c7adf4 100644 --- a/tests/README.md +++ b/tests/README.md @@ -4,7 +4,7 @@ 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 closed the ev3dev-lang-python repo you can use the `--recursive` option +already cloned the ev3dev-lang-python repo you can use the `--recursive` option when you git clone. Example: ```