A MorseGenerator library that uses LED to blink morse code
Dependents: MorseGenerator_Example2 9v1
MorseGenerator.h@1:bad1b4ca49df, 2014-09-17 (annotated)
- Committer:
- screamer
- Date:
- Wed Sep 17 17:09:04 2014 +0300
- Revision:
- 1:bad1b4ca49df
- Parent:
- 0:0ad54d10593c
* fixed - main.h usage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wm | 0:0ad54d10593c | 1 | #include <map> |
wm | 0:0ad54d10593c | 2 | #include <string> |
wm | 0:0ad54d10593c | 3 | #include "mbed.h" |
wm | 0:0ad54d10593c | 4 | |
wm | 0:0ad54d10593c | 5 | #define DIT_MS 100 |
wm | 0:0ad54d10593c | 6 | |
wm | 0:0ad54d10593c | 7 | |
wm | 0:0ad54d10593c | 8 | using namespace std; |
wm | 0:0ad54d10593c | 9 | |
wm | 0:0ad54d10593c | 10 | typedef map <char, string> MapType; |
wm | 0:0ad54d10593c | 11 | typedef void (*callback_type)(int); |
wm | 0:0ad54d10593c | 12 | |
wm | 0:0ad54d10593c | 13 | const string MORSE_LETTERS[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."}; |
wm | 0:0ad54d10593c | 14 | const string MORSE_NUMBERS[] = {".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----.", "-----"}; |
wm | 0:0ad54d10593c | 15 | |
wm | 0:0ad54d10593c | 16 | /** MorseGenerator class. |
wm | 0:0ad54d10593c | 17 | * |
wm | 0:0ad54d10593c | 18 | * Example: |
wm | 0:0ad54d10593c | 19 | * @code |
wm | 0:0ad54d10593c | 20 | * #include "mbed.h" |
wm | 0:0ad54d10593c | 21 | * #include "morsegenerator.h" |
wm | 0:0ad54d10593c | 22 | * |
wm | 0:0ad54d10593c | 23 | * DigitalOut myled(p18); |
wm | 0:0ad54d10593c | 24 | * |
wm | 0:0ad54d10593c | 25 | * void morse_callback(int val) { |
wm | 0:0ad54d10593c | 26 | * myled = val; |
wm | 0:0ad54d10593c | 27 | * } |
screamer | 1:bad1b4ca49df | 28 | * |
wm | 0:0ad54d10593c | 29 | * int main() { |
wm | 0:0ad54d10593c | 30 | * MorseGenerator morse = MorseGenerator(morse_callback); |
screamer | 1:bad1b4ca49df | 31 | * |
wm | 0:0ad54d10593c | 32 | * while (1) { |
wm | 0:0ad54d10593c | 33 | * morse.transmit("CQCQ DE M6SPX"); |
wm | 0:0ad54d10593c | 34 | * } |
wm | 0:0ad54d10593c | 35 | * } |
wm | 0:0ad54d10593c | 36 | * @endcode |
wm | 0:0ad54d10593c | 37 | */ |
wm | 0:0ad54d10593c | 38 | class MorseGenerator { |
wm | 0:0ad54d10593c | 39 | MapType morse_map; |
wm | 0:0ad54d10593c | 40 | callback_type callback; |
screamer | 1:bad1b4ca49df | 41 | |
wm | 0:0ad54d10593c | 42 | void generate_morse_map(); |
wm | 0:0ad54d10593c | 43 | void add_mappings(string morse_chars, const string morse_codes[]); |
wm | 0:0ad54d10593c | 44 | public: |
wm | 0:0ad54d10593c | 45 | /** Create a MorseGenerator that calls a specific callback |
wm | 0:0ad54d10593c | 46 | * |
wm | 0:0ad54d10593c | 47 | * @param callback called when turning on or off. |
wm | 0:0ad54d10593c | 48 | */ |
wm | 0:0ad54d10593c | 49 | MorseGenerator(callback_type callback); |
screamer | 1:bad1b4ca49df | 50 | |
wm | 0:0ad54d10593c | 51 | /** transmit a string |
wm | 0:0ad54d10593c | 52 | * |
wm | 0:0ad54d10593c | 53 | * @param message to transmit. |
wm | 0:0ad54d10593c | 54 | */ |
wm | 0:0ad54d10593c | 55 | void transmit(string message); |
screamer | 1:bad1b4ca49df | 56 | |
wm | 0:0ad54d10593c | 57 | /** transmit a char |
wm | 0:0ad54d10593c | 58 | * |
wm | 0:0ad54d10593c | 59 | * @param char to transmit. |
wm | 0:0ad54d10593c | 60 | */ |
wm | 0:0ad54d10593c | 61 | void transmit(char letter); |
wm | 0:0ad54d10593c | 62 | }; |