| 1 |
''' |
| 2 |
Gyroscope |
| 3 |
============ |
| 4 |
|
| 5 |
The gyroscope measures the rate of rotation around a device's x, y, |
| 6 |
and z axis. |
| 7 |
|
| 8 |
The :class:`Gyroscope` provides access to public methods to |
| 9 |
use gyroscope of your device. |
| 10 |
|
| 11 |
Simple Examples |
| 12 |
--------------- |
| 13 |
|
| 14 |
To enable gyroscope:: |
| 15 |
|
| 16 |
>>> from plyer import gyroscope |
| 17 |
>>> gyroscope.enable() |
| 18 |
|
| 19 |
To disable gyroscope:: |
| 20 |
|
| 21 |
>>> gyroscope.disable() |
| 22 |
|
| 23 |
To get the rate of rotation along the three axes:: |
| 24 |
|
| 25 |
>>> gyroscope.rotation |
| 26 |
(-0.0034587313421070576, -0.0073830625042319298, 0.0046892408281564713) |
| 27 |
|
| 28 |
To get the uncalibrated rate of rotation along the three axes along with the |
| 29 |
drift compensation:: |
| 30 |
|
| 31 |
>>> gyroscope.rotation_uncalib |
| 32 |
() |
| 33 |
where the first three values show the rate of rotation w/o drift |
| 34 |
compensation and the last three show the estimated drift along the three |
| 35 |
axes. |
| 36 |
|
| 37 |
Supported Platforms |
| 38 |
------------------- |
| 39 |
Android, iOS |
| 40 |
|
| 41 |
''' |
| 42 |
|
| 43 |
|
| 44 |
class Gyroscope: |
| 45 |
''' |
| 46 |
Gyroscope facade. |
| 47 |
|
| 48 |
.. versionadded:: 1.3.1 |
| 49 |
''' |
| 50 |
|
| 51 |
@property |
| 52 |
def rotation(self): |
| 53 |
''' |
| 54 |
Property that returns the rate of rotation around the device's local |
| 55 |
X, Y and Z axis. |
| 56 |
|
| 57 |
Along x-axis: angular speed around the X axis |
| 58 |
Along y-axis: angular speed around the Y axis |
| 59 |
Along z-axis: angular speed around the Z axis |
| 60 |
|
| 61 |
Returns (None, None, None) if no data is currently available. |
| 62 |
''' |
| 63 |
return self.get_orientation() |
| 64 |
|
| 65 |
@property |
| 66 |
def rotation_uncalib(self): |
| 67 |
''' |
| 68 |
Property that returns the current rate of rotation around the X, Y and |
| 69 |
Z axis. An estimation of the drift on each axis is reported as well. |
| 70 |
|
| 71 |
Along x-axis: angular speed (w/o drift compensation) around the X axis |
| 72 |
Along y-axis: angular speed (w/o drift compensation) around the Y axis |
| 73 |
Along z-axis: angular speed (w/o drift compensation) around the Z axis |
| 74 |
|
| 75 |
Along x-axis: estimated drift around X axis |
| 76 |
Along y-axis: estimated drift around Y axis |
| 77 |
Along z-axis: estimated drift around Z axis |
| 78 |
|
| 79 |
Returns (None, None, None, None, None, None) if no data is currently |
| 80 |
available. |
| 81 |
''' |
| 82 |
return self.get_rotation_uncalib() |
| 83 |
|
| 84 |
@property |
| 85 |
def orientation(self): |
| 86 |
''' |
| 87 |
WARNING:: This property is deprecated after API Level 8. |
| 88 |
Use `gyroscope.rotation` instead. |
| 89 |
|
| 90 |
Property that returns values of the current Gyroscope sensors, as |
| 91 |
a (x, y, z) tuple. Returns (None, None, None) if no data is currently |
| 92 |
available. |
| 93 |
''' |
| 94 |
return self.get_orientation() |
| 95 |
|
| 96 |
def enable(self): |
| 97 |
''' |
| 98 |
Activate the Gyroscope sensor. |
| 99 |
''' |
| 100 |
self._enable() |
| 101 |
|
| 102 |
def disable(self): |
| 103 |
''' |
| 104 |
Disable the Gyroscope sensor. |
| 105 |
''' |
| 106 |
self._disable() |
| 107 |
|
| 108 |
def get_orientation(self): |
| 109 |
return self._get_orientation() |
| 110 |
|
| 111 |
def get_rotation_uncalib(self): |
| 112 |
return self._get_rotation_uncalib() |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
def _enable(self): |
| 117 |
raise NotImplementedError() |
| 118 |
|
| 119 |
def _disable(self): |
| 120 |
raise NotImplementedError() |
| 121 |
|
| 122 |
def _get_orientation(self): |
| 123 |
raise NotImplementedError() |
| 124 |
|
| 125 |
def _get_rotation_uncalib(self): |
| 126 |
raise NotImplementedError() |