keep state on root.parent
This commit is contained in:
parent
8c495ceb2f
commit
a5362d719e
@ -2,6 +2,10 @@
|
||||
#:import RiseInTransition kivy.uix.screenmanager.RiseInTransition
|
||||
#:import facade plyer.compass
|
||||
|
||||
<RootScreen>:
|
||||
CompassScreen:
|
||||
MapScreen:
|
||||
|
||||
|
||||
<MapScreen>:
|
||||
BoxLayout:
|
||||
@ -13,10 +17,15 @@
|
||||
ActionPrevious:
|
||||
title: 'Social Cycling'
|
||||
with_previous: False
|
||||
ActionToggleButton:
|
||||
text: 'Start' if self.state == 'normal' else 'Stop'
|
||||
on_state:
|
||||
root.sensors_start() if self.state == 'down' else \
|
||||
root.sensors_stop()
|
||||
ActionButton:
|
||||
important: True
|
||||
text: 'we ride together'
|
||||
on_press: root.manager.current = 'compass'
|
||||
on_press: root.manager.current = 'compass' ; root.choose_destination()
|
||||
|
||||
MapView:
|
||||
id: mapview
|
||||
@ -45,44 +54,17 @@
|
||||
ActionPrevious:
|
||||
title: 'Social Cycling'
|
||||
with_previous: False
|
||||
ActionToggleButton:
|
||||
text: 'Start' if self.state == 'normal' else 'Stop'
|
||||
on_state:
|
||||
root.sensors_start() if self.state == 'down' else \
|
||||
root.sensors_stop()
|
||||
ActionButton:
|
||||
important: True
|
||||
text: 'set destination'
|
||||
on_press: root.manager.current = 'map'
|
||||
|
||||
BoxLayout:
|
||||
orientation: 'horizontal'
|
||||
size_hint_y: 0.07
|
||||
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
|
||||
|
||||
Label:
|
||||
text: root.gps_location
|
||||
|
||||
ToggleButton:
|
||||
text: 'Start' if self.state == 'normal' else 'Stop'
|
||||
on_state:
|
||||
root.start(1000, 0) if self.state == 'down' else \
|
||||
root.stop()
|
||||
|
||||
|
||||
|
||||
FloatLayout:
|
||||
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .08, .08, .08
|
||||
|
||||
87
main.py
87
main.py
@ -14,11 +14,15 @@ from kivy.animation import Animation
|
||||
from math import floor
|
||||
import random
|
||||
|
||||
#from LatLon23 import LatLon, Latitude, Longitude
|
||||
from pprint import pprint
|
||||
|
||||
root = None
|
||||
|
||||
class MapScreen(Screen):
|
||||
mapview = MapView()
|
||||
|
||||
def choose_destination(self):
|
||||
root.parent.dest_lat = self.ids.centermark.lat
|
||||
root.parent.dest_lon = self.ids.centermark.lon
|
||||
|
||||
|
||||
class CompassScreen(Screen):
|
||||
@ -30,13 +34,6 @@ class CompassScreen(Screen):
|
||||
gps_location = StringProperty()
|
||||
gps_status = StringProperty('Click Start to get GPS location updates')
|
||||
|
||||
def enable(self):
|
||||
self.facade.enable()
|
||||
Clock.schedule_interval(self.get_field, 1 / 5.)
|
||||
|
||||
def disable(self):
|
||||
self.facade.disable()
|
||||
Clock.unschedule(self.get_field)
|
||||
|
||||
def get_field(self, dt):
|
||||
needle_angle = 7
|
||||
@ -60,42 +57,56 @@ class CompassScreen(Screen):
|
||||
self._anim = Animation(needle_angle=needle_angle, d=.2, t='out_quad')
|
||||
self._anim.start(self)
|
||||
|
||||
def sensors_start(self):
|
||||
self.compass_enable()
|
||||
self.gps_start(1000, 0)
|
||||
|
||||
def start(self, minTime, minDistance):
|
||||
def sensors_stop(self):
|
||||
self.compass_disable()
|
||||
self.gps_stop()
|
||||
|
||||
def compass_enable(self):
|
||||
self.facade.enable()
|
||||
Clock.schedule_interval(self.get_field, 1 / 5.0)
|
||||
|
||||
def compass_disable(self):
|
||||
self.facade.disable()
|
||||
Clock.unschedule(self.get_field)
|
||||
|
||||
def gps_start(self, minTime, minDistance):
|
||||
gps.start(minTime, minDistance)
|
||||
|
||||
def stop(self):
|
||||
def gps_stop(self):
|
||||
gps.stop()
|
||||
|
||||
def on_pause(self):
|
||||
gps.stop()
|
||||
self.compass_disable()
|
||||
self.gps_stop()
|
||||
return True
|
||||
|
||||
def on_resume(self):
|
||||
gps.start(1000, 0)
|
||||
self.compass_enable()
|
||||
self.gps_start(1000, 0)
|
||||
|
||||
@mainthread
|
||||
def on_location(self, **kwargs):
|
||||
print('aguas on location')
|
||||
# print(kwargs)
|
||||
|
||||
# p = LatLon(Latitude(kwargs['lat']),
|
||||
# Longitude(kwargs['lon']))
|
||||
self.parent.parent.lat = kwargs['lat']
|
||||
self.parent.parent.lon = kwargs['lon']
|
||||
# self.parent.speed = kwargs['speed']
|
||||
# self.parent.bearing = kwargs['bearing']
|
||||
|
||||
# destination_point = LatLon(Latitude(28.89335172),
|
||||
# Longitude(76.59449171))
|
||||
|
||||
self.gps_location = '\n'.join([
|
||||
'{}={}'.format(k, v) for k, v in kwargs.items()])
|
||||
# self.gps_location += str(p.heading_initial(destination_point))
|
||||
# self.gps_location = '\n'.join([
|
||||
# '{}={}'.format(k, v) for k, v in kwargs.items()])
|
||||
|
||||
# bearing = atan2(sin(long2-long1)*cos(lat2), cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(long2-long1))
|
||||
# bearing = degrees(bearing)
|
||||
# bearing = (bearing + 360) % 360
|
||||
# https://stackoverflow.com/questions/4913349/haversine-formula-in-python-bearing-and-distance-between-two-gps-points#4913653
|
||||
|
||||
|
||||
@mainthread
|
||||
def on_status(self, stype, status):
|
||||
print('aguas on status')
|
||||
self.gps_status = 'type={}\n{}'.format(stype, status)
|
||||
|
||||
|
||||
@ -106,6 +117,9 @@ class FlockompassApp(App):
|
||||
lat = 19.3419
|
||||
lon = -99.1499
|
||||
|
||||
dest_lat = 19.3429
|
||||
dest_lon = -99.15
|
||||
|
||||
def move_around(self, t):
|
||||
self.lat += random.uniform(-0.01,0.01)
|
||||
self.lon += random.uniform(-0.01,0.01)
|
||||
@ -113,10 +127,6 @@ class FlockompassApp(App):
|
||||
self.ms.ids.mapview.center_on(self.lat, self.lon)
|
||||
|
||||
# where the marker's at
|
||||
print(
|
||||
self.ms.ids.centermark.lat,
|
||||
self.ms.ids.centermark.lon
|
||||
)
|
||||
|
||||
|
||||
def request_android_permissions(self):
|
||||
@ -133,8 +143,10 @@ class FlockompassApp(App):
|
||||
callback)
|
||||
|
||||
def build(self):
|
||||
global root
|
||||
|
||||
root = ScreenManager(transition=RiseInTransition())
|
||||
|
||||
self.ms = MapScreen(name='map')
|
||||
root.add_widget(self.ms)
|
||||
|
||||
@ -142,6 +154,13 @@ class FlockompassApp(App):
|
||||
cs = CompassScreen(name='compass')
|
||||
cs._anim = None
|
||||
cs.p = None
|
||||
root.add_widget(cs)
|
||||
|
||||
|
||||
if platform == "android":
|
||||
print("gps.py: Android detected. Requesting permissions")
|
||||
self.request_android_permissions()
|
||||
|
||||
|
||||
try:
|
||||
gps.configure(on_location=cs.on_location,
|
||||
@ -149,17 +168,9 @@ class FlockompassApp(App):
|
||||
except NotImplementedError:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
self.gps_status = 'GPS is not implemented for your platform'
|
||||
print('GPS is not implemented for your platform')
|
||||
|
||||
if platform == "android":
|
||||
print("gps.py: Android detected. Requesting permissions")
|
||||
self.request_android_permissions()
|
||||
|
||||
|
||||
|
||||
root.add_widget(cs)
|
||||
|
||||
Clock.schedule_interval(self.move_around, 2.0)
|
||||
Clock.schedule_interval(self.move_around, 7.0)
|
||||
|
||||
return root
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user