Crate megamorse

source ·
Expand description

MegaMorse is a flexible library for parsing morse code from strings, and playing them back using a custom decoder.

The library is designed to be flexible and easy to use, and can be used in no_std environments.

§Examples

use megamorse::{MorsePlayer, MorseDecoder, MorseWord, MorseCode, MorseSequence, morse};

// A simple Morse decoder that prints the Morse code to the console.
struct PrintDecoder;

impl MorseDecoder for PrintDecoder {
    type Error = ();

    fn on(&mut self, timeunits: usize) -> Result<(), Self::Error> {
        print!("{} ", "on".repeat(timeunits));
        Ok(())
    }

    fn off(&mut self, timeunits: usize) -> Result<(), Self::Error> {
        print!("{} ", "off".repeat(timeunits));
        Ok(())
    }
}

let mut player = MorsePlayer::new(PrintDecoder);

// Play the Morse code sequence for "Hello world".
player.play_str("Hello world").unwrap();

// Play the Morse code sequence for "SOS", using the morse macro.
let sos = morse!(... ___ ...);

for word in sos.into_iter() {
    player.play_word(word).unwrap();
}

Macros§

  • This macro is used to generate a static array of MorseWord structs from a literal whitespace-delimited sequence of dots and dashes. It’s main use should be generating compile-time Morse code sequences. It accepts the characters . for a dot, and - or _ for a dash.

Structs§

  • A Morse code player that uses a MorseDecoder to play Morse code sequences. The player can play Morse code sequences represented by MorseWord structs, or by a string of (morse-valid characters).
  • A struct representing a single morse code sequence that maps to a single character. For example, ‘a’, ‘0’ or ‘G’ all map to a single MorseWord.

Enums§

  • Enum representing a single Morse code symbol, either a dot or a dash.
  • Errors that can occur during Morse code playback.
  • Enum representing a single playable Morse code time unit.

Traits§

  • Trait representing a Morse code decoder. Can be used to construct a MorsePlayer, which then uses the decoder to play Morse code sequences.