-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathgyro_sl4a_test.py
162 lines (144 loc) · 5.55 KB
/
gyro_sl4a_test.py
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
'''
@copyright: Hariharan Srinath, 2012
@license: This work is licensed under a Creative Commons Attribution 3.0 Unported License. http://creativecommons.org/licenses/by/3.0/
'''
xmldata = """<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff314859"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="fill_parent"
android:layout_height="0px"
android:textSize="20dp"
android:id="@+id/txt_logo"
android:text="Gyro Test"
android:textColor="#ffffffff"
android:layout_weight="19"
android:gravity="center"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:orientation="horizontal"
android:layout_weight="27">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff314859"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff66a3d2"
android:id="@+id/txt_top"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff314859"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:orientation="horizontal"
android:layout_weight="27">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff66a3d2"
android:id="@+id/txt_left"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff314859"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff66a3d2"
android:layout_weight="1"
android:id="@+id/txt_right"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0px"
android:orientation="horizontal"
android:layout_weight="27">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff314859"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff66a3d2"
android:id="@+id/txt_bottom"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff314859"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>"""
import android
import math
droid = android.Android()
from fullscreenwrapper2 import *
class GyroTestLayout(Layout):
def __init__(self):
super(GyroTestLayout,self).__init__(xmldata,"GyroTest")
def on_show(self):
self.add_event(key_EventHandler(handler_function=self.close_app))
self.add_event(EventHandler("sensors", None, None, None, self.gyro))
def on_close(self):
pass
def gyro(self,view,event):
value = int(event["data"]["pitch"]*60.0/math.pi*2)
#self.views.txt_logo.text = str(value)
color, basecolor = self.get_color(abs(value))
if value > 0:
self.views.txt_top.background = color
self.views.txt_bottom.background = basecolor
else:
self.views.txt_top.background = basecolor
self.views.txt_bottom.background = color
value = int(event["data"]["roll"]*60.0/math.pi*4)
#self.views.txt_logo.text = str(value)
color, basecolor = self.get_color(abs(value))
if value > 0:
self.views.txt_right.background = color
self.views.txt_left.background = basecolor
else:
self.views.txt_right.background = basecolor
self.views.txt_left.background = color
def close_app(self,view,event):
FullScreenWrapper2App.exit_FullScreenWrapper2App()
colorvals = ["#ff66a3d2","#FF63BE7B", "#FF83C77D","#FFA2D07F", "#FFC1DA81", "#FFE0E383", "#FFFFEB84", "#FFFDD17F", "#FFFCB77A", "#FFFA9D75", "#FFF98370", "#FFF8696B"]
def get_color(self,value):
value = abs(value)
if value >59:
value = 59
if value < 0:
value = 0
return self.colorvals[int(value/5)],self.colorvals[0]
if __name__ == '__main__':
FullScreenWrapper2App.initialize(droid)
FullScreenWrapper2App.show_layout(GyroTestLayout())
droid.startSensingTimed(1,200)
FullScreenWrapper2App.eventloop()