Repository: kivy/kivy

Issue:
Fix HIDMotionEvent log formatting
This was posted by C_D on irc, seems to be a py3 issue, but not tested.

``` python
[INFO              ] Logger: Record log in /home/fpg/.kivy/logs/kivy_14-12-10_0.txt
[INFO              ] Kivy: v1.9.0-dev
[INFO              ] Python: v3.4.2 (default, Jan 11 2015, 22:16:42) 
[GCC 4.9.2 20141224 (prerelease)]
[INFO              ] Factory: 173 symbols loaded
[INFO              ] Image: Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO              ] Text: Provider: sdl2
[INFO              ] Window: Provider: egl_rpi
[INFO              ] GL: OpenGL version <b'OpenGL ES 2.0'>
[INFO              ] GL: OpenGL vendor <b'Broadcom'>
[INFO              ] GL: OpenGL renderer <b'VideoCore IV HW'>
[INFO              ] GL: OpenGL parsed version: 2, 0
[INFO              ] GL: Shading version <b'OpenGL ES GLSL ES 1.00'>
[INFO              ] GL: Texture max size <2048>
[INFO              ] GL: Texture max units <8>
[INFO              ] Shader: fragment shader: <b'Compiled'>
[INFO              ] Shader: vertex shader: <b'Compiled'>
[INFO              ] Window: virtual keyboard not allowed, single mode, not docked
[INFO              ] OSC: using <multiprocessing> for socket
[INFO              ] ProbeSysfs: device match: /dev/input/event0
[INFO              ] HIDInput: Read event from </dev/input/event0>
[INFO              ] ProbeSysfs: device match: /dev/input/event1
[INFO              ] HIDInput: Read event from </dev/input/event1>
[INFO              ] ProbeSysfs: device match: /dev/input/event2
[INFO              ] HIDInput: Read event from </dev/input/event2>
[INFO              ] Base: Start application main loop
[WARNING           ] stderr: Exception in thread Thread-1:
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 921, in _bootstrap_inner
[WARNING           ] stderr: Exception in thread Thread-3:
[INFO              ] GL: NPOT texture support is available
[WARNING           ] stderr:     self.run()
[WARNING           ] stderr: Exception in thread Thread-2:
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 869, in run
[WARNING           ] stderr:     self._target(*self._args, **self._kwargs)
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 921, in _bootstrap_inner
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/input/providers/hidinput.py", line 594, in _thread_run
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 921, in _bootstrap_inner
[WARNING           ] stderr:     self.run()
[WARNING           ] stderr:     " " * 256).split('\x00')[0]
[WARNING           ] stderr:     self.run()
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 869, in run
[WARNING           ] stderr:     self._target(*self._args, **self._kwargs)
[WARNING           ] stderr: TypeError: Type str doesn't support the buffer API
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 869, in run
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/input/providers/hidinput.py", line 594, in _thread_run
[WARNING           ] stderr: 
[WARNING           ] stderr:     self._target(*self._args, **self._kwargs)
[WARNING           ] stderr:     " " * 256).split('\x00')[0]
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/input/providers/hidinput.py", line 594, in _thread_run
[WARNING           ] stderr: TypeError: Type str doesn't support the buffer API
[WARNING           ] stderr:     " " * 256).split('\x00')[0]
[WARNING           ] stderr: 
[WARNING           ] stderr: TypeError: Type str doesn't support the buffer API
[WARNING           ] stderr: 
[INFO              ] Base: Leaving application in progress...
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "main.py", line 14, in <module>
[WARNING           ] stderr:     TutorialApp().run()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/app.py", line 824, in run
[WARNING           ] stderr:     runTouchApp()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/base.py", line 484, in runTouchApp
[WARNING           ] stderr:     EventLoop.window.mainloop()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", line 77, in mainloop
[WARNING           ] stderr:     self._mainloop()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", line 72, in _mainloop
[WARNING           ] stderr:     EventLoop.idle()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/base.py", line 333, in idle
[WARNING           ] stderr:     Clock.tick_draw()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/clock.py", line 490, in tick_draw
[WARNING           ] stderr:     self._process_events_before_frame()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/clock.py", line 634, in _process_events_before_frame
[WARNING           ] stderr:     for event in events[:]:
[WARNING           ] stderr: KeyboardInterrupt
```
## <bountysource-plugin>

Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/8855242-fix-hidmotionevent-log-formatting?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github).
</bountysource-plugin>



Discussion:
I can confirm that it works in python2 and not in python3. I dont know if this is specific to my hardware or not. I can recreate the bug running any of the kivy example code.

Hardware is Raspberry Pi (armv6) using this touch screen: http://www.dfrobot.com/index.php?route=product/product&product_id=1062

Heres a log showing it working properly in python2:

[INFO              ] Kivy: v1.9.0-dev
[INFO              ] Python: v2.7.9 (default, Dec 12 2014, 07:23:34) 
[GCC 4.9.2]
[INFO              ] Factory: 173 symbols loaded
[INFO              ] Image: Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO              ] Window: Provider: egl_rpi
[INFO              ] GL: OpenGL version <OpenGL ES 2.0>
[INFO              ] GL: OpenGL vendor <Broadcom>
[INFO              ] GL: OpenGL renderer <VideoCore IV HW>
[INFO              ] GL: OpenGL parsed version: 2, 0
[INFO              ] GL: Shading version <OpenGL ES GLSL ES 1.00>
[INFO              ] GL: Texture max size <2048>
[INFO              ] GL: Texture max units <8>
[INFO              ] Shader: fragment shader: <Compiled>
[INFO              ] Shader: vertex shader: <Compiled>
[INFO              ] Window: virtual keyboard not allowed, single mode, not docked
[INFO              ] Text: Provider: sdl2
[INFO              ] OSC: using <multiprocessing> for socket
[INFO              ] ProbeSysfs: device match: /dev/input/event0
[INFO              ] HIDInput: Read event from </dev/input/event0>
[INFO              ] ProbeSysfs: device match: /dev/input/event1
[INFO              ] HIDInput: Read event from </dev/input/event1>
[INFO              ] ProbeSysfs: device match: /dev/input/event2
[INFO              ] HIDInput: Read event from </dev/input/event2>
[INFO              ] Base: Start application main loop
[INFO              ] HIDMotionEvent: using <Logitech USB Keyboard>
[INFO              ] HIDMotionEvent: using <Logitech USB Keyboard>
[INFO              ] HIDMotionEvent: using <RoboPeakUSBDisplayTS>
[INFO              ] GL: NPOT texture support is available
[INFO              ] HIDMotionEvent: <RoboPeakUSBDisplayTS> range ABS X position is 0 - 320
[INFO              ] HIDMotionEvent: <RoboPeakUSBDisplayTS> range ABS Y position is 0 - 240
[INFO              ] HIDMotionEvent: <RoboPeakUSBDisplayTS> range ABS pressure is 0 - 1
[INFO              ] Base: Leaving application in progress...
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "main.py", line 77, in <module>
[WARNING           ] stderr:     PongApp().run()
[WARNING           ] stderr:   File "/usr/lib/python2.7/site-packages/kivy/app.py", line 824, in run
[WARNING           ] stderr:     runTouchApp()
[WARNING           ] stderr:   File "/usr/lib/python2.7/site-packages/kivy/base.py", line 484, in runTouchApp
[WARNING           ] stderr:     EventLoop.window.mainloop()
[WARNING           ] stderr:   File "/usr/lib/python2.7/site-packages/kivy/core/window/window_egl_rpi.py", line 77, in mainloop
[WARNING           ] stderr:     self._mainloop()
[WARNING           ] stderr:   File "/usr/lib/python2.7/site-packages/kivy/core/window/window_egl_rpi.py", line 72, in _mainloop
[WARNING           ] stderr:     EventLoop.idle()
[WARNING           ] stderr:   File "/usr/lib/python2.7/site-packages/kivy/base.py", line 333, in idle
[WARNING           ] stderr:     Clock.tick_draw()
[WARNING           ] stderr:   File "/usr/lib/python2.7/site-packages/kivy/clock.py", line 490, in tick_draw
[WARNING           ] stderr:     self._process_events_before_frame()
[WARNING           ] stderr:   File "/usr/lib/python2.7/site-packages/kivy/clock.py", line 633, in _process_events_before_frame
[WARNING           ] stderr:     remove = events.remove
[WARNING           ] stderr: KeyboardInterrupt

Can you check whether changing in kivy/input/providers/hidinput.py", line 594 `" " * 256).split('\x00')[0]` to `b" " * 256).split(b'\x00')[0]` fixes it?

Making progress, got slightly further before the next error.

EDIT: Better post a log of the same test program. Also I should be available in the IRC channel for the next 5 hours or so if that works with your time zone.

[INFO              ] Kivy: v1.9.0-dev
[INFO              ] Python: v3.4.2 (default, Jan 11 2015, 22:16:42)
[GCC 4.9.2 20141224 (prerelease)]
[INFO              ] Factory: 173 symbols loaded
[INFO              ] Image: Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO              ] Window: Provider: egl_rpi
[INFO              ] GL: OpenGL version <b'OpenGL ES 2.0'>
[INFO              ] GL: OpenGL vendor <b'Broadcom'>
[INFO              ] GL: OpenGL renderer <b'VideoCore IV HW'>
[INFO              ] GL: OpenGL parsed version: 2, 0
[INFO              ] GL: Shading version <b'OpenGL ES GLSL ES 1.00'>
[INFO              ] GL: Texture max size <2048>
[INFO              ] GL: Texture max units <8>
[INFO              ] Shader: fragment shader: <b'Compiled'>
[INFO              ] Shader: vertex shader: <b'Compiled'>
[INFO              ] Window: virtual keyboard not allowed, single mode, not docked
[INFO              ] Text: Provider: sdl2
[INFO              ] OSC: using <multiprocessing> for socket
[INFO              ] ProbeSysfs: device match: /dev/input/event0
[INFO              ] HIDInput: Read event from </dev/input/event0>
[INFO              ] ProbeSysfs: device match: /dev/input/event1
[INFO              ] HIDInput: Read event from </dev/input/event1>
[INFO              ] ProbeSysfs: device match: /dev/input/event2
[INFO              ] HIDInput: Read event from </dev/input/event2>
[INFO              ] Base: Start application main loop
[INFO              ] HIDMotionEvent: using <b'Logitech USB Keyboard'>
[INFO              ] HIDMotionEvent: using <b'Logitech USB Keyboard'>
[INFO              ] HIDMotionEvent: using <b'RoboPeakUSBDisplayTS'>
[INFO              ] HIDMotionEvent: <b'RoboPeakUSBDisplayTS'> range ABS X position is 0 - 320
[INFO              ] GL: NPOT texture support is available
[INFO              ] HIDMotionEvent: <b'RoboPeakUSBDisplayTS'> range ABS Y position is 0 - 240
[INFO              ] HIDMotionEvent: <b'RoboPeakUSBDisplayTS'> range ABS pressure is 0 - 1
[WARNING           ] stderr: Exception in thread Thread-3:
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 921, in _bootstrap_inner
[WARNING           ] stderr:     self.run()
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 869, in run
[WARNING           ] stderr:     self._target(_self._args, *_self._kwargs)
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/input/providers/hidinput.py", line 673, in _thread_run
[WARNING           ] stderr:     for i in range(len(data) / struct_input_event_sz):
[WARNING           ] stderr: TypeError: 'float' object cannot be interpreted as an integer
[WARNING           ] stderr:
[WARNING           ] stderr: Exception in thread Thread-1:
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 921, in _bootstrap_inner
[WARNING           ] stderr:     self.run()
[WARNING           ] stderr:   File "/usr/lib/python3.4/threading.py", line 869, in run
[WARNING           ] stderr:     self._target(_self._args, *_self._kwargs)
[INFO              ] Base: Leaving application in progress...
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/input/providers/hidinput.py", line 673, in _thread_run
[WARNING           ] stderr:   File "main.py", line 77, in <module>
[WARNING           ] stderr:     for i in range(len(data) / struct_input_event_sz):
[WARNING           ] stderr:     PongApp().run()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/app.py", line 824, in run
[WARNING           ] stderr: TypeError: 'float' object cannot be interpreted as an integer
[WARNING           ] stderr:
[WARNING           ] stderr:     runTouchApp()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/base.py", line 484, in runTouchApp
[WARNING           ] stderr:     EventLoop.window.mainloop()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", line 77, in mainloop
[WARNING           ] stderr:     self._mainloop()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/core/window/window_egl_rpi.py", line 72, in _mainloop
[WARNING           ] stderr:     EventLoop.idle()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/base.py", line 324, in idle
[WARNING           ] stderr:     Clock.tick()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/clock.py", line 483, in tick
[WARNING           ] stderr:     self._process_events()
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/clock.py", line 615, in _process_events
[WARNING           ] stderr:     event.tick(self._last_tick, remove)
[WARNING           ] stderr:   File "/usr/lib/python3.4/site-packages/kivy/clock.py", line 374, in tick
[WARNING           ] stderr:     ret = callback(self._dt)
[WARNING           ] stderr:   File "main.py", line 43, in update
[WARNING           ] stderr:     self.ball.move()
[WARNING           ] stderr:   File "main.py", line 30, in move
[WARNING           ] stderr:     self.pos = Vector(*self.velocity) + self.pos
[WARNING           ] stderr: KeyboardInterrupt

Try it with master because in master it seems to have int(...): https://github.com/kivy/kivy/blob/master/kivy/input/providers/hidinput.py#L673. 

Hi, sorry it took me so long to test.

I can confirm that this update https://github.com/kivy/kivy/pull/3072 seems to have fixed the issue.

One comment though, the HIDMotionEvents log messages are now little odd:

[INFO              ] HIDMotionEvent: using < b'Logitech USB Keyboard\x00                                                                                                                                                                                                                                          '>
[INFO              ] HIDMotionEvent: using < b'Logitech USB Keyboard\x00                                                                                                                                                                                                                                          '>

There is a trailing "\x00" followed by many (256?) space characters before the closing ''>". Its hard to show, it doesnt display properly when pasted here, I think the whitespace is removed automatically.

@cdrose You should consider doing a PR with a fix :). 

Ive been a bit hesitant to play with the kivy code yet, as I havent dug into it enough to really know how it all fits together. But I'll see what i can do =) Happy to help out where I can!

Well, this is a perfect place to start because the issue here is mostly with manipulating python strings/bytes. So it doesn't involve that much kivy itself.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.


Resolving patch:
diff --git a/kivy/input/providers/hidinput.py b/kivy/input/providers/hidinput.py
--- a/kivy/input/providers/hidinput.py
+++ b/kivy/input/providers/hidinput.py
@@ -608,8 +608,8 @@ def normalize(value, vmin, vmax):
             fd = open(input_fn, 'rb')
 
             # get the controler name (EVIOCGNAME)
-            device_name = str(fcntl.ioctl(fd, EVIOCGNAME + (256 << 16),
-                                      " " * 256)).split('\x00')[0]
+            device_name = fcntl.ioctl(fd, EVIOCGNAME + (256 << 16),
+                                      " " * 256).decode().strip()
             Logger.info('HIDMotionEvent: using <%s>' % device_name)
 
             # get abs infos


Test patch: