xref: /OK3568_Linux_fs/app/forlinx/forlinx_qt/ubootmenu/mainwindow.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun #include "mainwindow.h"
2*4882a593Smuzhiyun #include "ui_mainwindow.h"
3*4882a593Smuzhiyun #include <fcntl.h>
4*4882a593Smuzhiyun #include <sys/ioctl.h>
5*4882a593Smuzhiyun #include <linux/types.h>
6*4882a593Smuzhiyun #include <linux/spi/spidev.h>
7*4882a593Smuzhiyun #include <QMessageBox>
8*4882a593Smuzhiyun #include <unistd.h>
9*4882a593Smuzhiyun #include <QDir>
10*4882a593Smuzhiyun #include <QDebug>
11*4882a593Smuzhiyun 
MainWindow(QWidget * parent)12*4882a593Smuzhiyun MainWindow::MainWindow(QWidget *parent) :
13*4882a593Smuzhiyun     QMainWindow(parent),
14*4882a593Smuzhiyun     ui(new Ui::MainWindow)
15*4882a593Smuzhiyun {
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun     ui->setupUi(this);
18*4882a593Smuzhiyun 	setWindowState(Qt::WindowMaximized);
19*4882a593Smuzhiyun 	setWindowFlags(Qt::FramelessWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun 	qExec.start("/usr/sbin/fw_printenv video_mipi_edp");
22*4882a593Smuzhiyun     qExec.waitForFinished();
23*4882a593Smuzhiyun     QString result = qExec.readAllStandardOutput();
24*4882a593Smuzhiyun     char *p = result.toLatin1().data();
25*4882a593Smuzhiyun 	if (strstr(p + strlen("video_mipi_edp"), "mipi") != NULL) {
26*4882a593Smuzhiyun 		ui->video_mipi->setText(tr("video-mipi:on"));
27*4882a593Smuzhiyun 		QPalette   pal;
28*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::green);
29*4882a593Smuzhiyun 		ui->video_mipi->setPalette(pal);
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun 		ui->video_edp->setText(tr("video-edp:off"));
32*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
33*4882a593Smuzhiyun 		ui->video_edp->setPalette(pal);
34*4882a593Smuzhiyun 	} else if (strstr(p + strlen("video_mipi_edp"), "edp") != NULL) {
35*4882a593Smuzhiyun 		ui->video_edp->setText(tr("video-edp:on"));
36*4882a593Smuzhiyun 		QPalette   pal;
37*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::green);
38*4882a593Smuzhiyun 		ui->video_edp->setPalette(pal);
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun 		ui->video_mipi->setText(tr("video-mipi:off"));
41*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
42*4882a593Smuzhiyun 		ui->video_mipi->setPalette(pal);
43*4882a593Smuzhiyun 	} else {
44*4882a593Smuzhiyun 		QPalette   pal;
45*4882a593Smuzhiyun 		ui->video_edp->setText(tr("video-edp:off"));
46*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
47*4882a593Smuzhiyun 		ui->video_edp->setPalette(pal);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 		ui->video_mipi->setText(tr("video-mipi:off"));
50*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
51*4882a593Smuzhiyun 		ui->video_mipi->setPalette(pal);
52*4882a593Smuzhiyun 	}
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	qExec.start("/usr/sbin/fw_printenv video_hdmi");
55*4882a593Smuzhiyun     qExec.waitForFinished();
56*4882a593Smuzhiyun     result = qExec.readAllStandardOutput();
57*4882a593Smuzhiyun     p = result.toLatin1().data();
58*4882a593Smuzhiyun 	if (strstr(p + strlen("video_hdmi"), "hdmi") != NULL) {
59*4882a593Smuzhiyun 		ui->video_hdmi->setText(tr("video-hdmi:on"));
60*4882a593Smuzhiyun 		QPalette   pal;
61*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::green);
62*4882a593Smuzhiyun 		ui->video_hdmi->setPalette(pal);
63*4882a593Smuzhiyun 	} else {
64*4882a593Smuzhiyun 		ui->video_hdmi->setText(tr("video-hdmi:off"));
65*4882a593Smuzhiyun 		QPalette   pal;
66*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
67*4882a593Smuzhiyun 		ui->video_hdmi->setPalette(pal);
68*4882a593Smuzhiyun 	}
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 	qExec.start("/usr/sbin/fw_printenv video_lvds_rgb");
71*4882a593Smuzhiyun     qExec.waitForFinished();
72*4882a593Smuzhiyun     result = qExec.readAllStandardOutput();
73*4882a593Smuzhiyun     p = result.toLatin1().data();
74*4882a593Smuzhiyun 	if (strstr(p + strlen("video_lvds_rgb"), "lvds") != NULL) {
75*4882a593Smuzhiyun 		ui->video_lvds->setText(tr("video-lvds:on"));
76*4882a593Smuzhiyun 		QPalette   pal;
77*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::green);
78*4882a593Smuzhiyun 		ui->video_lvds->setPalette(pal);
79*4882a593Smuzhiyun 	} else {
80*4882a593Smuzhiyun 		ui->video_lvds->setText(tr("video-lvds:off"));
81*4882a593Smuzhiyun 		QPalette   pal;
82*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
83*4882a593Smuzhiyun 		ui->video_lvds->setPalette(pal);
84*4882a593Smuzhiyun 	}
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 	connect(ui->video_mipi, &QPushButton::clicked, this, &MainWindow::video_mipi_clicked);
87*4882a593Smuzhiyun 	connect(ui->video_hdmi, &QPushButton::clicked, this, &MainWindow::video_hdmi_clicked);
88*4882a593Smuzhiyun 	connect(ui->video_lvds, &QPushButton::clicked, this, &MainWindow::video_lvds_clicked);
89*4882a593Smuzhiyun 	connect(ui->video_edp, &QPushButton::clicked, this, &MainWindow::video_edp_clicked);
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 	connect(ui->exitBtn, &QPushButton::clicked, this, [=](){
92*4882a593Smuzhiyun 			close();
93*4882a593Smuzhiyun 			});
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun 
~MainWindow()96*4882a593Smuzhiyun MainWindow::~MainWindow()
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun     delete ui;
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun 
video_mipi_clicked()101*4882a593Smuzhiyun void MainWindow::video_mipi_clicked()
102*4882a593Smuzhiyun {
103*4882a593Smuzhiyun 	if (ui->video_mipi->text() == "video-mipi:on") {
104*4882a593Smuzhiyun 		ui->video_mipi->setText(tr("video-mipi:off"));
105*4882a593Smuzhiyun 		QPalette   pal;
106*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
107*4882a593Smuzhiyun 		ui->video_mipi->setPalette(pal);
108*4882a593Smuzhiyun 		system("fw_setenv video_mipi_edp none");
109*4882a593Smuzhiyun 	} else {
110*4882a593Smuzhiyun 		ui->video_mipi->setText(tr("video-mipi:on"));
111*4882a593Smuzhiyun 		QPalette   pal;
112*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::green);
113*4882a593Smuzhiyun 		ui->video_mipi->setPalette(pal);
114*4882a593Smuzhiyun 		system("fw_setenv video_mipi_edp mipi");
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 		ui->video_edp->setText(tr("video-edp:off"));
117*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
118*4882a593Smuzhiyun 		ui->video_edp->setPalette(pal);
119*4882a593Smuzhiyun 	}
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun 
video_lvds_clicked()122*4882a593Smuzhiyun void MainWindow::video_lvds_clicked()
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun 	if (ui->video_lvds->text() == "video-lvds:on") {
125*4882a593Smuzhiyun 		ui->video_lvds->setText(tr("video-lvds:off"));
126*4882a593Smuzhiyun 		QPalette   pal;
127*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
128*4882a593Smuzhiyun 		ui->video_lvds->setPalette(pal);
129*4882a593Smuzhiyun 		system("fw_setenv video_lvds_rgb none");
130*4882a593Smuzhiyun 	} else {
131*4882a593Smuzhiyun 		ui->video_lvds->setText(tr("video-lvds:on"));
132*4882a593Smuzhiyun 		QPalette   pal;
133*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::green);
134*4882a593Smuzhiyun 		ui->video_lvds->setPalette(pal);
135*4882a593Smuzhiyun 		system("fw_setenv video_lvds_rgb lvds");
136*4882a593Smuzhiyun 	}
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun 
video_edp_clicked()139*4882a593Smuzhiyun void MainWindow::video_edp_clicked()
140*4882a593Smuzhiyun {
141*4882a593Smuzhiyun 	if (ui->video_edp->text() == "video-edp:on") {
142*4882a593Smuzhiyun 		ui->video_edp->setText(tr("video-edp:off"));
143*4882a593Smuzhiyun 		QPalette   pal;
144*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
145*4882a593Smuzhiyun 		ui->video_edp->setPalette(pal);
146*4882a593Smuzhiyun 		system("fw_setenv video_mipi_edp none");
147*4882a593Smuzhiyun 	} else {
148*4882a593Smuzhiyun 		ui->video_edp->setText(tr("video-edp:on"));
149*4882a593Smuzhiyun 		QPalette   pal;
150*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::green);
151*4882a593Smuzhiyun 		ui->video_edp->setPalette(pal);
152*4882a593Smuzhiyun 		system("fw_setenv video_mipi_edp edp");
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 		ui->video_mipi->setText(tr("video-mipi:off"));
155*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
156*4882a593Smuzhiyun 		ui->video_mipi->setPalette(pal);
157*4882a593Smuzhiyun 	}
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun 
video_hdmi_clicked()160*4882a593Smuzhiyun void MainWindow::video_hdmi_clicked()
161*4882a593Smuzhiyun {
162*4882a593Smuzhiyun 	if (ui->video_hdmi->text() == "video-hdmi:on") {
163*4882a593Smuzhiyun 		ui->video_hdmi->setText(tr("video-hdmi:off"));
164*4882a593Smuzhiyun 		QPalette   pal;
165*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::red);
166*4882a593Smuzhiyun 		ui->video_hdmi->setPalette(pal);
167*4882a593Smuzhiyun 		system("fw_setenv video_hdmi off");
168*4882a593Smuzhiyun 	} else {
169*4882a593Smuzhiyun 		ui->video_hdmi->setText(tr("video-hdmi:on"));
170*4882a593Smuzhiyun 		QPalette   pal;
171*4882a593Smuzhiyun 		pal.setColor(QPalette::Button, Qt::green);
172*4882a593Smuzhiyun 		ui->video_hdmi->setPalette(pal);
173*4882a593Smuzhiyun 		system("fw_setenv video_hdmi hdmi");
174*4882a593Smuzhiyun 	}
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun 
178