diff --git a/src/keyer.cpp b/src/keyer.cpp index 6b12321..1514d2c 100644 --- a/src/keyer.cpp +++ b/src/keyer.cpp @@ -8,25 +8,25 @@ #include "sidetone.h" extern const uint LED_PIN; -extern const uint LEFT_PADDLE_PIN; -extern const uint RIGHT_PADDLE_PIN; +extern const uint DIT_PADDLE_PIN; +extern const uint DAH_PADDLE_PIN; extern const uint BUZZER_PIN; extern const uint CW_OUT_PIN; // extern const uint AUDIO_OUT_PIN; const uint SIDETONE_FREQ = 622; -bool left_paddle_pressed() +bool Keyer::dit_paddle_pressed() const { - if (!gpio_get(LEFT_PADDLE_PIN)) { + if (!gpio_get(DIT_PADDLE_PIN)) { return true; } return false; } -bool right_paddle_pressed() +bool Keyer::dah_paddle_pressed() const { - if (!gpio_get(RIGHT_PADDLE_PIN)) { + if (!gpio_get(DAH_PADDLE_PIN)) { return true; } return false; @@ -112,7 +112,7 @@ void Keyer::run() gpio_put(CW_OUT_PIN, 1); m_buzzer.on(SIDETONE_FREQ); } - if (left_paddle_pressed() || right_paddle_pressed()) { + if (dit_paddle_pressed() || dah_paddle_pressed()) { m_messageKeyingState = MessageState::Abort; } if (absolute_time_diff_us(timestamp, m_keying_until) <= 0) { @@ -131,7 +131,7 @@ void Keyer::run() gpio_put(CW_OUT_PIN, 1); m_buzzer.on(SIDETONE_FREQ); } - if (left_paddle_pressed() || right_paddle_pressed()) { + if (dit_paddle_pressed() || dah_paddle_pressed()) { m_messageKeyingState = MessageState::Abort; } if (absolute_time_diff_us(timestamp, m_keying_until) <= 0) { @@ -147,7 +147,7 @@ void Keyer::run() m_pausing_until = make_timeout_time_us(m_elementDuration); m_currentlyPausing = true; } - if (left_paddle_pressed() || right_paddle_pressed()) { + if (dit_paddle_pressed() || dah_paddle_pressed()) { m_messageKeyingState = MessageState::Abort; } if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { @@ -160,7 +160,7 @@ void Keyer::run() m_pausing_until = make_timeout_time_us(m_elementDuration * 3); m_currentlyPausing = true; } - if (left_paddle_pressed() || right_paddle_pressed()) { + if (dit_paddle_pressed() || dah_paddle_pressed()) { m_messageKeyingState = MessageState::Abort; } if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { @@ -174,7 +174,7 @@ void Keyer::run() (7 - 3)); // 7-3, because we aleady have the InterCharSpace of 3 m_currentlyPausing = true; } - if (left_paddle_pressed() || right_paddle_pressed()) { + if (dit_paddle_pressed() || dah_paddle_pressed()) { m_messageKeyingState = MessageState::Abort; } if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { @@ -202,7 +202,7 @@ void Keyer::run() // If we are in Straight key mode … if (m_mode == Mode::Straight) { - if (left_paddle_pressed()) { + if (dit_paddle_pressed()) { gpio_put(LED_PIN, 1); gpio_put(CW_OUT_PIN, 1); m_buzzer.on(SIDETONE_FREQ); @@ -218,10 +218,10 @@ void Keyer::run() // If we are in IambicA or IambicB-Mode … switch (m_paddleKeyingState) { case State::Wait: - if (left_paddle_pressed()) { + if (dit_paddle_pressed()) { m_keyNextIambicB = false; m_paddleKeyingState = State::Dit; - } else if (right_paddle_pressed()) { + } else if (dah_paddle_pressed()) { m_keyNextIambicB = false; m_paddleKeyingState = State::Dah; } else { @@ -245,7 +245,7 @@ void Keyer::run() // m_audioOut.on(SIDETONE_FREQ); } else { // If right paddle üressed -> note for Iambic B - if (right_paddle_pressed() && !m_keyNextIambicB) { + if (dah_paddle_pressed() && !m_keyNextIambicB) { m_keyNextIambicB = true; } @@ -270,7 +270,7 @@ void Keyer::run() // m_audioOut.on(SIDETONE_FREQ); } else { // If left paddle pressed -> Note for Iambic B - if (left_paddle_pressed() && !m_keyNextIambicB) { + if (dit_paddle_pressed() && !m_keyNextIambicB) { m_keyNextIambicB = true; } @@ -293,10 +293,10 @@ void Keyer::run() if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { m_currentlyPausing = false; - if (right_paddle_pressed()) { + if (dah_paddle_pressed()) { m_paddleKeyingState = State::Dah; m_keyNextIambicB = false; - } else if (left_paddle_pressed()) { + } else if (dit_paddle_pressed()) { m_paddleKeyingState = State::Dit; m_keyNextIambicB = false; } else { @@ -313,10 +313,10 @@ void Keyer::run() if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { m_currentlyPausing = false; - if (left_paddle_pressed()) { + if (dit_paddle_pressed()) { m_paddleKeyingState = State::Dit; m_keyNextIambicB = false; - } else if (right_paddle_pressed()) { + } else if (dah_paddle_pressed()) { m_paddleKeyingState = State::Dah; m_keyNextIambicB = false; } else { diff --git a/src/keyer.h b/src/keyer.h index 99ce35f..381f605 100644 --- a/src/keyer.h +++ b/src/keyer.h @@ -39,6 +39,9 @@ class Keyer final Abort, }; + bool dit_paddle_pressed() const; + bool dah_paddle_pressed() const; + uint8_t m_wpm {18}; Mode m_mode {Mode::IambicB}; diff --git a/src/raspikeyer.cpp b/src/raspikeyer.cpp index cb5614f..658ee3d 100644 --- a/src/raspikeyer.cpp +++ b/src/raspikeyer.cpp @@ -18,8 +18,8 @@ #include extern const uint LED_PIN = PICO_DEFAULT_LED_PIN; -extern const uint LEFT_PADDLE_PIN = 14; -extern const uint RIGHT_PADDLE_PIN = 15; +extern const uint DIT_PADDLE_PIN = 14; +extern const uint DAH_PADDLE_PIN = 15; extern const uint BUZZER_PIN = 18; extern const uint CW_OUT_PIN = 17; // extern const uint AUDIO_OUT_PIN = 16; @@ -37,12 +37,12 @@ void setup() gpio_put(LED_PIN, 0); // Setup pins for left and right paddles - gpio_init(LEFT_PADDLE_PIN); - gpio_set_dir(LEFT_PADDLE_PIN, GPIO_IN); - gpio_pull_up(LEFT_PADDLE_PIN); - gpio_init(RIGHT_PADDLE_PIN); - gpio_set_dir(RIGHT_PADDLE_PIN, GPIO_IN); - gpio_pull_up(RIGHT_PADDLE_PIN); + gpio_init(DIT_PADDLE_PIN); + gpio_set_dir(DIT_PADDLE_PIN, GPIO_IN); + gpio_pull_up(DIT_PADDLE_PIN); + gpio_init(DAH_PADDLE_PIN); + gpio_set_dir(DAH_PADDLE_PIN, GPIO_IN); + gpio_pull_up(DAH_PADDLE_PIN); gpio_init(CW_OUT_PIN); gpio_set_dir(CW_OUT_PIN, GPIO_OUT); gpio_put(CW_OUT_PIN, 0);