Skip to content

Commit

Permalink
add main screen
Browse files Browse the repository at this point in the history
  • Loading branch information
mzakharocsc committed Feb 17, 2021
1 parent dc32f3d commit 05204d9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
21 changes: 18 additions & 3 deletions look.kv
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -80,4 +85,14 @@ Screen:
screen_manager: screen_manager
nav_drawer: nav_drawer


<MainScreen>:
BoxLayout:
orientation: "vertical"
size_hint: [1, 1]
BoxLayout:
MDLabel:
id: label
text: "# 1"
halign: "center"
theme_text_color: "Primary"
font_style: "H1"
29 changes: 25 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 05204d9

Please sign in to comment.