diff options
author | Duncan McGreggor <duncan@canonical.com> | 2011-03-15 19:20:48 -0600 |
---|---|---|
committer | Duncan McGreggor <duncan@canonical.com> | 2011-03-15 19:20:48 -0600 |
commit | 86ed4bc861f7212098e51768608097876e186557 (patch) | |
tree | 975df841cc4928250d1e89fb94648183ad067417 /python | |
parent | 1d3a86286113d91382a5346f39a1829b3cd745d4 (diff) |
* Finished the device imlementation and added related unit tests.
* Fixed a but in lsinput function.
* Added more constants (some may not be needed).
Diffstat (limited to 'python')
-rw-r--r-- | python/TODO | 19 | ||||
-rw-r--r-- | python/evemu/const.py | 86 | ||||
-rw-r--r-- | python/evemu/device.py | 68 | ||||
-rw-r--r-- | python/evemu/testing.py | 14 | ||||
-rw-r--r-- | python/evemu/tests/test_device.py | 42 | ||||
-rw-r--r-- | python/evemu/tests/test_util.py | 12 | ||||
-rw-r--r-- | python/evemu/util.py | 2 |
7 files changed, 218 insertions, 25 deletions
diff --git a/python/TODO b/python/TODO index 863f9ac..11d365d 100644 --- a/python/TODO +++ b/python/TODO @@ -32,6 +32,25 @@ The script does this: * identifies a device file * writes the properties to the device file +Notes about the device function sigs in Henrik's code: + +oubiwann: cnd: henrik defined a bunch of evemu functions that operate on a pointer to the device +cnd: ok? +oubiwann: besides the pointer reference, these functions also take parameters +oubiwann: one of them being simply "code" +cnd: heh +cnd: I have a feeling "code" has the meaning given in the evdev protocol +oubiwann: in this context (parsing the device structure) can you think of what the "code" parameter might be? +cnd: i.e. ABS_X or REL_X or BTN_A +cnd: the evdev protocol has types, codes, and values +cnd: type is ABS, or REL, or KEY, etc. +oubiwann: yeah, type is also a param in some of these +cnd: code is a specific "variable" in each type group +oubiwann: got it +oubiwann: yeah, that makes sense +cnd: so REL_X defines relative motion in the X direction +oubiwann: thanks! + TODO ==== diff --git a/python/evemu/const.py b/python/evemu/const.py index 584414c..8a8d729 100644 --- a/python/evemu/const.py +++ b/python/evemu/const.py @@ -33,3 +33,89 @@ API = [ "evemu_has_prop", "evemu_has_event", ] + +EV_SYN = 0x00 +EV_KEY = 0x01 +EV_REL = 0x02 +EV_ABS = 0x03 +EV_MSC = 0x04 +EV_SW = 0x05 +EV_LED = 0x11 +EV_SND = 0x12 +EV_REP = 0x14 +EV_FF = 0x15 +EV_PWR = 0x16 +EV_FF_STATUS = 0x17 +EV_MAX = 0x1f +EV_CNT = EV_MAX + 1 + +EV_NAMES = { + EV_SYN: "Sync", + EV_KEY: "Keys or Buttons", + EV_REL: "Relative Axes", + EV_ABS: "Absolute Axes", + EV_MSC: "Miscellaneous", + EV_SW: "Switches", + EV_LED: "Leds", + EV_SND: "Sound", + EV_REP: "Repeat", + EV_FF: "Force Feedback", + EV_PWR: "Power Management", + EV_FF_STATUS: "Force Feedback Status", +} + +# Relative axes +REL_X = 0x00 +REL_Y = 0x01 +REL_Z = 0x02 +REL_RX = 0x03 +REL_RY = 0x04 +REL_RZ = 0x05 +REL_HWHEEL = 0x06 +REL_DIAL = 0x07 +REL_WHEEL = 0x08 +REL_MISC = 0x09 +REL_MAX = 0x0f +REL_CNT = REL_MAX+1 + +# Absolute axes +ABS_X = 0x00 +ABS_Y = 0x01 +ABS_Z = 0x02 +ABS_RX = 0x03 +ABS_RY = 0x04 +ABS_RZ = 0x05 +ABS_THROTTLE = 0x06 +ABS_RUDDER = 0x07 +ABS_WHEEL = 0x08 +ABS_GAS = 0x09 +ABS_BRAKE = 0x0a +ABS_HAT0X = 0x10 +ABS_HAT0Y = 0x11 +ABS_HAT1X = 0x12 +ABS_HAT1Y = 0x13 +ABS_HAT2X = 0x14 +ABS_HAT2Y = 0x15 +ABS_HAT3X = 0x16 +ABS_HAT3Y = 0x17 +ABS_PRESSURE = 0x18 +ABS_DISTANCE = 0x19 +ABS_TILT_X = 0x1a +ABS_TILT_Y = 0x1b +ABS_TOOL_WIDTH = 0x1c +ABS_VOLUME = 0x20 +ABS_MISC = 0x28 +ABS_MT_SLOT = 0x2f # MT slot being modified +ABS_MT_TOUCH_MAJOR = 0x30 # Major axis of touching ellipse +ABS_MT_TOUCH_MINOR = 0x31 # Minor axis (omit if circular) +ABS_MT_WIDTH_MAJOR = 0x32 # Major axis of approaching ellipse +ABS_MT_WIDTH_MINOR = 0x33 # Minor axis (omit if circular) +ABS_MT_ORIENTATION = 0x34 # Ellipse orientation +ABS_MT_POSITION_X = 0x35 # Center X ellipse position +ABS_MT_POSITION_Y = 0x36 # Center Y ellipse position +ABS_MT_TOOL_TYPE = 0x37 # Type of touching device +ABS_MT_BLOB_ID = 0x38 # Group a set of packets as a blob +ABS_MT_TRACKING_ID = 0x39 # Unique ID of initiated contact +ABS_MT_PRESSURE = 0x3a # Pressure on contact area +ABS_MAX = 0x3f +ABS_CNT = ABS_MAX+1 diff --git a/python/evemu/device.py b/python/evemu/device.py index 63949fb..1ac6e93 100644 --- a/python/evemu/device.py +++ b/python/evemu/device.py @@ -171,29 +171,65 @@ class EvEmuDevice(base.EvEmuBase): @property def id_product(self): - pass + return self._call( + self.get_lib().evemu_get_id_product, + self.get_device_pointer()) @property def id_version(self): - pass + return self._call( + self.get_lib().evemu_get_id_version, + self.get_device_pointer()) - def abs_minimum(self, code): - pass + """ + In the following methods, 'event_type' and 'event_code' take their meanings + from the input event system in linux (the input_event struct devined in + linux/input.h). - def abs_maximum(self, code): - pass + @event_type: one of the EV_* constants - def abs_fuzz(self, code): - pass + @event_code: a code related to the event type + """ - def abs_flat(self, code): - pass + def get_abs_minimum(self, event_code): + return self._call( + self.get_lib().evemu_get_abs_minimum, + self.get_device_pointer(), + event_code) - def abs_resolution(self, code): - pass + def get_abs_maximum(self, event_code): + return self._call( + self.get_lib().evemu_get_abs_maximum, + self.get_device_pointer(), + event_code) - def has_prop(self, code): - pass + def get_abs_fuzz(self, event_code): + return self._call( + self.get_lib().evemu_get_abs_fuzz, + self.get_device_pointer(), + event_code) - def has_event(self, event_type, code): - pass + def get_abs_flat(self, event_code): + return self._call( + self.get_lib().evemu_get_abs_flat, + self.get_device_pointer(), + event_code) + + def get_abs_resolution(self, event_code): + return self._call( + self.get_lib().evemu_get_abs_resolution, + self.get_device_pointer(), + event_code) + + def has_prop(self, event_code): + return self._call( + self.get_lib().evemu_has_prop, + self.get_device_pointer(), + event_code) + + def has_event(self, event_type, event_code): + return self._call( + self.get_lib().evemu_has_event, + self.get_device_pointer(), + event_type, + event_code) diff --git a/python/evemu/testing.py b/python/evemu/testing.py index eb57b74..12ae226 100644 --- a/python/evemu/testing.py +++ b/python/evemu/testing.py @@ -14,6 +14,20 @@ from evemu import exception from evemu import util +""" +XXX There's a lot of stuff that's been crammed in here now, and it's probably +time to think about putting it out into separate modules. For instance: + * test-case-specific code + * result-rendering code + * test-runner code + +What's more, talking with Chase and Henrik today (2011-03-15), they'd like to +see unit tests that mocked the uinput device and didn't require root access to +run, like the current tests do. The base code for that would likely go in +another module. +""" + + def skip(message): try: return unittest.skip(message) diff --git a/python/evemu/tests/test_device.py b/python/evemu/tests/test_device.py index fb51899..4eb8d20 100644 --- a/python/evemu/tests/test_device.py +++ b/python/evemu/tests/test_device.py @@ -107,7 +107,7 @@ class EvEmuDeviceTestCase(BaseTestCase): def test_version(self): self.create_testing_device() - self.assertEqual(self.device.version, "XX") + self.assertEqual(self.device.version, 0) def test_name(self): self.create_testing_device() @@ -123,11 +123,47 @@ class EvEmuDeviceTestCase(BaseTestCase): def test_id_product(self): self.create_testing_device() - self.assertEqual(self.device.id_product, None) + self.assertEqual(self.device.id_product, 1) def test_id_version(self): self.create_testing_device() - self.assertEqual(self.device.id_version, None) + self.assertEqual(self.device.id_version, 272) + + def test_get_abs_minimum(self): + self.create_testing_device() + for event_code in xrange(10): + self.assertEqual(self.device.get_abs_minimum(event_code), 0) + + def test_get_abs_maximum(self): + self.create_testing_device() + event_code = 0 + self.assertEqual(self.device.get_abs_maximum(event_code), 9600) + + def test_get_abs_fuzz(self): + self.create_testing_device() + event_code = 0 + self.assertEqual(self.device.get_abs_fuzz(event_code), 75) + + def test_get_abs_flat(self): + self.create_testing_device() + event_code = 0 + self.assertEqual(self.device.get_abs_flat(event_code), 0) + + def test_get_abs_resolution(self): + self.create_testing_device() + event_code = 0 + self.assertEqual(self.device.get_abs_resolution(event_code), 0) + + def test_has_prop(self): + self.create_testing_device() + event_code = 0 + self.assertEqual(self.device.has_prop(event_code), 0) + + def test_has_event(self): + self.create_testing_device() + event_type = 0 + event_code = 0 + self.assertEqual(self.device.has_event(event_type, event_code), 1) if __name__ == "__main__": diff --git a/python/evemu/tests/test_util.py b/python/evemu/tests/test_util.py index 2f92707..1145036 100644 --- a/python/evemu/tests/test_util.py +++ b/python/evemu/tests/test_util.py @@ -16,12 +16,12 @@ class CommandsTestCase(Non26BaseTestCase): def test_lsinput(self): # let's just check the first one - results = util.lsinput()[0] - self.assertEqual(results.get("device"), "/dev/input/event0") - self.assertTrue(results.get("bustype") is not None) - self.assertTrue(results.get("name") is not None) - self.assertTrue(results.get("product") is not None) - self.assertTrue(results.get("version") is not None) + result = util.lsinput()[0] + self.assertEqual(result.get("device"), "/dev/input/event0") + self.assertTrue(result.get("bustype") is not None) + self.assertTrue(result.get("name") is not None) + self.assertTrue(result.get("product") is not None) + self.assertTrue(result.get("version") is not None) class DirectoriesTestCase(Non26BaseTestCase): diff --git a/python/evemu/util.py b/python/evemu/util.py index 76b17bd..eaabee0 100644 --- a/python/evemu/util.py +++ b/python/evemu/util.py @@ -35,6 +35,8 @@ def lsinput(): value = value[1:-1] if key: data[key] = value + if data: + devices.append(data) return devices |