Skip to content

Commit

Permalink
Add alerts for temperature and battery
Browse files Browse the repository at this point in the history
  • Loading branch information
mel-florance committed Jul 16, 2022
1 parent e610090 commit 7e6482b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
4 changes: 3 additions & 1 deletion include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -94,9 +94,11 @@ private slots:
std::unique_ptr<TelloController> controller;
std::unique_ptr<QTimer> poll_infos_timer;
std::unique_ptr<QTimer> record_timer;
std::unique_ptr<QTimer> alert_timer;
bool is_connected;
bool is_video_started;
bool is_flying;
bool is_alerting;
float drone_rotation;

void enable_flight_controls(bool enable);
Expand Down
31 changes: 30 additions & 1 deletion mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,26 @@
</property>
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="handleWidth">
<number>4</number>
</property>
<property name="childrenCollapsible">
<bool>true</bool>
<bool>false</bool>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -1154,6 +1163,26 @@ QGroupBox{
<string>Recording...</string>
</property>
</widget>
<widget class="QLabel" name="alert_message">
<property name="geometry">
<rect>
<x>100</x>
<y>250</y>
<width>351</width>
<height>110</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">QLabel{color:red; font-size: 32px;border: 1px solid red; text-align: center}</string>
</property>
<property name="text">
<string>BATTERY ALERT
4%</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<property name="sizePolicy">
Expand Down
35 changes: 34 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cv::Mat>();
Expand All @@ -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);
Expand Down Expand Up @@ -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) + " %)");
}
Expand All @@ -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");
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7e6482b

Please sign in to comment.