first attempt to send messages

This commit is contained in:
Martin Brodbeck 2024-02-23 14:45:42 +01:00
parent e8901e514d
commit b6ca08f32f
2 changed files with 21 additions and 19 deletions

View file

@ -58,10 +58,10 @@ void Keyer::run()
{ {
auto timestamp = get_absolute_time(); auto timestamp = get_absolute_time();
// If there is something to send … // If there is some message to send …
if (!m_messageQueue.empty() || m_messageKeyingState != MessageState::Wait) { if (!m_messageQueue.empty() || m_messageKeyingState != MessageState::Wait) {
// Stop all paddle keying, if necessary // Stop all paddle keying, if necessary
if (m_PaddleKeyingState != State::Wait) { if (m_paddleKeyingState != State::Wait) {
gpio_put(LED_PIN, 0); gpio_put(LED_PIN, 0);
gpio_put(CW_OUT_PIN, 0); gpio_put(CW_OUT_PIN, 0);
m_buzzer.off(); m_buzzer.off();
@ -69,12 +69,13 @@ void Keyer::run()
m_currentlyPausing = false; m_currentlyPausing = false;
m_currentlyKeying = false; m_currentlyKeying = false;
m_previousState = State::Abort; m_previousState = State::Abort;
m_PaddleKeyingState = State::Wait; m_paddleKeyingState = State::Wait;
} }
switch (m_messageKeyingState) { switch (m_messageKeyingState) {
case MessageState::Wait: case MessageState::Wait:
m_messageChar = m_messageQueue.front(); m_messageChar = m_messageQueue.front();
m_messageQueue.pop();
switch (m_messageChar) { switch (m_messageChar) {
case '.': case '.':
@ -181,6 +182,7 @@ void Keyer::run()
m_currentlyKeying = false; m_currentlyKeying = false;
std::queue<char> emptyQueue; std::queue<char> emptyQueue;
std::swap(m_messageQueue, emptyQueue); std::swap(m_messageQueue, emptyQueue);
m_messageKeyingState = MessageState::Wait;
break; break;
} }
default: default:
@ -206,20 +208,20 @@ void Keyer::run()
} }
// If we are in IambicA or IambicB-Mode … // If we are in IambicA or IambicB-Mode …
switch (m_PaddleKeyingState) { switch (m_paddleKeyingState) {
case State::Wait: case State::Wait:
if (left_paddle_pressed()) { if (left_paddle_pressed()) {
m_keyNextIambicB = false; m_keyNextIambicB = false;
m_PaddleKeyingState = State::Dit; m_paddleKeyingState = State::Dit;
} else if (right_paddle_pressed()) { } else if (right_paddle_pressed()) {
m_keyNextIambicB = false; m_keyNextIambicB = false;
m_PaddleKeyingState = State::Dah; m_paddleKeyingState = State::Dah;
} else { } else {
if (m_mode == Mode::IambicB && m_keyNextIambicB) { if (m_mode == Mode::IambicB && m_keyNextIambicB) {
if (m_previousState == State::Dit) if (m_previousState == State::Dit)
m_PaddleKeyingState = State::Dah; m_paddleKeyingState = State::Dah;
else else
m_PaddleKeyingState = State::Dit; m_paddleKeyingState = State::Dit;
m_keyNextIambicB = false; m_keyNextIambicB = false;
} }
@ -246,7 +248,7 @@ void Keyer::run()
m_buzzer.off(); m_buzzer.off();
// m_audioOut.off(); // m_audioOut.off();
m_previousState = State::Dit; m_previousState = State::Dit;
m_PaddleKeyingState = State::DitPause; m_paddleKeyingState = State::DitPause;
} }
} }
break; break;
@ -271,7 +273,7 @@ void Keyer::run()
m_buzzer.off(); m_buzzer.off();
// m_audioOut.off(); // m_audioOut.off();
m_previousState = State::Dah; m_previousState = State::Dah;
m_PaddleKeyingState = State::DahPause; m_paddleKeyingState = State::DahPause;
} }
} }
break; break;
@ -284,13 +286,13 @@ void Keyer::run()
m_currentlyPausing = false; m_currentlyPausing = false;
if (right_paddle_pressed()) { if (right_paddle_pressed()) {
m_PaddleKeyingState = State::Dah; m_paddleKeyingState = State::Dah;
m_keyNextIambicB = false; m_keyNextIambicB = false;
} else if (left_paddle_pressed()) { } else if (left_paddle_pressed()) {
m_PaddleKeyingState = State::Dit; m_paddleKeyingState = State::Dit;
m_keyNextIambicB = false; m_keyNextIambicB = false;
} else { } else {
m_PaddleKeyingState = State::Wait; m_paddleKeyingState = State::Wait;
} }
} }
} }
@ -304,13 +306,13 @@ void Keyer::run()
m_currentlyPausing = false; m_currentlyPausing = false;
if (left_paddle_pressed()) { if (left_paddle_pressed()) {
m_PaddleKeyingState = State::Dit; m_paddleKeyingState = State::Dit;
m_keyNextIambicB = false; m_keyNextIambicB = false;
} else if (right_paddle_pressed()) { } else if (right_paddle_pressed()) {
m_PaddleKeyingState = State::Dah; m_paddleKeyingState = State::Dah;
m_keyNextIambicB = false; m_keyNextIambicB = false;
} else { } else {
m_PaddleKeyingState = State::Wait; m_paddleKeyingState = State::Wait;
} }
} }
} }
@ -324,11 +326,11 @@ void Keyer::run()
m_currentlyPausing = false; m_currentlyPausing = false;
m_currentlyKeying = false; m_currentlyKeying = false;
m_previousState = State::Abort; m_previousState = State::Abort;
m_PaddleKeyingState = State::Wait; m_paddleKeyingState = State::Wait;
break; break;
default: default:
break; break;
} }
} }
void Keyer::stop() { m_PaddleKeyingState = State::Abort; } void Keyer::stop() { m_paddleKeyingState = State::Abort; }

View file

@ -48,7 +48,7 @@ class Keyer final
Sidetone m_buzzer; Sidetone m_buzzer;
// Sidetone m_audioOut; // Sidetone m_audioOut;
State m_PaddleKeyingState {State::Wait}; State m_paddleKeyingState {State::Wait};
State m_previousState {State::Wait}; State m_previousState {State::Wait};
std::queue<char> m_messageQueue; std::queue<char> m_messageQueue;