File: accelerometer.py

package info (click to toggle)
python-plyer 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,808 kB
  • sloc: python: 13,395; sh: 217; makefile: 177
file content (75 lines) | stat: -rw-r--r-- 1,626 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'''
Accelerometer
============

The accelerometer is a motion sensor that detects the change (delta) in
movement relative to the current device orientation, in three dimensions
along the x, y, and z axis.

The :class:`Accelerometer` provides access to public methods to
use accelerometer of your device.

Simple Examples
---------------

To enable accelerometer::

    >>> from plyer import accelerometer
    >>> accelerometer.enable()

To disable accelerometer::

    >>> accelerometer.disable()

To get the acceleration::

    >>> accelerometer.acceleration
    (-10.048464775085449, 6.825869083404541, 7.7260890007019043)

Supported Plaforms
------------------
Android, iOS, OS X, Linux

'''


class Accelerometer:
    '''
    Accelerometer facade.
    '''

    @property
    def acceleration(self):
        '''
        Property that returns values of the current acceleration
        sensors, as a (x, y, z) tuple. Returns (None, None, None)
        if no data is currently available.
        '''
        return self.get_acceleration()

    def enable(self):
        '''
        Activate the accelerometer sensor. Throws an error if the
        hardware is not available or not implemented on.
        '''
        self._enable()

    def disable(self):
        '''
        Disable the accelerometer sensor.
        '''
        self._disable()

    def get_acceleration(self):
        return self._get_acceleration()

    # private

    def _enable(self):
        raise NotImplementedError()

    def _disable(self):
        raise NotImplementedError()

    def _get_acceleration(self):
        raise NotImplementedError()