From 046d5d882640933ac486eaf0eea17338029462b7 Mon Sep 17 00:00:00 2001 From: Chris Frankland-Wright Date: Mon, 23 Jun 2025 14:48:39 +0100 Subject: [PATCH] setup dependencies --- hermione.py | 109 +++++++++++++++++++++++++++++++++++++++++++ hermione_config.json | 8 ++++ setup.sh | 24 ++++++++++ 3 files changed, 141 insertions(+) create mode 100644 hermione.py create mode 100644 hermione_config.json create mode 100644 setup.sh diff --git a/hermione.py b/hermione.py new file mode 100644 index 0000000..5d3a007 --- /dev/null +++ b/hermione.py @@ -0,0 +1,109 @@ +import json +import subprocess +import time +import threading +import os +from datetime import datetime + +CONFIG_FILE = "hermione_config.json" + +# Load config or create default +def load_config(): + if not os.path.exists(CONFIG_FILE): + default_config = { + "framerate": 25, + "start_mode": "system", + "manual_time": "12:00:00", + "duration_seconds": 3600, + "ltc_gen_path": "ltc-gen.exe", + "autostart_timeout": 5 + } + with open(CONFIG_FILE, "w") as f: + json.dump(default_config, f, indent=4) + return default_config + else: + with open(CONFIG_FILE, "r") as f: + return json.load(f) + +# Save updated config +def save_config(config): + with open(CONFIG_FILE, "w") as f: + json.dump(config, f, indent=4) + +# Prompt with timeout +def prompt_with_timeout(prompt, timeout): + print(prompt, end='', flush=True) + input_data = [] + + def get_input(): + try: + input_data.append(input()) + except EOFError: + pass + + thread = threading.Thread(target=get_input) + thread.daemon = True + thread.start() + thread.join(timeout) + return input_data[0] if input_data else "" + +# Get timecode based on config +def get_start_time(config): + if config["start_mode"] == "system": + now = datetime.now() + return now.strftime("%H:%M:%S") + else: + return config["manual_time"] + +# Run ltc-gen +def run_ltc_gen(config): + start_time = get_start_time(config) + framerate = str(config["framerate"]) + duration = str(config["duration_seconds"]) + ltc_gen_path = config["ltc_gen_path"] + + cmd = [ + ltc_gen_path, + "-f", framerate, + "-l", duration, + "-t", start_time + ] + + print(f"\n🎬 Running Hermione with:") + print(f" Start Time: {start_time}") + print(f" Framerate: {framerate} fps") + print(f" Duration: {duration} seconds") + print(f" Executable: {ltc_gen_path}\n") + + try: + subprocess.run(cmd) + except FileNotFoundError: + print(f"❌ Error: {ltc_gen_path} not found!") + except Exception as e: + print(f"❌ Failed to run Hermione: {e}") + +# Main logic +def main(): + config = load_config() + user_input = prompt_with_timeout( + "\nPress [Enter] to run with config or type 'm' to modify (auto-starts in 5s): ", + config.get("autostart_timeout", 5) + ) + + if user_input.lower() == 'm': + try: + config["framerate"] = int(input("Enter framerate (e.g. 25): ")) + config["start_mode"] = input("Start from system time or manual? (system/manual): ").strip().lower() + if config["start_mode"] == "manual": + config["manual_time"] = input("Enter manual start time (HH:MM:SS): ") + config["duration_seconds"] = int(input("Enter duration in seconds: ")) + config["ltc_gen_path"] = input("Enter path to ltc-gen.exe (or leave blank for default): ") or config["ltc_gen_path"] + save_config(config) + except Exception as e: + print(f"⚠️ Error updating config: {e}") + return + + run_ltc_gen(config) + +if __name__ == "__main__": + main() diff --git a/hermione_config.json b/hermione_config.json new file mode 100644 index 0000000..cd64a0a --- /dev/null +++ b/hermione_config.json @@ -0,0 +1,8 @@ +{ + "framerate": 25, + "start_mode": "system", + "manual_time": "12:00:00", + "duration_seconds": 3600, + "ltc_gen_path": "ltc-gen.exe", + "autostart_timeout": 5 +} diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..7fe25e5 --- /dev/null +++ b/setup.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -e + +echo "🔧 Installing dependencies for NTP Timeturner..." + +# Update and upgrade packages +sudo apt update && sudo apt upgrade -y + +# Essential tools +sudo apt install -y git curl python3 python3-pip build-essential + +# Audio tools +sudo apt install -y alsa-utils ffmpeg portaudio19-dev python3-pyaudio + +# LTC decoding tools +sudo apt install -y ltc-tools + +# Optional: Network management (if needed later) +# sudo apt install -y network-manager + +# Python packages +pip3 install numpy + +echo "✅ Setup complete. Reboot recommended if this is the first run."