canibalised plyer compass example

This commit is contained in:
rgarcia-herrera 2020-07-16 17:42:33 -05:00
parent f3d2a924a4
commit 328d8e3ebb
3 changed files with 81 additions and 27 deletions

View File

@ -36,7 +36,7 @@ version = 0.1
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,kivy,mapview,plyer,requests,urllib3,chardet,idna
requirements = python3,kivy,hostpython3,mapview,plyer,requests,urllib3,chardet,idna
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes

View File

@ -1,6 +1,6 @@
#:import random random.random
#:import RiseInTransition kivy.uix.screenmanager.RiseInTransition
#:import facade plyer.compass
<MapScreen>:
@ -36,38 +36,76 @@
<CompassScreen>:
facade: facade
orientation: 'vertical'
padding: '20dp'
spacing: '10dp'
BoxLayout:
orientation: 'vertical'
canvas:
Color:
rgb: .98, .98, .98
Rectangle:
size: self.size
orientation: 'vertical'
BoxLayout:
orientation: 'horizontal'
size_hint: 1, .1
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
BoxLayout:
orientation: 'vertical'
Label:
text: "Earth's Magnetic Field"
Label:
text: 'including hard iron calibration'
Label:
text: '(' + str(root.x_calib) + ','
Label:
text: str(root.y_calib) + ','
Label:
text: str(root.z_calib) + ')'
# BoxLayout:
# orientation: 'vertical'
# canvas:
# Color:
# rgb: .98, .98, .98
# Rectangle:
# size: self.size
Image:
source: 'rose.png'
# Image:
# source: 'rose.png'
Image:
source: 'needle.png'
# Image:
# source: 'needle.png'
ActionBar:
pos_hint: {'top':1}
ActionView:
use_separator: True
ActionPrevious:
title: 'Social Cycling'
with_previous: False
ActionButton:
important: True
text: 'set destination'
on_press: root.manager.current = 'map'
# ActionBar:
# pos_hint: {'top':1}
# ActionView:
# use_separator: True
# ActionPrevious:
# title: 'Social Cycling'
# with_previous: False
# ActionButton:
# important: True
# text: 'set destination'
# on_press: root.manager.current = 'map'
Label:
text: app.gps_location
# Label:
# text: app.gps_location
Label:
text: app.gps_status
# Label:
# text: app.gps_status

16
main.py
View File

@ -1,4 +1,5 @@
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager, Screen, RiseInTransition
from kivy.properties import NumericProperty, StringProperty
from kivy.lang import Builder
@ -16,6 +17,21 @@ class MapScreen(Screen):
class CompassScreen(Screen):
hue = NumericProperty(0)
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
class FlockompassApp(App):