Program for generating morse code via a callback.

morsegenerator.h

Committer:
stevep
Date:
2012-04-30
Revision:
0:44a2d3f18e9f
Child:
1:23b6dc8f569e

File content as of revision 0:44a2d3f18e9f:

#include <map>
#include <string>
#include "mbed.h"

#define DIT_MS 100

typedef std::map <char, std::string> MapType;
typedef void (*callback_type)(int);

const std::string MORSE_LETTERS[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
const std::string MORSE_NUMBERS[] = {".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "-----"};

class MorseGenerator {
    MapType morse_map;
    callback_type callback;
    
    void generate_morse_map();
    void add_mappings(std::string morse_chars, const std::string morse_codes[]);
public:
    /** Create a MorseGenerator that calls a specific callback
     *
     * @param callback called when turning on or off.
     */
    MorseGenerator(callback_type callback);
    
    /** transmit a string
     *
     * @param message to transmit.
     */
    void transmit(std::string message);
    
    /** transmit a char
     *
     * @param char to transmit.
     */
    void transmit(char letter);
};