diff --git a/Calendar/E-Paper.py b/Calendar/E-Paper.py index 8702fc0..6fd51af 100644 --- a/Calendar/E-Paper.py +++ b/Calendar/E-Paper.py @@ -13,7 +13,7 @@ from Assets import path from LoopTimer import LoopTimer import locale from DebugConsole import DebugConsole -from settings import datetime_encoding, language, render_to_display, render_to_file, display_colours, location, api_key, owm_paid_subscription, choosen_design, ical_urls, highlighted_ical_urls, rss_feeds, update_interval, calibrate_hours, crypto_coins +from settings import datetime_encoding, language, render_to_display, render_to_file, display_colours, location, api_key, owm_paid_subscription, choosen_design, ical_urls, highlighted_ical_urls, rss_feeds, update_interval, calibrate_hours, crypto_coins, max_loop_count, run_on_hour from MonthOvPanel import MonthOvPanel from DayListPanel import DayListPanel from DayViewPanel import DayViewPanel @@ -59,7 +59,7 @@ available_panels = { "image-frame": ImageFramePanel } -loop_timer = LoopTimer(update_interval, run_on_hour=True) +loop_timer = LoopTimer(update_interval, run_on_hour=run_on_hour, max_loop_count=max_loop_count) """Main loop starts from here""" @@ -115,8 +115,12 @@ def main(): debug.print_line("=> Finished rendering" + "\n") loop_timer.end_loop() - sleep_time = loop_timer.time_until_next() + if loop_timer.was_last_loop(): + debug.print_line("Maximum loop count " + str(loop_timer.loop_count) + " reached, exiting.") + return + + sleep_time = loop_timer.time_until_next() debug.print_line("This loop took " + str(loop_timer.get_last_duration()) + " to execute.") debug.print_line("Sleeping " + str(sleep_time) + " until next loop.") diff --git a/Calendar/LoopTimer.py b/Calendar/LoopTimer.py index 6640050..76e093c 100644 --- a/Calendar/LoopTimer.py +++ b/Calendar/LoopTimer.py @@ -8,14 +8,16 @@ class LoopTimer (object): """Manages loop times and sleeps until next loop.""" - def __init__(self, loop_interval, run_on_hour=False): + def __init__(self, loop_interval, run_on_hour=False, max_loop_count=0): self.interval = int(str(loop_interval)) self.on_hour = run_on_hour self.loop_history = [] + self.loop_count = 0 + self.max_loop_count = int(str(max_loop_count)) def begin_loop(self): begin_time = datetime.now() - print('\n__________Starting new loop__________') + print('\n__________Starting new loop [' + str(self.loop_count) + ']__________') print('Datetime: ' + str(begin_time) + '\n') self.__add_beginning__(begin_time) @@ -33,6 +35,15 @@ class LoopTimer (object): def end_loop(self): end_time = datetime.now() self.__add_ending__(end_time) + + self.loop_count += 1 + while self.loop_count > 86400: + self.loop_count -= 86400 + + def was_last_loop(self): + if self.max_loop_count == 0: + return False + return self.max_loop_count <= self.loop_count def get_current(self): return self.loop_history[-1] diff --git a/Calendar/settings.py.sample b/Calendar/settings.py.sample index 63ec04a..52f6c9f 100644 --- a/Calendar/settings.py.sample +++ b/Calendar/settings.py.sample @@ -19,9 +19,11 @@ week_starts_on = "Monday" display_colours = "bwr" language = "en" datetime_encoding = "UTF-8" # UTF-8 -units = "metric" #aviation (celcius,degrees/knots), metric (celcius,kmh), imperial(f,mph) +units = "metric" # aviation (celcius,degrees/knots), metric (celcius,kmh), imperial(f,mph) hours = "24" update_interval = 60 +max_loop_count = 0 # From 0 to 86400 representing the maximum number the loop is executed, with 0 being unlimited +run_on_hour = True # If True, updates calendar every full hour, ignoring differing update_interval """DESIGN""" diff --git a/README.md b/README.md index 1643cea..f261eb1 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ Once the packages are installed, navigate to the home directory, open 'E-Paper-M |units| Selecting units allows switching units from km/h (kilometer per hour) and °C (degree Celcius) to mph (miles per hour) and °F (degree Fahrenheit). Possible options are `"metric"`, `"imperial"` or `"aviation"` (Celsius, Degree/Knots). | |hours | Which time format do you prefer? This will change the sunrise and sunset times from 24-hours format to 12-hours format. Possible options are `"24"` for 24-hours and `"12"` for 12-hours.| |update_interval | The update delay between two updates in minutes. By default there is always an update on a full hour.| +|max_loop_count | From 0 to 86400 representing the maximum number of times the loop is going to be executed, with `0` being unlimited.| +|run_on_hour | If `True`, updates calendar every full hour, ignoring differing update_interval.| ### Design | Parameter | Description |