forked from UnexplodedMinds/Stratofier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
115 lines (93 loc) · 3.27 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
Stratofier Stratux AHRS Display
(c) 2018 Allen K. Lair, Sky Fun
*/
#include <QApplication>
#include <QGuiApplication>
#include <QScreen>
#include <QtDebug>
#include <QDir>
#include <QSettings>
#include <QFontDatabase>
#include "AHRSMainWin.h"
#include "Keyboard.h"
#if defined( Q_OS_ANDROID )
#include "ScreenLocker.h"
#endif
#include "StreamReader.h"
QSettings *g_pSet = nullptr;
Keyboard *g_pKeyboard = nullptr;
// This needs to stay global so it's not destroyed when the orientation changes
StreamReader *g_pStratuxStream = nullptr;
int main( int argc, char *argv[] )
{
#if defined( Q_OS_ANDROID )
QGuiApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
#endif
QApplication guiApp( argc, argv );
QStringList qslArgs = guiApp.arguments();
QString qsArg;
QString qsToken, qsVal;
bool bMax = true;
QString qsIP;
bool bPortrait = true;
AHRSMainWin *pMainWin = 0;
QString qsCurrWorkPath( "/home/pi/Stratofier" ); // If you put Stratofier anywhere else, specify home=<whatever> as an argument when running
#if defined( Q_OS_ANDROID )
ScreenLocker locker; // Keeps screen on until app exit where it's destroyed.
#endif
foreach( qsArg, qslArgs )
{
QStringList qsl = qsArg.split( '=' );
if( qsl.count() == 2 )
{
qsToken = qsl.first();
qsVal = qsl.last();
if( qsToken == "initdisp" )
bMax = (qsVal == "max");
else if( qsToken == "ip" )
qsIP = qsVal;
else if( qsToken == "orient" )
bPortrait = (qsVal == "portrait");
else if( qsToken == "home" )
qsCurrWorkPath = qsVal;
}
}
// For Android, override any command line setting for portrait/landscape
#if defined( Q_OS_ANDROID )
QScreen *pScreen = QGuiApplication::primaryScreen();
bPortrait = ((pScreen->orientation() == Qt::PortraitOrientation) || (pScreen->orientation() == Qt::InvertedPortraitOrientation));
// For running locally we need to set the correct working path so relative references work both locally and on the Pi
#else
QDir::setCurrent( qsCurrWorkPath );
#endif
QCoreApplication::setOrganizationName( "Sky Fun" );
QCoreApplication::setOrganizationDomain( "skyfun.space" );
QCoreApplication::setApplicationName( "Stratofier" );
QGuiApplication::setApplicationDisplayName( "Stratofier" );
#if !defined( Q_OS_ANDROID )
g_pSet = new QSettings( "./config.ini", QSettings::IniFormat );
#else
g_pSet = new QSettings;
#endif
qsIP = g_pSet->value( "StratuxIP", "192.168.10.1" ).toString();
qInfo() << "Starting Stratofier";
g_pStratuxStream = new StreamReader( qsIP );
pMainWin = new AHRSMainWin( qsIP, bPortrait, g_pStratuxStream );
// This is the normal mode for a dedicated Raspberry Pi touchscreen or on Android
if( bMax )
pMainWin->showMaximized();
// This is only intended for running directly on the host PC without an emulator
else
{
pMainWin->show();
if( bPortrait )
pMainWin->setGeometry( 0, 0, /* 768, 1024 */ 648, 1152 );
else
pMainWin->setGeometry( 0, 0, /* 1024, 768 */ 1152, 648 );
}
guiApp.exec();
delete g_pStratuxStream;
g_pStratuxStream = nullptr;
return 0;
}