File: compass.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 (113 lines) | stat: -rw-r--r-- 2,540 bytes parent folder | download | duplicates (3)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'''
Compass
=======

The :class:`Compass` provides access to public methods to use compass of your
device.

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

To enable compass::

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

To disable compass::

    >>> compass.disable()

To get the field::

    >>> compass.field()
    (-23.721826553344727, -5.7114701271057129, -36.749668121337891)

To get the uncalibrated field along with iron bias estimation::

    >>> compass.field_uncalib()
    (a,b,c,x,y,z)
    # a,b,c denote the Geomagnetic field strength
    # (without hard iron calibration) along the three axes.
    # x,y,z denote the Iron bias estimation along the three axes.

Supported Platforms
-------------------
Android, iOS

'''


class Compass:
    '''Compass facade.

    .. versionadded:: 1.2.0
    '''

    @property
    def orientation(self):
        '''
        WARNING:: This property is deprecated after API level 8.
        Use `compass.field` instead.

        Property that returns values of the current compass
        (magnetic field) sensors, as a (x, y, z) tuple.
        Returns (None, None, None) if no data is currently available.
        '''
        return self.get_orientation()

    @property
    def field(self):
        '''
        .. versionadded:: 1.3.1

        Property that returns values of the current compass
        (magnetic field) sensors, as a (x, y, z) tuple.
        Returns (None, None, None) if no data is currently available.
        '''
        return self.get_orientation()

    @property
    def field_uncalib(self):
        '''
        .. versionadded:: 1.3.1

        Property that returns the current value of Uncalibrated Magnetic Field
        (without hard iron calibration) along with the iron bias estimation
        along the three axes.
        '''
        return self.get_field_uncalib()

    def enable(self):
        '''
        Activate the compass sensor.
        '''
        self._enable()

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

    def get_orientation(self):
        return self._get_orientation()

    def get_field_uncalib(self):
        '''
        .. versionadded:: 1.3.1
        '''
        return self._get_field_uncalib()

    # private

    def _enable(self):
        raise NotImplementedError()

    def _disable(self):
        raise NotImplementedError()

    def _get_orientation(self):
        raise NotImplementedError()

    def _get_field_uncalib(self):
        raise NotImplementedError()