viri-leds-dmx-sacn/main.py

61 lines
1.3 KiB
Python
Raw Normal View History

2023-08-07 11:39:15 +00:00
#!/usr/bin/env python3
import logging
from argparse import ArgumentParser
from queue import Queue
from sys import exit
from time import sleep
2023-08-07 18:05:20 +00:00
from conf import load_and_validate_config
2023-08-07 11:39:15 +00:00
from dmx_queue import DMXQueue
2023-08-07 12:48:18 +00:00
from mqtt_queue import MQTTQueue
2023-08-07 11:39:15 +00:00
logging.basicConfig(
2023-08-07 13:06:38 +00:00
level=logging.INFO,
format="%(asctime)s %(name)20s [%(levelname)-8s] %(message)s",
2023-08-07 11:39:15 +00:00
)
LOG = logging.getLogger("main")
2023-08-07 11:39:15 +00:00
2023-08-07 12:48:18 +00:00
def main():
2023-08-07 11:39:15 +00:00
parser = ArgumentParser()
2023-08-07 12:46:22 +00:00
parser.add_argument(
"--config",
default="config.toml",
2023-08-07 12:46:22 +00:00
)
2023-08-07 11:39:15 +00:00
args = parser.parse_args()
2023-08-07 18:05:20 +00:00
config = load_and_validate_config(args.config)
2023-08-07 11:39:15 +00:00
LOG.info("Welcome to Voc2DMX")
2023-08-07 11:39:15 +00:00
queues = {}
dmx_workers = {}
LOG.info("Initializing worker queues ...")
mqttq = MQTTQueue(config, queues)
2023-08-07 11:39:15 +00:00
mqttq.start()
for universe in config.universes:
queues[universe] = Queue()
dmx_workers[universe] = DMXQueue(config, universe, queues[universe])
dmx_workers[universe].start()
LOG.info("initialization done, now running. Press Ctrl-C to stop")
2023-08-07 11:39:15 +00:00
try:
while True:
sleep(1)
finally:
LOG.warning("Got interrupt, stopping queues ...")
2023-08-07 11:39:15 +00:00
mqttq.stop()
for universe in config.universes:
dmx_workers[universe].stop()
2023-08-07 11:39:15 +00:00
LOG.info("Bye!")
2023-08-07 11:39:15 +00:00
2023-08-07 12:48:18 +00:00
if __name__ == "__main__":
2023-08-07 11:39:15 +00:00
main()