Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add on/off times to turn map on/off at specific times #45

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add "LOCAL" to the key so the user will know that is is NOT UTC.

OFF_TIME_KEY = "off_time"

__VALID_KEYS__ = [
LED_MODE_KEY,
PIXEL_COUNT_KEY,
Expand All @@ -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__ = [
Expand Down Expand Up @@ -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:
Expand Down
25 changes: 24 additions & 1 deletion controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions data/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mode": "ws2801",
"mode": "ws281x",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets leave the default config alone.

"pixel_count": 50,
"spi_port": 0,
"spi_device": 0,
Expand All @@ -12,5 +12,7 @@
"snow_twinkle": true,
"night_category_proportion": 0.1,
"brightness_proportion": 0.6,
"visualizer": 0
"visualizer": 0,
"on_time": "",
"off_time": ""
}
31 changes: 27 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
```

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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. |
Expand Down