From df85ca42677a6007f5ef9ebec2b1e51d35822d7e Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 26 Feb 2024 15:57:13 +0100 Subject: [PATCH] Sending chars via WKdemo --- src/keyer.cpp | 31 +++++++++++++++++++------------ src/keyer.h | 1 + src/morse.cpp | 4 ++-- src/raspi_keyer.cpp | 22 +++++----------------- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/keyer.cpp b/src/keyer.cpp index bca845b..23e859a 100644 --- a/src/keyer.cpp +++ b/src/keyer.cpp @@ -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()) { diff --git a/src/keyer.h b/src/keyer.h index 3b7e2ba..b6c378b 100644 --- a/src/keyer.h +++ b/src/keyer.h @@ -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(); diff --git a/src/morse.cpp b/src/morse.cpp index 97ff2a2..a6ffa32 100644 --- a/src/morse.cpp +++ b/src/morse.cpp @@ -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; diff --git a/src/raspi_keyer.cpp b/src/raspi_keyer.cpp index f4559c5..f50d3a6 100644 --- a/src/raspi_keyer.cpp +++ b/src/raspi_keyer.cpp @@ -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(); }