chore(cpn): refactor firmware flashing to use edgetx rs_dfu (#6521)

Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com>
This commit is contained in:
Neil Horne
2025-09-14 09:59:34 +10:00
committed by GitHub
co-authored by raphaelcoeffic
parent 23830197b3
commit dbce54dec6
105 changed files with 2926 additions and 3676 deletions
+30
View File
@@ -0,0 +1,30 @@
project(progress)
set(${PROJECT_NAME}_NAMES
progressdialog
progresswidget
)
AddHeadersSources()
qt_wrap_cpp(${PROJECT_NAME}_SRCS
)
add_library(${PROJECT_NAME}
${${PROJECT_NAME}_HDRS}
${${PROJECT_NAME}_SRCS}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
${CPN_COMMON_LIB}
)
target_include_directories(${PROJECT_NAME}
PRIVATE
"${CMAKE_SOURCE_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}"
PUBLIC
"${CMAKE_CURRENT_LIST_DIR}"
)
+96
View File
@@ -0,0 +1,96 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "progresswidget.h"
#include "progressdialog.h"
#include "ui_progressdialog.h"
#include "appdata.h"
#include <QTimer>
ProgressDialog::ProgressDialog(QWidget *parent, const QString &title, const QIcon &icon, bool forceOpen):
QDialog(parent),
ui(new Ui::ProgressDialog),
locked(false),
keepOpen(false)
{
ui->setupUi(this);
setWindowTitle(title);
setWindowIcon(icon);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
if (forceOpen) {
ui->outputProgress->forceOpen();
}
resize(0, 0);
connect(ui->outputProgress, &ProgressWidget::locked, this, &ProgressDialog::on_outputProgress_locked);
show();
}
ProgressDialog::~ProgressDialog()
{
delete ui;
}
ProgressWidget * ProgressDialog::progress()
{
return ui->outputProgress;
}
void ProgressDialog::on_closeButton_clicked()
{
if (!locked) {
ui->outputProgress->stop();
emit rejected();
if (!keepOpen)
close();
}
}
void ProgressDialog::on_outputProgress_detailsToggled()
{
QTimer::singleShot(0, [=]() { adjustSize(); });
}
void ProgressDialog::on_outputProgress_locked(bool lock)
{
ui->closeButton->setEnabled(!lock);
locked = lock;
}
bool ProgressDialog::isEmpty() const
{
return ui->outputProgress->isEmpty();
}
void ProgressDialog::setProcessStarted()
{
ui->closeButton->setText(tr("Cancel"));
}
void ProgressDialog::setProcessStopped()
{
ui->closeButton->setText(tr("Close"));
}
void ProgressDialog::on_outputProgress_keepOpen(bool val)
{
keepOpen = val;
}
+58
View File
@@ -0,0 +1,58 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <QDialog>
namespace Ui
{
class ProgressDialog;
}
class ProgressWidget;
class ProgressDialog : public QDialog
{
Q_OBJECT
public:
ProgressDialog(QWidget *parent, const QString &label, const QIcon &icon, bool forceOpen=false);
~ProgressDialog();
ProgressWidget * progress();
bool isEmpty() const;
public slots:
void setProcessStarted();
void setProcessStopped();
private slots:
void on_closeButton_clicked();
void on_outputProgress_detailsToggled();
void on_outputProgress_locked(bool);
void on_outputProgress_keepOpen(bool);
private:
Ui::ProgressDialog *ui;
bool locked;
bool keepOpen;
};
+102
View File
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProgressDialog</class>
<widget class="QDialog" name="ProgressDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>646</width>
<height>211</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Flash Firmware</string>
</property>
<property name="windowIcon">
<iconset resource="companion.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>7</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>7</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="ProgressWidget" name="outputProgress" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>6</number>
</property>
<item>
<spacer name="spacer1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="closeButton">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ProgressWidget</class>
<extends>QWidget</extends>
<header>progresswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>closeButton</tabstop>
</tabstops>
<resources>
<include location="companion.qrc"/>
</resources>
<connections/>
</ui>
+220
View File
@@ -0,0 +1,220 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "progresswidget.h"
#include "ui_progresswidget.h"
#include "appdata.h"
#include <QApplication>
#include <QDebug>
#include <QTimer>
#include <QThread>
#include <QScrollBar>
ProgressWidget::ProgressWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ProgressWidget),
m_forceOpen(false),
m_hasDetails(false)
{
ui->setupUi(this);
ui->info->hide();
ui->checkBox->hide();
ui->textEdit->hide();
ui->checkBox->setChecked(g.outputDisplayDetails());
connect(ui->checkBox, &QCheckBox::toggled, this, &ProgressWidget::onShowDetailsToggled);
QFont newFont(ui->textEdit->font());
newFont.setFamily("Courier");
#ifdef __APPLE__
newFont.setPointSize(13);
ui->textEdit->setAttribute(Qt::WA_MacNormalSize);
#elif defined WIN32 || !defined __GNUC__
newFont.setPointSize(9);
#endif
ui->textEdit->setFont(newFont);
}
ProgressWidget::~ProgressWidget()
{
delete ui;
}
void ProgressWidget::stop()
{
emit stopped();
}
void ProgressWidget::clearDetails() const
{
ui->textEdit->clear();
}
void ProgressWidget::forceOpen()
{
m_forceOpen = true;
ui->checkBox->hide();
toggleDetails();
}
void ProgressWidget::setInfo(const QString &text)
{
ui->info->show();
ui->info->setText(text);
}
void ProgressWidget::setMaximum(int value)
{
ui->progressBar->setMaximum(value);
}
int ProgressWidget::maximum()
{
return ui->progressBar->maximum();
}
void ProgressWidget::setValue(int value)
{
ui->progressBar->setValue(value);
}
void ProgressWidget::addText(const QString &text, const bool richText)
{
if (!m_hasDetails) {
m_hasDetails = true;
if (!m_forceOpen)
toggleDetails();
}
QTextCursor cursor(ui->textEdit->textCursor());
// is the scrollbar at the end?
bool atEnd = (ui->textEdit->verticalScrollBar()->value() == ui->textEdit->verticalScrollBar()->maximum());
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor, 1);
if (richText)
cursor.insertHtml(text);
else
cursor.insertText(text);
if (atEnd) {
ui->textEdit->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
}
}
void ProgressWidget::addHtml(const QString & text)
{
addText(text, true);
}
void ProgressWidget::addMessage(const QString & text, const int & type, bool richText)
{
QString color;
switch (type) {
case QtDebugMsg:
color = "dimgrey"; // not important messages, may be filtered out
break;
case QtWarningMsg: // use warning level as emphasis
color = "orangered";
break;
case QtCriticalMsg: // use critical as a warning
color = "darkred";
break;
case QtFatalMsg: // fatal for hard errors
color = "red";
break;
case QtInfoMsg: // default plain text
default:
break;
}
if (color.isEmpty()) {
if (richText)
addHtml(text % "<br>");
else
addText(text % "\n");
}
else {
addHtml(QString("<font color=%1>").arg(color) % text % "</font><br>");
}
}
QString ProgressWidget::getText() const
{
return ui->textEdit->toPlainText();
}
bool ProgressWidget::isEmpty() const
{
return getText().isEmpty();
}
bool ProgressWidget::detailsVisible() const
{
return ui->textEdit->isVisible();
}
void ProgressWidget::onShowDetailsToggled(bool checked)
{
g.outputDisplayDetails(checked);
toggleDetails();
}
void ProgressWidget::toggleDetails()
{
bool showDetails = m_forceOpen || (m_hasDetails && g.outputDisplayDetails());
if (!m_forceOpen)
ui->checkBox->show();
if ((!showDetails && ui->textEdit->isVisible()) || (showDetails && !ui->textEdit->isVisible())) {
ui->textEdit->setMinimumHeight(showDetails ? 300 : 0);
ui->textEdit->setVisible(showDetails);
emit detailsToggled();
}
}
void ProgressWidget::setProgressColor(const QColor &color)
{
ui->progressBar->setStyleSheet(QString("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: %1; text-align:center;}:").arg(color.name()));
}
#define HLINE_SEPARATOR "================================================================================="
void ProgressWidget::addSeparator()
{
addText("\n" HLINE_SEPARATOR "\n");
}
void ProgressWidget::lock(bool lock)
{
emit locked(lock);
}
void ProgressWidget::forceKeepOpen(bool value)
{
emit keepOpen(value);
}
void ProgressWidget::refresh()
{
ui->info->update();
ui->progressBar->update();
ui->textEdit->update();
}
+72
View File
@@ -0,0 +1,72 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#pragma once
#include <QWidget>
namespace Ui {
class ProgressWidget;
}
class ProgressWidget : public QWidget
{
Q_OBJECT
public:
explicit ProgressWidget(QWidget *parent);
~ProgressWidget();
QString getText() const;
int maximum();
bool isEmpty() const;
bool detailsVisible() const;
public slots:
void lock(bool lock);
void addText(const QString &text, const bool richText = false);
void addHtml(const QString &text);
void addMessage(const QString & text, const int & type = QtInfoMsg, bool richText = false);
void setInfo(const QString &text);
void setMaximum(int value);
void setValue(int value);
void setProgressColor(const QColor &color);
void addSeparator();
void forceOpen();
void stop();
void clearDetails() const;
void forceKeepOpen(bool value);
void refresh();
signals:
void detailsToggled();
void locked(bool);
void stopped();
void keepOpen(bool);
protected slots:
void toggleDetails();
void onShowDetailsToggled(bool checked);
private:
Ui::ProgressWidget *ui;
bool m_forceOpen;
bool m_hasDetails;
};
+156
View File
@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProgressWidget</class>
<widget class="QWidget" name="ProgressWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>753</width>
<height>474</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>650</width>
<height>0</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item alignment="Qt::AlignTop">
<widget class="QLabel" name="info">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Show Details</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTextEdit" name="textEdit">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Courier</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="html">
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Courier'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>