dit and dah instead of l and r

This commit is contained in:
Martin Brodbeck 2024-03-05 09:12:09 +01:00
parent b076f2c637
commit 4c1a8fc062
3 changed files with 31 additions and 28 deletions

View file

@ -8,25 +8,25 @@
#include "sidetone.h" #include "sidetone.h"
extern const uint LED_PIN; extern const uint LED_PIN;
extern const uint LEFT_PADDLE_PIN; extern const uint DIT_PADDLE_PIN;
extern const uint RIGHT_PADDLE_PIN; extern const uint DAH_PADDLE_PIN;
extern const uint BUZZER_PIN; extern const uint BUZZER_PIN;
extern const uint CW_OUT_PIN; extern const uint CW_OUT_PIN;
// extern const uint AUDIO_OUT_PIN; // extern const uint AUDIO_OUT_PIN;
const uint SIDETONE_FREQ = 622; 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 true;
} }
return false; 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 true;
} }
return false; return false;
@ -112,7 +112,7 @@ void Keyer::run()
gpio_put(CW_OUT_PIN, 1); gpio_put(CW_OUT_PIN, 1);
m_buzzer.on(SIDETONE_FREQ); m_buzzer.on(SIDETONE_FREQ);
} }
if (left_paddle_pressed() || right_paddle_pressed()) { if (dit_paddle_pressed() || dah_paddle_pressed()) {
m_messageKeyingState = MessageState::Abort; m_messageKeyingState = MessageState::Abort;
} }
if (absolute_time_diff_us(timestamp, m_keying_until) <= 0) { if (absolute_time_diff_us(timestamp, m_keying_until) <= 0) {
@ -131,7 +131,7 @@ void Keyer::run()
gpio_put(CW_OUT_PIN, 1); gpio_put(CW_OUT_PIN, 1);
m_buzzer.on(SIDETONE_FREQ); m_buzzer.on(SIDETONE_FREQ);
} }
if (left_paddle_pressed() || right_paddle_pressed()) { if (dit_paddle_pressed() || dah_paddle_pressed()) {
m_messageKeyingState = MessageState::Abort; m_messageKeyingState = MessageState::Abort;
} }
if (absolute_time_diff_us(timestamp, m_keying_until) <= 0) { 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_pausing_until = make_timeout_time_us(m_elementDuration);
m_currentlyPausing = true; m_currentlyPausing = true;
} }
if (left_paddle_pressed() || right_paddle_pressed()) { if (dit_paddle_pressed() || dah_paddle_pressed()) {
m_messageKeyingState = MessageState::Abort; m_messageKeyingState = MessageState::Abort;
} }
if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { 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_pausing_until = make_timeout_time_us(m_elementDuration * 3);
m_currentlyPausing = true; m_currentlyPausing = true;
} }
if (left_paddle_pressed() || right_paddle_pressed()) { if (dit_paddle_pressed() || dah_paddle_pressed()) {
m_messageKeyingState = MessageState::Abort; m_messageKeyingState = MessageState::Abort;
} }
if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { 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 (7 - 3)); // 7-3, because we aleady have the InterCharSpace of 3
m_currentlyPausing = true; m_currentlyPausing = true;
} }
if (left_paddle_pressed() || right_paddle_pressed()) { if (dit_paddle_pressed() || dah_paddle_pressed()) {
m_messageKeyingState = MessageState::Abort; m_messageKeyingState = MessageState::Abort;
} }
if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { 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 we are in Straight key mode …
if (m_mode == Mode::Straight) { if (m_mode == Mode::Straight) {
if (left_paddle_pressed()) { if (dit_paddle_pressed()) {
gpio_put(LED_PIN, 1); gpio_put(LED_PIN, 1);
gpio_put(CW_OUT_PIN, 1); gpio_put(CW_OUT_PIN, 1);
m_buzzer.on(SIDETONE_FREQ); m_buzzer.on(SIDETONE_FREQ);
@ -218,10 +218,10 @@ 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 (dit_paddle_pressed()) {
m_keyNextIambicB = false; m_keyNextIambicB = false;
m_paddleKeyingState = State::Dit; m_paddleKeyingState = State::Dit;
} else if (right_paddle_pressed()) { } else if (dah_paddle_pressed()) {
m_keyNextIambicB = false; m_keyNextIambicB = false;
m_paddleKeyingState = State::Dah; m_paddleKeyingState = State::Dah;
} else { } else {
@ -245,7 +245,7 @@ void Keyer::run()
// m_audioOut.on(SIDETONE_FREQ); // m_audioOut.on(SIDETONE_FREQ);
} else { } else {
// If right paddle üressed -> note for Iambic B // If right paddle üressed -> note for Iambic B
if (right_paddle_pressed() && !m_keyNextIambicB) { if (dah_paddle_pressed() && !m_keyNextIambicB) {
m_keyNextIambicB = true; m_keyNextIambicB = true;
} }
@ -270,7 +270,7 @@ void Keyer::run()
// m_audioOut.on(SIDETONE_FREQ); // m_audioOut.on(SIDETONE_FREQ);
} else { } else {
// If left paddle pressed -> Note for Iambic B // If left paddle pressed -> Note for Iambic B
if (left_paddle_pressed() && !m_keyNextIambicB) { if (dit_paddle_pressed() && !m_keyNextIambicB) {
m_keyNextIambicB = true; m_keyNextIambicB = true;
} }
@ -293,10 +293,10 @@ void Keyer::run()
if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) {
m_currentlyPausing = false; m_currentlyPausing = false;
if (right_paddle_pressed()) { if (dah_paddle_pressed()) {
m_paddleKeyingState = State::Dah; m_paddleKeyingState = State::Dah;
m_keyNextIambicB = false; m_keyNextIambicB = false;
} else if (left_paddle_pressed()) { } else if (dit_paddle_pressed()) {
m_paddleKeyingState = State::Dit; m_paddleKeyingState = State::Dit;
m_keyNextIambicB = false; m_keyNextIambicB = false;
} else { } else {
@ -313,10 +313,10 @@ void Keyer::run()
if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) { if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0) {
m_currentlyPausing = false; m_currentlyPausing = false;
if (left_paddle_pressed()) { if (dit_paddle_pressed()) {
m_paddleKeyingState = State::Dit; m_paddleKeyingState = State::Dit;
m_keyNextIambicB = false; m_keyNextIambicB = false;
} else if (right_paddle_pressed()) { } else if (dah_paddle_pressed()) {
m_paddleKeyingState = State::Dah; m_paddleKeyingState = State::Dah;
m_keyNextIambicB = false; m_keyNextIambicB = false;
} else { } else {

View file

@ -39,6 +39,9 @@ class Keyer final
Abort, Abort,
}; };
bool dit_paddle_pressed() const;
bool dah_paddle_pressed() const;
uint8_t m_wpm {18}; uint8_t m_wpm {18};
Mode m_mode {Mode::IambicB}; Mode m_mode {Mode::IambicB};

View file

@ -18,8 +18,8 @@
#include <config.h> #include <config.h>
extern const uint LED_PIN = PICO_DEFAULT_LED_PIN; extern const uint LED_PIN = PICO_DEFAULT_LED_PIN;
extern const uint LEFT_PADDLE_PIN = 14; extern const uint DIT_PADDLE_PIN = 14;
extern const uint RIGHT_PADDLE_PIN = 15; extern const uint DAH_PADDLE_PIN = 15;
extern const uint BUZZER_PIN = 18; extern const uint BUZZER_PIN = 18;
extern const uint CW_OUT_PIN = 17; extern const uint CW_OUT_PIN = 17;
// extern const uint AUDIO_OUT_PIN = 16; // extern const uint AUDIO_OUT_PIN = 16;
@ -37,12 +37,12 @@ void setup()
gpio_put(LED_PIN, 0); gpio_put(LED_PIN, 0);
// Setup pins for left and right paddles // Setup pins for left and right paddles
gpio_init(LEFT_PADDLE_PIN); gpio_init(DIT_PADDLE_PIN);
gpio_set_dir(LEFT_PADDLE_PIN, GPIO_IN); gpio_set_dir(DIT_PADDLE_PIN, GPIO_IN);
gpio_pull_up(LEFT_PADDLE_PIN); gpio_pull_up(DIT_PADDLE_PIN);
gpio_init(RIGHT_PADDLE_PIN); gpio_init(DAH_PADDLE_PIN);
gpio_set_dir(RIGHT_PADDLE_PIN, GPIO_IN); gpio_set_dir(DAH_PADDLE_PIN, GPIO_IN);
gpio_pull_up(RIGHT_PADDLE_PIN); gpio_pull_up(DAH_PADDLE_PIN);
gpio_init(CW_OUT_PIN); gpio_init(CW_OUT_PIN);
gpio_set_dir(CW_OUT_PIN, GPIO_OUT); gpio_set_dir(CW_OUT_PIN, GPIO_OUT);
gpio_put(CW_OUT_PIN, 0); gpio_put(CW_OUT_PIN, 0);