diff --git a/configuration/configuration.py b/configuration/configuration.py index 409ad1e..4801e48 100644 --- a/configuration/configuration.py +++ b/configuration/configuration.py @@ -46,6 +46,9 @@ METAR_STATION_INACTIVE_MINUTES_KEY = "metar_station_inactive_minutes" DEFAULT_METAR_STATION_INACTIVE_MINUTES = 3 * 60 +ON_TIME_KEY = "on_time" +OFF_TIME_KEY = "off_time" + __VALID_KEYS__ = [ LED_MODE_KEY, PIXEL_COUNT_KEY, @@ -59,7 +62,9 @@ BRIGHTNESS_PROPORTION_KEY, VISUALIZER_INDEX_KEY, PIXEL_ORDER_KEY, - METAR_STATION_INACTIVE_MINUTES_KEY + METAR_STATION_INACTIVE_MINUTES_KEY, + ON_TIME_KEY, + OFF_TIME_KEY ] __VALID_PIXEL_ORDERS__ = [ @@ -503,6 +508,44 @@ def get_airport_configs(): return __load_station_config__(get_airport_file()) +def get_on_time(): + """ + Get the ON time for the map. + If the value is not in the configuration, then no on/off function is used. + + Returns: + str: The ON time (ie. 0830 for 8:30AM). + """ + try: + value = CONFIG[ON_TIME_KEY] + + if value == "" or int(value) < 0 or int(value) > 2359: + return None + else: + return value + except Exception: + return None + + +def get_off_time(): + """ + Get the OFF time for the map. + If the value is not in the configuration, then no on/off function is used. + + Returns: + str: The OFF time (ie. 2100 for 9:00PM). + """ + try: + value = CONFIG[OFF_TIME_KEY] + + if value == "" or int(value) < 0 or int(value) > 2359: + return None + + return value + except Exception: + return None + + def __load_station_config__( config_file: str ) -> dict: diff --git a/controller.py b/controller.py index 538637b..111f180 100644 --- a/controller.py +++ b/controller.py @@ -2,6 +2,7 @@ # Dylan Rush 2017 # Additional modifications: # 2018-2020, John Marzulli +# 2022, Darryl Quinn # dylanhrush.com # Uses RPi.GPIO library: https://sourceforge.net/p/raspberry-gpio-python/wiki/BasicUsage/ # Free for personal use. Prohibited for commercial without consent @@ -144,6 +145,7 @@ def render_thread(): tic = time.perf_counter() toc = time.perf_counter() debug_pixels_timer = None + display = True loaded_visualizers = visualizers.VisualizerManager.initialize_visualizers( renderer, @@ -163,7 +165,28 @@ def render_thread(): renderer.clear() last_visualizer = visualizer_index - loaded_visualizers[visualizer_index].update(delta_time) + on_time = configuration.get_on_time() + #safe_logging.safe_log("on_time= {} type is {}".format(on_time, type(on_time))) + off_time = configuration.get_off_time() + #safe_logging.safe_log("off_time= {} type is {}".format(off_time, type(off_time))) + + if not (on_time is None or off_time is None): + current_time = int(datetime.now().strftime("%H%M")) + #safe_logging.safe_log('Current/On/Off times: {} / {} / {}'.format(current_time, on_time, off_time)) + if int(on_time) <= current_time < int(off_time): + if display is False: + safe_logging.safe_log('Waking up at {} until {}'.format(current_time, off_time)) + display = True + else: + if display is True: + safe_logging.safe_log('Going to sleep at {} until {}'.format(current_time, on_time)) + display = False + + if display: + loaded_visualizers[visualizer_index].update(delta_time) + else: + all_stations(colors_lib.OFF) + time.sleep(10.0) show_debug_pixels = debug_pixels_timer is None or ( datetime.utcnow() - debug_pixels_timer).total_seconds() > 60.0 diff --git a/data/config.json b/data/config.json index 50eff63..bbb5423 100644 --- a/data/config.json +++ b/data/config.json @@ -1,5 +1,5 @@ { - "mode": "ws2801", + "mode": "ws281x", "pixel_count": 50, "spi_port": 0, "spi_device": 0, @@ -12,5 +12,7 @@ "snow_twinkle": true, "night_category_proportion": 0.1, "brightness_proportion": 0.6, - "visualizer": 0 + "visualizer": 0, + "on_time": "", + "off_time": "" } \ No newline at end of file diff --git a/readme.md b/readme.md index 4af017e..63ffe6e 100644 --- a/readme.md +++ b/readme.md @@ -109,7 +109,9 @@ You do not need to include ALL of these values. Any values provided in this file "snow_twinkle": true, "night_category_proportion": 0.05, "brightness_proportion": 1.0, - "visualizer": 0 + "visualizer": 0, + "on_time": "0800", + "off_time": "2130" } ``` @@ -211,16 +213,36 @@ This controls which type of LED system to use for controlling the lights. #### pixel_count -If you are using ws2801 based LEDs then you may need to change "pixel_count". Each strand will come with a numbe rof LEDs. You you are using a single strand, then set this number to that count. If you have combined strands, then set the total number of lights. +If you are using ws2801 based LEDs then you may need to change "pixel_count". Each strand will come with a number of LEDs. If you are using a single strand, then set this number to that count. If you have combined strands, then set the total number of lights. #### spi_device and spi_port You will probably not need to change this. If you do need to change this, then you probably know what to do. +#### gpio_pin + +Used with ws281x mode strings to set the GPIO pin. ie. 18 + #### airports_file This is the file that contains the airport names and the wiring configuration for them. +#### on_time + +This is the (local) time when the map will start displaying. ie. 0800 is 8:00am + +Defaults to "" which means the display will always be on. + +_NOTE:_ If this is set, the off_time value must also be set. + +#### off_time + +This is the (local) time when the map will stop displaying. ie. 2130 is 9:30pm + +Defaults to "" which means the display will always be on. + +_NOTE:_ If this is set, the on_time value must also be set. + ### Airports File #### Annotated Example File @@ -450,8 +472,9 @@ This mode cycles all of the stations through the spectrum, but all stations shif ## Version History | Version | Change | -| ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 2.1 | Change precipitation visualizer to pulse the snow color to make it distinct from "nothing" +|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 2.2 | Add support for on/off times for displaying the map. | +| 2.1 | Change precipitation visualizer to pulse the snow color to make it distinct from "nothing" | | 2.0.1 | Minor tweak to ceiling categorization. | | 2.0 | Add a remote control app that allows for brightness, night effects, and more to be changed on the fly. Add support for WS2811 and WS2812 based lights. Major performance improvements for adressable RGB LEDs. Selectable visualizers. Removed support for hard wired GPIO based LEDs. | | 1.10 | Add service that allows the configuration to be updated remotely without using the command line. |