/* Minimal Morse encoder for the KE0WPC beacon.
 * Apache License 2.0 */

#ifndef BEACON_MORSE_H
#define BEACON_MORSE_H

#include <stdbool.h>
#include <stdint.h>

/* Callbacks supplied by the transmitter layer. */
typedef struct {
    void (*key_down)(void);          /* start carrier            */
    void (*key_up)(void);            /* stop carrier             */
    void (*delay_ms)(uint32_t ms);   /* abortable delay          */
    bool (*aborted)(void);           /* true -> stop immediately */

    /* Milliseconds of extra carrier the key_down/key_up pair adds on top
     * of the requested element length, e.g. a PA bias ramp. Subtracted
     * from every element so the dit/dah weighting stays correct. */
    uint16_t key_overhead_ms;
} morse_io_t;

/* Look up the dit/dah pattern for one character.
 * Returns a NUL-terminated string of '.' and '-', or NULL if the character
 * has no representation. Lower case is folded to upper case. */
const char *MORSE_Pattern(char c);

/* Send a whole string. Space separates words. Unknown characters are
 * skipped. Returns false if aborted partway through. */
bool MORSE_SendString(const morse_io_t *io, const char *text, uint16_t wpm);

#endif /* BEACON_MORSE_H */
