-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (58 loc) · 2.26 KB
/
Copy pathmain.py
File metadata and controls
70 lines (58 loc) · 2.26 KB
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
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.textinput import TextInput
from jnius import autoclass
import csv
import datetime
import sys
import os
class BetterTextInput(TextInput):
def _keyboard_on_key_down(self, window, keycode, text, modifiers):
self.hook()
super(BetterTextInput, self)._keyboard_on_key_down(window, keycode, text, modifiers)
def hook(self):
raise NotImplementedError
class MainApp(App):
def build(self):
self.hw = autoclass('org.renpy.android.Hardware')
self.hw.accelerometerEnable(1)
self.hw.orientationSensorEnable(1)
Clock.schedule_interval(self.update, 0.2)
self.intro = self.root.ids['intro']
self.root.ids['path'].text = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'readings.csv')
self.setpath()
self.root.ids['path'].hook = self.stop
self.root.ids['path'].bind(focus=self.setpath)
self.progress = self.root.ids['progress']
self.capture = False
self.n = 0
def start(self):
self.root.ids['path'].focus = False
now = str(datetime.datetime.utcnow())
self.intro.text = "Started capture at %s\n\nFile: %s\n" % (now, self.path)
with open(self.path, 'w') as f:
writer = csv.writer(f)
writer.writerow('Timestamp x y z yaw pitch roll'.split(' '))
self.capture = True
def stop(self):
if self.capture:
self.intro.text += "Ended capture at %s" % str(datetime.datetime.utcnow())
self.capture = False
def setpath(self, *args):
self.n = 0
self.path = self.root.ids['path'].text
self.intro.text = "File path set to '%s'" % self.path
def update(self, dt):
if self.capture:
x, y, z = self.hw.accelerometerReading()
yaw, pitch, roll = self.hw.orientationSensorReading()
with open(self.path, 'a') as f:
writer = csv.writer(f)
now = str(datetime.datetime.utcnow())
writer.writerow([now, x, y, z, yaw, pitch, roll])
self.n += 1
self.progress.text = '(%i rows)' % self.n
def quit(self, btn_instance):
sys.exit(0)
if __name__ == '__main__':
MainApp().run()