PX4FirmwareUpgrader.cc 1.81 KB
Newer Older
1 2 3 4
#include <QFileDialog>
#include <QDesktopServices>
#include <QSettings>

5 6 7 8 9 10
#include "PX4FirmwareUpgrader.h"
#include "ui_PX4FirmwareUpgrader.h"

#include <QGC.h>
#include <QDebug>

11

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
PX4FirmwareUpgrader::PX4FirmwareUpgrader(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PX4FirmwareUpgrader)
{
    ui->setupUi(this);

    connect(ui->selectFileButton, SIGNAL(clicked()), this, SLOT(selectFirmwareFile()));
    connect(ui->flashButton, SIGNAL(clicked()), this, SIGNAL(upgrade()));
}

PX4FirmwareUpgrader::~PX4FirmwareUpgrader()
{
    delete ui;
}

void PX4FirmwareUpgrader::selectFirmwareFile()
{
29 30 31 32 33 34 35 36 37 38
    QSettings settings;
    QString path = settings.value("PX4_FIRMWARE_PATH",
                                     QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)).toString();
    const QString widgetFileExtension(".px4");
    QString fileName = QFileDialog::getOpenFileName(this, tr("Specify File Name"),
                       path,
                       tr("PX4 Firmware (*%1);;").arg(widgetFileExtension));
    settings.setValue("PX4_FIRMWARE_PATH", fileName);
    qDebug() << "EMITTING SIGNAL";
    emit firmwareFileNameSet(fileName);
39 40 41 42 43 44 45 46 47 48
}

void PX4FirmwareUpgrader::setDetectionStatusText(const QString &text)
{
    ui->detectionStatusLabel->setText(text);
}

void PX4FirmwareUpgrader::setFlashStatusText(const QString &text)
{
    ui->flashProgressLabel->setText(text);
49
    qDebug() << __FILE__ << __LINE__ << "LABEL" << text;
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
}

void PX4FirmwareUpgrader::setFlashProgress(int percent)
{
    ui->flashProgressBar->setValue(percent);
}

void PX4FirmwareUpgrader::setPortName(const QString &portname)
{
    // Prepend newly found port to the list
    if (ui->serialPortComboBox->findText(portname) == -1)
    {
        ui->serialPortComboBox->insertItem(0, portname);
        ui->serialPortComboBox->setEditText(portname);
    }
}