feature: added possibility to change hardware interface from GUI
This commit is contained in:
@@ -25,8 +25,8 @@
|
|||||||
// V2 USB Atmega8
|
// V2 USB Atmega8
|
||||||
// V3 STM32F07
|
// V3 STM32F07
|
||||||
|
|
||||||
#define PORT_PATH "/dev/ttyACM0"
|
// #define PORT_PATH "/dev/ttyACM0"
|
||||||
//#define PORT_PATH "/dev/pts/4"
|
// #define PORT_PATH "/dev/pts/4"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
// not needed anymore -> usb
|
// not needed anymore -> usb
|
||||||
@@ -34,10 +34,16 @@ using namespace std;
|
|||||||
// #define BASEPORT 0x378
|
// #define BASEPORT 0x378
|
||||||
// #define BASEPORT 0xd000
|
// #define BASEPORT 0xd000
|
||||||
|
|
||||||
HardwareSetup::HardwareSetup() {
|
HardwareSetup::HardwareSetup(DataBase * db) {
|
||||||
// if (ioperm(BASEPORT, 3, 1)) {
|
// if (ioperm(BASEPORT, 3, 1)) {
|
||||||
// //perror("ioperm");
|
// //perror("ioperm");
|
||||||
// }
|
// }
|
||||||
|
this->db = db;
|
||||||
|
this->PORT_PATH =
|
||||||
|
this->db->getData("select interface from interface where id like 1", 1)
|
||||||
|
.at(0)
|
||||||
|
.at(0)
|
||||||
|
.toStdString();
|
||||||
this->stop = 0;
|
this->stop = 0;
|
||||||
#ifdef ATMEGA
|
#ifdef ATMEGA
|
||||||
this->handle = nullptr;
|
this->handle = nullptr;
|
||||||
@@ -362,12 +368,12 @@ void HardwareSetup::connectSTM32() {
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
fd = open(PORT_PATH, O_RDONLY);
|
fd = open(this->PORT_PATH.c_str(), O_RDONLY);
|
||||||
while (this->fd < 0) {
|
while (this->fd < 0) {
|
||||||
// wait 1 second
|
// wait 1 second
|
||||||
sleep(1);
|
sleep(1);
|
||||||
cout << "Port can't be opened" << endl;
|
cout << "Port can't be opened" << endl;
|
||||||
fd = open(PORT_PATH, O_RDONLY);
|
fd = open(PORT_PATH.c_str(), O_RDONLY);
|
||||||
if (this->stop) {
|
if (this->stop) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "database.h"
|
||||||
#include "datatypes.h"
|
#include "datatypes.h"
|
||||||
#include "serial_port.h"
|
#include "serial_port.h"
|
||||||
|
|
||||||
@@ -39,11 +40,13 @@ class HardwareSetup : public QThread {
|
|||||||
bool getDea();
|
bool getDea();
|
||||||
int * findBit(int * array, int zahl);
|
int * findBit(int * array, int zahl);
|
||||||
std::unique_ptr<serial_port> sport;
|
std::unique_ptr<serial_port> sport;
|
||||||
|
DataBase * db;
|
||||||
|
std::string PORT_PATH;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setStop();
|
void setStop();
|
||||||
~HardwareSetup();
|
~HardwareSetup();
|
||||||
HardwareSetup();
|
HardwareSetup(DataBase * db);
|
||||||
signals:
|
signals:
|
||||||
void Shell(int, int);
|
void Shell(int, int);
|
||||||
void Dea(int, int);
|
void Dea(int, int);
|
||||||
|
|||||||
@@ -50,6 +50,21 @@ MainWindow::MainWindow(QWidget * parent)
|
|||||||
SLOT(WindowRennen()));
|
SLOT(WindowRennen()));
|
||||||
|
|
||||||
this->db = std::make_unique<DataBase>();
|
this->db = std::make_unique<DataBase>();
|
||||||
|
vector<vector<QString>> interface =
|
||||||
|
this->db->getData("select * from interface", 1);
|
||||||
|
if (interface.size() > 0) {
|
||||||
|
std::cout << "interface existiert" << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cout << "interface existiert nicht" << std::endl;
|
||||||
|
// create interface
|
||||||
|
std::string statement =
|
||||||
|
"CREATE TABLE \"Interface\" ( \"id\" INTEGER PRIMARY KEY "
|
||||||
|
"AUTOINCREMENT, \"interface\" TEXT )";
|
||||||
|
this->db->setData(statement);
|
||||||
|
statement = "insert into interface (interface) values ('/dev/ttyAMC0')";
|
||||||
|
this->db->setData(statement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void MainWindow::closeEvent(QCloseEvent * event) {
|
void MainWindow::closeEvent(QCloseEvent * event) {
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ Training::Training(QWidget * parent, DataBase * db)
|
|||||||
started = true;
|
started = true;
|
||||||
paused = false;
|
paused = false;
|
||||||
|
|
||||||
this->Hardware = std::make_shared<HardwareSetup>();
|
this->Hardware = std::make_shared<HardwareSetup>(this->db);
|
||||||
Hardware->start();
|
Hardware->start();
|
||||||
|
|
||||||
QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this,
|
QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this,
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ WindowRace::WindowRace(DataBase * db, QWidget * parent)
|
|||||||
|
|
||||||
paused = false;
|
paused = false;
|
||||||
|
|
||||||
Hardware = std::make_unique<HardwareSetup>();
|
Hardware = std::make_unique<HardwareSetup>(this->db);
|
||||||
Hardware->start();
|
Hardware->start();
|
||||||
|
|
||||||
QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this,
|
QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "ui_windowssettings.h"
|
#include "ui_windowssettings.h"
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <qcolordialog.h>
|
#include <qcolordialog.h>
|
||||||
#include <qmessagebox.h>
|
#include <qmessagebox.h>
|
||||||
@@ -12,6 +13,8 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
using std::string;
|
using std::string;
|
||||||
@@ -21,6 +24,8 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
|
|||||||
: QMainWindow(parent), ui(new Ui::WindowsSettings) {
|
: QMainWindow(parent), ui(new Ui::WindowsSettings) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
QObject::connect(ui->cBInterface, SIGNAL(activated(int)), this,
|
||||||
|
SLOT(changeInterface()));
|
||||||
QObject::connect(ui->pBSpeichernStrecke, SIGNAL(clicked()), this,
|
QObject::connect(ui->pBSpeichernStrecke, SIGNAL(clicked()), this,
|
||||||
SLOT(StreckeSpeichernSlot()));
|
SLOT(StreckeSpeichernSlot()));
|
||||||
QObject::connect(ui->pBAbbrechenStrecke, SIGNAL(clicked()), this,
|
QObject::connect(ui->pBAbbrechenStrecke, SIGNAL(clicked()), this,
|
||||||
@@ -199,7 +204,27 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent)
|
|||||||
|
|
||||||
// fill listView of cars
|
// fill listView of cars
|
||||||
this->repaintCars();
|
this->repaintCars();
|
||||||
// this->ui->wEditCarColor->grab()
|
|
||||||
|
// setup Hardware interface
|
||||||
|
QStringList cbInterfaceList = QStringList();
|
||||||
|
cbInterfaceList.append("/dev/ttyAMC0");
|
||||||
|
|
||||||
|
std::string path = "/dev/pts/";
|
||||||
|
for (const auto & entry : fs::directory_iterator(path)) {
|
||||||
|
std::string pathToAppend = entry.path();
|
||||||
|
cbInterfaceList.append(QString::fromStdString(pathToAppend));
|
||||||
|
}
|
||||||
|
this->ui->cBInterface->addItems(cbInterfaceList);
|
||||||
|
|
||||||
|
// preset combobox from database
|
||||||
|
QString dataFromDatabase =
|
||||||
|
this->db->getData("select interface from interface where id like 1", 1)
|
||||||
|
.at(0)
|
||||||
|
.at(0);
|
||||||
|
int id = this->ui->cBInterface->findText(dataFromDatabase);
|
||||||
|
if (id > -1) {
|
||||||
|
this->ui->cBInterface->setCurrentIndex(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowsSettings::saveEditCar() {
|
void WindowsSettings::saveEditCar() {
|
||||||
@@ -495,6 +520,15 @@ string WindowsSettings::currentDateTime() {
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowsSettings::changeInterface() {
|
||||||
|
std::string curInterface =
|
||||||
|
this->ui->cBInterface->currentText().toStdString();
|
||||||
|
std::string statement = "update interface set interface = '" +
|
||||||
|
curInterface + "' where id like 1";
|
||||||
|
cout << statement << endl;
|
||||||
|
this->db->setData(statement);
|
||||||
|
}
|
||||||
|
|
||||||
void WindowsSettings::createRaceListAndClose() {
|
void WindowsSettings::createRaceListAndClose() {
|
||||||
vector<int> selectedCarIds;
|
vector<int> selectedCarIds;
|
||||||
foreach (const QModelIndex & index,
|
foreach (const QModelIndex & index,
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class WindowsSettings : public QMainWindow {
|
|||||||
void openEditColor();
|
void openEditColor();
|
||||||
void openNewColor();
|
void openNewColor();
|
||||||
void saveNewCar();
|
void saveNewCar();
|
||||||
|
void changeInterface();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WINDOWSSETTINGS_H
|
#endif // WINDOWSSETTINGS_H
|
||||||
|
|||||||
@@ -20,9 +20,18 @@
|
|||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><html><head/><body><p>Rennliste Erstellen</p></body></html></string>
|
<string><html><head/><body><p>Rennliste Erstellen</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="tabShape">
|
||||||
|
<enum>QTabWidget::Rounded</enum>
|
||||||
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>4</number>
|
<number>4</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="tabsClosable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="movable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<widget class="QWidget" name="Dauer">
|
<widget class="QWidget" name="Dauer">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Dauer</string>
|
<string>Dauer</string>
|
||||||
@@ -705,6 +714,42 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_8">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Schnittstelle</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_56">
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_55">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_33">
|
||||||
|
<property name="title">
|
||||||
|
<string>Hardwareschnittstelle</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_57">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="cBInterface"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_4">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QWidget" name="CreateList">
|
<widget class="QWidget" name="CreateList">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Rennliste Erstellen</string>
|
<string>Rennliste Erstellen</string>
|
||||||
@@ -786,6 +831,56 @@
|
|||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>Strecke</tabstop>
|
||||||
|
<tabstop>lVCars</tabstop>
|
||||||
|
<tabstop>lVDrivers</tabstop>
|
||||||
|
<tabstop>pBCancel</tabstop>
|
||||||
|
<tabstop>pBcreateListClose</tabstop>
|
||||||
|
<tabstop>lEMinTimeSec2</tabstop>
|
||||||
|
<tabstop>lEMinTimeSec3</tabstop>
|
||||||
|
<tabstop>pbAbbrechenDauer</tabstop>
|
||||||
|
<tabstop>pbSaveAndExitDauer</tabstop>
|
||||||
|
<tabstop>pbSaveDauer</tabstop>
|
||||||
|
<tabstop>lEShellKurvenAussen</tabstop>
|
||||||
|
<tabstop>lEShellKurvenInnen</tabstop>
|
||||||
|
<tabstop>lEShellGeraden</tabstop>
|
||||||
|
<tabstop>lEShellSteilkurveaussen</tabstop>
|
||||||
|
<tabstop>lEShellSteilkurveInnen</tabstop>
|
||||||
|
<tabstop>lEDeaKurvenAussen</tabstop>
|
||||||
|
<tabstop>lEDeaKurvenInnen</tabstop>
|
||||||
|
<tabstop>lEDeaGeraden</tabstop>
|
||||||
|
<tabstop>lEDeaSteilkurveAussen</tabstop>
|
||||||
|
<tabstop>lEDeaSteilkurveInnen</tabstop>
|
||||||
|
<tabstop>pBAbbrechenStrecke</tabstop>
|
||||||
|
<tabstop>pBSpeichernStrecke</tabstop>
|
||||||
|
<tabstop>tabWidget</tabstop>
|
||||||
|
<tabstop>lEEditCarName</tabstop>
|
||||||
|
<tabstop>lEEditCarEngine</tabstop>
|
||||||
|
<tabstop>pBEditCarChangeColor</tabstop>
|
||||||
|
<tabstop>pBEditCarSave</tabstop>
|
||||||
|
<tabstop>lVCarSavedCars</tabstop>
|
||||||
|
<tabstop>leNewCarName</tabstop>
|
||||||
|
<tabstop>lENewCarEngine</tabstop>
|
||||||
|
<tabstop>pBNewCarChangeColor</tabstop>
|
||||||
|
<tabstop>pBNewCarSave</tabstop>
|
||||||
|
<tabstop>lvNewCar</tabstop>
|
||||||
|
<tabstop>pBCarClose</tabstop>
|
||||||
|
<tabstop>tabWidget_2</tabstop>
|
||||||
|
<tabstop>lENewDriverName</tabstop>
|
||||||
|
<tabstop>pBNewDriverSave</tabstop>
|
||||||
|
<tabstop>lVNewDriverSavedDrivers</tabstop>
|
||||||
|
<tabstop>pBNewDriverClose</tabstop>
|
||||||
|
<tabstop>lEDriverEditName</tabstop>
|
||||||
|
<tabstop>pushButton_2</tabstop>
|
||||||
|
<tabstop>lVDriverEditSavedDrivers</tabstop>
|
||||||
|
<tabstop>pBDriverEditClose</tabstop>
|
||||||
|
<tabstop>lEMinRundenzeit</tabstop>
|
||||||
|
<tabstop>leRenndauer</tabstop>
|
||||||
|
<tabstop>lEMinRundenzeitAktRennen</tabstop>
|
||||||
|
<tabstop>lEMinTimeSec1</tabstop>
|
||||||
|
<tabstop>cBInterface</tabstop>
|
||||||
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
Reference in New Issue
Block a user