summaryrefslogtreecommitdiff
path: root/external/plyer/platforms/ios/accelerometer.py
blob: bf1ef02e31ad41071c3040724bd04f0af2f28cc3 (plain) (blame)
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
'''
iOS accelerometer
-----------------

Taken from: http://pyobjus.readthedocs.org/en/latest/pyobjus_ios.html \
            #accessing-accelerometer
'''

from plyer.facades import Accelerometer
from pyobjus import autoclass


class IosAccelerometer(Accelerometer):

    def __init__(self):
        super(IosAccelerometer, self).__init__()
        self.bridge = autoclass('bridge').alloc().init()
        self.bridge.motionManager.setAccelerometerUpdateInterval_(0.1)

    def _enable(self):
        self.bridge.startAccelerometer()

    def _disable(self):
        self.bridge.stopAccelerometer()

    def _get_acceleration(self):
        return (
            self.bridge.ac_x,
            self.bridge.ac_y,
            self.bridge.ac_z)


def instance():
    return IosAccelerometer()