Skip to content

Commit

Permalink
Refactored service boot delay for enabling power button
Browse files Browse the repository at this point in the history
The issue with the previous implementation was that firstly on an
exception execution continued and secondly that it would disable
the button when Dashboard was not running. This approach delays
enabling the button for 20 sec after service starts.
  • Loading branch information
Radu authored and radujipa committed Jun 20, 2017
1 parent 35ae49e commit 5c7c88d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
15 changes: 4 additions & 11 deletions kano_peripherals/ck2_pro_hat/driver/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,14 @@ def _launch_shutdown_menu():
if not is_enabled.value:
return


#
# FIXME: The problem: The poppa menu eventually pops up on a naked PI
# with no powerhat board connected, right in the middle of Dashboard loading up,
# grabbing user input and consequently blocking the user completely.
# Solution: prevent the poppa menu from appearing if the Dashboard
# has not been running for long enough.
#
dashboard_up_seconds=20
try:
dashboard_times=os.popen('ps -p $(pidof kano-dashboard) -o etimes=').read().strip()
if (not dashboard_times.startswith('error') and int(dashboard_times) < dashboard_up_seconds):
# The dashboard is loading up, do not popup the menu now, discard event
return
except:
pass

if time.time() - startup_timestamp < 20:
return

# TODO: The env vars bellow are a workaround the fact that Qt5 apps are
# stacking on top of each other creating multiple mice, events propagating
Expand All @@ -219,6 +210,8 @@ def _launch_shutdown_menu():
' /usr/bin/shutdown-menu'
)

startup_timestamp = time.time()

kano_hat = CK2ProHat()
kano_hat.initialise()

Expand Down
15 changes: 4 additions & 11 deletions kano_peripherals/pi_hat/driver/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,23 +338,14 @@ def _launch_shutdown_menu():
if not is_enabled.value:
return


#
# FIXME: The problem: The poppa menu eventually pops up on a naked PI
# with no pihat board connected, right in the middle of Dashboard loading up,
# grabbing user input and consequently blocking the user completely.
# Solution: prevent the poppa menu from appearing if the Dashboard
# has not been running for long enough.
#
dashboard_up_seconds=20
try:
dashboard_times=os.popen('ps -p $(pidof kano-dashboard) -o etimes=').read().strip()
if (not dashboard_times.startswith('error') and int(dashboard_times) < dashboard_up_seconds):
# The dashboard is loading up, do not popup the menu now, discard event
return
except:
pass

if time.time() - startup_timestamp < 20:
return

# TODO: The env vars bellow are a workaround the fact that Qt5 apps are
# stacking on top of each other creating multiple mice, events propagating
Expand All @@ -367,6 +358,8 @@ def _launch_shutdown_menu():
' /usr/bin/shutdown-menu'
)

startup_timestamp = time.time()

kano_hat = KanoHat()
kano_hat.initialise()

Expand Down

0 comments on commit 5c7c88d

Please sign in to comment.