1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-17 23:28:50 -05:00

CW Keyer: retain only text, dashes and dots

This commit is contained in:
f4exb 2016-12-11 21:52:53 +01:00
parent abad9d7299
commit e4e2eea9d5
5 changed files with 133 additions and 450 deletions

View File

@ -169,7 +169,7 @@ CWKeyer::CWKeyer() :
m_elementOn(false),
m_loop(false),
m_asciiChar('\0'),
m_mode(CWKey),
m_mode(CWNone),
m_keyIambicState(KeySilent),
m_textState(TextStart)
{
@ -215,49 +215,20 @@ void CWKeyer::setMode(CWMode mode)
{
m_textState = TextStart;
}
m_mode = mode;
}
}
void CWKeyer::setKey(bool key)
{
if (m_mode == CWKey)
{
qDebug() << "CWKeyer::setKey: " << key;
m_key = key;
}
}
void CWKeyer::setDot(bool dotOn)
{
if (m_mode == CWIambic)
{
if (dotOn)
else if (mode == CWDots)
{
m_dash = false;
m_dot = true;
m_dash = false;
m_keyIambicState = KeySilent;
}
else
{
m_dot = false;
}
}
}
void CWKeyer::setDash(bool dashOn)
{
if (m_mode == CWIambic)
{
if (dashOn)
else if (mode == CWDashes)
{
m_dot = false;
m_dash = true;
m_keyIambicState = KeySilent;
}
else
{
m_dash = false;
}
m_mode = mode;
}
}
@ -265,20 +236,16 @@ int CWKeyer::getSample()
{
QMutexLocker mutexLocker(&m_mutex);
if (m_mode == CWKey)
{
return m_key ? 1 : 0;
}
else if (m_mode == CWIambic)
{
nextStateIambic();
return m_key ? 1 : 0;
}
else if (m_mode == CWText)
if (m_mode == CWText)
{
nextStateText();
return m_key ? 1 : 0;
}
else if ((m_mode == CWDots) || (m_mode == CWDashes))
{
nextStateIambic();
return m_key ? 1 : 0;
}
else
{
return 0;

View File

@ -31,8 +31,8 @@ public:
{
CWNone,
CWText,
CWKey,
CWIambic
CWDots,
CWDashes
} CWMode;
typedef enum
@ -67,10 +67,6 @@ public:
void setMode(CWMode mode);
void setLoop(bool loop) { m_loop = loop; }
void setKey(bool key);
void setDot(bool dotOn);
void setDash(bool dashOn);
int getSample();
bool eom();
void resetText() { m_textState = TextStart; }

View File

@ -27,10 +27,7 @@ CWKeyerGUI::CWKeyerGUI(QWidget* parent) :
QWidget(parent),
ui(new Ui::CWKeyerGUI),
m_messageQueue(0),
m_cwKeyer(0),
m_key(0x30),
m_keyDot(0x31),
m_keyDash(0x32)
m_cwKeyer(0)
{
ui->setupUi(this);
}
@ -50,9 +47,8 @@ void CWKeyerGUI::setBuddies(MessageQueue* messageQueue, CWKeyer* cwKeyer)
void CWKeyerGUI::resetToDefaults()
{
m_key = false;
m_keyDot = false;
m_keyDash = false;
ui->cwTextEdit->setText("");
ui->cwSpeed->setValue(13);
}
QByteArray CWKeyerGUI::serialize() const
@ -61,9 +57,6 @@ QByteArray CWKeyerGUI::serialize() const
s.writeString(1, ui->cwTextEdit->text());
s.writeS32(2, ui->cwSpeed->value());
s.writeS32(3, ui->morseKeyAssign->currentIndex());
s.writeS32(4, ui->iambicKeyDotAssign->currentIndex());
s.writeS32(5, ui->iambicKeyDashAssign->currentIndex());
return s.final();
}
@ -87,12 +80,6 @@ bool CWKeyerGUI::deserialize(const QByteArray& data)
ui->cwTextEdit->setText(aString);
d.readS32(2, &aValue, 13);
ui->cwSpeed->setValue(aValue);
d.readS32(3, &aValue, 0);
ui->morseKeyAssign->setCurrentIndex(aValue);
d.readS32(4, &aValue, 1);
ui->iambicKeyDotAssign->setCurrentIndex(aValue);
d.readS32(5, &aValue, 2);
ui->iambicKeyDashAssign->setCurrentIndex(aValue);
applySettings();
return true;
@ -118,49 +105,37 @@ void CWKeyerGUI::on_cwSpeed_valueChanged(int value)
m_cwKeyer->setWPM(value);
}
void CWKeyerGUI::on_morseKey_toggled(bool checked)
void CWKeyerGUI::on_playDots_toggled(bool checked)
{
//ui->morseKey->setEnabled(!checked);
ui->iambicKey->setEnabled(!checked);
ui->playStop->setEnabled(!checked);
m_cwKeyer->setMode(checked ? CWKeyer::CWKey : CWKeyer::CWNone);
//ui->playDots->setEnabled(!checked); // release other source inputs
ui->playDashes->setEnabled(!checked);
ui->playText->setEnabled(!checked);
m_cwKeyer->setMode(checked ? CWKeyer::CWDots : CWKeyer::CWNone);
}
void CWKeyerGUI::on_morseKeyAssign_currentIndexChanged(int index)
void CWKeyerGUI::on_playDashes_toggled(bool checked)
{
if ((index >= 0) && (index < 9)) {
m_key = 0x30 + index;
}
}
ui->playDots->setEnabled(!checked); // release other source inputs
//ui->playDashes->setEnabled(!checked);
ui->playText->setEnabled(!checked);
void CWKeyerGUI::on_iambicKey_toggled(bool checked)
{
ui->morseKey->setEnabled(!checked);
//ui->iambicKey->setEnabled(!checked);
ui->playStop->setEnabled(!checked);
m_cwKeyer->setMode(checked ? CWKeyer::CWIambic : CWKeyer::CWNone);
}
void CWKeyerGUI::on_iambicKeyDotAssign_currentIndexChanged(int index)
{
if ((index >= 0) && (index < 9)) {
m_keyDot = 0x30 + index;
}
}
void CWKeyerGUI::on_iambicKeyDashAssign_currentIndexChanged(int index)
{
if ((index >= 0) && (index < 9)) {
m_keyDash = 0x30 + index;
}
m_cwKeyer->setMode(checked ? CWKeyer::CWDashes : CWKeyer::CWNone);
}
void CWKeyerGUI::on_playText_toggled(bool checked)
{
ui->morseKey->setEnabled(!checked);
ui->iambicKey->setEnabled(!checked);
//ui->playStop->setEnabled(!checked);
ui->playDots->setEnabled(!checked); // release other source inputs
ui->playDashes->setEnabled(!checked);
//ui->playText->setEnabled(!checked);
m_cwKeyer->setMode(checked ? CWKeyer::CWText : CWKeyer::CWNone);
if (checked) {
ui->playStop->setChecked(true);
} else {
ui->playStop->setChecked(false);
}
}
void CWKeyerGUI::on_playLoop_toggled(bool checked)
@ -191,79 +166,4 @@ void CWKeyerGUI::applySettings()
value = ui->cwSpeed->value();
ui->cwSpeedText->setText(QString("%1").arg(value));
m_cwKeyer->setWPM(value);
value = ui->morseKeyAssign->currentIndex();
if ((value >= 0) && (value < 9)) {
m_key = 0x30 + value;
}
value = ui->iambicKeyDotAssign->currentIndex();
if ((value >= 0) && (value < 9)) {
m_keyDot = 0x30 + value;
}
value = ui->iambicKeyDashAssign->currentIndex();
if ((value >= 0) && (value < 9)) {
m_keyDash = 0x30 + value;
}
}
void CWKeyerGUI::keyPressEvent(QKeyEvent* keyEvent)
{
int key = keyEvent->key();
// Escape halts CW engine and releases keyboard immediately
// Thus keyboard cannot be left stuck
if (key == Qt::Key_Escape)
{
m_cwKeyer->setMode(CWKeyer::CWNone);
ui->morseKey->setChecked(false);
ui->iambicKey->setChecked(false);
ui->playStop->setChecked(false);
ui->morseKey->setEnabled(true);
ui->iambicKey->setEnabled(true);
ui->playStop->setEnabled(true);
this->releaseKeyboard();
return;
}
if (!keyEvent->isAutoRepeat())
{
qDebug() << "CWKeyerGUI::keyPressEvent: key"
<< ": " << key;
if (key == m_key)
{
m_cwKeyer->setKey(true);
}
else if (key == m_keyDot)
{
m_cwKeyer->setDot(true);
}
else if (key == m_keyDash)
{
m_cwKeyer->setDash(true);
}
}
}
void CWKeyerGUI::keyReleaseEvent(QKeyEvent* keyEvent)
{
if (!keyEvent->isAutoRepeat())
{
qDebug() << "CWKeyerGUI::keyReleaseEvent: key"
<< ": " << keyEvent->key();
if (keyEvent->key() == m_key)
{
m_cwKeyer->setKey(false);
}
else if (keyEvent->key() == m_keyDot)
{
m_cwKeyer->setDot(false);
}
else if (keyEvent->key() == m_keyDash)
{
m_cwKeyer->setDash(false);
}
}
}

View File

@ -42,18 +42,11 @@ public:
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
protected:
void keyPressEvent(QKeyEvent* keyEvent);
void keyReleaseEvent(QKeyEvent* keyEvent);
private:
Ui::CWKeyerGUI* ui;
MessageQueue* m_messageQueue;
CWKeyer* m_cwKeyer;
int m_key;
int m_keyDot;
int m_keyDash;
void applySettings();
@ -61,11 +54,8 @@ private slots:
void on_cwTextClear_clicked(bool checked);
void on_cwTextEdit_editingFinished();
void on_cwSpeed_valueChanged(int value);
void on_morseKey_toggled(bool checked);
void on_morseKeyAssign_currentIndexChanged(int index);
void on_iambicKey_toggled(bool checked);
void on_iambicKeyDotAssign_currentIndexChanged(int index);
void on_iambicKeyDashAssign_currentIndexChanged(int index);
void on_playDots_toggled(bool checked);
void on_playDashes_toggled(bool checked);
void on_playText_toggled(bool checked);
void on_playLoop_toggled(bool checked);
void on_playStop_toggled(bool checked);

View File

@ -72,9 +72,9 @@
</widget>
</item>
<item>
<widget class="ButtonSwitch" name="morseKey">
<widget class="ButtonSwitch" name="playDots">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -85,108 +85,62 @@
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Morse key</string>
</property>
<property name="icon">
<iconset resource="../resources/res.qrc">
<normaloff>:/morsekey.png</normaloff>:/morsekey.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="morseKeyAssign">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>35</width>
<height>16777215</height>
</size>
<property name="palette">
<palette>
<active>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>106</red>
<green>104</green>
<blue>100</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="toolTip">
<string>Morse key assignment</string>
<string>Send dots</string>
</property>
<property name="text">
<string>.</string>
</property>
<item>
<property name="text">
<string>0</string>
</property>
</item>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>9</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="ButtonSwitch" name="iambicKey">
<widget class="ButtonSwitch" name="playDashes">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -197,176 +151,53 @@
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Iambic key</string>
</property>
<property name="icon">
<iconset resource="../resources/res.qrc">
<normaloff>:/iambickey.png</normaloff>:/iambickey.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="iambicKeyDotAssign">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>35</width>
<height>16777215</height>
</size>
<property name="palette">
<palette>
<active>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>106</red>
<green>104</green>
<blue>100</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="toolTip">
<string>Iambic key dot assignment</string>
<property name="text">
<string>-</string>
</property>
<property name="currentIndex">
<number>1</number>
</property>
<item>
<property name="text">
<string>0</string>
</property>
</item>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>9</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="iambicKeyDashAssign">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>35</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="toolTip">
<string>Iambic key dash assignment</string>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<item>
<property name="text">
<string>0</string>
</property>
</item>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>3</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>5</string>
</property>
</item>
<item>
<property name="text">
<string>6</string>
</property>
</item>
<item>
<property name="text">
<string>7</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>9</string>
</property>
</item>
</widget>
</item>
<item>
@ -379,7 +210,7 @@
<item>
<widget class="ButtonSwitch" name="playText">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -446,7 +277,7 @@
<item>
<widget class="ButtonSwitch" name="playLoop">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -478,7 +309,7 @@
<item>
<widget class="ButtonSwitch" name="playStop">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -579,7 +410,6 @@
</customwidget>
</customwidgets>
<tabstops>
<tabstop>morseKey</tabstop>
<tabstop>playLoop</tabstop>
</tabstops>
<resources>