Program for generating morse code via a callback.
Diff: morsegenerator.h
- Revision:
- 0:44a2d3f18e9f
- Child:
- 1:23b6dc8f569e
diff -r 000000000000 -r 44a2d3f18e9f morsegenerator.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/morsegenerator.h Mon Apr 30 21:05:30 2012 +0000 @@ -0,0 +1,37 @@ +#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); +}; \ No newline at end of file