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
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
36 changes: 36 additions & 0 deletions plyer/platforms/linux/accelerometer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'''
Linux accelerometer
---------------------
'''

from plyer.facades import Accelerometer
import os
import glob
import re

class LinuxAccelerometer(Accelerometer):

def _enable(self):
pass

def _disable(self):
pass

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.

except IndexError:
# FIXME: decide whether it should return 0,0,0 or raise an exception
# when no accelerometer is present.
return (0, 0, 0)

with open(pos, "r") as p:
t = p.read()
coords = re.findall(r"[-]?\d+\.?\d*", t)
# Apparently the acceleration on sysfs goes from -1000 to 1000.
# I divide it by 100 to make it equivalent to Android.
# The negative is because the coordinates are inverted on Linux
return [float(i)/-100 for i in coords]

def instance():
return LinuxAccelerometer()
31 changes: 31 additions & 0 deletions plyer/platforms/win/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
from urllib import quote
from plyer.facades import Email

class WindowsEmail(Email):
def _send(self, **kwargs):
recipient = kwargs.get('recipient')
subject = kwargs.get('subject')
text = kwargs.get('text')
create_chooser = kwargs.get('create_chooser')

uri = "mailto:"
if recipient:
uri += str(recipient)
if subject:
uri += "?" if not "?" in uri else "&"
uri += "subject="
uri += quote(str(subject))
if text:
uri += "?" if not "?" in uri else "&"
uri += "body="
uri += quote(str(text))

try:
os.startfile(uri)
except WindowsError:
print "Warning: unable to find a program able to send emails."


def instance():
return WindowsEmail()