2020-07-16 16:25:49 +00:00
|
|
|
from kivy.app import App
|
2020-07-16 22:42:33 +00:00
|
|
|
from kivy.clock import Clock
|
2020-07-16 16:25:49 +00:00
|
|
|
from kivy.uix.screenmanager import ScreenManager, Screen, RiseInTransition
|
2020-07-16 18:43:28 +00:00
|
|
|
from kivy.properties import NumericProperty, StringProperty
|
2020-07-16 16:25:49 +00:00
|
|
|
from kivy.lang import Builder
|
|
|
|
|
from kivy_garden.mapview import MapView
|
2020-07-16 18:43:28 +00:00
|
|
|
from plyer import gps
|
|
|
|
|
from kivy.clock import mainthread
|
|
|
|
|
from kivy.utils import platform
|
|
|
|
|
|
|
|
|
|
|
2020-07-16 16:25:49 +00:00
|
|
|
|
|
|
|
|
class MapScreen(Screen):
|
|
|
|
|
hue = NumericProperty(0)
|
|
|
|
|
mapview = MapView(zoom=11, lat=50.6394, lon=3.057)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompassScreen(Screen):
|
|
|
|
|
hue = NumericProperty(0)
|
2020-07-16 22:42:33 +00:00
|
|
|
x_calib = NumericProperty(0)
|
|
|
|
|
y_calib = NumericProperty(0)
|
|
|
|
|
z_calib = NumericProperty(0)
|
|
|
|
|
def enable(self):
|
|
|
|
|
self.facade.enable()
|
|
|
|
|
Clock.schedule_interval(self.get_field, 1 / 20.)
|
|
|
|
|
|
|
|
|
|
def disable(self):
|
|
|
|
|
self.facade.disable()
|
|
|
|
|
Clock.unschedule(self.get_field)
|
|
|
|
|
|
|
|
|
|
def get_field(self, dt):
|
|
|
|
|
if self.facade.field != (None, None, None):
|
|
|
|
|
self.x_calib, self.y_calib, self.z_calib = self.facade.field
|
|
|
|
|
|
2020-07-16 16:25:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class FlockompassApp(App):
|
|
|
|
|
|
2020-07-16 18:43:28 +00:00
|
|
|
gps_location = StringProperty()
|
|
|
|
|
gps_status = StringProperty('Click Start to get GPS location updates')
|
|
|
|
|
|
|
|
|
|
def request_android_permissions(self):
|
|
|
|
|
from android.permissions import request_permissions, Permission
|
|
|
|
|
|
|
|
|
|
def callback(permissions, results):
|
|
|
|
|
if all([res for res in results]):
|
|
|
|
|
print("callback. All permissions granted.")
|
|
|
|
|
else:
|
|
|
|
|
print("callback. Some permissions refused.")
|
|
|
|
|
|
|
|
|
|
request_permissions([Permission.ACCESS_COARSE_LOCATION,
|
|
|
|
|
Permission.ACCESS_FINE_LOCATION],
|
|
|
|
|
callback)
|
|
|
|
|
|
|
|
|
|
@mainthread
|
|
|
|
|
def on_location(self, **kwargs):
|
|
|
|
|
self.gps_location = '\n'.join([
|
|
|
|
|
'{}={}'.format(k, v) for k, v in kwargs.items()])
|
|
|
|
|
|
|
|
|
|
@mainthread
|
|
|
|
|
def on_status(self, stype, status):
|
|
|
|
|
self.gps_status = 'type={}\n{}'.format(stype, status)
|
|
|
|
|
|
|
|
|
|
|
2020-07-16 16:25:49 +00:00
|
|
|
def build(self):
|
2020-07-16 18:43:28 +00:00
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
gps.configure(on_location=self.on_location,
|
|
|
|
|
on_status=self.on_status)
|
|
|
|
|
except NotImplementedError:
|
|
|
|
|
import traceback
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
self.gps_status = 'GPS is not implemented for your platform'
|
|
|
|
|
|
|
|
|
|
if platform == "android":
|
|
|
|
|
print("gps.py: Android detected. Requesting permissions")
|
|
|
|
|
self.request_android_permissions()
|
2020-07-16 16:25:49 +00:00
|
|
|
|
|
|
|
|
root = ScreenManager(transition=RiseInTransition())
|
|
|
|
|
root.add_widget(MapScreen(name='map'))
|
|
|
|
|
root.add_widget(CompassScreen(name='compass'))
|
|
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
FlockompassApp().run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Button:
|
|
|
|
|
# text: 'Use FallOutTransition'
|
|
|
|
|
# on_release: root.manager.transition = FallOutTransition()
|
|
|
|
|
|
|
|
|
|
# Button:
|
|
|
|
|
# text: 'Use RiseInTransition'
|
|
|
|
|
# on_release: root.manager.transition = RiseInTransition()
|
|
|
|
|
|