Bsongis/horus create radiodata from scratch (#4251)
[Companion] It's now possible to add models on an empty EEPROM, save and reload the .otx
This commit is contained in:
@@ -442,7 +442,9 @@ int OpenTxFirmware::getCapability(Capability capability)
|
||||
{
|
||||
switch (capability) {
|
||||
case Models:
|
||||
if (IS_ARM(board))
|
||||
if (IS_HORUS(board))
|
||||
return 0;
|
||||
else if (IS_ARM(board))
|
||||
return 60;
|
||||
else if (board == BOARD_M128)
|
||||
return 30;
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#define ER9X_EEPROM_FILE_TYPE "ER9X_EEPROM_FILE"
|
||||
#define EEPE_EEPROM_FILE_HEADER "EEPE EEPROM FILE"
|
||||
#define HEX_FILES_FILTER "HEX files (*.hex);;"
|
||||
#define BIN_FILES_FILTER "BIN files (*.bin);;"
|
||||
#define EXTERNAL_EEPROM_FILES_FILTER "EEPROM files (*.bin *.hex);;" BIN_FILES_FILTER HEX_FILES_FILTER
|
||||
|
||||
@@ -137,7 +137,7 @@ MainWindow::MainWindow():
|
||||
if (fileType==STORAGE_TYPE_EEPE || fileType==STORAGE_TYPE_EEPM || fileType==STORAGE_TYPE_BIN) {
|
||||
MdiChild * child = createMdiChild();
|
||||
if (child->loadFile(str)) {
|
||||
if (!(printing && model >= 0 && model<GetCurrentFirmware()->getCapability(Models) && !printfilename.isEmpty())) {
|
||||
if (!(printing && model >= 0 && (GetCurrentFirmware()->getCapability(Models) == 0 || model<GetCurrentFirmware()->getCapability(Models)) && !printfilename.isEmpty())) {
|
||||
statusBar()->showMessage(tr("File loaded"), 2000);
|
||||
child->show();
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
|
||||
#include "mdichild.h"
|
||||
#include "ui_mdichild.h"
|
||||
#include "xmlinterface.h"
|
||||
#include "hexinterface.h"
|
||||
#include "mainwindow.h"
|
||||
#include "modeledit/modeledit.h"
|
||||
#include "generaledit/generaledit.h"
|
||||
@@ -156,6 +154,9 @@ void MdiChild::showModelsListContextMenu(const QPoint & pos)
|
||||
contextMenu.addSeparator();
|
||||
contextMenu.addAction(CompanionIcon("simulate.png"), tr("&Simulate model"), this, SLOT(modelSimulate()), tr("Alt+S"));
|
||||
}
|
||||
else if (IS_HORUS(GetCurrentFirmware()->getBoard())) {
|
||||
contextMenu.addAction(CompanionIcon("add.png"), tr("&Add model"), this, SLOT(modelAdd()));
|
||||
}
|
||||
|
||||
// TODO context menu for radio settings
|
||||
// contextMenu.addAction(CompanionIcon("edit.png"), tr("&Edit"), this, SLOT(EditModel()));
|
||||
@@ -224,7 +225,7 @@ void MdiChild::doPaste(QByteArray * gmData, int index)
|
||||
size += sizeof(GeneralSettings);
|
||||
}
|
||||
else if (c == 'M') {
|
||||
if (index < GetCurrentFirmware()->getCapability(Models)) {
|
||||
if (GetCurrentFirmware()->getCapability(Models) == 0 || index < GetCurrentFirmware()->getCapability(Models)) {
|
||||
// Model data
|
||||
int ret = QMessageBox::Yes;
|
||||
if (!radioData.models[index].isEmpty()) {
|
||||
@@ -333,6 +334,24 @@ void MdiChild::generalEdit()
|
||||
t->show();
|
||||
}
|
||||
|
||||
void MdiChild::modelAdd()
|
||||
{
|
||||
if (radioData.categories.size() == 0) {
|
||||
CategoryData category("Models");
|
||||
radioData.categories.push_back(category);
|
||||
}
|
||||
|
||||
ModelData model;
|
||||
model.category = radioData.categories.size() - 1;
|
||||
model.used = true;
|
||||
sprintf(model.filename, "model%lu.bin", radioData.models.size()+1);
|
||||
sprintf(model.name, "Model%lu", radioData.models.size()+1);
|
||||
radioData.models.push_back(model);
|
||||
radioData.setCurrentModel(radioData.models.size() - 1);
|
||||
setModified();
|
||||
//modelEdit();
|
||||
}
|
||||
|
||||
void MdiChild::modelEdit()
|
||||
{
|
||||
int row = getCurrentRow();
|
||||
|
||||
@@ -21,18 +21,14 @@
|
||||
#ifndef _MDICHILD_H_
|
||||
#define _MDICHILD_H_
|
||||
|
||||
#include <QtGui>
|
||||
#include "eeprominterface.h"
|
||||
#include "modelslist.h"
|
||||
#include <QtGui>
|
||||
|
||||
namespace Ui {
|
||||
class MdiChild;
|
||||
}
|
||||
|
||||
#define ER9X_EEPROM_FILE_TYPE "ER9X_EEPROM_FILE"
|
||||
#define EEPE_EEPROM_FILE_HEADER "EEPE EEPROM FILE"
|
||||
#define EEPE_MODEL_FILE_HEADER "EEPE MODEL FILE"
|
||||
|
||||
class MdiChild : public QWidget
|
||||
{
|
||||
friend class ModelsListWidget;
|
||||
@@ -74,6 +70,7 @@ class MdiChild : public QWidget
|
||||
void showModelsListContextMenu(const QPoint & pos);
|
||||
void checkAndInitModel(int row);
|
||||
void generalEdit();
|
||||
void modelAdd();
|
||||
void modelEdit();
|
||||
void wizardEdit();
|
||||
void openModelEditWindow();
|
||||
@@ -94,7 +91,6 @@ class MdiChild : public QWidget
|
||||
private:
|
||||
bool maybeSave();
|
||||
void setCurrentFile(const QString & fileName);
|
||||
bool loadOtxFile(const QString & fileName);
|
||||
void doCopy(QByteArray * gmData);
|
||||
void doPaste(QByteArray * gmData, int index);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "modeledit.h"
|
||||
#include "../helpers.h"
|
||||
#include "helpers.h"
|
||||
#include "ui_modeledit.h"
|
||||
#include "setup.h"
|
||||
#include "heli.h"
|
||||
@@ -120,9 +120,14 @@ void ModelEdit::on_pushButton_clicked()
|
||||
|
||||
void ModelEdit::launchSimulation()
|
||||
{
|
||||
RadioData *simuData = new RadioData();
|
||||
RadioData * simuData = new RadioData();
|
||||
simuData->generalSettings = generalSettings;
|
||||
simuData->models[0] = model;
|
||||
if (simuData->models.size() == 0) {
|
||||
simuData->models.push_back(model);
|
||||
}
|
||||
else {
|
||||
simuData->models[0] = model;
|
||||
}
|
||||
startSimulation(this, *simuData, 0);
|
||||
delete simuData;
|
||||
}
|
||||
|
||||
@@ -252,13 +252,13 @@ void TreeModel::refresh()
|
||||
TreeItem * defaultCategoryItem = NULL;
|
||||
|
||||
if (IS_HORUS(board)) {
|
||||
for (unsigned int i = 0; i < radioData->categories.size(); i++) {
|
||||
for (unsigned i = 0; i < radioData->categories.size(); i++) {
|
||||
TreeItem * current = rootItem->appendChild(-1);
|
||||
current->setData(0, QString(radioData->categories[i].name));
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int i=0; i<(unsigned)GetCurrentFirmware()->getCapability(Models) && i<radioData->models.size(); i++) {
|
||||
for (unsigned i=0; i<radioData->models.size(); i++) {
|
||||
ModelData & model = radioData->models[i];
|
||||
int currentColumn = 0;
|
||||
TreeItem * current;
|
||||
|
||||
@@ -57,6 +57,9 @@ bool CategorizedStorageFormat::load(RadioData & radioData)
|
||||
setError(QObject::tr("Can't extract %1").arg(QString(line)));
|
||||
return false;
|
||||
}
|
||||
if ((int)radioData.models.size() <= modelIndex) {
|
||||
radioData.models.resize(modelIndex + 1);
|
||||
}
|
||||
if (!loadModelFromByteArray(radioData.models[modelIndex], modelBuffer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ bool SdcardFormat::writeFile(const QByteArray & data, const QString & filename)
|
||||
QString path = this->filename + "/" + filename;
|
||||
QFile file(path);
|
||||
if (!file.open(QFile::WriteOnly)) {
|
||||
setError(QObject::tr("Error opening file %1:\n%2.").arg(path).arg(file.errorString()));
|
||||
qDebug() << "File" << path << "write error";
|
||||
setError(QObject::tr("Error opening file %1 in write mode:\n%2.").arg(path).arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
file.write(data.data(), data.size());
|
||||
|
||||
Reference in New Issue
Block a user