From b2dd1e28a1af88e5b250dc44ded4b34942e68ee0 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Sun, 18 Feb 2024 17:14:47 +0100 Subject: [PATCH] audio out added --- src/keyer.cpp | 22 ++++++++++++++++------ src/keyer.h | 5 ++--- src/raspi_keyer.cpp | 1 + src/sidetone.h | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/keyer.cpp b/src/keyer.cpp index 07e8b6b..68395ed 100644 --- a/src/keyer.cpp +++ b/src/keyer.cpp @@ -8,7 +8,9 @@ extern const uint LED_PIN; extern const uint LEFT_PADDLE_PIN; extern const uint RIGHT_PADDLE_PIN; +extern const uint BUZZER_PIN; extern const uint CW_OUT_PIN; +extern const uint AUDIO_OUT_PIN; const uint SIDETONE_FREQ = 622; @@ -34,7 +36,10 @@ uint64_t calcElementDurationUs(uint8_t wpm) return duration; } -Keyer::Keyer(uint8_t wpm, Mode mode) : m_wpm(wpm), m_mode(mode) { m_elementDuration = calcElementDurationUs(m_wpm); } +Keyer::Keyer(uint8_t wpm, Mode mode) : m_wpm(wpm), m_mode(mode), m_buzzer(BUZZER_PIN), m_audioOut(AUDIO_OUT_PIN) +{ + m_elementDuration = calcElementDurationUs(m_wpm); +} void Keyer::setSpeed(uint8_t wpm) { @@ -71,7 +76,8 @@ void Keyer::run() m_keying_until = make_timeout_time_us(m_elementDuration); gpio_put(LED_PIN, 1); gpio_put(CW_OUT_PIN, 1); - m_Sidetone.on(SIDETONE_FREQ); + m_buzzer.on(SIDETONE_FREQ); + m_audioOut.on(SIDETONE_FREQ); } else { // If right paddle üressed -> note for Iambic B if (right_paddle_pressed() && !m_keyNextIambicB) { @@ -83,7 +89,8 @@ void Keyer::run() m_currentlyKeying = false; gpio_put(LED_PIN, 0); gpio_put(CW_OUT_PIN, 0); - m_Sidetone.off(); + m_buzzer.off(); + m_audioOut.off(); m_previousState = State::Dit; m_state = State::DitPause; } @@ -95,7 +102,8 @@ void Keyer::run() m_keying_until = make_timeout_time_us(m_elementDuration * 3); gpio_put(LED_PIN, 1); gpio_put(CW_OUT_PIN, 1); - m_Sidetone.on(SIDETONE_FREQ); + m_buzzer.on(SIDETONE_FREQ); + m_audioOut.on(SIDETONE_FREQ); } else { // If left paddle pressed -> Note for Iambic B if (left_paddle_pressed() && !m_keyNextIambicB) { @@ -107,7 +115,8 @@ void Keyer::run() m_currentlyKeying = false; gpio_put(LED_PIN, 0); gpio_put(CW_OUT_PIN, 0); - m_Sidetone.off(); + m_buzzer.off(); + m_audioOut.off(); m_previousState = State::Dah; m_state = State::DahPause; } @@ -156,7 +165,8 @@ void Keyer::run() case State::Abort: gpio_put(LED_PIN, 0); gpio_put(CW_OUT_PIN, 0); - m_Sidetone.off(); + m_buzzer.off(); + m_audioOut.off(); m_keyNextIambicB = false; m_currentlyPausing = false; m_currentlyKeying = false; diff --git a/src/keyer.h b/src/keyer.h index bc71240..d74563f 100644 --- a/src/keyer.h +++ b/src/keyer.h @@ -3,8 +3,6 @@ #include "settings.h" #include "sidetone.h" -extern const uint BUZZER_PIN; - class Keyer final { public: @@ -33,7 +31,8 @@ class Keyer final absolute_time_t m_keying_until{0}; absolute_time_t m_pausing_until{0}; - Sidetone m_Sidetone{BUZZER_PIN}; + Sidetone m_buzzer; + Sidetone m_audioOut; State m_state{State::Wait}; State m_previousState{State::Wait}; diff --git a/src/raspi_keyer.cpp b/src/raspi_keyer.cpp index d672787..60f1fd7 100644 --- a/src/raspi_keyer.cpp +++ b/src/raspi_keyer.cpp @@ -17,6 +17,7 @@ extern const uint LEFT_PADDLE_PIN = 14; extern const uint RIGHT_PADDLE_PIN = 15; extern const uint BUZZER_PIN = 18; extern const uint CW_OUT_PIN = 17; +extern const uint AUDIO_OUT_PIN = 16; // Stuff for communicating between cores enum class KeyerQueueCommand { diff --git a/src/sidetone.h b/src/sidetone.h index 0a2a8b2..ced5273 100644 --- a/src/sidetone.h +++ b/src/sidetone.h @@ -3,11 +3,11 @@ class Sidetone { public: + Sidetone() = delete; Sidetone(uint gpio); void on(uint freq); void off(); private: - Sidetone(){}; uint m_gpio{0}; }; \ No newline at end of file