Skip to content

Commit 651f99e

Browse files
committed
Fixed #711 - Winkey supports HW Button - pressing a HWbutton during keying will call the Halt method
1 parent f43acbb commit 651f99e

File tree

6 files changed

+46
-28
lines changed

6 files changed

+46
-28
lines changed

cwkey/CWKeyer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void CWKeyer::__openCWKey()
159159
connect(cwKey, &CWKey::keyHWButton2Pressed, this, &CWKeyer::cwKeyHWButton2PressedHandler);
160160
connect(cwKey, &CWKey::keyHWButton3Pressed, this, &CWKeyer::cwKeyHWButton3PressedHandler);
161161
connect(cwKey, &CWKey::keyHWButton4Pressed, this, &CWKeyer::cwKeyHWButton4PressedHandler);
162+
connect(cwKey, &CWKey::keyHWButtonHaltPressed, this, &CWKeyer::cwKeyHWButtonHaltHandler);
162163

163164
connectedCWKeyProfile = newProfile;
164165

@@ -404,6 +405,11 @@ void CWKeyer::cwKeyHWButton4PressedHandler()
404405
emit cwKeyHWButton4Pressed();
405406
}
406407

408+
void CWKeyer::cwKeyHWButtonHaltHandler()
409+
{
410+
emit cwKeyHWHaltPressed();
411+
}
412+
407413
CWKeyer::CWKeyer(QObject *parent ) :
408414
QObject(parent),
409415
cwKey(nullptr),

cwkey/CWKeyer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CWKeyer : public QObject
2828
void cwKeyHWButton2Pressed();
2929
void cwKeyHWButton3Pressed();
3030
void cwKeyHWButton4Pressed();
31+
void cwKeyHWHaltPressed();
3132

3233
public slots:
3334
void start();
@@ -57,6 +58,7 @@ private slots:
5758
void cwKeyHWButton2PressedHandler();
5859
void cwKeyHWButton3PressedHandler();
5960
void cwKeyHWButton4PressedHandler();
61+
void cwKeyHWButtonHaltHandler();
6062

6163
private:
6264
explicit CWKeyer(QObject *parent = nullptr);

cwkey/drivers/CWKey.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class CWKey : public QObject
8585
void keyHWButton2Pressed();
8686
void keyHWButton3Pressed();
8787
void keyHWButton4Pressed();
88+
void keyHWButtonHaltPressed();
8889

8990
public:
9091
explicit CWKey(CWKeyModeID mode, qint32 defaultWPM, QObject *parent = nullptr);

cwkey/drivers/CWWinKey.cpp

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CWWinKey::CWWinKey(const QString &portName,
1919
CWKeySerialInterface(portName, baudrate, 5000),
2020
isInHostMode(false),
2121
xoff(false),
22+
isBusy(false),
2223
paddleSwap(paddleSwap),
2324
version(0)
2425
{
@@ -324,46 +325,52 @@ void CWWinKey::handleReadyRead()
324325
qCDebug(runtime) << "\tStatus Information Message:";
325326
xoff = false;
326327

327-
if ( rcvByte == 0xC0 ) qCDebug(runtime) << "\t\tIdle";
328+
if ( rcvByte == 0xC0 )
329+
{
330+
qCDebug(runtime) << "\t\tIdle";
331+
isBusy = false;
332+
}
328333
else
329334
{
330335
if ( version >= 20 && rcvByte & 0x08 )
331336
{
332337
qCDebug(runtime) << "\tPushButton Status Byte";
333-
if ( rcvByte & 0x01 )
334-
{
335-
qCDebug(runtime) << "\t\tButton1 pressed";
336-
emit keyHWButton1Pressed();
337-
}
338-
if ( rcvByte & 0x02 )
339-
{
340-
qCDebug(runtime) << "\t\tButton2 pressed";
341-
emit keyHWButton2Pressed();
342-
}
343-
if ( rcvByte & 0x04 )
344-
{
345-
qCDebug(runtime) << "\t\tButton3 pressed";
346-
emit keyHWButton3Pressed();
347-
}
348-
if ( rcvByte & 0x10 )
338+
339+
auto handleButton = [&](quint8 mask, const char *text, const std::function<void()> &signalFn)
349340
{
350-
qCDebug(runtime) << "\t\tButton4 pressed";
351-
emit keyHWButton4Pressed();
352-
}
341+
if ( rcvByte & mask )
342+
{
343+
qCDebug(runtime) << "\t\t" << text;
344+
if ( isBusy )
345+
emit keyHWButtonHaltPressed();
346+
else
347+
signalFn();
348+
}
349+
};
350+
351+
handleButton(0x01, "Button1 pressed", [this]{ emit keyHWButton1Pressed(); });
352+
handleButton(0x02, "Button2 pressed", [this]{ emit keyHWButton2Pressed(); });
353+
handleButton(0x04, "Button3 pressed", [this]{ emit keyHWButton3Pressed(); });
354+
handleButton(0x10, "Button4 pressed", [this]{ emit keyHWButton4Pressed(); });
353355
}
354356
else
355357
{
356358
qCDebug(runtime) << "\tStatus Byte";
357359

358-
if ( rcvByte & 0x01 )
360+
auto handleFlag = [&](quint8 mask, const char *text, const std::function<void()> &action = nullptr)
359361
{
360-
qCDebug(runtime) << "\t\tBuffer 2/3 full";
361-
xoff = true; //slow down in sending Write Buffer - to block tryAsyncWrite
362-
}
363-
if ( rcvByte & 0x02 ) qCDebug(runtime) << "\t\tBrk-in";
364-
if ( rcvByte & 0x04 ) qCDebug(runtime) << "\t\tKey Busy";
365-
if ( rcvByte & 0x08 ) qCDebug(runtime) << "\t\tTunning";
366-
if ( rcvByte & 0x0F ) qCDebug(runtime) << "\t\tWaiting";
362+
if ( rcvByte & mask )
363+
{
364+
qCDebug(runtime) << "\t\t" << text;
365+
if (action) action();
366+
}
367+
};
368+
369+
handleFlag(0x01, "Buffer 2/3 full", [&]{xoff = true; isBusy = true;});
370+
handleFlag(0x02, "Brk-in");
371+
handleFlag(0x04, "Key Busy", [&]{ isBusy = true; });
372+
handleFlag(0x08, "Tunning");
373+
handleFlag(0x0F, "Waiting");
367374
}
368375
}
369376
}

cwkey/drivers/CWWinKey.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CWWinKey : public CWKey,
3030

3131
bool isInHostMode;
3232
bool xoff;
33+
bool isBusy;
3334
bool paddleSwap;
3435

3536
QMutex writeBufferMutex;

ui/MainWindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ MainWindow::MainWindow(QWidget* parent) :
233233
connect(CWKeyer::instance(), &CWKeyer::cwKeyHWButton2Pressed, ui->cwconsoleWidget, &CWConsoleWidget::cwKeyMacroF2);
234234
connect(CWKeyer::instance(), &CWKeyer::cwKeyHWButton3Pressed, ui->cwconsoleWidget, &CWConsoleWidget::cwKeyMacroF3);
235235
connect(CWKeyer::instance(), &CWKeyer::cwKeyHWButton4Pressed, ui->cwconsoleWidget, &CWConsoleWidget::cwKeyMacroF4);
236+
connect(CWKeyer::instance(), &CWKeyer::cwKeyHWHaltPressed, ui->cwconsoleWidget, &CWConsoleWidget::haltButtonPressed);
236237

237238
FldigiTCPServer* fldigi = new FldigiTCPServer(this);
238239
connect(fldigi, &FldigiTCPServer::addContact, ui->newContactWidget, &NewContactWidget::saveExternalContact);

0 commit comments

Comments
 (0)