Commit 3a2cf94c authored by Leander Schulten's avatar Leander Schulten
Browse files

move driver loading in new file

load and start new driver if you select another file in the settings pane
parent 96dffbed
......@@ -38,7 +38,8 @@ SOURCES += main.cpp \
controlitemdata.cpp \
dmxinterface.cpp \
errornotifier.cpp \
settings.cpp
settings.cpp \
driver.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
......@@ -76,7 +77,8 @@ HEADERS += \
controlitemdata.h \
HardwareInterface.h \
errornotifier.h \
settings.h
settings.h \
driver.h
# Default rules for deployment.
......
import QtQuick 2.7
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.0
import QtQuick.Layouts 1.3
import QtQuick.Dialogs 1.2
Pane{
......@@ -18,9 +18,12 @@ Pane{
MouseArea{
anchors.fill: parent
onClicked: {
fileDialog.folder = Settings.jsonSettingsFilePath;
//fileDialog.folder = Settings.jsonSettingsFilePath;
fileDialog.open();
fileDialog.addSelection(Settings.jsonSettingsFilePath);
/*fileDialog.addSelection(Settings.jsonSettingsFilePath);
fileDialog.callback = function(file){
Settings.jsonSettingsFilePath = file;
};*/
}
}
}
......@@ -38,15 +41,25 @@ Pane{
fileDialog.folder = Settings.driverFilePath;
fileDialog.open();
fileDialog.addSelection(Settings.driverFilePath);
fileDialog.callback = function(file){
console.log(file);
Settings.driverFilePath = file;
};
}
}
}
}
FileDialog{
property var callback;
id: fileDialog
title: "Please choose a file"
onAccepted: {
title: "Please choose a file"
onAccepted: {
console.log("fftey:"+callback);
if(callback)callback(fileDialog.fileUrl.toString().substring(8));
}
onSelectionAccepted: console.log("3")
onVisibleChanged: console.info("this")
onRejected: console.log("rej")
Component.onCompleted: console.log("comp")
}
}
#include "driver.h"
#include <QLibrary>
#include <QDebug>
#include "errornotifier.h"
#include "programm.h"
#include "dmxchannelfilter.h"
#include <QDir>
HardwareInterface * driver = nullptr;
namespace Driver {
bool loadAndStartDriver(QString path){
if(!loadDriver(path)){
return false;
}
if(driver){
if(!driver->init())
return false;
driver->start();
return true;
}
return false;
}
bool loadDriver(QString path){
#if defined(Q_OS_WIN)
typedef HardwareInterface * (*getDriverFunc)();
getDriverFunc getDriver = reinterpret_cast<getDriverFunc>(QLibrary::resolve(path,"getDriver"));
if(getDriver!=nullptr){
HardwareInterface * inter = getDriver();
if(inter != nullptr){
inter->setErrorCallback([](QString s){
qDebug()<<s;
ErrorNotifier::get()->newError(s);
});
inter->setSetValuesCallback([](unsigned char* values, int size, double time){
DMXChannelFilter::initValues(values,size);
Programm::fill(values,size,time);
DMXChannelFilter::filterValues(values,size);
qDebug()<<"Hi";
});
if(driver){
driver->stop();
delete driver;
}
driver=inter;
return true;
}
}else{
if(!QFile::exists(path)){
ErrorNotifier::get()->newError("Driver File not existing : " + path + '\n' + "Home dir is : " + QDir::currentPath());
}else{
ErrorNotifier::get()->newError("Can not resolve Function getDriver in Library at Location "+path);
}
}
#else
#warning Driverloading is only supported for Windows
#endif
return false;
}
HardwareInterface* getCurrentDriver(){
return driver;
}
void stopAndUnloadDriver(){
if (driver) {
driver->stop();
delete driver;
}
}
}
#ifndef DRIVER_H
#define DRIVER_H
#include "settings.h"
#include "HardwareInterface.h"
namespace Driver {
/**
* @brief loadAndStartDriver load see: @see loadDriver() starts the loaded driver
* @param path a path to the dll, where the Funktion getDriver can be called
* @return true for success, false for failure
*/
bool loadAndStartDriver(QString path);
/**
* @brief loadDriver Loads the driver from a path and stop and delete the old driver
* @param path The path to the dll where the driver can be loaded
* @return true for success, false for failure
*/
bool loadDriver(QString path);
/**
* @brief getCurrentDriver return the current loaded driver
* @return the driver or a nullptr, if no driver is loaded
*/
HardwareInterface * getCurrentDriver();
/**
* @brief stopAndUnloadDriver stop and remove the driver, call this, when you close the application
*/
void stopAndUnloadDriver();
}
#endif // DRIVER_H
......@@ -26,9 +26,13 @@ public:
* @param errorMessage The Message to show
*/
void newError(QString errorMessage){
this->errorMessage = errorMessage;
this->errorMessage += errorMessage;
this->errorMessage += ". \n";
emit errorMessageChanged();
}
static void showError(QString errorMessage){
get()->newError(errorMessage);
}
signals:
void errorMessageChanged();
public slots:
......
......@@ -30,6 +30,7 @@
#include "HardwareInterface.h"
#include "settings.h"
#include <QDir>
#include "driver.h"
int main(int argc, char *argv[])
{
......@@ -102,6 +103,10 @@ int main(int argc, char *argv[])
app.connect(&app,&QGuiApplication::lastWindowClosed,[&](){
QFile savePath(settings.getJsonSettingsFilePath());
ApplicationData::saveData(savePath);
Driver::stopAndUnloadDriver();
});
settings.connect(&settings,&Settings::driverFilePathChanged,[&](){
Driver::loadAndStartDriver(settings.getDriverFilePath());
});
......@@ -124,39 +129,10 @@ int main(int argc, char *argv[])
// Treiber laden
#if defined(Q_OS_WIN)
QString driverFilepath = settings.getDriverFilePath();
typedef HardwareInterface * (*getDriverFunc)();
getDriverFunc getDriver = reinterpret_cast<getDriverFunc>(QLibrary::resolve(driverFilepath,"getDriver"));
if(getDriver!=nullptr){
HardwareInterface * inter = getDriver();
if(inter != nullptr){
inter->setErrorCallback([](QString s){
qDebug()<<s;
ErrorNotifier::get()->newError(s);
});
inter->setSetValuesCallback([](unsigned char* values, int size, double time){
DMXChannelFilter::initValues(values,size);
Programm::fill(values,size,time);
DMXChannelFilter::filterValues(values,size);
qDebug()<<"Hi";
});
}
inter->init();
inter->start();
}else{
if(!QFile::exists(driverFilepath)){
ErrorNotifier::get()->newError("Driver File not existing : " + driverFilepath + '\n' + "Home dir is : " + QDir::currentPath());
}else{
ErrorNotifier::get()->newError("Can not resolve Function getDriver in Library at Location "+driverFilepath);
}
if(!Driver::loadAndStartDriver(settings.getDriverFilePath())){
ErrorNotifier::showError("Cant start driver.");
}
#endif
//ControlPanel::getLastCreated()->addDimmerGroupControl();
return app.exec();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment