-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.cpp
99 lines (81 loc) · 2.18 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
#include "mainwindow.h"
#ifdef EFM32_LOADER_GUI
#include <QApplication>
#include <QCoreApplication>
#include <QStyle>
#include <QStyleFactory>
#else
#include <QCoreApplication>
#endif
#include <QSettings>
#include <QDebug>
#include <QTimer>
#include "clhandler.h"
#include <iostream>
extern QTextStream cout;
void print_usage()
{
cout << "Usage\n";
cout << "UART: gecko_loader <port_name> <file_path> uart <boot_pol>\n";
cout << "USB: gecko_loader <port_name> <file_path> usb\n";
cout.flush();
}
int main(int argc, char *argv[])
{
#ifdef EFM32_LOADER_GUI
QApplication a(argc, argv);
QStyle *style = QStyleFactory::create("Fusion");
a.setStyle(style);
QPalette darkPalette;
darkPalette.setColor(QPalette::Highlight, QColor("#5aa02c"));
darkPalette.setColor(QPalette::HighlightedText, QColor("#eee"));
qApp->setPalette(darkPalette);
#else
QCoreApplication a(argc, argv);
#endif
a.setOrganizationDomain("settings");
a.setApplicationName("Gecko Loader");
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, a.applicationDirPath());
QSettings::setDefaultFormat(QSettings::IniFormat);
CLHandler handler;
#ifdef EFM32_LOADER_GUI
MainWindow w;
if(argc == 1)
{
w.show();
}
else {
#endif
cout << "Gecko Loader CLI\n";
if(argc != 4 && argc != 5)
{
cout << "Wrong number of arguments.\n";
print_usage();
exit(EXIT_FAILURE);
}
handler.portName = QString(argv[1]);
handler.filePath = QString(argv[2]);
handler.transport = QString(argv[3]).toLower();
if(handler.transport == "uart")
{
if(argc != 5)
{
cout << "Wrong number of arguments.\n";
print_usage();
exit(EXIT_FAILURE);
}
handler.bootPol = QString(argv[4]);
if(handler.bootPol != "0" && handler.bootPol != "1")
{
cout << "ERROR: <boot_pol> must be 0 or 1\n";
print_usage();
exit(EXIT_FAILURE);
}
}
QObject::connect(&handler, SIGNAL(done()), &a, SLOT(quit()));
QTimer::singleShot(0, &handler, SLOT(run()));
#ifdef EFM32_LOADER_GUI
}
#endif
return a.exec();
}