morse_engine.py 1.68 KB
import time
from typing import Final

from src import morse_code
from .abstract import LEDController, TouchSensor, ProximitySensor

# Constants (Keep same or tests will break)
THRESHOLD: Final[int] = 75
UNIT_TIME: Final[float] = 0.24

RED   : Final[tuple[int, int, int]] = (255, 0,   0)
YELLOW: Final[tuple[int, int, int]] = (220, 160, 0)
GREEN : Final[tuple[int, int, int]] = (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: float, px: LEDController):
    """
    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: float) -> str:
    """
    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: ProximitySensor, pixels: LEDController, touch: TouchSensor):
    """
    Runs Morse code translation based on proximity input.

    Args:
        apds: proximity sensor.
        pixels: LED controller object.
        touch: touch sensor for confirming input.
    """
    morse = ""                # Dots, dashs, and slashes so far
    start = time.monotonic()  # Time when proximity sensor was first triggered

    # Main loop
    while True:
        if touch.value:
            print("Touched!")
        print("the message should be here", "<==")