From 251c365095494a7320039253c169c6772440e5fe Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 14 Feb 2024 11:32:09 +0100 Subject: [PATCH] new feature: stopping keyer --- src/keyer.cpp | 15 ++++++++++++++- src/keyer.h | 2 ++ src/raspi_keyer.cpp | 8 +++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/keyer.cpp b/src/keyer.cpp index 3e81201..afe5f85 100644 --- a/src/keyer.cpp +++ b/src/keyer.cpp @@ -149,8 +149,21 @@ void Keyer::run() } break; - + case State::Abort: + gpio_put(LED_PIN, 0); + m_Sidetone.off(); + m_keyNextIambicB = false; + m_currentlyPausing = false; + m_currentlyKeying = false; + m_previousState = State::Abort; + state = State::Wait; + break; default: break; } +} + +void Keyer::stop() +{ + state = State::Abort; } \ No newline at end of file diff --git a/src/keyer.h b/src/keyer.h index bc32db9..95e4aa9 100644 --- a/src/keyer.h +++ b/src/keyer.h @@ -15,6 +15,7 @@ public: Dit, Dah, InterCharSpace, + Abort, }; Keyer() = delete; Keyer(uint8_t wpm, Mode mode); @@ -23,6 +24,7 @@ public: void setSpeed(uint8_t wpm); void run(); + void stop(); private: State state{State::Wait}; diff --git a/src/raspi_keyer.cpp b/src/raspi_keyer.cpp index d904166..34c283f 100644 --- a/src/raspi_keyer.cpp +++ b/src/raspi_keyer.cpp @@ -23,6 +23,7 @@ enum class KeyerQueueCommand Run, Stop, Config, + Wait, }; struct KeyerQueueData { @@ -69,11 +70,16 @@ void core1_main() keyer.run(); break; case KeyerQueueCommand::Stop: + keyer.stop(); + data.cmd = KeyerQueueCommand::Wait; break; case KeyerQueueCommand::Config: - // set speed and wpm + keyer.setSpeed(data.wpm); + keyer.setMode(data.mode); data.cmd = KeyerQueueCommand::Run; break; + case KeyerQueueCommand::Wait: + break; default: break; }