[gui][script] Rearcam / reworks / kodi button / shutdown/reboot buttons

This commit is contained in:
hawkeyexp 2018-06-22 00:03:19 +02:00
parent 3a59525055
commit c72958438f
12 changed files with 387 additions and 41 deletions

BIN
assets/back-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
assets/bg_exit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
assets/bg_rearcam.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
assets/kodi-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
assets/rearcam-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
assets/reboot-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
assets/recordactive-hot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -23,5 +23,12 @@
<file>record-hot.png</file>
<file>stop-hot.png</file>
<file>save-hot.png</file>
<file>reboot-hot.png</file>
<file>back-hot.png</file>
<file>bg_exit.png</file>
<file>kodi-hot.png</file>
<file>bg_rearcam.png</file>
<file>rearcam-hot.png</file>
<file>recordactive-hot.png</file>
</qresource>
</RCC>

View File

@ -46,6 +46,7 @@ public:
signals:
void exit();
void reboot();
void openSettings();
void toggleCursor();
void TriggerScriptDay();
@ -57,6 +58,9 @@ signals:
void cameraRecord();
void openConnectDialog();
void showBrightnessSlider();
void startKodi();
void showRearCam();
void hideRearCam();
private slots:
void on_horizontalSliderBrightness_valueChanged(int value);
@ -68,6 +72,9 @@ private slots:
void showTime();
void cameraControlShow();
void cameraControlHide();
void toggleExit();
void showRearCamBG();
void hideRearCamBG();
private:
Ui::MainWindow* ui_;
@ -76,8 +83,14 @@ private:
QFile *brightnessFile;
char brightness_str[5];
bool wifiButtonForce = false;
bool cameraButtonForce = false;
bool kodiButtonForce = false;
bool brightnessButtonForce = false;
bool nightModeEnabled = false;
bool DayNightModeState = false;
bool devModeEnabled = false;
bool wallpaperDayFileExists = false;
@ -86,7 +99,13 @@ private:
bool wallpaperDevNightFileExists = false;
bool masterButtonBGState = false;
bool exitMenuVisible = false;
bool rearCamEnabled = false;
bool dashcamBGState = false;
bool rearcamState = false;
bool dashCamRecording = false;
};
}

View File

@ -23,6 +23,7 @@
#include "ui_mainwindow.h"
#include <QTimer>
#include <QDateTime>
#include <QMessageBox>
namespace f1x
{
@ -43,8 +44,8 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
QPushButton:focus { background: url(:/circle.png); } \
QPushButton:pressed { background: url(:/circle-pressed.png); } \
QSlider:horizontal { background: url(:/slider.png); border: 1px solid #ffffff; border-radius: 2px; min-height: 32px;} \
QSlider::groove:horizontal { background: #6d6d6d; height: 32px;} \
QSlider::handle:horizontal { background: white; height: 52px; width: 52px; margin: 0 0;} \
QSlider::groove:horizontal { background: #6d6d6d; height: 32px;} \
QSlider::handle:horizontal { background: white; height: 52px; width: 52px; margin: 0 0;} \
QLabel { color: #ffffff; font-weight: bold;} \
");
@ -89,13 +90,26 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
ui_->setupUi(this);
connect(ui_->pushButtonSettings, &QPushButton::clicked, this, &MainWindow::openSettings);
connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::exit);
connect(ui_->pushButtonSettings, &QPushButton::clicked, this, &MainWindow::cameraHide);
connect(ui_->pushButtonSettings, &QPushButton::clicked, this, &MainWindow::cameraControlHide);
connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::toggleExit);
connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::cameraStop);
connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::cameraHide);
connect(ui_->pushButtonExit, &QPushButton::clicked, this, &MainWindow::cameraControlHide);
connect(ui_->pushButtonShutdown, &QPushButton::clicked, this, &MainWindow::exit);
connect(ui_->pushButtonReboot, &QPushButton::clicked, this, &MainWindow::reboot);
connect(ui_->pushButtonCancel, &QPushButton::clicked, this, &MainWindow::toggleExit);
connect(ui_->pushButtonCameraShow, &QPushButton::clicked, this, &MainWindow::cameraShow);
connect(ui_->pushButtonCameraShow, &QPushButton::clicked, this, &MainWindow::cameraControlShow);
connect(ui_->pushButtonCameraHide, &QPushButton::clicked, this, &MainWindow::cameraHide);
connect(ui_->pushButtonCameraHide, &QPushButton::clicked, this, &MainWindow::cameraControlHide);
connect(ui_->pushButtonStop, &QPushButton::clicked, this, &MainWindow::cameraStop);
connect(ui_->pushButtonRecord, &QPushButton::clicked, this, &MainWindow::cameraRecord);
connect(ui_->pushButtonRearcam, &QPushButton::clicked, this, &MainWindow::showRearCamBG);
connect(ui_->pushButtonRearcam, &QPushButton::clicked, this, &MainWindow::showRearCam);
connect(ui_->pushButtonRearcamBack, &QPushButton::clicked, this, &MainWindow::hideRearCamBG);
connect(ui_->pushButtonRearcamBack, &QPushButton::clicked, this, &MainWindow::hideRearCam);
connect(ui_->pushButtonRearcamBack, &QPushButton::clicked, this, &MainWindow::cameraControlHide);
connect(ui_->pushButtonSave, &QPushButton::clicked, this, &MainWindow::cameraSave);
connect(ui_->pushButtonToggleCursor, &QPushButton::clicked, this, &MainWindow::toggleCursor);
connect(ui_->pushButtonDay, &QPushButton::clicked, this, &MainWindow::TriggerScriptDay);
@ -103,6 +117,7 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
connect(ui_->pushButtonNight, &QPushButton::clicked, this, &MainWindow::TriggerScriptNight);
connect(ui_->pushButtonNight, &QPushButton::clicked, this, &MainWindow::switchGuiToNight);
connect(ui_->pushButtonWirelessConnection, &QPushButton::clicked, this, &MainWindow::openConnectDialog);
connect(ui_->pushButtonKodi, &QPushButton::clicked, this, &MainWindow::startKodi);
connect(ui_->pushButtonBrightness, &QPushButton::clicked, this, &MainWindow::showBrightnessSlider);
QTimer *timer=new QTimer(this);
@ -113,13 +128,16 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
bool cursorButtonForce = cursorButtonFile.exists();
QFileInfo wifiButtonFile("/etc/button_wifi_visible");
bool wifiButtonForce = wifiButtonFile.exists();
this->wifiButtonForce = wifiButtonFile.exists();
QFileInfo cameraButtonFile("/etc/button_camera_visible");
bool cameraButtonForce = cameraButtonFile.exists();
this->cameraButtonForce = cameraButtonFile.exists();
QFileInfo brightnessButtonFile("/etc/button_brightness_visible");
bool brightnessButtonForce = brightnessButtonFile.exists();
this->brightnessButtonForce = brightnessButtonFile.exists();
QFileInfo kodiInstalledFile("/usr/bin/kodi");
this->kodiButtonForce = kodiInstalledFile.exists();
if (configuration->hasTouchScreen() && !cursorButtonForce) {
ui_->pushButtonToggleCursor->hide();
@ -130,9 +148,13 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
ui_->masterButtonBG->setPixmap(image);
ui_->pushButtonStop->hide();
ui_->pushButtonRecord->hide();
ui_->pushButtonRecordActive->hide();
ui_->pushButtonSave->hide();
ui_->pushButtonRearcam->hide();
ui_->pushButtonRearcamBack->hide();
ui_->rearcamBG->hide();
if (!cameraButtonForce) {
if (!this->cameraButtonForce) {
ui_->pushButtonCameraShow->hide();
ui_->pushButtonCameraHide->hide();
} else {
@ -140,22 +162,30 @@ MainWindow::MainWindow(configuration::IConfiguration::Pointer configuration, QWi
ui_->pushButtonCameraHide->hide();
}
if (!wifiButtonForce) {
if (!this->wifiButtonForce) {
ui_->pushButtonWirelessConnection->hide();
}
QFileInfo brightnessFile(brightnessFilename);
if (!brightnessFile.exists() && !brightnessButtonForce) {
if (!brightnessFile.exists() && !this->brightnessButtonForce) {
ui_->pushButtonBrightness->hide();
}
if (!this->kodiButtonForce) {
ui_->pushButtonKodi->hide();
}
ui_->horizontalSliderBrightness->hide();
if (!configuration->showClock()) {
ui_->Digital_clock->hide();
}
ui_->pushButtonShutdown->hide();
ui_->pushButtonReboot->hide();
ui_->pushButtonCancel->hide();
// init bg's on startup
if (!this->nightModeEnabled) {
if (this->devModeEnabled) {
@ -202,7 +232,8 @@ void f1x::openauto::autoapp::ui::MainWindow::on_pushButtonBrightness_clicked()
{
this->brightnessSliderVisible = !this->brightnessSliderVisible;
if (this->brightnessSliderVisible) {
f1x::openauto::autoapp::ui::MainWindow::cameraControlHide();
f1x::openauto::autoapp::ui::MainWindow::cameraControlHide();
f1x::openauto::autoapp::ui::MainWindow::cameraHide();
// Get the current brightness value
this->brightnessFile = new QFile(this->brightnessFilename);
if (this->brightnessFile->open(QIODevice::ReadOnly)) {
@ -281,27 +312,69 @@ void f1x::openauto::autoapp::ui::MainWindow::switchGuiToDay()
void f1x::openauto::autoapp::ui::MainWindow::cameraControlHide()
{
ui_->pushButtonCameraHide->hide();
ui_->pushButtonStop->hide();
ui_->pushButtonRecord->hide();
ui_->pushButtonSave->hide();
ui_->dashcamBG->hide();
this->dashcamBGState = false;
ui_->pushButtonCameraShow->show();
if (this->cameraButtonForce) {
ui_->pushButtonCameraHide->hide();
ui_->pushButtonStop->hide();
ui_->pushButtonRecord->hide();
ui_->pushButtonRecordActive->hide();
ui_->pushButtonRearcam->hide();
ui_->pushButtonSave->hide();
ui_->dashcamBG->hide();
this->dashcamBGState = false;
ui_->pushButtonCameraShow->show();
}
}
void f1x::openauto::autoapp::ui::MainWindow::cameraControlShow()
{
ui_->pushButtonCameraShow->hide();
QPixmap image;
image.load(":/bg_dashcam.png");
ui_->dashcamBG->setPixmap(image);
ui_->dashcamBG->show();
ui_->pushButtonStop->show();
ui_->pushButtonRecord->show();
ui_->pushButtonSave->show();
this->dashcamBGState = true;
ui_->pushButtonCameraHide->show();
if (this->cameraButtonForce) {
ui_->pushButtonCameraShow->hide();
QPixmap image;
image.load(":/bg_dashcam.png");
ui_->dashcamBG->setPixmap(image);
ui_->dashcamBG->show();
ui_->pushButtonStop->show();
ui_->pushButtonRecord->show();
ui_->pushButtonRearcam->show();
ui_->pushButtonSave->show();
this->dashcamBGState = true;
ui_->pushButtonCameraHide->show();
}
}
void f1x::openauto::autoapp::ui::MainWindow::toggleExit()
{
if (!this->exitMenuVisible) {
f1x::openauto::autoapp::ui::MainWindow::cameraControlHide();
if (this->brightnessSliderVisible) {
ui_->horizontalSliderBrightness->hide();
this->brightnessSliderVisible = false;
}
ui_->pushButtonShutdown->show();
ui_->pushButtonReboot->show();
ui_->pushButtonCancel->show();
QPixmap image;
image.load(":/bg_exit.png");
ui_->exitBG->setPixmap(image);
ui_->exitBG->show();
this->exitMenuVisible = true;
} else {
ui_->pushButtonShutdown->hide();
ui_->pushButtonReboot->hide();
ui_->pushButtonCancel->hide();
ui_->exitBG->hide();
this->exitMenuVisible = false;
}
}
void f1x::openauto::autoapp::ui::MainWindow::showRearCamBG()
{
ui_->pushButtonRearcamBack->show();
}
void f1x::openauto::autoapp::ui::MainWindow::hideRearCamBG()
{
ui_->pushButtonRearcamBack->hide();
}
void f1x::openauto::autoapp::ui::MainWindow::showTime()
@ -311,27 +384,61 @@ void f1x::openauto::autoapp::ui::MainWindow::showTime()
ui_->Digital_clock->setText(time_text);
/**if (configuration_->showClock()) {
if (ui_->Digital_clock->isVisible() == true) {
ui_->Digital_clock->hide();
}
if (ui_->Digital_clock->isVisible() == true) {
ui_->Digital_clock->hide();
}
} else {
if (ui_->Digital_clock->isVisible() == false) {
ui_->Digital_clock->show();
}
if (ui_->Digital_clock->isVisible() == false) {
ui_->Digital_clock->show();
}
}**/
QFileInfo nightModeFile("/tmp/night_mode_enabled");
this->nightModeEnabled = nightModeFile.exists();
QFileInfo rearCamFile("/tmp/rearcam_enabled");
this->rearCamEnabled = rearCamFile.exists();
QFileInfo dashCamRecordingFile("/tmp/dashcam_is_recording");
this->dashCamRecording = dashCamRecordingFile.exists();
if (this->dashcamBGState) {
if (this->dashCamRecording) {
if (ui_->pushButtonRecord->isVisible() == true) {
ui_->pushButtonRecordActive->show();
ui_->pushButtonRecord->hide();
}
} else {
if (ui_->pushButtonRecordActive->isVisible() == true) {
ui_->pushButtonRecord->show();
ui_->pushButtonRecordActive->hide();
}
}
}
if (this->nightModeEnabled) {
if (!this->DayNightModeState) {
this->DayNightModeState = true;
f1x::openauto::autoapp::ui::MainWindow::switchGuiToNight();
}
if (!this->DayNightModeState) {
this->DayNightModeState = true;
f1x::openauto::autoapp::ui::MainWindow::switchGuiToNight();
}
} else {
if (this->DayNightModeState) {
this->DayNightModeState = false;
f1x::openauto::autoapp::ui::MainWindow::switchGuiToDay();
}
if (this->DayNightModeState) {
this->DayNightModeState = false;
f1x::openauto::autoapp::ui::MainWindow::switchGuiToDay();
}
}
if (this->rearCamEnabled) {
if (!this->rearcamState) {
f1x::openauto::autoapp::ui::MainWindow::cameraControlHide();
f1x::openauto::autoapp::ui::MainWindow::showRearCamBG();
f1x::openauto::autoapp::ui::MainWindow::showRearCam();
this->rearcamState = true;
}
} else {
if (this->rearcamState) {
f1x::openauto::autoapp::ui::MainWindow::hideRearCamBG();
f1x::openauto::autoapp::ui::MainWindow::hideRearCam();
this->rearcamState = false;
}
}
}

View File

@ -80,6 +80,29 @@
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonKodi">
<property name="geometry">
<rect>
<x>30</x>
<y>104</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/kodi-hot.png</normaloff>:/kodi-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonToggleCursor">
<property name="geometry">
<rect>
@ -340,6 +363,52 @@
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonRecordActive">
<property name="geometry">
<rect>
<x>216</x>
<y>384</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/recordactive-hot.png</normaloff>:/recordactive-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonRearcam">
<property name="geometry">
<rect>
<x>286</x>
<y>384</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/rearcam-hot.png</normaloff>:/rearcam-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonSave">
<property name="geometry">
<rect>
@ -363,6 +432,118 @@
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="exitBG">
<property name="geometry">
<rect>
<x>284</x>
<y>198</y>
<width>232</width>
<height>84</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButtonShutdown">
<property name="geometry">
<rect>
<x>294</x>
<y>208</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/power-hot.png</normaloff>:/power-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonReboot">
<property name="geometry">
<rect>
<x>368</x>
<y>208</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/reboot-hot.png</normaloff>:/reboot-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButtonCancel">
<property name="geometry">
<rect>
<x>442</x>
<y>208</y>
<width>64</width>
<height>64</height>
</rect>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/back-hot.png</normaloff>:/back-hot.png</iconset>
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="rearcamBG">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>480</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButtonRearcamBack">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>480</height>
</rect>
</property>
<property name="icon">
<iconset resource="../../../assets/resources.qrc">
<normaloff>:/bg_rearcam.png</normaloff>:/bg_rearcam.png</iconset>
</property>
<property name="iconSize">
<size>
<width>800</width>
<height>480</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</widget>
</widget>
<tabstops>

View File

@ -110,6 +110,10 @@ int main(int argc, char* argv[])
qApplication.setOverrideCursor(cursor);
});
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::reboot, [&qApplication]() {
system("sudo shutdown -r now");
});
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::cameraHide, [&qApplication]() {
#ifdef RASPBERRYPI3
system("/opt/crankshaft/cameracontrol.py Background &");
@ -128,6 +132,25 @@ int main(int argc, char* argv[])
#endif
});
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::hideRearCam, [&qApplication]() {
#ifdef RASPBERRYPI3
system("/opt/crankshaft/cameracontrol.py DashcamMode &");
system("sudo rm /tmp/rearcam_enabled &");
OPENAUTO_LOG(info) << "[CS] Ran RPiCameraControl script.";
#else
OPENAUTO_LOG(info) << "[CS] You are not running this on a Raspberry Pi, skipping Cam script.";
#endif
});
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::showRearCam, [&qApplication]() {
#ifdef RASPBERRYPI3
system("/opt/crankshaft/cameracontrol.py Rearcam &");
OPENAUTO_LOG(info) << "[CS] Ran RPiCameraControl script.";
#else
OPENAUTO_LOG(info) << "[CS] You are not running this on a Raspberry Pi, skipping Cam script.";
#endif
});
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::cameraRecord, [&qApplication]() {
#ifdef RASPBERRYPI3
system("/opt/crankshaft/cameracontrol.py Record &");
@ -173,6 +196,15 @@ int main(int argc, char* argv[])
#endif
});
QObject::connect(&mainWindow, &autoapp::ui::MainWindow::startKodi, [&qApplication]() {
#ifdef RASPBERRYPI3
system("/usr/bin/kodi &");
OPENAUTO_LOG(info) << "[CS] Run kodi binary.";
#else
OPENAUTO_LOG(info) << "[CS] You are not running this on a Raspberry Pi, skipping kodi.";
#endif
});
mainWindow.showFullScreen();
aasdk::usb::USBWrapper usbWrapper(usbContext);