[Morse] Moved Morse code table to flash
This commit is contained in:
parent
f004966e57
commit
7d141fbbc2
1 changed files with 66 additions and 59 deletions
|
@ -6,66 +6,66 @@
|
||||||
*/
|
*/
|
||||||
struct Morse_t {
|
struct Morse_t {
|
||||||
char c; // ASCII character
|
char c; // ASCII character
|
||||||
const char* m; // Morse code representation
|
char m[7]; // Morse code representation
|
||||||
};
|
};
|
||||||
/*!
|
/*!
|
||||||
\endcond
|
\endcond
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// array of all Morse code characters
|
// array of all Morse code characters
|
||||||
static const Morse_t MorseTable[MORSE_LENGTH] = {
|
const Morse_t MorseTable[MORSE_LENGTH] PROGMEM = {
|
||||||
{.c = 'A', .m = ".-"},
|
{'A', ".-"},
|
||||||
{.c = 'B', .m = "-..."},
|
{'B',"-..."},
|
||||||
{.c = 'C', .m = "-.-."},
|
{'C', "-.-."},
|
||||||
{.c = 'D', .m = "-.."},
|
{'D',"-.."},
|
||||||
{.c = 'E', .m = "."},
|
{'E',"."},
|
||||||
{.c = 'F', .m = "..-."},
|
{'F',"..-."},
|
||||||
{.c = 'G', .m = "--."},
|
{'G',"--."},
|
||||||
{.c = 'H', .m = "...."},
|
{'H',"...."},
|
||||||
{.c = 'I', .m = ".."},
|
{'I',".."},
|
||||||
{.c = 'J', .m = ".---"},
|
{'J',".---"},
|
||||||
{.c = 'K', .m = "-.-"},
|
{'K',"-.-"},
|
||||||
{.c = 'L', .m = ".-.."},
|
{'L',".-.."},
|
||||||
{.c = 'M', .m = "--"},
|
{'M',"--"},
|
||||||
{.c = 'N', .m = "-."},
|
{'N',"-."},
|
||||||
{.c = 'O', .m = "---"},
|
{'O',"---"},
|
||||||
{.c = 'P', .m = ".--."},
|
{'P',".--."},
|
||||||
{.c = 'Q', .m = "--.-"},
|
{'Q',"--.-"},
|
||||||
{.c = 'R', .m = ".-."},
|
{'R',".-."},
|
||||||
{.c = 'S', .m = "..."},
|
{'S',"..."},
|
||||||
{.c = 'T', .m = "-"},
|
{'T',"-"},
|
||||||
{.c = 'U', .m = "..-"},
|
{'U',"..-"},
|
||||||
{.c = 'V', .m = "...-"},
|
{'V',"...-"},
|
||||||
{.c = 'W', .m = ".--"},
|
{'W',".--"},
|
||||||
{.c = 'X', .m = "-..-"},
|
{'X',"-..-"},
|
||||||
{.c = 'Y', .m = "-.--"},
|
{'Y',"-.--"},
|
||||||
{.c = 'Z', .m = "--.."},
|
{'Z',"--.."},
|
||||||
{.c = '1', .m = ".----"},
|
{'1',".----"},
|
||||||
{.c = '2', .m = "..---"},
|
{'2',"..---"},
|
||||||
{.c = '3', .m = "...--"},
|
{'3',"...--"},
|
||||||
{.c = '4', .m = "....-"},
|
{'4',"....-"},
|
||||||
{.c = '5', .m = "....."},
|
{'5',"....."},
|
||||||
{.c = '6', .m = "-...."},
|
{'6',"-...."},
|
||||||
{.c = '7', .m = "--..."},
|
{'7',"--..."},
|
||||||
{.c = '8', .m = "---.."},
|
{'8',"---.."},
|
||||||
{.c = '9', .m = "----."},
|
{'9',"----."},
|
||||||
{.c = '0', .m = "-----"},
|
{'0',"-----"},
|
||||||
{.c = '.', .m = ".-.-.-"},
|
{'.',".-.-.-"},
|
||||||
{.c = ',', .m = "--..--"},
|
{',',"--..--"},
|
||||||
{.c = ':', .m = "---..."},
|
{':',"---..."},
|
||||||
{.c = '?', .m = "..--.."},
|
{'?',"..--.."},
|
||||||
{.c = '\'', .m = ".----."},
|
{'\'',".----."},
|
||||||
{.c = '-', .m = "-....-"},
|
{'-',"-....-"},
|
||||||
{.c = '/', .m = "-..-."},
|
{'/',"-..-."},
|
||||||
{.c = '(', .m = "-.--."},
|
{'(',"-.--."},
|
||||||
{.c = ')', .m = "-.--.-"},
|
{')',"-.--.-"},
|
||||||
{.c = '\"', .m = ".-..-."},
|
{'\"',".-..-."},
|
||||||
{.c = '=', .m = "-...-"},
|
{'=',"-...-"},
|
||||||
{.c = '+', .m = ".-.-."},
|
{'+',".-.-."},
|
||||||
{.c = '@', .m = ".--.-."},
|
{'@',".--.-."},
|
||||||
{.c = ' ', .m = "_"}, // space is used to separate words
|
{' ',"_"}, // space is used to separate words
|
||||||
{.c = 0x01, .m = "-.-.-"}, // ASCII SOH (start of heading) is used as alias for start signal
|
{0x01,"-.-.-"}, // ASCII SOH (start of heading) is used as alias for start signal
|
||||||
{.c = 0x02, .m = ".-.-."} // ASCII EOT (end of transmission) is used as alias for stop signal
|
{0x02,".-.-."} // ASCII EOT (end of transmission) is used as alias for stop signal
|
||||||
};
|
};
|
||||||
|
|
||||||
MorseClient::MorseClient(PhysicalLayer* phy) {
|
MorseClient::MorseClient(PhysicalLayer* phy) {
|
||||||
|
@ -107,19 +107,25 @@ size_t MorseClient::write(uint8_t* buff, size_t len) {
|
||||||
|
|
||||||
size_t MorseClient::write(uint8_t b) {
|
size_t MorseClient::write(uint8_t b) {
|
||||||
// find the correct Morse code in array
|
// find the correct Morse code in array
|
||||||
uint8_t pos;
|
Morse_t mc;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for(pos = 0; pos < MORSE_LENGTH; pos++) {
|
for(uint8_t pos = 0; pos < MORSE_LENGTH; pos++) {
|
||||||
if(MorseTable[pos].c == toupper(b)) {
|
memcpy_P(&mc, &MorseTable[pos], sizeof(Morse_t));
|
||||||
|
if(mc.c == toupper(b)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the requested code was found in the array
|
// check if the requested code was found in the array
|
||||||
if(found) {
|
if(found) {
|
||||||
|
DEBUG_PRINT(mc.c);
|
||||||
|
DEBUG_PRINT('\t');
|
||||||
|
DEBUG_PRINTLN(mc.m);
|
||||||
|
|
||||||
// iterate over Morse code representation and output appropriate tones
|
// iterate over Morse code representation and output appropriate tones
|
||||||
for(uint8_t i = 0; i < strlen(MorseTable[pos].m); i++) {
|
for(uint8_t i = 0; i < strlen(mc.m); i++) {
|
||||||
switch(MorseTable[pos].m[i]) {
|
switch(mc.m[i]) {
|
||||||
case '.':
|
case '.':
|
||||||
_phy->transmitDirect(_base);
|
_phy->transmitDirect(_base);
|
||||||
delay(_dotLength);
|
delay(_dotLength);
|
||||||
|
@ -139,6 +145,7 @@ size_t MorseClient::write(uint8_t b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// letter space
|
// letter space
|
||||||
|
DEBUG_PRINTLN();
|
||||||
delay(_dotLength * 3);
|
delay(_dotLength * 3);
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue