-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScreenCompass.py
267 lines (216 loc) · 5.48 KB
/
ScreenCompass.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
from kivy.uix.widget import Widget
from kivy.core.text import Label
from kivy.graphics.opengl import *
from kivy.graphics import *
from kivy.properties import ObjectProperty
from kivy.core.window import Window
from kivy.animation import Animation
class ScreenCompass(Widget):
def __init__(self, **kwargs):
super(ScreenCompass, self).__init__(**kwargs)
self.screen = 0
self.mtitle = "Compass"
self.orgSize = [145.0*2.0, 145.0*2.0]
self.size = [self.orgSize[0],self.orgSize[1]]
self.pos = [self.size[0]*.5, self.size[1]*.5]
self.scale = 1.0
self.rotation = 0.0
self.updateItC = 0
self.drawIt()
def getCallbacks(self):
return ['gpsD','comCal','comCalAccelGyro']
def settingsNeedIt(self):
return False
def getSize(self):
return [self.orgSize[0],self.orgSize[1], 0.25, -1.0 ]
#return self.orgSize
def setPos(self, pos):
#print("comapass pos",self.pos," size",self.size)
self.pos = pos
def setScale(self, scale):
self.scale = scale
def setRot(self, rot):
self.rotation = rot
def setGui(self, gui):
self.gui = gui
#self.drawIt()
def setHdg(self, v):
if self.gui.animation:
if v > 180.0:
v = -360.0+v
Animation.cancel_all(self.r,'angle')
a = self.r.angle
if (v - a) < -180.0 or (v - a) > 180.0 :
self.r.angle*=-1.0
anim = Animation(angle=v, t='out_quad' )
anim.start( self.r )
else:
self.r.angle = v
def setCog(self, v):
if self.gui.animation:
if v > 180.0:
v = -360.0+v
Animation.cancel_all(self.rCog,'angle')
a = self.rCog.angle
if (v - a) < -180.0 or (v - a) > 180.0 :
self.rCog.angle*=-1.0
anim = Animation(angle=v)
anim.start(self.rCog)
else:
self.rCog.angle = v
def updateItFromScreenChange(self,a='',b=''):
print("updateItFromScreenChange")
def getWidget(self):
return self
def setColor(self,t):
if t == "w":
Color(1,1,1,1)
elif t == "b":
Color(1,1,1,1)
elif t == "cog":
Color(0,1,0,1)
elif t == "hdg":
Color(1,0,0,1)
def drawArrow(self,w):
w = w*0.5+3
points = [
-w,145, w, 145,
w, 130, 0,125,
-w,130, -w,145
]
Line( points=points )
def drawIt(self):
with self.canvas:
self.setColor('w')
PushMatrix()
self.centPos = Translate(0,0,0)
self.comScale = Scale(1,1,1)
self.comRot = Rotate(0,0,0,1)
# HDG
PushMatrix()
self.rHdg = Rotate(0,0,0,-1)
self.setColor("hdg")
l = Label(text="HDG", font_size=12)
l.refresh()
Rectangle(
size = l.size,
pos = ((0-l.size[0]/2.0),130),
texture = l.texture
)
self.drawArrow(l.size[0])
self.setColor("w")
PopMatrix()
#HDG
self.r = Rotate(0,0,0,1)
# COG
PushMatrix()
self.rCog = Rotate(0,0,0,-1)
self.setColor("cog")
l = Label(text="COG", font_size=12)
l.refresh()
Rectangle(
size = l.size,
pos = ((0-l.size[0]/2.0),130),
texture = l.texture
)
self.drawArrow(l.size[0])
self.setColor('w')
PopMatrix()
# COG
# NESW
PushMatrix()
comDir = "NESW"
for d in comDir:
l = Label(text=d, font_size=20)
l.refresh()
Rectangle(
size = l.size,
pos = ((0-l.size[0]/2.0),70),
texture = l.texture
)
Rotate(-90,0,0,1)
PopMatrix()
# NESW
for d in range(0,360,30):
l = Label(text=str(d), font_size=12)
l.refresh()
Rectangle(
size = l.size,
pos = ((0-l.size[0]/2.0),90),
texture = l.texture
)
Rotate(-30,0,0,1)
for l5 in range(0,360,5):
Rotate(5,0,0,1)
Rectangle(
pos = (0, 120),
size = (1, 2)
)
for l10 in range(0,360,10):
Rotate(10,0,0,1)
Rectangle(
pos = (-1, 106),
size = (2, 10)
)
for l45 in range(0,360,45):
Rotate(45,0,0,1)
Rectangle(
pos = (-3, 120),
size = (6, 10)
)
self.bind( pos = self.updateIt )
#self.bind( size = self.updateOfSize )
#self.bind( scale = self.scale )
#self.bind( rotation = self.rotation )
PopMatrix()
def updateOfSize(self,a='',b=''):
print("compass.update of size",self.size,"\na",a,"\nb",b)
def update(self, fromWho, vals):
if self.gui.rl.current[:7] in [ "Compass", 'Widgets']:
pass
else:
return 0
ms = self.gui.th.getTimestamp(True)
if ( self.gui.sen.comCalAccelGyro.lastTimeIter + 5000000.0 ) < ms:
#print("comCalAccel not comming old")
if fromWho == "comCal":
self.setHdg( int(vals[0]) )
if fromWho == 'gps':
self.setCog( int(vals['bearing']) )
elif fromWho == 'comCalAccelGyro':
self.setHdg( int(vals[2]) )
def updateIt(self, *args):
#print("compass.updateIt")
try:
aoeuobc = self.gui
except:
return 0
if self.gui.rl.current[:7] in ["Compass","Widgets"]:
pass
else:
return 0
#self.size[0],self.size[1] = self.orgSize[0],self.orgSize[1]
if 0:
print("ScreenCompass - > update_rect")
print(" size parest ", self.parent.size)
print(" self.orgSize",self.orgSize)
print(" self size ",self.size)
print(" self pos ",self.pos)
#self.rec.pos = self.pos
#self.rec.size = self.size
if self.gui.rl.current == 'Compass':
ws = Window.size
self.centPos.x = ws[0]*.5
self.centPos.y = ws[1]*.5-self.gui.btH
s = (ws[0]/2.0)/140.0
self.comScale.x = s
self.comScale.y = s
self.comScale.z = s
elif self.gui.rl.current[:7] == 'Widgets':
self.centPos.x = self.pos[0]
self.centPos.y = self.pos[1]
self.comScale.x = self.scale
self.comScale.y = self.scale
self.comRot.angle = self.rotation
#self.drawIt()
self.updateItC+=1