Skip to content

Commit

Permalink
Improve CamTracker code (2)
Browse files Browse the repository at this point in the history
When starting CamTracker, wait until it has properly shut down
  • Loading branch information
dostuffthatmatters committed Nov 10, 2023
1 parent bfd1730 commit 7b9a965
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/core/modules/sun_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SunTracking:
def __init__(self, initial_config: types.Config):
self.config = initial_config
self.last_start_time = time.time()
self.waiting_for_shutdown: bool = False

def run(self, new_config: types.Config) -> None:
"""Called in every cycle of the main loop. Start and stops CamTracker
Expand All @@ -50,6 +51,17 @@ def run(self, new_config: types.Config) -> None:
measurements_should_be_running
) or False

# if CamTracker is supposed to shut down but is
# still running wait until it has shut down
if self.waiting_for_shutdown:
if camtracker_is_running:
logger.debug("Waiting for CamTracker to shut down")
self.stop_sun_tracking_automation()
return
else:
logger.info("CamTracker has shut down")
self.waiting_for_shutdown = False

# main logic for active automation
# start sun tracking if supposed to be running and not active
if measurements_should_be_running and (not camtracker_is_running):
Expand Down Expand Up @@ -177,6 +189,7 @@ def stop_sun_tracking_automation(self) -> None:
After detection it will move it's mirrors to parking position and end
itself."""

self.waiting_for_shutdown = True
with open(self.stop_file_path) as f:
f.write("")

Expand Down

0 comments on commit 7b9a965

Please sign in to comment.