diff --git a/include/mainwindow.h b/include/mainwindow.h index ffc6f54..90ada9e 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -71,9 +71,9 @@ private slots: void on_pollinfos(); void on_videoframe(cv::Mat matrix); void on_record_timer(); + void on_alert_timer(); void on_button_start_recording_clicked(); - void on_splitter_splitterMoved(int pos, int index); protected: @@ -94,9 +94,11 @@ private slots: std::unique_ptr controller; std::unique_ptr poll_infos_timer; std::unique_ptr record_timer; + std::unique_ptr alert_timer; bool is_connected; bool is_video_started; bool is_flying; + bool is_alerting; float drone_rotation; void enable_flight_controls(bool enable); diff --git a/mainwindow.ui b/mainwindow.ui index 81833eb..65324c2 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -44,17 +44,26 @@ + + true + 0 0 + + 1 + Qt::Horizontal + + 4 + - true + false @@ -1154,6 +1163,26 @@ QGroupBox{ Recording... + + + + 100 + 250 + 351 + 110 + + + + QLabel{color:red; font-size: 32px;border: 1px solid red; text-align: center} + + + BATTERY ALERT +4% + + + Qt::AlignCenter + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 423a339..768c004 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -9,6 +9,7 @@ MainWindow::MainWindow(QWidget *parent) is_connected(false), is_video_started(false), is_flying(false), + is_alerting(false), drone_rotation(0.0f) { qRegisterMetaType(); @@ -22,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent) ui->button_start_recording->setDisabled(true); ui->recording_dot->setVisible(false); ui->recording_text->setVisible(false); + ui->alert_message->setVisible(false); enable_flight_controls(false); QPixmap pxr(960, 720); @@ -112,7 +114,17 @@ void MainWindow::on_connected() // poll_infos_timer->start(3000); } -void MainWindow::on_battery(int percent) { +void MainWindow::on_battery(int percent) +{ + if (percent < 10 && !is_alerting && is_flying) { + auto ptr = new QTimer(this); + connect(ptr, SIGNAL(timeout()), this, SLOT(on_alert_timer())); + alert_timer.reset(ptr); + alert_timer->start(1000); + is_alerting = true; + ui->alert_message->setText("BATTERY ALERT\n" + QString::number(percent) + " %\nLAND QUICKLY !"); + } + progress_bar->setValue(percent); progress_bar->setFormat("Battery (" + QString::number(percent) + " %)"); } @@ -130,6 +142,15 @@ void MainWindow::on_height(int centimeters) { } void MainWindow::on_temperature(int degrees) { + if (degrees > 90 && !is_alerting && is_flying) { + auto ptr = new QTimer(this); + connect(ptr, SIGNAL(timeout()), this, SLOT(on_alert_timer())); + alert_timer.reset(ptr); + alert_timer->start(1000); + is_alerting = true; + ui->alert_message->setText("TEMPERATURE ALERT\n" + QString::number(degrees) + "°C\nLAND QUICKLY !"); + } + ui->drone_temperature->setText(QString::number(degrees) + "°C"); } @@ -271,6 +292,13 @@ void MainWindow::resize_ui_elements() ui->recording_dot->geometry().width(), ui->recording_dot->geometry().height() }); + + ui->alert_message->setGeometry(QRect{ + (ui->tabWidget->geometry().width()/2) - 350/2, + (ui->tabWidget->geometry().height()/2) - 140/2, + 350, + 140 + }); } void MainWindow::on_button_takeoff_clicked() @@ -532,6 +560,11 @@ void MainWindow::on_record_timer() ui->recording_dot->setVisible(!ui->recording_dot->isVisible()); } +void MainWindow::on_alert_timer() +{ + ui->alert_message->setVisible(!ui->alert_message->isVisible()); +} + void MainWindow::on_button_start_recording_clicked() { if (video_recorder) {