File: main.py

package info (click to toggle)
python-plyer 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,668 kB
  • sloc: python: 13,112; sh: 217; makefile: 177
file content (114 lines) | stat: -rw-r--r-- 3,527 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
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
114
#!/usr/bin/python
# -*- coding: utf-8 -*-

from kivy.app import App
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import NumericProperty
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout

interface = Builder.load_string('''
#:import facade plyer.compass
<CompassInterface>:
    facade: facade
    orientation: 'vertical'
    padding: '20dp'
    spacing: '10dp'
    BoxLayout:
        orientation: 'vertical'
        BoxLayout:
            orientation: 'horizontal'
            size_hint: 1, .1
            Button:
                id: enable_button
                text: 'Enable Sensor'
                disabled: False
                on_release:
                    root.enable()
                    disable_button.disabled = not disable_button.disabled
                    enable_button.disabled = not enable_button.disabled
            Button:
                id: disable_button
                text: 'Disable Sensor'
                disabled: True
                on_release:
                    root.disable()
                    disable_button.disabled = not disable_button.disabled
                    enable_button.disabled = not enable_button.disabled
        BoxLayout:
            orientation: 'vertical'
            Label:
                text: "Earth's Magnetic Field"
            Label:
                text: 'including hard iron calibration'
            Label:
                text: '(' + str(root.x_calib) + ','
            Label:
                text: str(root.y_calib) + ','
            Label:
                text: str(root.z_calib) + ')'
            Label:
                text: "Earth's Magnetic Field"
            Label:
                text: 'w/o hard iron calibration'
            Label:
                text: '(' + str(root.x_field) + ','
            Label:
                text: str(root.y_field) + ','
            Label:
                text: str(root.z_field) + ')'
            Label:
                text: 'Hard Iron Calibration'
            Label:
                text: '(' + str(root.x_iron) + ','
            Label:
                text: str(root.y_iron) + ','
            Label:
                text: str(root.z_iron) + ')'
            Label:
                text: 'All the values are in μT'
''')


class CompassInterface(BoxLayout):

    x_calib = NumericProperty(0)
    y_calib = NumericProperty(0)
    z_calib = NumericProperty(0)
    x_field = NumericProperty(0)
    y_field = NumericProperty(0)
    z_field = NumericProperty(0)
    x_iron = NumericProperty(0)
    y_iron = NumericProperty(0)
    z_iron = NumericProperty(0)

    facade = ObjectProperty()

    def enable(self):
        self.facade.enable()
        Clock.schedule_interval(self.get_field, 1 / 20.)
        Clock.schedule_interval(self.get_field_uncalib, 1 / 20.)

    def disable(self):
        self.facade.disable()
        Clock.unschedule(self.get_field)
        Clock.unschedule(self.get_field_uncalib)

    def get_field(self, dt):
        if self.facade.field != (None, None, None):
            self.x_calib, self.y_calib, self.z_calib = self.facade.field

    def get_field_uncalib(self, dt):
        if self.facade.field_uncalib != (None, None, None, None, None, None):
            self.x_field, self.y_field, self.z_field, self.x_iron,\
                self.y_iron, self.z_iron = self.facade.field_uncalib


class CompassTestApp(App):
    def build(self):
        return CompassInterface()


if __name__ == '__main__':
    CompassTestApp().run()