From 05204d9e84a671cfa200e0ca411489373f2976ef Mon Sep 17 00:00:00 2001 From: Mikhail Zakharov Date: Wed, 17 Feb 2021 15:25:46 -0500 Subject: [PATCH] add main screen --- look.kv | 21 ++++++++++++++++++--- main.py | 29 +++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/look.kv b/look.kv index 4fd4673..f587484 100644 --- a/look.kv +++ b/look.kv @@ -2,12 +2,17 @@ ScrollView: MDList: OneLineListItem: - text: "Orientation view" + text: "Main" + on_press: + root.nav_drawer.set_state("close") + root.screen_manager.current = "Main" + OneLineListItem: + text: "Orientation" on_press: root.nav_drawer.set_state("close") root.screen_manager.current = "Ori" OneLineListItem: - text: "Accelerometer view" + text: "Accelerometer" on_press: root.nav_drawer.set_state("close") root.screen_manager.current = "Force" @@ -80,4 +85,14 @@ Screen: screen_manager: screen_manager nav_drawer: nav_drawer - +: + BoxLayout: + orientation: "vertical" + size_hint: [1, 1] + BoxLayout: + MDLabel: + id: label + text: "# 1" + halign: "center" + theme_text_color: "Primary" + font_style: "H1" diff --git a/main.py b/main.py index 9c1041b..dcfbf13 100644 --- a/main.py +++ b/main.py @@ -144,7 +144,8 @@ def stop(self): class CommonScreen(Screen): event_time = 0 - accuracy_lookup = {3:'H', 2: 'M', 1:'L'} + update_cnt = 0 + accuracy_lookup = {3:'High', 2: 'Med', 1:'Low'} labels = ['Azimuth', 'Pitch', 'Roll'] #each axis has a different resolution resolution_adjust = [8, 2, 2] @@ -228,7 +229,7 @@ def get_value(self): if debug is not None: log.warning(f"detect: '{debug}' ori: idx={event_time_idx}/{len(points_t)-1} buf={points_t[-6:]}\nacc_time: {acc_time} acc_idx={self.event_time_idx}/{len(acc_points_t)-1}") - # remove a few samples that may have been contaminated with the event TODO: use mcmc or some other method to remove contaminated samples? + # remove a few samples that may have been contaminated with the event TODO: use mcmc or some other method to find transition event_time_idx -= 7 orig_points = points @@ -250,7 +251,7 @@ def get_value(self): self.worker.q.put(('std', (self.event_time + acc_offset, event))) self.worker.q.put(('flush', None)) - self.toolbar.title = f'{self.name}. #{self.worker.event_count} | rate:{snsr.rate:.1f}@{self.accuracy_lookup.get(snsr.accuracy,"?")}' + self.toolbar.title = f'{self.name} | #{self.worker.event_count} | Data:{snsr.rate:.1f}/sec | {self.accuracy_lookup.get(snsr.accuracy,"?")}' self.update_cnt += 1 if self.update_cnt == GRAPH_DRAW_EVERY_FRAMES or detected: @@ -262,6 +263,24 @@ def get_value(self): return False, acc_points, points, std +class MainScreen(CommonScreen): + def __init__(self, **kwargs): + self.worker = kwargs.pop('worker') + self.toolbar = kwargs.pop('toolbar') + super().__init__(**kwargs) + + def start(self): + log.debug(f'{self.name}: start') + Clock.schedule_interval(self.get_value, POLL_RATE) + self.ids.label.text = f'# {self.worker.event_count}' + + def get_value(self, dt): + draw, _, _, _ = super().get_value() + if not draw: + return + self.ids.label.text = f'# {self.worker.event_count}' + + class AccelerometerScreen(CommonScreen): def __init__(self, **kwargs): self.worker = kwargs.pop('worker') @@ -362,7 +381,7 @@ def build(self): self.worker = None self.screen = Builder.load_file('look.kv') sm = self.screen.ids.screen_manager - self.theme_cls.primary_palette = "DeepPurple" + self.theme_cls.primary_palette = "Teal" self.theme_cls.theme_style = "Dark" #get config @@ -380,6 +399,8 @@ def build(self): self.worker = Worker(config=config) toolbar = self.screen.ids.toolbar + screen = MainScreen(name='Main', worker=self.worker, toolbar=toolbar) + sm.add_widget(screen) screen = OrientationScreen(name='Ori', worker=self.worker, toolbar=toolbar) sm.add_widget(screen) screen = AccelerometerScreen(name='Force', worker=self.worker, toolbar=toolbar)