Sending chars via WKdemo

This commit is contained in:
Martin Brodbeck 2024-02-26 15:57:13 +01:00
parent 701bf8f6b4
commit df85ca4267
4 changed files with 27 additions and 31 deletions

View file

@ -50,7 +50,6 @@ void Keyer::setSpeed(uint8_t wpm)
void Keyer::sendMessage(std::string msg)
{
printf("Queue size: %d\n", m_messageQueue.size());
std::string morse = messageToMorse(msg);
for (char c : morse) {
@ -58,23 +57,31 @@ void Keyer::sendMessage(std::string msg)
}
}
void Keyer::sendCharacter(char ch)
{
std::string morse = charToMorse(ch);
for (char c : morse) {
m_messageQueue.push(c);
}
}
void Keyer::run()
{
auto timestamp = get_absolute_time();
// If there is some message to send …
//if (!m_messageQueue.empty() || m_messageKeyingState != MessageState::Wait) {
if (!m_messageQueue.empty()) {
if (!m_messageQueue.empty() || m_messageKeyingState != MessageState::Wait) {
// Stop all paddle keying, if necessary
if (m_paddleKeyingState != State::Wait) {
//gpio_put(LED_PIN, 0);
//gpio_put(CW_OUT_PIN, 0);
//m_buzzer.off();
//m_keyNextIambicB = false;
//m_currentlyPausing = false;
//m_currentlyKeying = false;
//m_previousState = State::Abort;
//m_paddleKeyingState = State::Wait;
gpio_put(LED_PIN, 0);
gpio_put(CW_OUT_PIN, 0);
m_buzzer.off();
m_keyNextIambicB = false;
m_currentlyPausing = false;
m_currentlyKeying = false;
m_previousState = State::Abort;
m_paddleKeyingState = State::Wait;
}
switch (m_messageKeyingState) {
@ -167,7 +174,7 @@ void Keyer::run()
break;
case MessageState::InterWordSpace:
if (!m_currentlyPausing) {
m_pausing_until = make_timeout_time_us(m_elementDuration * 7);
m_pausing_until = make_timeout_time_us(m_elementDuration * (7-3)); // 7-3, because we aleady have the InterCharSpace of 3
m_currentlyPausing = true;
}
if (left_paddle_pressed() || right_paddle_pressed()) {

View file

@ -15,6 +15,7 @@ class Keyer final
void setMode(Mode mode) { m_mode = mode; }
void setSpeed(uint8_t wpm);
void sendMessage(std::string msg);
void sendCharacter(char ch);
void run();
void stop();

View file

@ -78,7 +78,7 @@ std::string messageToMorse(std::string &msg)
// Append word space if last char was not a blank
if (msg.back() != ' ') {
//morseString.push_back('w');
morseString.push_back('w');
}
return morseString;
@ -102,7 +102,7 @@ std::string charToMorse(char ch) {
}
}
//morseString.push_back('c');
morseString.push_back('c');
return morseString;

View file

@ -37,7 +37,7 @@ struct KeyerQueueData {
KeyerQueueCommand cmd;
uint8_t wpm;
Mode mode;
std::string message;
char message;
};
queue_t keyerQueue;
@ -93,8 +93,7 @@ void core1_main()
data.cmd = KeyerQueueCommand::Run;
break;
case KeyerQueueCommand::SendMessage:
printf("Sending: %s\n", data.message.c_str());
keyer.sendMessage(data.message);
keyer.sendCharacter(data.message);
data.cmd = KeyerQueueCommand::Run;
break;
case KeyerQueueCommand::Wait:
@ -150,9 +149,7 @@ void cdc_task()
[[fallthrough]];
case '.':
{
printf("TODO: Send it: %c\n", buf[0]);
std::string msg(1, buf[0]);
KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, Mode::IambicB, msg};
KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, Mode::IambicB, buf[0]};
queue_add_blocking(&keyerQueue, &keyerQueueData);
break;
}
@ -221,29 +218,20 @@ int main()
}
lastWpm = currentWpm;
KeyerQueueData keyerQueueData {KeyerQueueCommand::Run, currentWpm, settings.mode, ""};
KeyerQueueData keyerQueueData {KeyerQueueCommand::Run, currentWpm, settings.mode, 0};
queue_add_blocking(&keyerQueue, &keyerQueueData);
static bool used = false;
while (true) {
currentWpm = calcWPM(potiRead(), settings.wpmPotiMin, settings.wpmPotiMax);
// If WPM in settings is set to 0 -> take speed from poti
if (settings.wpm == 0 && (currentWpm != lastWpm)) {
KeyerQueueData keyerQueueData {KeyerQueueCommand::Config, currentWpm, settings.mode, ""};
KeyerQueueData keyerQueueData {KeyerQueueCommand::Config, currentWpm, settings.mode, 0};
queue_add_blocking(&keyerQueue, &keyerQueueData);
printf("WPM has changed to: %d\n", currentWpm);
lastWpm = currentWpm;
}
// busy_wait_ms(5000);
if (!used) {
// KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, settings.mode, "cq cq de dg2smb dg2smb
// pse k"}; queue_add_blocking(&keyerQueue, &keyerQueueData);
used = true;
}
tud_task();
cdc_task();
}