move from tabs to spaces
This commit is contained in:
parent
a6aad07f05
commit
fa45072998
86 changed files with 2611 additions and 2486 deletions
166
src/main.cpp
166
src/main.cpp
|
|
@ -30,104 +30,112 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
QApplication a(argc, argv);
|
||||
|
||||
//set info
|
||||
QCoreApplication::setOrganizationName("UVOS");
|
||||
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
||||
QCoreApplication::setApplicationName("SHinterface");
|
||||
QCoreApplication::setApplicationVersion("0.6");
|
||||
//set info
|
||||
QCoreApplication::setOrganizationName("UVOS");
|
||||
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
||||
QCoreApplication::setApplicationName("SHinterface");
|
||||
QCoreApplication::setApplicationVersion("0.6");
|
||||
|
||||
QDir::setCurrent(a.applicationDirPath());
|
||||
QDir::setCurrent(a.applicationDirPath());
|
||||
|
||||
//parse comand line
|
||||
#ifndef Q_OS_ANDROID
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("Smart Home Interface");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
QCommandLineOption tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection"));
|
||||
parser.addOption(tcpOption);
|
||||
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "adress");
|
||||
parser.addOption(hostOption);
|
||||
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set server Port in TCP mode or Serial port in serial mode"), "port");
|
||||
parser.addOption(portOption);
|
||||
QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main", "Use serial connection"));
|
||||
parser.addOption(serialOption);
|
||||
QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
|
||||
parser.addOption(baudOption);
|
||||
QCommandLineOption settingsPathOption(QStringList() << "c" << "config", QCoreApplication::translate("main", "Set config file"), "configFilePath");
|
||||
parser.addOption(settingsPathOption);
|
||||
QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main", "Set if instance is not main instance"));
|
||||
parser.addOption(secondaryOption);
|
||||
parser.process(a);
|
||||
#endif
|
||||
//parse comand line
|
||||
#ifndef Q_OS_ANDROID
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("Smart Home Interface");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
QCommandLineOption tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection"));
|
||||
parser.addOption(tcpOption);
|
||||
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main",
|
||||
"Set server host ip addres"), "adress");
|
||||
parser.addOption(hostOption);
|
||||
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main",
|
||||
"Set server Port in TCP mode or Serial port in serial mode"), "port");
|
||||
parser.addOption(portOption);
|
||||
QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main",
|
||||
"Use serial connection"));
|
||||
parser.addOption(serialOption);
|
||||
QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
|
||||
parser.addOption(baudOption);
|
||||
QCommandLineOption settingsPathOption(QStringList() << "c" << "config", QCoreApplication::translate("main",
|
||||
"Set config file"), "configFilePath");
|
||||
parser.addOption(settingsPathOption);
|
||||
QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main",
|
||||
"Set if instance is not main instance"));
|
||||
parser.addOption(secondaryOption);
|
||||
parser.process(a);
|
||||
#endif
|
||||
|
||||
QIODevice* masterIODevice = nullptr;
|
||||
QIODevice* masterIODevice = nullptr;
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
if(parser.isSet(tcpOption))
|
||||
{
|
||||
QTcpSocket* microSocket = new QTcpSocket;
|
||||
#ifndef Q_OS_ANDROID
|
||||
if(parser.isSet(tcpOption))
|
||||
{
|
||||
QTcpSocket* microSocket = new QTcpSocket;
|
||||
|
||||
int port = 6856;
|
||||
if(parser.isSet(portOption)) port = parser.value(portOption).toInt();
|
||||
int port = 6856;
|
||||
if(parser.isSet(portOption)) port = parser.value(portOption).toInt();
|
||||
|
||||
QString host("127.0.0.1");
|
||||
if(parser.isSet(hostOption)) host = parser.value(hostOption);
|
||||
std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
|
||||
microSocket->connectToHost(host, port, QIODevice::ReadWrite);
|
||||
if(!microSocket->waitForConnected(1000))
|
||||
{
|
||||
std::cout<<"Can not connect to to Server.\n";
|
||||
QMessageBox::critical(nullptr, "Error", "Can not connect to to Server");
|
||||
return 1;
|
||||
}
|
||||
masterIODevice = microSocket;
|
||||
}
|
||||
else
|
||||
{
|
||||
QSerialPort* microPort = new QSerialPort;
|
||||
if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption));
|
||||
else microPort->setPortName("ttyUSB0");
|
||||
QString host("127.0.0.1");
|
||||
if(parser.isSet(hostOption)) host = parser.value(hostOption);
|
||||
std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
|
||||
microSocket->connectToHost(host, port, QIODevice::ReadWrite);
|
||||
if(!microSocket->waitForConnected(1000))
|
||||
{
|
||||
std::cout<<"Can not connect to to Server.\n";
|
||||
QMessageBox::critical(nullptr, "Error", "Can not connect to to Server");
|
||||
return 1;
|
||||
}
|
||||
masterIODevice = microSocket;
|
||||
}
|
||||
else
|
||||
{
|
||||
QSerialPort* microPort = new QSerialPort;
|
||||
if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption));
|
||||
else microPort->setPortName("ttyUSB0");
|
||||
|
||||
if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
|
||||
else microPort->setBaudRate(BAUD);
|
||||
if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
|
||||
else microPort->setBaudRate(BAUD);
|
||||
|
||||
if(!microPort->open(QIODevice::ReadWrite)) std::cout<<"Can not open serial port "<<microPort->portName().toStdString()<<". Continueing in demo mode"<<'\n';
|
||||
masterIODevice = microPort;
|
||||
}
|
||||
if(!microPort->open(QIODevice::ReadWrite)) std::cout<<"Can not open serial port "<<microPort->portName().toStdString()
|
||||
<<". Continueing in demo mode"<<'\n';
|
||||
masterIODevice = microPort;
|
||||
}
|
||||
|
||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
|
||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "",
|
||||
!parser.isSet(secondaryOption));
|
||||
|
||||
#else
|
||||
QTcpSocket* microSocket = new QTcpSocket;
|
||||
microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite);
|
||||
if(!microSocket->waitForConnected(1000))
|
||||
{
|
||||
std::cout<<"Can not connect to to Server.\n";
|
||||
return 1;
|
||||
}
|
||||
masterIODevice = microSocket;
|
||||
#else
|
||||
QTcpSocket* microSocket = new QTcpSocket;
|
||||
microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite);
|
||||
if(!microSocket->waitForConnected(1000))
|
||||
{
|
||||
std::cout<<"Can not connect to to Server.\n";
|
||||
return 1;
|
||||
}
|
||||
masterIODevice = microSocket;
|
||||
|
||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
|
||||
#endif
|
||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "",
|
||||
!parser.isSet(secondaryOption));
|
||||
#endif
|
||||
|
||||
|
||||
//mainwindow
|
||||
MainWindow w(&mainObject);
|
||||
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
|
||||
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
|
||||
//mainwindow
|
||||
MainWindow w(&mainObject);
|
||||
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
|
||||
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
|
||||
QObject::connect(&w, &MainWindow::sigSave, &mainObject, &MainObject::storeToDisk);
|
||||
QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem);
|
||||
if(!mainObject.micro.connected()) w.changeHeaderLableText("No io debug only!");
|
||||
QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem);
|
||||
if(!mainObject.micro.connected()) w.changeHeaderLableText("No io debug only!");
|
||||
|
||||
w.show();
|
||||
w.show();
|
||||
|
||||
int retVal = a.exec();
|
||||
int retVal = a.exec();
|
||||
|
||||
if(masterIODevice)
|
||||
delete masterIODevice;
|
||||
return retVal;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue