diff --git a/hardwaresetup.cpp b/hardwaresetup.cpp index 60d2f5e..e474dd9 100644 --- a/hardwaresetup.cpp +++ b/hardwaresetup.cpp @@ -25,8 +25,8 @@ // V2 USB Atmega8 // V3 STM32F07 -#define PORT_PATH "/dev/ttyACM0" -//#define PORT_PATH "/dev/pts/4" +// #define PORT_PATH "/dev/ttyACM0" +// #define PORT_PATH "/dev/pts/4" using namespace std; // not needed anymore -> usb @@ -34,10 +34,16 @@ using namespace std; // #define BASEPORT 0x378 // #define BASEPORT 0xd000 -HardwareSetup::HardwareSetup() { +HardwareSetup::HardwareSetup(DataBase * db) { // if (ioperm(BASEPORT, 3, 1)) { // //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; #ifdef ATMEGA this->handle = nullptr; @@ -362,12 +368,12 @@ void HardwareSetup::connectSTM32() { close(fd); } usleep(10000); - fd = open(PORT_PATH, O_RDONLY); + fd = open(this->PORT_PATH.c_str(), O_RDONLY); while (this->fd < 0) { // wait 1 second sleep(1); cout << "Port can't be opened" << endl; - fd = open(PORT_PATH, O_RDONLY); + fd = open(PORT_PATH.c_str(), O_RDONLY); if (this->stop) { break; } diff --git a/hardwaresetup.h b/hardwaresetup.h index 4703fff..c16dee0 100644 --- a/hardwaresetup.h +++ b/hardwaresetup.h @@ -11,6 +11,7 @@ #include #endif +#include "database.h" #include "datatypes.h" #include "serial_port.h" @@ -39,11 +40,13 @@ class HardwareSetup : public QThread { bool getDea(); int * findBit(int * array, int zahl); std::unique_ptr sport; + DataBase * db; + std::string PORT_PATH; public: void setStop(); ~HardwareSetup(); - HardwareSetup(); + HardwareSetup(DataBase * db); signals: void Shell(int, int); void Dea(int, int); diff --git a/mainwindow.cpp b/mainwindow.cpp index b7f2f6b..28b82c5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -50,6 +50,21 @@ MainWindow::MainWindow(QWidget * parent) SLOT(WindowRennen())); this->db = std::make_unique(); + vector> 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) { Q_UNUSED(event); diff --git a/training.cpp b/training.cpp index 8bd4861..a601fdf 100644 --- a/training.cpp +++ b/training.cpp @@ -39,7 +39,7 @@ Training::Training(QWidget * parent, DataBase * db) started = true; paused = false; - this->Hardware = std::make_shared(); + this->Hardware = std::make_shared(this->db); Hardware->start(); QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this, diff --git a/windowrace.cpp b/windowrace.cpp index 1387d5f..7f9196e 100644 --- a/windowrace.cpp +++ b/windowrace.cpp @@ -64,7 +64,7 @@ WindowRace::WindowRace(DataBase * db, QWidget * parent) paused = false; - Hardware = std::make_unique(); + Hardware = std::make_unique(this->db); Hardware->start(); QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this, diff --git a/windowssettings.cpp b/windowssettings.cpp index 4385950..9a79aaf 100644 --- a/windowssettings.cpp +++ b/windowssettings.cpp @@ -4,6 +4,7 @@ #include "ui_windowssettings.h" #include #include +#include #include #include #include @@ -12,6 +13,8 @@ #include #include +namespace fs = std::filesystem; + using std::cout; using std::endl; using std::string; @@ -21,6 +24,8 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent) : QMainWindow(parent), ui(new Ui::WindowsSettings) { ui->setupUi(this); + QObject::connect(ui->cBInterface, SIGNAL(activated(int)), this, + SLOT(changeInterface())); QObject::connect(ui->pBSpeichernStrecke, SIGNAL(clicked()), this, SLOT(StreckeSpeichernSlot())); QObject::connect(ui->pBAbbrechenStrecke, SIGNAL(clicked()), this, @@ -199,7 +204,27 @@ WindowsSettings::WindowsSettings(DataBase * db, QWidget * parent) // fill listView of cars 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() { @@ -495,6 +520,15 @@ string WindowsSettings::currentDateTime() { 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() { vector selectedCarIds; foreach (const QModelIndex & index, diff --git a/windowssettings.h b/windowssettings.h index 0c4b4c5..4b04ea7 100644 --- a/windowssettings.h +++ b/windowssettings.h @@ -55,6 +55,7 @@ class WindowsSettings : public QMainWindow { void openEditColor(); void openNewColor(); void saveNewCar(); + void changeInterface(); }; #endif // WINDOWSSETTINGS_H diff --git a/windowssettings.ui b/windowssettings.ui index 27e8646..c09d153 100644 --- a/windowssettings.ui +++ b/windowssettings.ui @@ -20,9 +20,18 @@ <html><head/><body><p>Rennliste Erstellen</p></body></html> + + QTabWidget::Rounded + 4 + + false + + + false + Dauer @@ -705,6 +714,42 @@ + + + Schnittstelle + + + + + + + + Hardwareschnittstelle + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Rennliste Erstellen @@ -786,6 +831,56 @@ 1 + + Strecke + lVCars + lVDrivers + pBCancel + pBcreateListClose + lEMinTimeSec2 + lEMinTimeSec3 + pbAbbrechenDauer + pbSaveAndExitDauer + pbSaveDauer + lEShellKurvenAussen + lEShellKurvenInnen + lEShellGeraden + lEShellSteilkurveaussen + lEShellSteilkurveInnen + lEDeaKurvenAussen + lEDeaKurvenInnen + lEDeaGeraden + lEDeaSteilkurveAussen + lEDeaSteilkurveInnen + pBAbbrechenStrecke + pBSpeichernStrecke + tabWidget + lEEditCarName + lEEditCarEngine + pBEditCarChangeColor + pBEditCarSave + lVCarSavedCars + leNewCarName + lENewCarEngine + pBNewCarChangeColor + pBNewCarSave + lvNewCar + pBCarClose + tabWidget_2 + lENewDriverName + pBNewDriverSave + lVNewDriverSavedDrivers + pBNewDriverClose + lEDriverEditName + pushButton_2 + lVDriverEditSavedDrivers + pBDriverEditClose + lEMinRundenzeit + leRenndauer + lEMinRundenzeitAktRennen + lEMinTimeSec1 + cBInterface +