From 11eef9f02ed0dd90aa7b09a48b9c52156baf28e7 Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 30 Jul 2019 09:27:55 +0200 Subject: [PATCH] CW keyer keyboard input: implemented controls in CW keyer --- sdrbase/dsp/cwkeyer.cpp | 39 +++++++++++++++++++++++++++++++++ sdrbase/dsp/cwkeyer.h | 3 +++ sdrbase/dsp/cwkeyersettings.cpp | 3 +++ sdrbase/dsp/cwkeyersettings.h | 1 + sdrgui/gui/cwkeyergui.cpp | 17 ++++++++++++++ sdrgui/gui/cwkeyergui.h | 1 + 6 files changed, 64 insertions(+) diff --git a/sdrbase/dsp/cwkeyer.cpp b/sdrbase/dsp/cwkeyer.cpp index bae4bf6d7..89f63869e 100644 --- a/sdrbase/dsp/cwkeyer.cpp +++ b/sdrbase/dsp/cwkeyer.cpp @@ -205,6 +205,18 @@ int CWKeyer::getSample() nextStateIambic(); return m_key ? 1 : 0; } + else if (m_settings.m_mode == CWKeyerSettings::CWKeyboard) + { + if (m_settings.m_keyboardIambic) + { + nextStateIambic(); + return m_key ? 1 : 0; + } + else + { + return (m_dot || m_dash) ? 1 : 0; + } + } else { return 0; @@ -408,6 +420,27 @@ bool CWKeyer::eom() return !(m_textPointer < m_settings.m_text.length()); } +void CWKeyer::setKeyboardDots() +{ + m_dot = true; + m_dash = false; + m_keyIambicState = KeySilent; +} + +void CWKeyer::setKeyboardDashes() +{ + m_dot = false; + m_dash = true; + m_keyIambicState = KeySilent; +} + +void CWKeyer::setKeyboardSilence() +{ + m_dot = false; + m_dash = false; + m_keyIambicState = KeySilent; +} + CWSmoother::CWSmoother() : m_fadeInCounter(0), m_fadeOutCounter(0), @@ -547,6 +580,12 @@ void CWKeyer::applySettings(const CWKeyerSettings& settings, bool force) m_dash = true; m_keyIambicState = KeySilent; } + else if (settings.m_mode == CWKeyerSettings::CWKeyboard) + { + m_dot = false; + m_dash = false; + m_keyIambicState = KeySilent; + } } if ((m_settings.m_text != settings.m_text) || force) diff --git a/sdrbase/dsp/cwkeyer.h b/sdrbase/dsp/cwkeyer.h index 9e48e3dc9..743e686ad 100644 --- a/sdrbase/dsp/cwkeyer.h +++ b/sdrbase/dsp/cwkeyer.h @@ -112,6 +112,9 @@ public: bool eom(); void resetText() { m_textState = TextStart; } void stopText() { m_textState = TextStop; } + void setKeyboardDots(); + void setKeyboardDashes(); + void setKeyboardSilence(); private: QMutex m_mutex; diff --git a/sdrbase/dsp/cwkeyersettings.cpp b/sdrbase/dsp/cwkeyersettings.cpp index 26e5a733c..307f1bff3 100644 --- a/sdrbase/dsp/cwkeyersettings.cpp +++ b/sdrbase/dsp/cwkeyersettings.cpp @@ -31,6 +31,7 @@ void CWKeyerSettings::resetToDefaults() m_sampleRate = 48000; m_text = ""; m_wpm = 13; + m_keyboardIambic = true; m_dotKey = Qt::Key_Period; m_dotKeyModifiers = Qt::NoModifier; m_dashKey = Qt::Key_Minus; @@ -50,6 +51,7 @@ QByteArray CWKeyerSettings::serialize() const s.writeU32(8, (unsigned int) m_dotKeyModifiers); s.writeS32(9, (int) m_dashKey); s.writeU32(10, (unsigned int) m_dashKeyModifiers); + s.writeBool(11, m_keyboardIambic); return s.final(); } @@ -83,6 +85,7 @@ bool CWKeyerSettings::deserialize(const QByteArray& data) m_dashKey = (Qt::Key) (intval < 0 ? 0 : intval); d.readU32(10, &uintval, 0); m_dashKeyModifiers = (Qt::KeyboardModifiers) uintval; + d.readBool(11, &m_keyboardIambic, true); return true; } diff --git a/sdrbase/dsp/cwkeyersettings.h b/sdrbase/dsp/cwkeyersettings.h index f7a7f6a03..f59beafa3 100644 --- a/sdrbase/dsp/cwkeyersettings.h +++ b/sdrbase/dsp/cwkeyersettings.h @@ -41,6 +41,7 @@ public: int m_sampleRate; QString m_text; int m_wpm; + bool m_keyboardIambic; Qt::Key m_dotKey; Qt::KeyboardModifiers m_dotKeyModifiers; Qt::Key m_dashKey; diff --git a/sdrgui/gui/cwkeyergui.cpp b/sdrgui/gui/cwkeyergui.cpp index 3e7e7dd81..1eb60bef1 100644 --- a/sdrgui/gui/cwkeyergui.cpp +++ b/sdrgui/gui/cwkeyergui.cpp @@ -156,6 +156,12 @@ void CWKeyerGUI::on_playStop_toggled(bool checked) } } +void CWKeyerGUI::on_keyingStyle_toggled(bool checked) +{ + m_settings.m_keyboardIambic = !checked; + applySettings(); +} + void CWKeyerGUI::on_keyDotCapture_toggled(bool checked) { if (checked && ui->keyDashCapture->isChecked()) @@ -262,10 +268,20 @@ void CWKeyerGUI::keyboardKeyPressed(Qt::Key key, Qt::KeyboardModifiers keyModifi if ((key == settings.m_dotKey) && (keyModifiers == settings.m_dotKeyModifiers)) { qDebug("CWKeyerGUI::keyboardKeyPressed: dot %s", release ? "released" : "pressed"); + if (release) { + m_cwKeyer->setKeyboardSilence(); + } else { + m_cwKeyer->setKeyboardDots(); + } } else if ((key == settings.m_dashKey) && (keyModifiers == settings.m_dashKeyModifiers)) { qDebug("CWKeyerGUI::keyboardKeyPressed: dash %s", release ? "released" : "pressed"); + if (release) { + m_cwKeyer->setKeyboardSilence(); + } else { + m_cwKeyer->setKeyboardDashes(); + } } } @@ -301,6 +317,7 @@ void CWKeyerGUI::displaySettings() ui->cwTextEdit->setText(m_settings.m_text); ui->cwSpeed->setValue(m_settings.m_wpm); ui->cwSpeedText->setText(QString("%1").arg(m_settings.m_wpm)); + ui->keyingStyle->setChecked(!m_settings.m_keyboardIambic); setKeyLabel(ui->keyDotLabel, m_settings.m_dotKey, m_settings.m_dotKeyModifiers); setKeyLabel(ui->keyDashLabel, m_settings.m_dashKey, m_settings.m_dashKeyModifiers); diff --git a/sdrgui/gui/cwkeyergui.h b/sdrgui/gui/cwkeyergui.h index cb0dada35..5167751fd 100644 --- a/sdrgui/gui/cwkeyergui.h +++ b/sdrgui/gui/cwkeyergui.h @@ -80,6 +80,7 @@ private slots: void on_playText_toggled(bool checked); void on_playLoopCW_toggled(bool checked); void on_playStop_toggled(bool checked); + void on_keyingStyle_toggled(bool checked); void on_keyDotCapture_toggled(bool checked); void on_keyDashCapture_toggled(bool checked); void on_keyboardKeyer_toggled(bool checked);