Skip to content

Commit

Permalink
thinkgear-improvements
Browse files Browse the repository at this point in the history
Thinkgear improvements
  • Loading branch information
donarturo11 authored Feb 21, 2025
2 parents 9f8e3b3 + ec0801c commit 50370a1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
28 changes: 14 additions & 14 deletions src/GUI/SettingsWidget/DeviceSettings/SerialPortSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
#include "DeviceTypes.h"
#include "DeviceSettingsWidget.h"

const DeviceType serialTypes[] {
{"ThinkGearStreamParser", "ThinkGear Stream Parser"},
{"TwoByteRawParser", "2-byte raw wave parser (unsigned 12-bit)"}
};
const QVector<qint32> standardBaudrates( {
115200, 57600, 38400, 19200, 9600
}
);

#ifndef STANDARD_BAUDS
#define STANDARD_BAUDS { 115200, 57600, 38400, 19200, 9600 }
#endif
#ifndef THINKGEAR_BAUDS
#define THINKGEAR_BAUDS { 57600, 9600 }
#endif

SerialPortSettings::SerialPortSettings(QWidget *parent) :
DeviceSettings(parent)
{
for (auto t : serialTypes) {
_types.append(t);
for (auto t : deviceTypes) {
if (t.porttype == "serial") {
_types.append(t);
}
}
_type = nullptr;
refreshBauds();
Expand Down Expand Up @@ -48,9 +47,10 @@ DeviceSettings* SerialPortSettings::create(QWidget *w)

void SerialPortSettings::refreshBauds()
{
_bauds.clear();
for (auto b : standardBaudrates) {
_bauds.append(b);
if (_type) {
_bauds = (_type->name == "ThinkGearStreamParser")
? QList<qint32>(THINKGEAR_BAUDS)
: QList<qint32>(STANDARD_BAUDS);
}
emit baudrateListChanged();
}
Expand Down
21 changes: 19 additions & 2 deletions src/QBrainwaveInterface/SerialPortConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,36 @@ SerialPortConnection::SerialPortConnection(QObject *parent)
: DeviceConnection(parent)
{
_dev = new QSerialPort(this);
connect(this, &DeviceConnection::deviceIsClosing, this, &SerialPortConnection::onDeviceIsClosing);
}

SerialPortConnection::~SerialPortConnection()
{
disconnect(this, &DeviceConnection::deviceIsClosing, this, &SerialPortConnection::onDeviceIsClosing);
disconnect(this, nullptr, this, nullptr);
if (_dev) delete _dev;
}

void SerialPortConnection::setupConnection(QVariantMap args)
{
device()->setPortName(QVariant(args["portname"]).toString());
device()->setBaudRate(QVariant(args["baudrate"]).toInt());
auto deviceType = args["type"].toString();
if (deviceType == "ThinkGearStreamParser") {
connect(this, &DeviceConnection::connectionStatusChanged,
[this](auto status) {
switch(status) {
case Device::ConnectionStatus::Connected:
qDebug() << "Connecting ThinkGear";
device()->write("\xc2", 1);
device()->flush();
break;
case Device::ConnectionStatus::Disconnecting:
qDebug() << "Disconnecting ThinkGear";
device()->write("\xc1", 1);
device()->flush();
break;
}
});
}
}

void SerialPortConnection::onDeviceIsClosing()
Expand Down

0 comments on commit 50370a1

Please sign in to comment.