more cleanup

This commit is contained in:
Martin Brodbeck 2024-02-28 14:39:55 +01:00
parent 45c0d367f5
commit 4775a12d45
3 changed files with 33 additions and 51 deletions

View file

@ -49,15 +49,6 @@ void Keyer::setSpeed(uint8_t wpm)
m_elementDuration = calcElementDurationUs(wpm);
}
//void Keyer::sendMessage(std::string msg)
//{
// std::string morse = messageToMorse(msg);
//
// for (char c : morse) {
// m_messageQueue.push(c);
// }
//}
void Keyer::sendCharacter(const char ch)
{
char morseSymbols[32] {0};
@ -69,12 +60,6 @@ void Keyer::sendCharacter(const char ch)
for (size_t i = 0; i < strlen(morseSymbols); i++) {
m_messageQueue.push(morseSymbols[i]);
}
// std::string morse = charToMorse(ch);
// for (char c : morse) {
// m_messageQueue.push(c);
// }
}
void Keyer::run()

View file

@ -1,7 +1,5 @@
// #include <algorithm>
#include <map>
#include <string>
// #include <regex>
#include "morse.h"
@ -67,6 +65,35 @@ std::map<char, std::string> morseMap = {
{']', "-.--."}, // ] => <KN> [sic!]
};
bool charToMorse(const char ch, char *morseSymbols)
{
size_t index {0};
if (ch != ' ' && !morseMap.contains(ch)) {
return false;
}
if (ch == ' ') {
morseSymbols[index++] = 'w';
} else {
for (unsigned int i = 0; i < morseMap[ch].length(); i++) {
char m = morseMap[ch][i];
morseSymbols[index++] = m;
if (i < morseMap[ch].length() - 1) {
morseSymbols[index++] = 'i';
}
}
morseSymbols[index++] = 'c';
}
morseSymbols[index] = '\0';
return true;
}
/*
void refurbishMessage(std::string &msg)
{
@ -90,7 +117,7 @@ void refurbishMessage(std::string &msg)
msg = std::regex_replace(msg, std::regex("(\\s+)"), " ");
}
*/
/*
std::string messageToMorse(std::string &msg)
{
// refurbishMessage(msg);
@ -131,7 +158,9 @@ std::string messageToMorse(std::string &msg)
return morseString;
}
*/
/*
std::string charToMorse(const char ch)
{
std::string morseString {};
@ -155,32 +184,4 @@ std::string charToMorse(const char ch)
return morseString;
}
bool charToMorse(const char ch, char *morseSymbols)
{
size_t index {0};
if (ch != ' ' && !morseMap.contains(ch)) {
return false;
}
if (ch == ' ') {
morseSymbols[index++] = 'w';
} else {
for (unsigned int i = 0; i < morseMap[ch].length(); i++) {
char m = morseMap[ch][i];
morseSymbols[index++] = m;
if (i < morseMap[ch].length() - 1) {
morseSymbols[index++] = 'i';
}
}
morseSymbols[index++] = 'c';
}
morseSymbols[index] = '\0';
return true;
}
*/

View file

@ -1,7 +1,3 @@
#pragma once
//#include <string>
//std::string messageToMorse(std::string &msg);
//std::string charToMorse(const char ch);
bool charToMorse(const char ch, char * morseSymbols);