Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed_blinky by
Diff: MorseCharacter.cpp
- Revision:
- 7:b1e0b6f381ba
- Child:
- 8:ec3e22e9100e
diff -r e8cd76f38fa9 -r b1e0b6f381ba MorseCharacter.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MorseCharacter.cpp Sun Aug 24 01:47:19 2014 +0000 @@ -0,0 +1,64 @@ +#include "MorseCharacter.h" + +const char MorseCharacter::numbers[] = { + 0xBF, // 0 + 0xAF, // 1 + 0xA7, // 2 + 0xA3, // 3 + 0xA1, // 4 + 0xA0, // 5 + 0xB0, // 6 + 0xB8, // 7 + 0xBC, // 8 + 0xBE // 9 + }; +const char MorseCharacter::letters[] = { + 0x48, // A + 0x90, // B + 0x94, // C + 0x70, // D + 0x20, // E + 0x84, // F + 0x78, // G + 0x80, // H + 0x40, // I + 0x8E, // J + 0x74, // K + 0x88, // L + 0x58, // M + 0x50, // N + 0x7C, // O + 0x8C, // P + 0x9A, // Q + 0x68, // R + 0x60, // S + 0x30, // T + 0x64, // U + 0x82, // V + 0x6C, // W + 0x92, // X + 0x96, // Y + 0x98 // Z + }; + +MorseCharacter::MorseCharacter(char character) { + if(character >= '0' && character <= '9') + mSequence = numbers[character-'0']; + if(character >= 'a' && character <= 'z') + mSequence = letters[character-'a']; + if(character >= 'A' && character <= 'Z') + mSequence = letters[character-'A']; + else + mSequence = 0x00; +} +char MorseCharacter::getNumberOfParts() { + return this->mSequence >> 5; +} +char MorseCharacter::getPart(int partNumber) { + char length = this->getNumberOfParts(); + if(partNumber >= length) { + return 0xFF; // error or space + } else { + return (this->mSequence >> (length-partNumber)) & 0x01; // 1:dash, 0:dit + } +}