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 # (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy # 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 # (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes # Sets custom source for any requirements with recipes

View File

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

16
main.py
View File

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