diff --git a/configs/launchpad-scripts/lps_0_6.sh b/configs/launchpad-scripts/lps_0_6.sh new file mode 100755 index 0000000..264c808 --- /dev/null +++ b/configs/launchpad-scripts/lps_0_6.sh @@ -0,0 +1,4 @@ +#! /bin/bash +set -e + +gnome-terminal -- tinker \ No newline at end of file diff --git a/configs/launchpad-scripts/lps_0_7.sh b/configs/launchpad-scripts/lps_0_7.sh new file mode 100755 index 0000000..e4cea50 --- /dev/null +++ b/configs/launchpad-scripts/lps_0_7.sh @@ -0,0 +1,4 @@ +#! /bin/bash +set -e + +cd ~ && gnome-terminal \ No newline at end of file diff --git a/scripts/launchpad-script-launcher b/scripts/launchpad-script-launcher index c13c8cc..5e514c5 100755 --- a/scripts/launchpad-script-launcher +++ b/scripts/launchpad-script-launcher @@ -15,10 +15,10 @@ def blink_cell( launchpad: launchpad_py.Launchpad, x: int, y: int, red: int, green: int, times: int ): for i in range(times): + time.sleep(0.125) launchpad.LedCtrlXY(x, y, red, green) time.sleep(0.125) - launchpad.Reset() - time.sleep(0.125) + launchpad.LedCtrlXY(x, y, 0, 0) def main() -> int: @@ -67,6 +67,24 @@ def main() -> int: logger.info("Listening for button presses") try: while True: + # Search for all scripts with coordinates + all_known_scripts = list(SCRIPT_DIR.glob("lps_*_*.*")) + + # Build a list of registered coordinates + registered_coords = set() + for script in all_known_scripts: + parts = script.name.split("_") + if len(parts) != 3: + logger.error(f"Invalid script name {script}") + continue + x = int(parts[1]) + y = int(parts[2].split(".")[0]) + registered_coords.add((x, y)) + + # Dimly light all registered cells + for x, y in registered_coords: + launchpad.LedCtrlXY(x, y + 1, 1, 1) + # Check if there has been a button event if launchpad.ButtonChanged(): event = launchpad.ButtonStateXY() @@ -94,23 +112,25 @@ def main() -> int: all_scripts = list(SCRIPT_DIR.glob(f"{script_name}.*")) if len(all_scripts) == 0: logger.info(f"No script found for button {x},{y}") - blink_cell(launchpad, x, raw_y, 3, 3, 2) + blink_cell(launchpad, x, raw_y, 1, 1, 2) continue if len(all_scripts) > 1: logger.error(f"Multiple scripts found for button {x},{y}") - blink_cell(launchpad, x, raw_y, 3, 3, 2) + blink_cell(launchpad, x, raw_y, 1, 1, 2) continue if not all_scripts[0].is_file(): logger.error(f"Script for button {x},{y} is not a file") - blink_cell(launchpad, x, raw_y, 3, 3, 2) + blink_cell(launchpad, x, raw_y, 1, 1, 2) continue if not all_scripts[0].stat().st_mode & 0o111: logger.error(f"Script for button {x},{y} is not executable") - blink_cell(launchpad, x, raw_y, 3, 3, 2) + blink_cell(launchpad, x, raw_y, 1, 1, 2) continue # Set the cell to orange to indicate that the script is running + time.sleep(0.125) launchpad.LedCtrlXY(x, raw_y, 3, 3) + time.sleep(0.125) # Run the script logger.info(f"Running script {all_scripts[0]}") @@ -120,9 +140,7 @@ def main() -> int: # If we get a bad return code, blink the cell red if proc.returncode != 0: logger.error(f"Script {all_scripts[0]} returned {proc.returncode}") - launchpad.LedCtrlXY(x, raw_y, 3, 0) - time.sleep(0.5) - launchpad.LedCtrlXY(x, raw_y, 0, 0) + blink_cell(launchpad, x, raw_y, 3, 0, 2) continue # If we get a good return code, blink the cell green