From 328d8e3ebb685f1c261017184ce909f18e60fe50 Mon Sep 17 00:00:00 2001 From: rgarcia-herrera Date: Thu, 16 Jul 2020 17:42:33 -0500 Subject: [PATCH] canibalised plyer compass example --- buildozer.spec | 2 +- flockompass.kv | 90 +++++++++++++++++++++++++++++++++++--------------- main.py | 16 +++++++++ 3 files changed, 81 insertions(+), 27 deletions(-) diff --git a/buildozer.spec b/buildozer.spec index 5ad84cf..ab70d40 100644 --- a/buildozer.spec +++ b/buildozer.spec @@ -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 diff --git a/flockompass.kv b/flockompass.kv index c924d3b..042f4d1 100644 --- a/flockompass.kv +++ b/flockompass.kv @@ -1,6 +1,6 @@ #:import random random.random #:import RiseInTransition kivy.uix.screenmanager.RiseInTransition - +#:import facade plyer.compass : @@ -36,38 +36,76 @@ : + 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 \ No newline at end of file diff --git a/main.py b/main.py index e86db91..883010b 100644 --- a/main.py +++ b/main.py @@ -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):