-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cea1cdb
Showing
6 changed files
with
472 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# This file is used to ignore files which are generated | ||
# ---------------------------------------------------------------------------- | ||
|
||
*~ | ||
*.autosave | ||
*.a | ||
*.core | ||
*.moc | ||
*.o | ||
*.obj | ||
*.orig | ||
*.rej | ||
*.so | ||
*.so.* | ||
*_pch.h.cpp | ||
*_resource.rc | ||
*.qm | ||
.#* | ||
*.*# | ||
core | ||
!core/ | ||
tags | ||
.DS_Store | ||
.directory | ||
*.debug | ||
Makefile* | ||
*.prl | ||
*.app | ||
moc_*.cpp | ||
ui_*.h | ||
qrc_*.cpp | ||
Thumbs.db | ||
*.res | ||
*.rc | ||
/.qmake.cache | ||
/.qmake.stash | ||
|
||
# qtcreator generated files | ||
*.pro.user* | ||
|
||
# xemacs temporary files | ||
*.flc | ||
|
||
# Vim temporary files | ||
.*.swp | ||
|
||
# Visual Studio generated files | ||
*.ib_pdb_index | ||
*.idb | ||
*.ilk | ||
*.pdb | ||
*.sln | ||
*.suo | ||
*.vcproj | ||
*vcproj.*.*.user | ||
*.ncb | ||
*.sdf | ||
*.opensdf | ||
*.vcxproj | ||
*vcxproj.* | ||
|
||
# MinGW generated files | ||
*.Debug | ||
*.Release | ||
|
||
# Python byte code | ||
*.pyc | ||
|
||
# Binaries | ||
# -------- | ||
*.dll | ||
*.exe | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
QT += core gui serialport | ||
|
||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | ||
|
||
CONFIG += c++17 | ||
|
||
# You can make your code fail to compile if it uses deprecated APIs. | ||
# In order to do so, uncomment the following line. | ||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
||
SOURCES += \ | ||
main.cpp \ | ||
picokeyer.cpp | ||
|
||
HEADERS += \ | ||
picokeyer.h | ||
|
||
FORMS += \ | ||
picokeyer.ui | ||
|
||
# Default rules for deployment. | ||
qnx: target.path = /tmp/$${TARGET}/bin | ||
else: unix:!android: target.path = /opt/$${TARGET}/bin | ||
!isEmpty(target.path): INSTALLS += target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "picokeyer.h" | ||
|
||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
PicoKeyer w; | ||
w.show(); | ||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
#include "picokeyer.h" | ||
#include "ui_picokeyer.h" | ||
|
||
#include <QInputDialog> | ||
#include <QMessageBox> | ||
#include <QSerialPortInfo> | ||
|
||
//#include <QDebug> | ||
|
||
PicoKeyer::PicoKeyer(QWidget *parent) | ||
: QMainWindow(parent) | ||
, ui(new Ui::PicoKeyer) | ||
{ | ||
ui->setupUi(this); | ||
wpmLabel = new QLabel("WPM", this); | ||
statusBar()->addPermanentWidget(wpmLabel); | ||
ui->lineEdit->setFocus(); | ||
i_interval = s.value("interval", 50).toInt(); | ||
i_baudRate = s.value("baud", 115200).toInt(); | ||
i_wpm = s.value("wpm", 20).toInt(); | ||
s_sport = s.value("sport", "COM3").toString(); | ||
connectToKeyer(); | ||
tim = new QTimer(this); | ||
tim->setInterval(i_interval); // allows print of incoming data in one shot | ||
// this timer is started by on_readyRead() | ||
connect(tim, &QTimer::timeout, this, &PicoKeyer::on_timeout); | ||
QTimer::singleShot(550, this, &PicoKeyer::setNewWPM); | ||
} | ||
|
||
PicoKeyer::~PicoKeyer() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void PicoKeyer::on_actionE_xit_triggered() | ||
{ | ||
close(); | ||
} | ||
|
||
void PicoKeyer::on_lineEdit_returnPressed() | ||
{ | ||
if(sport) | ||
{ | ||
//qDebug()<<sport->isOpen(); | ||
const QString out = ui->lineEdit->text(); | ||
for(int i = 0; i < out.length(); i++) { | ||
sport->putChar(out.at(i).toLatin1()); | ||
} | ||
ui->plainTextEdit->appendPlainText("SENDING: "); | ||
ui->plainTextEdit->moveCursor(QTextCursor::End); | ||
sport->putChar('\r'); | ||
sport->flush(); | ||
} | ||
ui->lineEdit->selectAll(); | ||
} | ||
|
||
void PicoKeyer::connectToKeyer() | ||
{ | ||
if(!sport) { | ||
sport = new QSerialPort(this); | ||
} | ||
sport->close(); // if already opened, close it first | ||
connect(sport, &QSerialPort::errorOccurred, this, [=](int error) { | ||
if(error > 0) { | ||
ui->plainTextEdit->appendPlainText("Serial Error: " + QString::number(error)); | ||
ui->plainTextEdit->moveCursor(QTextCursor::End); | ||
} | ||
}); | ||
sport->setPortName(s_sport); | ||
if(sport->open(QIODevice::ReadWrite)) { | ||
ui->plainTextEdit->appendPlainText("SERIAL PORT " + s_sport + " OPENED"); | ||
ui->plainTextEdit->appendPlainText("Bit Params: " + QString::number(sport->dataBits()) + QString::number(sport->parity()) + QString::number(sport->stopBits())); | ||
ui->plainTextEdit->appendPlainText("Flow Control: " + QString::number(sport->flowControl())); | ||
ui->plainTextEdit->moveCursor(QTextCursor::End); | ||
sport->setBaudRate(i_baudRate); | ||
connect(sport, &QSerialPort::readyRead, this, &PicoKeyer::on_readyRead, Qt::UniqueConnection); | ||
// sport->write(QString::number(i_wpm).toLatin1()); | ||
// sport->write("\r"); | ||
} | ||
else { | ||
ui->plainTextEdit->appendPlainText("UNABLE TO OPEN SERIAL PORT " + s_sport); | ||
ui->plainTextEdit->moveCursor(QTextCursor::End); | ||
} | ||
} | ||
|
||
void PicoKeyer::on_action_Serial_Port_triggered() | ||
{ | ||
const QList<QSerialPortInfo> portinfos = QSerialPortInfo::availablePorts(); | ||
QStringList ports; | ||
foreach (QSerialPortInfo i, portinfos) { | ||
ports<<i.portName(); | ||
} | ||
s_sport = QInputDialog::getItem(this, "Choose Serial Port", "Select the serial port that is connected to the Keyer", ports); | ||
if(s_sport.isEmpty()) { | ||
s_sport = s.value("sport", "COM3").toString(); // return to saved value | ||
return; | ||
} | ||
else { | ||
s.setValue("sport", s_sport); // save for next time | ||
connectToKeyer(); | ||
} | ||
} | ||
|
||
void PicoKeyer::on_readyRead() | ||
{ | ||
tim->stop(); | ||
if(sport) | ||
inbytes.append(sport->readAll()); | ||
tim->start(); | ||
} | ||
|
||
void PicoKeyer::on_action_Baud_Rate_triggered() | ||
{ | ||
const QString rate = QInputDialog::getItem(this, "Choose Baud Rate", "Select the baud rate.\n\nDefault for Pico USB is 115200.", QStringList()<<"115200"<<"57600"<<"19200"<<"9600"); | ||
if(rate.isEmpty()) | ||
return; | ||
if(sport) { | ||
sport->setBaudRate(rate.toInt()); | ||
s.setValue("baud", rate.toInt()); | ||
ui->plainTextEdit->appendPlainText("SERIAL PORT BAUD RATE SET TO " + rate); | ||
ui->plainTextEdit->moveCursor(QTextCursor::End); | ||
} | ||
} | ||
|
||
|
||
void PicoKeyer::on_action_WPM_triggered() | ||
{ | ||
int curr = s.value("wpm", 15).toInt(); | ||
int rate = QInputDialog::getInt(this, "Choose WPM Rate", "Select the WPM rate.\n\nMin. is 5.", curr, 5, 50); | ||
if((rate > 4) && (rate < 51)) | ||
{ | ||
i_wpm = rate; | ||
setNewWPM(); | ||
} | ||
else { | ||
ui->plainTextEdit->appendPlainText("INVALID WPM RATE!\n\nMust be between 5 and 50 inclusive."); | ||
ui->plainTextEdit->moveCursor(QTextCursor::End); | ||
} | ||
} | ||
|
||
|
||
void PicoKeyer::on_clearButton_clicked() | ||
{ | ||
ui->plainTextEdit->clear(); | ||
} | ||
|
||
void PicoKeyer::on_timeout() | ||
{ | ||
tim->stop(); | ||
if(inbytes.length() > 0) { | ||
//qDebug()<<"inbytes:"<<inbytes; | ||
QString out = inbytes; | ||
out.replace('\0', '?'); | ||
inbytes.clear(); | ||
ui->plainTextEdit->insertPlainText(out); | ||
ui->plainTextEdit->moveCursor(QTextCursor::End); | ||
} | ||
} | ||
|
||
void PicoKeyer::setNewWPM() | ||
{ | ||
// if(tim) { | ||
// tim->stop(); | ||
// tim->setInterval((int) ((1200/i_wpm) * 20)); | ||
// s.setValue("interval", tim->interval()); | ||
// } | ||
QString srate = "@" + QString::number(i_wpm) + "\r"; | ||
if(sport) { | ||
ui->plainTextEdit->appendPlainText("WPM RATE SET TO " + QString::number(i_wpm)); | ||
ui->plainTextEdit->moveCursor(QTextCursor::End); | ||
sport->write(srate.toLatin1()); | ||
sport->flush(); | ||
s.setValue("wpm", i_wpm); | ||
} | ||
wpmLabel->setText(QString::number(i_wpm) + " WPM"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef PICOKEYER_H | ||
#define PICOKEYER_H | ||
|
||
#include <QLabel> | ||
#include <QSerialPort> | ||
#include <QSettings> | ||
#include <QTimer> | ||
#include <QMainWindow> | ||
|
||
QT_BEGIN_NAMESPACE | ||
namespace Ui { class PicoKeyer; } | ||
QT_END_NAMESPACE | ||
|
||
class PicoKeyer : public QMainWindow | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
PicoKeyer(QWidget *parent = nullptr); | ||
~PicoKeyer(); | ||
|
||
private slots: | ||
void on_actionE_xit_triggered(); | ||
void on_lineEdit_returnPressed(); | ||
void on_action_Serial_Port_triggered(); | ||
void on_action_Baud_Rate_triggered(); | ||
void on_action_WPM_triggered(); | ||
void on_readyRead(); | ||
void on_clearButton_clicked(); | ||
void on_timeout(); | ||
void connectToKeyer(); | ||
void setNewWPM(); | ||
private: | ||
Ui::PicoKeyer *ui; | ||
QLabel *wpmLabel; | ||
QSerialPort *sport = nullptr; | ||
QTimer *tim = nullptr; | ||
QByteArray inbytes; | ||
QSettings s = QSettings("PicoKeyer.ini", QSettings::IniFormat, this); | ||
// load the following from QSettings s; | ||
int i_interval = 2000; | ||
int i_baudRate = 115200; | ||
int i_wpm = 20; | ||
QString s_sport = "COM3"; | ||
}; | ||
#endif // PICOKEYER_H |
Oops, something went wrong.