morse_engine.py 1.47 KB
import time
from src import morse_code

# Constants (Keep same or tests will break)
THRESHOLD = 75
UNIT_TIME = 0.24

RED = (255, 0, 0)
YELLOW = (220, 160, 0)
GREEN = (0, 255, 0)

# Legacy ham radio license requirement
# - 0.24 sec unit time (5 words per minute)
# Fastest recorded transcription on a straight key
# - 0.034 sec unit time (35 words per minute)


def set_color(elapsed_t, px):
    """
    Lights the LEDs on the trinkey depending on the length of input.
    
    Args:
        elapsed_t (float): duration of proximity detection.
        px : LED controller object.
    """
    pass


def add_mark(elapsed_t):
    """
    Determines if input is a dot (.), dash (-), or nothing ("") based 
    on the length of input.
    
    Args:
        elapsed_t (float): duration of proximity detection.

    Returns:
        str: dot (.), dash (-), or empty ("").
    """
    pass


def run_morse_engine(apds, pixels, touch):
    """
    Runs Morse code translation based on proximity input.

    Args:
        apds: proximity sensor.
        pixels: LED controller object.
        touch: touch sensor for confirming input.
    """
    down = None  # Time when proximity sensor was first triggered
    elapsed = 0  # Duration proximity sensor has been triggered
    message = ""  # Translated part of message
    letter = ""  # Dots and dashes of current (unfinished) letter

    # Main loop
    while True:
        if touch.value:
            print("Touched!")

        print(message, letter, "<==")