Expand description
Morse code encoder to turn text into morse code text or signals.
The encoder takes &str literals or characters and turns them into a fixed length char array. Then client code can encode these characters to morse code either character by character, from slices, or all in one go. Encoded morse code can be retrieved as morse character arrays ie. [‘.’,‘-’,‘.’] or Signal Duration Multipliers SDMArray to calculate individual signal durations by the client code.
This module is designed to be no_std compliant so it also should work on embedded platforms.
use morse_codec::encoder::Encoder;
const MSG_MAX: usize = 16;
let mut encoder = Encoder::<MSG_MAX>::new()
// We have the message to encode ready and pass it to the builder.
// We pass true as second parameter to tell the encoder editing will
// continue from the end of this first string.
.with_message("SOS", true)
.build();
// Encode the whole message
encoder.encode_message_all();
let encoded_charrays = encoder.get_encoded_message_as_morse_charrays();
encoded_charrays.for_each(|charray| {
for ch in charray.unwrap().iter()
.filter(|ch| ch.is_some()) {
print!("{}", ch.unwrap() as char);
}
print!(" ");
});
// This should print "... --- ..."
Structs§
- Encoder
- Morse
Encoder - Morse
Notation - Notation characters to be used while outputting morse code as signal characters ie: “… — …”
Default is ‘.’ for dit, ‘-’ as dah and ‘/’ for word delimiter.
You can change these characters by using
with_notation
builder method of Encoder. You can use byte characters b’X’ or chars if utf8 feature is enabled like: ‘X’
Enums§
- SDM
- Signal Duration Multiplier can be 1x (short), 3x (long) or 7x (word space). SDM signals are either High, or Low which corresponds to electrically closed active signals or spaces inbetween them.
Type Aliases§
- Morse
Charray - SDMArray
- Signal Duration Multipliers are arrays of u8 values which can be used to multiply by a short signal duration constant to calculate durations of all signals in a letter or message.