Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux accel #51

Closed
wants to merge 4 commits into from
Closed

Linux accel #51

wants to merge 4 commits into from

Conversation

depau
Copy link
Contributor

@depau depau commented Apr 2, 2014

Please check the comments in line 23. I didn't know which behavior was better, the choice is up to you.

Apparently there's no need to use evdev or stuff: according to IBM sysfs is reliable. You just need a glob to look for an accelerometer.
I'm not sure though about the range of the acceleration: on my PC it's from 1000 to -1000 (on android it's 10 to -10), but I don't know if it's related to the hardware used. I wanted to make it consisted so I simply divided it by 100, but if sysfs is not consistent we need to fix that and figure something out.

BTW I tested it and it works, at least with my accelerometer.
This is IBM's script I was talking about, where they use sysfs: http://www.ibm.com/developerworks/apps/download/index.jsp?contentid=150021&filename=knockAge-0.1.zip&method=http&locale=

(I forgot to checkout master before creating the new branch, I guess that if you merge this pr it will also merge the commits from the windows_email branch...)


def _get_acceleration(self):
try:
pos = glob.glob("/sys/devices/platform/*/position")[0]
Copy link
Member

Choose a reason for hiding this comment

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

About #49 (comment): No, I don't see a similar mechanism on OS X. There is another method described here: https://github.com/robinedwards/Mac-MotionSensor/blob/master/unimotion.c but I haven't tested it yet.

@depau
Copy link
Contributor Author

depau commented Apr 2, 2014

@trivedigaurav Could you please try this module:
http://code.google.com/p/pyapplesms/source/checkout
Check it out, install/build it and run the example to see if it works. Then I'll push the branch and I'll let you test it, and then the kivy team will decide how to include the module, whether to include the source code or put the pre-built module.

@depau
Copy link
Contributor Author

depau commented Apr 2, 2014

This is the experimental branch for mac os x's accelerometer implementation, you need to install the pyapplesms module first.
https://github.com/Davideddu/plyer/tree/macosx_accel

@trivedigaurav
Copy link
Member

Nope, I am afraid this doesn't work on my system:

an error occurred: No motion sensor available

@depau
Copy link
Contributor Author

depau commented Apr 2, 2014

Well you don't have a motion sensor apparently... Are you trying it on a desktop mac? Do you have a MacBook?

@trivedigaurav
Copy link
Member

I tried on a MacBook Pro 15-inch, Early 2011 on OS X 10.9.1.

@depau
Copy link
Contributor Author

depau commented Apr 2, 2014

I don't know, maybe it doesn't have the sudden motion sensor... edit example.py, remove the exception catcher and see if the complete exception givers more information...
According to apple all Intel based MacBooks have the accelerometer, except the ones with the SSD: http://support.apple.com/kb/ht1935

@trivedigaurav
Copy link
Member

I found the issue here. Apparently there have been some differences in the way you make the IOCTL call on 64-bit OS X is a bit different. After integrating the patch specified here: http://code.google.com/p/websaver/issues/detail?id=3, I was able to get the accelerometer working on my macbook.

@trivedigaurav
Copy link
Member

One caveat that I can see is that pyapplesms is under LGPL, so I am not sure how we'd be affected by it. It may be a good idea to check that before we use the library.

@trivedigaurav
Copy link
Member

@Davideddu I think we should raise an exception on enable if no accelerometer is present.

@depau
Copy link
Contributor Author

depau commented May 20, 2014

I think so too, but I don't know if it's the case as the documentation doesn't say when and what exception is raised...

@trivedigaurav
Copy link
Member

I think a good way to do this would be to check all the necessary stuff in
instance(), return the accelerometer class only if the prerequisites are
there. Otherwise raise an exception. Check out
https://github.com/kivy/plyer/blob/master/plyer/platforms/linux/notification.pyfor
an example.

On Mon, May 19, 2014 at 10:09 PM, Davide Depau [email protected]:

I think so too, but I don't know if it's the case as the documentation
doesn't say when and what exception is raised...


Reply to this email directly or view it on GitHubhttps://github.com//pull/51#issuecomment-43579561
.

@depau
Copy link
Contributor Author

depau commented May 20, 2014

Yeah that would work. Tomorrow I'm planning on using the computer, I'll figure out something...

@trivedigaurav
Copy link
Member

@Davideddu Also note that your PR has some unintended file changes as well from your win_email branch. You should fix those issues as well.

@depau
Copy link
Contributor Author

depau commented May 23, 2014

@trivedigaurav I don't think removing again the win email patches will do any good. I'd either have to rebase it (obviously I mistakenly branched linux_accel from win_email instead of master) which I'm not gonna do because the I already pushed those commits, or delete the files and re-commit, which is probably going to make problems when merging, or amend the commit, same as rebase.

About the exception, what do you think of an EnvironmentError(errno.ENODEV) ?
https://docs.python.org/2/library/exceptions.html#exceptions.EnvironmentError
https://docs.python.org/2/library/errno.html#errno.ENODEV

It seems to best describe the problem, because it's not an OS related error, but hardware. In other words OSError would be the first choice, but as Linux is the coolest OS in the world and of course it supports accelerometers we're not gonna call it that way :) :D

@trivedigaurav
Copy link
Member

@Davideddu I have created a cleaned up version of your request (#68), so that it can be easily merged.

@depau
Copy link
Contributor Author

depau commented Jun 28, 2014

Perfect, thank you, @trivedigaurav! Sorry I'm at an intermediate git level, that would have been too complicated for me!

@depau
Copy link
Contributor Author

depau commented Aug 4, 2014

As @trivedigaurav made the new pull request this is better closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants