diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 1acd6988f..ef6b2a2f1 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -88,18 +88,11 @@ add_subdirectory(thirdparty/qxtcommandoptions) set(common_SRCS eeprominterface.cpp - firmwares/th9x/th9xeeprom.cpp # TODO not needed - firmwares/th9x/th9xinterface.cpp firmwares/er9x/er9xeeprom.cpp firmwares/er9x/er9xinterface.cpp - firmwares/gruvin9x/gruvin9xeeprom.cpp - firmwares/gruvin9x/gruvin9xinterface.cpp firmwares/ersky9x/ersky9xeeprom.cpp firmwares/ersky9x/ersky9xinterface.cpp firmwares/opentx/opentxeeprom.cpp - firmwares/opentx/open9xStockeeprom.cpp - firmwares/opentx/open9xGruvin9xeeprom.cpp - firmwares/opentx/open9xSky9xeeprom.cpp firmwares/opentx/opentxinterface.cpp ) diff --git a/companion/src/companion.cpp b/companion/src/companion.cpp index 2786f85e2..039250e91 100644 --- a/companion/src/companion.cpp +++ b/companion/src/companion.cpp @@ -1,168 +1,127 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if defined(JOYSTICKS) || defined(SIMU_AUDIO) - #include - #undef main -#endif -#include "mainwindow.h" -#include "version.h" -#include "eeprominterface.h" -#include "appdata.h" - -#if defined WIN32 || !defined __GNUC__ -#include -#define sleep(x) Sleep(x*1000) -#else -#include -#endif - -#ifdef __APPLE__ -#include - -class MyProxyStyle : public QProxyStyle - { - public: - void polish ( QWidget * w ) { - QMenu* mn = dynamic_cast(w); - QPushButton* pb = dynamic_cast(w); - if(!(mn || pb) && !w->testAttribute(Qt::WA_MacNormalSize)) - w->setAttribute(Qt::WA_MacSmallSize); - } - }; -#endif - -int main(int argc, char *argv[]) -{ - Q_INIT_RESOURCE(companion); - - QApplication app(argc, argv); - app.setApplicationName("OpenTX Companion"); - app.setOrganizationName("OpenTX"); - app.setOrganizationDomain("open-tx.org"); - app.setAttribute(Qt::AA_DontShowIconsInMenus, false); - - g.init(); - - QStringList strl = QApplication::arguments(); - if (strl.contains("--version")) { - printf("%s\n", VERSION); - fflush(stdout); - exit(0); - } - -#ifdef __APPLE__ - app.setStyle(new MyProxyStyle); -#endif - - QTranslator companionTranslator; - companionTranslator.load(":/companion_" + g.locale()); - QTranslator qtTranslator; - qtTranslator.load((QString)"qt_" + g.locale().left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); - app.installTranslator(&companionTranslator); - app.installTranslator(&qtTranslator); - - // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); - -#if defined(JOYSTICKS) || defined(SIMU_AUDIO) - uint32_t sdlFlags = 0; - #ifdef JOYSTICKS - sdlFlags |= SDL_INIT_JOYSTICK; - #endif - #ifdef SIMU_AUDIO - sdlFlags |= SDL_INIT_AUDIO; - #endif - if (SDL_Init(sdlFlags) < 0) { - fprintf(stderr, "ERROR: couldn't initialize SDL: %s\n", SDL_GetError()); - } -#endif - - registerEEpromInterfaces(); - registerOpenTxFirmwares(); - registerSimulators(); - - if (g.profile[g.id()].fwType().isEmpty()){ - g.profile[g.id()].fwType(default_firmware_variant->getId()); - g.profile[g.id()].fwName(""); - } - - QString splashScreen; - splashScreen = ":/images/splash.png"; - - QPixmap pixmap = QPixmap(splashScreen); - QSplashScreen *splash = new QSplashScreen(pixmap); - - current_firmware_variant = GetFirmware(g.profile[g.id()].fwType()); - - MainWindow *mainWin = new MainWindow(); - if (g.showSplash()) { - splash->show(); - QTimer::singleShot(1000*SPLASH_TIME, splash, SLOT(close())); - QTimer::singleShot(1000*SPLASH_TIME, mainWin, SLOT(show())); - } - else { - mainWin->show(); - } - - int result = app.exec(); - - delete splash; - delete mainWin; - - unregisterSimulators(); - unregisterOpenTxFirmwares(); - unregisterEEpromInterfaces(); - -#if defined(JOYSTICKS) || defined(SIMU_AUDIO) - SDL_Quit(); -#endif - - return result; -} +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(JOYSTICKS) || defined(SIMU_AUDIO) + #include + #undef main +#endif +#include "mainwindow.h" +#include "version.h" +#include "eeprominterface.h" +#include "appdata.h" + +#if defined WIN32 || !defined __GNUC__ +#include +#define sleep(x) Sleep(x*1000) +#else +#include +#endif + +#ifdef __APPLE__ +#include + +class MyProxyStyle : public QProxyStyle + { + public: + void polish ( QWidget * w ) { + QMenu* mn = dynamic_cast(w); + QPushButton* pb = dynamic_cast(w); + if(!(mn || pb) && !w->testAttribute(Qt::WA_MacNormalSize)) + w->setAttribute(Qt::WA_MacSmallSize); + } + }; +#endif + +int main(int argc, char *argv[]) +{ + Q_INIT_RESOURCE(companion); + + QApplication app(argc, argv); + app.setApplicationName("OpenTX Companion"); + app.setOrganizationName("OpenTX"); + app.setOrganizationDomain("open-tx.org"); + app.setAttribute(Qt::AA_DontShowIconsInMenus, false); + + g.init(); + + QStringList strl = QApplication::arguments(); + if (strl.contains("--version")) { + printf("%s\n", VERSION); + fflush(stdout); + exit(0); + } + +#ifdef __APPLE__ + app.setStyle(new MyProxyStyle); +#endif + + QTranslator companionTranslator; + companionTranslator.load(":/companion_" + g.locale()); + QTranslator qtTranslator; + qtTranslator.load((QString)"qt_" + g.locale().left(2), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + app.installTranslator(&companionTranslator); + app.installTranslator(&qtTranslator); + + // QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); + +#if defined(JOYSTICKS) || defined(SIMU_AUDIO) + uint32_t sdlFlags = 0; + #ifdef JOYSTICKS + sdlFlags |= SDL_INIT_JOYSTICK; + #endif + #ifdef SIMU_AUDIO + sdlFlags |= SDL_INIT_AUDIO; + #endif + if (SDL_Init(sdlFlags) < 0) { + fprintf(stderr, "ERROR: couldn't initialize SDL: %s\n", SDL_GetError()); + } +#endif + + registerEEpromInterfaces(); + registerOpenTxFirmwares(); + registerSimulators(); + + if (g.profile[g.id()].fwType().isEmpty()){ + g.profile[g.id()].fwType(default_firmware_variant->getId()); + g.profile[g.id()].fwName(""); + } + + QString splashScreen; + splashScreen = ":/images/splash.png"; + + QPixmap pixmap = QPixmap(splashScreen); + QSplashScreen *splash = new QSplashScreen(pixmap); + + current_firmware_variant = GetFirmware(g.profile[g.id()].fwType()); + + MainWindow *mainWin = new MainWindow(); + if (g.showSplash()) { + splash->show(); + QTimer::singleShot(1000*SPLASH_TIME, splash, SLOT(close())); + QTimer::singleShot(1000*SPLASH_TIME, mainWin, SLOT(show())); + } + else { + mainWin->show(); + } + + int result = app.exec(); + + delete splash; + delete mainWin; + + unregisterSimulators(); + unregisterOpenTxFirmwares(); + unregisterEEpromInterfaces(); + +#if defined(JOYSTICKS) || defined(SIMU_AUDIO) + SDL_Quit(); +#endif + + return result; +} diff --git a/companion/src/comparedialog.cpp b/companion/src/comparedialog.cpp index 4da955162..5e5ac8398 100644 --- a/companion/src/comparedialog.cpp +++ b/companion/src/comparedialog.cpp @@ -17,7 +17,7 @@ class DragDropHeader { } bool general_settings; uint8_t models_count; - uint8_t models[C9X_MAX_MODELS]; + uint8_t models[CPN_MAX_MODELS]; }; CompareDialog::CompareDialog(QWidget * parent, Firmware * firmware): diff --git a/companion/src/comparedialog.h b/companion/src/comparedialog.h index efdec3f1d..2074701c9 100644 --- a/companion/src/comparedialog.h +++ b/companion/src/comparedialog.h @@ -1,41 +1,41 @@ -#ifndef _COMPAREDIALOG_H -#define _COMPAREDIALOG_H - -#include -#include "multimodelprinter.h" - -namespace Ui { - class CompareDialog; -} - -class CompareDialog : public QDialog -{ - Q_OBJECT - - public: - CompareDialog(QWidget *parent, Firmware * firmware); - ~CompareDialog(); - - protected: - MultiModelPrinter multimodelprinter; - ModelData model1; - ModelData model2; - bool model1Valid; - bool model2Valid; - Ui::CompareDialog * ui; - - protected slots: - void on_printButton_clicked(); - void on_printFileButton_clicked(); - - protected: - void closeEvent(QCloseEvent * event); - bool handleDroppedModel(const QMimeData * mimeData, ModelData & model, QLabel * label); - void dropEvent(QDropEvent *event); - void dragMoveEvent(QDragMoveEvent *event); - void dragEnterEvent(QDragEnterEvent *event); - void dragLeaveEvent(QDragLeaveEvent *event); - void printDiff(); -}; - -#endif // _COMPAREDIALOG_H +#ifndef _COMPAREDIALOG_H +#define _COMPAREDIALOG_H + +#include +#include "multimodelprinter.h" + +namespace Ui { + class CompareDialog; +} + +class CompareDialog : public QDialog +{ + Q_OBJECT + + public: + CompareDialog(QWidget *parent, Firmware * firmware); + ~CompareDialog(); + + protected: + MultiModelPrinter multimodelprinter; + ModelData model1; + ModelData model2; + bool model1Valid; + bool model2Valid; + Ui::CompareDialog * ui; + + protected slots: + void on_printButton_clicked(); + void on_printFileButton_clicked(); + + protected: + void closeEvent(QCloseEvent * event); + bool handleDroppedModel(const QMimeData * mimeData, ModelData & model, QLabel * label); + void dropEvent(QDropEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dragEnterEvent(QDragEnterEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void printDiff(); +}; + +#endif // _COMPAREDIALOG_H diff --git a/companion/src/constants.h b/companion/src/constants.h index 79adce4e7..8599413ad 100644 --- a/companion/src/constants.h +++ b/companion/src/constants.h @@ -17,28 +17,26 @@ enum BoardEnum { BOARD_HORUS }; -#define C9X_MAX_MODELS 60 -#define C9X_MAX_TIMERS 3 -#define C9X_MAX_FLIGHT_MODES 9 -#define C9X_MAX_MIXERS 64 -#define C9X_MAX_INPUTS 32 -#define C9X_MAX_EXPOS 64 -#define C9X_MAX_CURVES 32 -#define C9X_MAX_POINTS 17 -#define C9X_MAX_GVARS 9 -#define C9X_MAX_ENCODERS 2 -#define C9X_NUM_CHNOUT 32 // number of real output channels -#define C9X_NUM_CSW 64 // number of custom switches -#define C9X_MAX_CUSTOM_FUNCTIONS 64 // number of functions assigned to switches -#define C9X_NUM_MODULES 2 -#define NUM_STICKS 4 -#define NUM_AUX_TRIMS 2 -#define BOARD_9X_NUM_POTS 3 -#define C9X_NUM_POTS 8 -#define NUM_CAL_PPM 4 -#define NUM_CYC 3 -#define C9X_NUM_SWITCHES 32 -#define C9X_NUM_KEYS 32 +#define CPN_MAX_MODELS 60 +#define CPN_MAX_TIMERS 3 +#define CPN_MAX_FLIGHT_MODES 9 +#define CPN_MAX_MIXERS 64 +#define CPN_MAX_INPUTS 32 +#define CPN_MAX_EXPOS 64 +#define CPN_MAX_CURVES 32 +#define CPN_MAX_POINTS 17 +#define CPN_MAX_GVARS 9 +#define CPN_MAX_ENCODERS 2 +#define CPN_MAX_CHNOUT 32 // number of real output channels +#define CPN_MAX_CSW 64 // number of custom switches +#define CPN_MAX_CUSTOM_FUNCTIONS 64 // number of functions assigned to switches +#define CPN_MAX_MODULES 2 +#define CPN_MAX_STICKS 4 +#define CPN_MAX_AUX_TRIMS 2 +#define CPN_MAX_POTS 8 +#define CPN_MAX_CYC 3 +#define CPN_MAX_SWITCHES 32 +#define CPN_MAX_KEYS 32 const char * const ARROW_LEFT = "\xE2\x86\x90"; const char * const ARROW_UP = "\xE2\x86\x91"; diff --git a/companion/src/eepromimportexport.h b/companion/src/eepromimportexport.h index 08f90a72e..9c1a45a6a 100644 --- a/companion/src/eepromimportexport.h +++ b/companion/src/eepromimportexport.h @@ -1,19 +1,3 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ - #ifndef eeprom_importexport_h #define eeprom_importexport_h diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index 467df8992..010e9fb2e 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -5,11 +5,9 @@ #include #include "eeprominterface.h" #include "firmwares/er9x/er9xinterface.h" -#include "firmwares/th9x/th9xinterface.h" -#include "firmwares/gruvin9x/gruvin9xinterface.h" +#include "firmwares/ersky9x/ersky9xinterface.h" #include "firmwares/opentx/opentxinterface.h" #include "firmwares/opentx/opentxeeprom.h" -#include "firmwares/ersky9x/ersky9xinterface.h" #include "appdata.h" #include "helpers.h" #include "wizarddata.h" @@ -24,6 +22,8 @@ const uint8_t chout_ar[] = { // First number is 0..23 -> template setup, Second 4,1,2,3 , 4,1,3,2 , 4,2,1,3 , 4,2,3,1 , 4,3,1,2 , 4,3,2,1 }; +static const char specialCharsTab[] = "_-.,"; + void setEEPROMString(char *dst, const char *src, int size) { memcpy(dst, src, size); @@ -47,6 +47,52 @@ void getEEPROMString(char *dst, const char *src, int size) } } +int8_t char2idx(char c) +{ + if (c==' ') return 0; + if (c>='A' && c<='Z') return 1+c-'A'; + if (c>='a' && c<='z') return -1-c+'a'; + if (c>='0' && c<='9') return 27+c-'0'; + for (int8_t i=0;;i++) { + char cc = specialCharsTab[i]; + if (cc==0) return 0; + if (cc==c) return 37+i; + } +} + +#define ZCHAR_MAX 40 +char idx2char(int8_t idx) +{ + if (idx == 0) return ' '; + if (idx < 0) { + if (idx > -27) return 'a' - idx - 1; + idx = -idx; + } + if (idx < 27) return 'A' + idx - 1; + if (idx < 37) return '0' + idx - 27; + if (idx <= ZCHAR_MAX) return specialCharsTab[idx-37]; + return ' '; +} + +void setEEPROMZString(char *dst, const char *src, int size) +{ + for (int i=size-1; i>=0; i--) + dst[i] = char2idx(src[i]); +} + +void getEEPROMZString(char *dst, const char *src, int size) +{ + for (int i=size-1; i>=0; i--) + dst[i] = idx2char(src[i]); + dst[size] = '\0'; + for (int i=size-1; i>=0; i--) { + if (dst[i] == ' ') + dst[i] = '\0'; + else + break; + } +} + float ValToTim(int value) { return ((value < -109 ? 129+value : (value < 7 ? (113+value)*5 : (53+value)*10))/10.0); @@ -525,15 +571,15 @@ QString RawSource::toString(const ModelData * model) const bool RawSource::isPot() const { return (type == SOURCE_TYPE_STICK && - index >= NUM_STICKS && - index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots)); + index >= CPN_MAX_STICKS && + index < CPN_MAX_STICKS+GetCurrentFirmware()->getCapability(Pots)); } bool RawSource::isSlider() const { return (type == SOURCE_TYPE_STICK && - index >= NUM_STICKS+GetCurrentFirmware()->getCapability(Pots) && - index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders)); + index >= CPN_MAX_STICKS+GetCurrentFirmware()->getCapability(Pots) && + index < CPN_MAX_STICKS+GetCurrentFirmware()->getCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders)); } QString RawSwitch::toString() const @@ -804,7 +850,7 @@ void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox b->setCurrentIndex(value); } if (model && IS_ARM(board)) { - for (int i=0; isensorData[i].isAvailable()) { RawSource item = RawSource(SOURCE_TYPE_TELEMETRY, 3*i); b->addItem(item.toString(model), val+i); @@ -1005,7 +1051,7 @@ GeneralSettings::GeneralSettings() contrast = 25; vBatWarn = 90; - for (int i=0; i= NUM_STICKS) + if (channel >= CPN_MAX_STICKS) return -1; else return chout_ar[4*templateSetup + channel] - 1; @@ -1235,14 +1281,14 @@ ModelData & ModelData::operator = (const ModelData & src) ExpoData * ModelData::insertInput(const int idx) { - memmove(&expoData[idx+1], &expoData[idx], (C9X_MAX_EXPOS-(idx+1))*sizeof(ExpoData)); + memmove(&expoData[idx+1], &expoData[idx], (CPN_MAX_EXPOS-(idx+1))*sizeof(ExpoData)); expoData[idx].clear(); return &expoData[idx]; } bool ModelData::isInputValid(const unsigned int idx) const { - for (int i=0; imode == 0) break; if (expo->chn == idx) @@ -1253,7 +1299,7 @@ bool ModelData::isInputValid(const unsigned int idx) const bool ModelData::hasExpos(uint8_t inputIdx) const { - for (int i=0; i ModelData::expos(int input) const { QVector result; - for (int i=0; ichn==input && ed->mode!=0) { result << ed; @@ -1288,7 +1334,7 @@ QVector ModelData::expos(int input) const QVector ModelData::mixes(int channel) const { QVector result; - for (int i=0; idestCh == channel+1) { result << md; @@ -1301,12 +1347,12 @@ void ModelData::removeInput(const int idx) { unsigned int chn = expoData[idx].chn; - memmove(&expoData[idx], &expoData[idx+1], (C9X_MAX_EXPOS-(idx+1))*sizeof(ExpoData)); - expoData[C9X_MAX_EXPOS-1].clear(); + memmove(&expoData[idx], &expoData[idx+1], (CPN_MAX_EXPOS-(idx+1))*sizeof(ExpoData)); + expoData[CPN_MAX_EXPOS-1].clear(); //also remove input name if removing last line for this input bool found = false; - for (int i=0; igetCapability(VirtualInputs)) { - for (int i=0; igetBoard())) { - for (int i=0; ichn = i; expo->mode = INPUT_MODE_BOTH; @@ -1433,7 +1479,7 @@ void ModelData::setDefaultMixes(const GeneralSettings & settings) setDefaultInputs(settings); } - for (int i=0; idestCh = i+1; mix->weight = 100; @@ -1451,7 +1497,7 @@ void ModelData::setDefaultValues(unsigned int id, const GeneralSettings & settin clear(); used = true; sprintf(name, "MODEL%02d", id+1); - for (int i=0; i1024 && i1024 && i= phaseIdx) nextPhase += 1; phaseIdx = nextPhase; @@ -1498,7 +1544,7 @@ int ModelData::getGVarFieldValue(int phaseIdx, int gvarIdx) void ModelData::setTrimValue(int phaseIdx, int trimIdx, int value) { - for (uint8_t i=0; i - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ - #ifndef eeprom_interface_h #define eeprom_interface_h @@ -434,7 +418,7 @@ class CurveData { CurveType type; bool smooth; int count; - CurvePoint points[C9X_MAX_POINTS]; + CurvePoint points[CPN_MAX_POINTS]; char name[6+1]; }; @@ -467,7 +451,7 @@ enum MltpxValue { class MixData { public: MixData() { clear(); } - unsigned int destCh; // 1..C9X_NUM_CHNOUT + unsigned int destCh; // 1..CPN_MAX_CHNOUT RawSource srcRaw; int weight; RawSwitch swtch; @@ -544,7 +528,7 @@ class LogicalSwitchData { // Logical Switches data enum AssignFunc { FuncOverrideCH1 = 0, - FuncOverrideCH32 = FuncOverrideCH1+C9X_NUM_CHNOUT-1, + FuncOverrideCH32 = FuncOverrideCH1+CPN_MAX_CHNOUT-1, FuncTrainer, FuncTrainerRUD, FuncTrainerELE, @@ -569,7 +553,7 @@ enum AssignFunc { FuncBackgroundMusic, FuncBackgroundMusicPause, FuncAdjustGV1, - FuncAdjustGVLast = FuncAdjustGV1+C9X_MAX_GVARS-1, + FuncAdjustGVLast = FuncAdjustGV1+CPN_MAX_GVARS-1, FuncSetFailsafeInternalModule, FuncSetFailsafeExternalModule, FuncRangeCheckInternalModule, @@ -613,15 +597,15 @@ class CustomFunctionData { // Function Switches data class FlightModeData { public: FlightModeData() { clear(0); } - int trimMode[NUM_STICKS+NUM_AUX_TRIMS]; - int trimRef[NUM_STICKS+NUM_AUX_TRIMS]; - int trim[NUM_STICKS+NUM_AUX_TRIMS]; + int trimMode[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS]; + int trimRef[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS]; + int trim[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS]; RawSwitch swtch; char name[10+1]; unsigned int fadeIn; unsigned int fadeOut; - int rotaryEncoders[C9X_MAX_ENCODERS]; - int gvars[C9X_MAX_GVARS]; + int rotaryEncoders[CPN_MAX_ENCODERS]; + int gvars[CPN_MAX_GVARS]; void clear(const int phase); }; @@ -877,7 +861,7 @@ class ModuleData { unsigned int channelsStart; int channelsCount; // 0=8 channels unsigned int failsafeMode; - int failsafeChannels[C9X_NUM_CHNOUT]; + int failsafeChannels[CPN_MAX_CHNOUT]; struct { @@ -901,18 +885,18 @@ class ModuleData { QString polarityToString() const { return ppm.pulsePol ? QObject::tr("Positive") : QObject::tr("Negative"); } // TODO ModelPrinter }; -#define C9X_MAX_SCRIPTS 7 -#define C9X_MAX_SCRIPT_INPUTS 10 +#define CPN_MAX_SCRIPTS 7 +#define CPN_MAX_SCRIPT_INPUTS 10 class ScriptData { public: ScriptData() { clear(); } char filename[10+1]; char name[10+1]; - int inputs[C9X_MAX_SCRIPT_INPUTS]; + int inputs[CPN_MAX_SCRIPT_INPUTS]; void clear() { memset(this, 0, sizeof(ScriptData)); } }; -#define C9X_MAX_SENSORS 32 +#define CPN_MAX_SENSORS 32 class SensorData { public: @@ -1049,7 +1033,7 @@ class ModelData { bool used; char name[15+1]; - TimerData timers[C9X_MAX_TIMERS]; + TimerData timers[CPN_MAX_TIMERS]; bool noGlobalFunctions; bool thrTrim; // Enable Throttle Trim int trimInc; // Trim Increments @@ -1061,27 +1045,27 @@ class ModelData { bool extendedLimits; // TODO xml bool extendedTrims; bool throttleReversed; - FlightModeData flightModeData[C9X_MAX_FLIGHT_MODES]; - MixData mixData[C9X_MAX_MIXERS]; - LimitData limitData[C9X_NUM_CHNOUT]; + FlightModeData flightModeData[CPN_MAX_FLIGHT_MODES]; + MixData mixData[CPN_MAX_MIXERS]; + LimitData limitData[CPN_MAX_CHNOUT]; - char inputNames[C9X_MAX_INPUTS][4+1]; - ExpoData expoData[C9X_MAX_EXPOS]; + char inputNames[CPN_MAX_INPUTS][4+1]; + ExpoData expoData[CPN_MAX_EXPOS]; - CurveData curves[C9X_MAX_CURVES]; - LogicalSwitchData logicalSw[C9X_NUM_CSW]; - CustomFunctionData customFn[C9X_MAX_CUSTOM_FUNCTIONS]; + CurveData curves[CPN_MAX_CURVES]; + LogicalSwitchData logicalSw[CPN_MAX_CSW]; + CustomFunctionData customFn[CPN_MAX_CUSTOM_FUNCTIONS]; SwashRingData swashRingData; unsigned int thrTraceSrc; uint64_t switchWarningStates; unsigned int switchWarningEnable; unsigned int potsWarningMode; - bool potsWarningEnabled[C9X_NUM_POTS]; - int potPosition[C9X_NUM_POTS]; + bool potsWarningEnabled[CPN_MAX_POTS]; + int potPosition[CPN_MAX_POTS]; bool displayChecklist; // TODO structure - char gvars_names[C9X_MAX_GVARS][6+1]; - bool gvars_popups[C9X_MAX_GVARS]; + char gvars_names[CPN_MAX_GVARS][6+1]; + bool gvars_popups[CPN_MAX_GVARS]; MavlinkData mavlink; unsigned int telemetryProtocol; FrSkyData frsky; @@ -1090,11 +1074,11 @@ class ModelData { unsigned int trainerMode; - ModuleData moduleData[C9X_NUM_MODULES+1/*trainer*/]; + ModuleData moduleData[CPN_MAX_MODULES+1/*trainer*/]; - ScriptData scriptData[C9X_MAX_SCRIPTS]; + ScriptData scriptData[CPN_MAX_SCRIPTS]; - SensorData sensorData[C9X_MAX_SENSORS]; + SensorData sensorData[CPN_MAX_SENSORS]; unsigned int toplcdTimer; @@ -1170,9 +1154,9 @@ class GeneralSettings { unsigned int version; unsigned int variant; - int calibMid[NUM_STICKS+C9X_NUM_POTS]; - int calibSpanNeg[NUM_STICKS+C9X_NUM_POTS]; - int calibSpanPos[NUM_STICKS+C9X_NUM_POTS]; + int calibMid[CPN_MAX_STICKS+CPN_MAX_POTS]; + int calibSpanNeg[CPN_MAX_STICKS+CPN_MAX_POTS]; + int calibSpanPos[CPN_MAX_STICKS+CPN_MAX_POTS]; unsigned int currModel; // 0..15 unsigned int contrast; unsigned int vBatWarn; @@ -1250,7 +1234,7 @@ class GeneralSettings { unsigned int switchUnlockStates; unsigned int hw_uartMode; unsigned int backlightColor; - CustomFunctionData customFn[C9X_MAX_CUSTOM_FUNCTIONS]; + CustomFunctionData customFn[CPN_MAX_CUSTOM_FUNCTIONS]; char switchName[18][3+1]; unsigned int switchConfig[18]; char stickName[4][3+1]; @@ -1279,7 +1263,7 @@ class GeneralSettings { class RadioData { public: GeneralSettings generalSettings; - ModelData models[C9X_MAX_MODELS]; + ModelData models[CPN_MAX_MODELS]; }; enum Capability { @@ -1471,8 +1455,8 @@ inline void applyStickModeToModel(ModelData &model, unsigned int mode) ModelData model_copy = model; // trims - for (int p=0; p -#include -#include "helpers.h" -#include "gruvin9xeeprom.h" -#include - -#define EEPROM_VER 106 - -extern void getEEPROMZString(char *dst, const char *src, int size); - -RawSwitch gruvin9xToSwitch(int8_t sw) -{ - if (sw == 0) - return RawSwitch(SWITCH_TYPE_NONE); - else if (sw <= 9) - return RawSwitch(SWITCH_TYPE_SWITCH, sw); - else - return RawSwitch(SWITCH_TYPE_VIRTUAL, sw > 0 ? sw-9 : sw+9); -} - -t_Gruvin9xTrainerMix_v103::operator TrainerMix() -{ - TrainerMix c9x; - c9x.src = srcChn; - c9x.swtch = gruvin9xToSwitch(swtch); - c9x.weight = (25 * studWeight) / 8; - c9x.mode = mode; - return c9x; -} - -t_Gruvin9xTrainerMix_v104::operator TrainerMix() -{ - TrainerMix c9x; - c9x.src = srcChn; - c9x.weight = studWeight; - c9x.mode = mode; - return c9x; -} - -t_Gruvin9xTrainerData_v103::operator TrainerData () -{ - TrainerData c9x; - for (int i=0; i 6) { - c9x.curve.type = CurveReference::CURVE_REF_CUSTOM; - c9x.curve.value = curve - 6; - } - else if (curve > 0) { - c9x.curve.type = CurveReference::CURVE_REF_FUNC; - c9x.curve.value = curve; - } - return c9x; -} - -t_Gruvin9xLimitData::t_Gruvin9xLimitData() -{ - memset(this, 0, sizeof(t_Gruvin9xLimitData)); -} - -t_Gruvin9xLimitData::operator LimitData () -{ - LimitData c9x; - c9x.min = 10*(min-100); - c9x.max = 10*(max+100); - c9x.revert = revert; - c9x.offset = offset; - return c9x; -} - -t_Gruvin9xMixData::t_Gruvin9xMixData() -{ - memset(this, 0, sizeof(t_Gruvin9xMixData)); -} - -t_Gruvin9xMixData::operator MixData () -{ - MixData c9x; - c9x.destCh = destCh; - c9x.weight = weight; - c9x.swtch = gruvin9xToSwitch(swtch); - - if (srcRaw == 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); - } - else if (srcRaw <= 7) { - c9x.srcRaw = RawSource(SOURCE_TYPE_STICK, srcRaw-1); - } - else if (srcRaw == 8) { - c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); - } - else if (srcRaw == 9) { - if (swtch < 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, -swtch - 1); - c9x.weight = -weight; - } - else { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, swtch - 1); - } - if (mltpx != MLTPX_REP) - c9x.swtch = RawSwitch(SWITCH_TYPE_NONE); - } - else if (srcRaw <= 12) { - c9x.srcRaw = RawSource(SOURCE_TYPE_CYC, srcRaw-10); - } - else if (srcRaw <= 20) { - c9x.srcRaw = RawSource(SOURCE_TYPE_PPM, srcRaw-13); - } - else { - c9x.srcRaw = RawSource(SOURCE_TYPE_CH, srcRaw-21); - } - - c9x.delayUp = delayUp; - c9x.delayDown = delayDown; - c9x.speedUp = speedUp; - c9x.speedDown = speedDown; - c9x.carryTrim = carryTrim; - c9x.mltpx = (MltpxValue)mltpx; - c9x.mixWarn = mixWarn; - c9x.sOffset = sOffset; - - if (curve > 6) { - c9x.curve.type = CurveReference::CURVE_REF_CUSTOM; - c9x.curve.value = curve - 6; - } - else if (curve > 0) { - c9x.curve.type = CurveReference::CURVE_REF_FUNC; - c9x.curve.value = curve; - } - - return c9x; -} - -RawSource gruvin9xToSource(int8_t value) -{ - if (value == 0) { - return RawSource(SOURCE_TYPE_NONE); - } - else if (value <= 7) { - return RawSource(SOURCE_TYPE_STICK, value - 1); - } - else if (value == 8) { - return RawSource(SOURCE_TYPE_MAX); - } - else if (value == 9) { - return RawSource(SOURCE_TYPE_MAX); - } - else if (value <= 12) { - return RawSource(SOURCE_TYPE_CYC, value-10); - } - else if (value <= 20) { - return RawSource(SOURCE_TYPE_PPM, value-13); - } - else if (value <= 36) { - return RawSource(SOURCE_TYPE_CH, value-21); - } - else { - return RawSource(SOURCE_TYPE_TELEMETRY, value-36); - } -} - -Gruvin9xLogicalSwitchData::operator LogicalSwitchData () -{ - LogicalSwitchData c9x; - c9x.func = func; - c9x.val1 = v1; - c9x.val2 = v2; - - if ((c9x.func >= LS_FN_VPOS && c9x.func <= LS_FN_ANEG) || c9x.func >= LS_FN_EQUAL) { - c9x.val1 = gruvin9xToSource(v1).toValue(); - } - - if (c9x.func >= LS_FN_EQUAL) { - c9x.val2 = gruvin9xToSource(v2).toValue(); - } - - if (c9x.func >= LS_FN_AND && c9x.func <= LS_FN_XOR) { - c9x.val1 = gruvin9xToSwitch(v1).toValue(); - c9x.val2 = gruvin9xToSwitch(v2).toValue(); - } - - return c9x; -} - -Gruvin9xCustomFunctionData::operator CustomFunctionData () -{ - CustomFunctionData c9x; - c9x.swtch = gruvin9xToSwitch(swtch); - c9x.func = (AssignFunc)(func + G9X_NUM_CHNOUT); - return c9x; -} - -t_Gruvin9xSwashRingData::t_Gruvin9xSwashRingData() -{ - memset(this, 0, sizeof(t_Gruvin9xSwashRingData)); -} - -t_Gruvin9xSwashRingData::operator SwashRingData () -{ - SwashRingData c9x; - c9x.elevatorWeight = invertELE ? -100 : 100; - c9x.aileronWeight = invertAIL ? -100 : 100; - c9x.collectiveWeight = invertCOL ? -100 : 100; - c9x.type = type; - c9x.collectiveSource = gruvin9xToSource(collectiveSource); - c9x.value = value; - return c9x; -} - -t_Gruvin9xFlightModeData_v102::operator FlightModeData () -{ - FlightModeData c9x; - for (int i=0; i> (2*i)) & 0x03); - c9x.swtch = gruvin9xToSwitch(swtch); - getEEPROMZString(c9x.name, name, sizeof(name)); - c9x.fadeIn = fadeIn; - c9x.fadeOut = fadeOut; - return c9x; -} - -extern RawSwitch getEr9xTimerMode(int mode); - -t_Gruvin9xTimerData::operator TimerData () -{ - TimerData c9x; - c9x.mode = getEr9xTimerMode(mode); - c9x.val = val; - return c9x; -} - -t_Gruvin9xFrSkyChannelData::t_Gruvin9xFrSkyChannelData() -{ - memset(this, 0, sizeof(t_Gruvin9xFrSkyChannelData)); -} - -t_Gruvin9xFrSkyChannelData::operator FrSkyChannelData () -{ - FrSkyChannelData c9x; - c9x.ratio = ratio; - c9x.alarms[0].value = alarms_value[0]; - c9x.alarms[0].level = alarms_level & 3; - c9x.alarms[0].greater = alarms_greater & 1; - c9x.alarms[1].value = alarms_value[1]; - c9x.alarms[1].level = (alarms_level >> 2) & 3; - c9x.alarms[1].greater = (alarms_greater >> 1) & 1; - c9x.type = type; - return c9x; -} - -t_Gruvin9xFrSkyData::t_Gruvin9xFrSkyData() -{ - memset(this, 0, sizeof(t_Gruvin9xFrSkyData)); -} - -t_Gruvin9xFrSkyData::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - return c9x; -} - -t_Gruvin9xModelData_v102::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMString(c9x.name, name, sizeof(name)); - c9x.timers[0] = timer1; - c9x.timers[1] = timer2; - - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_SILV_A; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_SILV_B; - break; - case 5: - c9x.moduleData[0].protocol = PULSES_SILV_C; - break; - case 6: - c9x.moduleData[0].protocol = PULSES_CTP1009; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc-2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - for (int i=0; i 125) { - c9x.flightModeData[i].trimRef[j] = 0; - c9x.flightModeData[i].trim[j] = 0; - } - else if (flightModeData[i].trim[j] < -125) { - c9x.flightModeData[i].trimRef[j] = 129 + flightModeData[i].trim[j]; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - else { - c9x.flightModeData[i].trim[j] += subtrim[j]; - } - } - } - for (int i=0; i 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ -#ifndef gruvin9xeeprom_h -#define gruvin9xeeprom_h - -#include -#include "eeprominterface.h" -#define GR9X_MAX_CSFUNC 13 - -PACK(typedef struct t_Gruvin9xTrainerMix_v103 { - uint8_t srcChn:3; //0-7 = ch1-8 - int8_t swtch:5; - int8_t studWeight:6; - uint8_t mode:2; //off,add-mode,subst-mode - - operator TrainerMix(); - t_Gruvin9xTrainerMix_v103() { memset(this, 0, sizeof(t_Gruvin9xTrainerMix_v103)); } - -}) Gruvin9xTrainerMix_v103; // - -PACK(typedef struct t_Gruvin9xTrainerMix_v104 { - uint8_t srcChn:6; // 0-7 = ch1-8 - uint8_t mode:2; // off,add-mode,subst-mode - int8_t studWeight; - - operator TrainerMix(); - t_Gruvin9xTrainerMix_v104() { memset(this, 0, sizeof(t_Gruvin9xTrainerMix_v104)); } -}) Gruvin9xTrainerMix_v104; // - -PACK(typedef struct t_Gruvin9xTrainerData_v103 { - int16_t calib[4]; - Gruvin9xTrainerMix_v103 mix[4]; - - operator TrainerData(); -}) Gruvin9xTrainerData_v103; - -PACK(typedef struct t_Gruvin9xTrainerData_v104 { - int16_t calib[4]; - Gruvin9xTrainerMix_v104 mix[4]; - - operator TrainerData(); - t_Gruvin9xTrainerData_v104() { memset(this, 0, sizeof(t_Gruvin9xTrainerData_v104)); } -}) Gruvin9xTrainerData_v104; - -PACK(typedef struct t_Gruvin9xFrSkyRSSIAlarm { - uint8_t level:2; - int8_t value:6; -}) Gruvin9xFrSkyRSSIAlarm; - -PACK(typedef struct t_Gruvin9xGeneral_v103 { - uint8_t myVers; - int16_t calibMid[7]; - int16_t calibSpanNeg[7]; - int16_t calibSpanPos[7]; - uint16_t chkSum; - uint8_t currModel; //0..15 - uint8_t contrast; - uint8_t vBatWarn; - int8_t txVoltageCalibration; - int8_t lightSw; - Gruvin9xTrainerData_v103 trainer; - uint8_t view; //index of subview in main scrren - uint8_t disableThrottleWarning:1; - int8_t switchWarning:2; // -1=down, 0=off, 1=up - uint8_t beeperVal:3; - uint8_t disableMemoryWarning:1; - uint8_t disableAlarmWarning:1; - uint8_t stickMode; - uint8_t inactivityTimer; - uint8_t throttleReversed:1; - uint8_t minuteBeep:1; - uint8_t preBeep:1; - uint8_t flashBeep:1; - uint8_t disableSplashScreen:1; - uint8_t enableTelemetryAlarm:1; // 0=no, 1=yes (Sound alarm when there's no telem. data coming in) - uint8_t spare:2; - uint8_t filterInput; - uint8_t lightAutoOff; - uint8_t templateSetup; //RETA order according to chout_ar array - int8_t PPM_Multiplier; - Gruvin9xFrSkyRSSIAlarm frskyRssiAlarms[2]; - - operator GeneralSettings(); - t_Gruvin9xGeneral_v103() { memset(this, 0, sizeof(t_Gruvin9xGeneral_v103)); } -}) Gruvin9xGeneral_v103; - -PACK(typedef struct t_Gruvin9xGeneral_v104 { - uint8_t myVers; - int16_t calibMid[7]; - int16_t calibSpanNeg[7]; - int16_t calibSpanPos[7]; - uint16_t chkSum; - uint8_t currModel; //0..15 - uint8_t contrast; - uint8_t vBatWarn; - int8_t txVoltageCalibration; - int8_t lightSw; - Gruvin9xTrainerData_v104 trainer; - uint8_t view; //index of subview in main scrren - uint8_t disableThrottleWarning:1; - int8_t switchWarning:2; // -1=down, 0=off, 1=up - uint8_t beeperVal:3; - uint8_t disableMemoryWarning:1; - uint8_t disableAlarmWarning:1; - uint8_t stickMode; - uint8_t inactivityTimer; - uint8_t throttleReversed:1; - uint8_t minuteBeep:1; - uint8_t preBeep:1; - uint8_t flashBeep:1; - uint8_t disableSplashScreen:1; - uint8_t enableTelemetryAlarm:1; // 0=no, 1=yes (Sound alarm when there's no telem. data coming in) - uint8_t spare:2; - uint8_t filterInput; - uint8_t lightAutoOff; - uint8_t templateSetup; //RETA order according to chout_ar array - int8_t PPM_Multiplier; - Gruvin9xFrSkyRSSIAlarm frskyRssiAlarms[2]; - - operator GeneralSettings(); - t_Gruvin9xGeneral_v104() { memset(this, 0, sizeof(t_Gruvin9xGeneral_v104)); } -}) Gruvin9xGeneral_v104; - -typedef Gruvin9xGeneral_v104 Gruvin9xGeneral; - -// eeprom modelspec - -PACK(typedef struct t_Gruvin9xExpoData { - uint8_t mode:2; // 0=end, 1=pos, 2=neg, 3=both - uint8_t chn:2; - uint8_t curve:4; // 0=no curve, 1-6=std curves, 7-10=CV1-CV4, 11-15=CV9-CV13 - int8_t swtch:5; - uint8_t phase:3; // if negPhase is 0: 0=normal, 5=FP4 if negPhase is 1: 5=!FP4 - uint8_t negPhase:1; - uint8_t weight:7; - int8_t expo; - - operator ExpoData(); - t_Gruvin9xExpoData(); -}) Gruvin9xExpoData; - -PACK(typedef struct t_Gruvin9xLimitData { - int8_t min; - int8_t max; - bool revert; - int16_t offset; - - operator LimitData(); - t_Gruvin9xLimitData(); -}) Gruvin9xLimitData; - -#define MLTPX_ADD 0 -#define MLTPX_MUL 1 -#define MLTPX_REP 2 - -PACK(typedef struct t_Gruvin9xMixData { - uint8_t destCh:5; // 0, 1..C9X_NUM_CHNOUT - uint8_t mixWarn:3; // mixer warning - uint8_t srcRaw; // - int8_t weight; - int8_t swtch; - uint8_t curve; // 0=symmetrisch, 1=no neg, 2=no pos - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - uint8_t carryTrim:1; - uint8_t mltpx:3; // multiplex method 0=+ 1=* 2=replace - int8_t phase:4; // -5=!FP4, 0=normal, 5=FP4 - int8_t sOffset; - - operator MixData(); - t_Gruvin9xMixData(); -}) Gruvin9xMixData; - -PACK(typedef struct t_Gruvin9xLogicalSwitchData { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; - - operator LogicalSwitchData(); - t_Gruvin9xLogicalSwitchData() { memset(this, 0, sizeof(t_Gruvin9xLogicalSwitchData)); } -}) Gruvin9xLogicalSwitchData; - -PACK(typedef struct t_Gruvin9xSafetySwData { // Safety Switches data - int8_t swtch; - int8_t val; - - t_Gruvin9xSafetySwData() { memset(this, 0, sizeof(t_Gruvin9xSafetySwData)); } -}) Gruvin9xSafetySwData; - -PACK(typedef struct t_Gruvin9xCustomFunctionData { // Function Switches data - int8_t swtch; // input - uint8_t func; - - operator CustomFunctionData(); - t_Gruvin9xCustomFunctionData() { memset(this, 0, sizeof(t_Gruvin9xCustomFunctionData)); } -}) Gruvin9xCustomFunctionData; - -PACK(typedef struct t_Gruvin9xFrSkyChannelData { - uint16_t ratio:12; // (Maximum resistor divider input volts +/- calibration. 0 means channel not used. - // 0.01v steps from 0 to 40.95V. Ex. 6.60 Volts = 660. 40.95V = 4095 - uint16_t type:4; // channel display unit (0=volts, 1=raw, 2-15=reserverd.) - uint8_t alarms_value[2]; // raw sample values 0..255 - uint8_t alarms_level:4; // two pairs of 2bits. none=0, yel=1, org=2, red=3 - uint8_t alarms_greater:2; // two alarms, 1 bit each. 0=LT(<), 1=GT(>) - uint8_t spare:2; - uint8_t barMin; // minimum for bar display (raw ADC value) - uint8_t barMax; // ditto for max display (would G:NOT usually = ratio) - - operator FrSkyChannelData(); - t_Gruvin9xFrSkyChannelData(); -}) Gruvin9xFrSkyChannelData; - -PACK(typedef struct t_Gruvin9xFrSkyData { - Gruvin9xFrSkyChannelData channels[2]; - - operator FrSkyData(); - t_Gruvin9xFrSkyData(); -}) Gruvin9xFrSkyData; - -PACK(typedef struct t_Gruvin9xSwashRingData { // Swash Ring data - uint8_t invertELE:1; - uint8_t invertAIL:1; - uint8_t invertCOL:1; - uint8_t type:5; - uint8_t collectiveSource; - uint8_t value; - - operator SwashRingData(); - t_Gruvin9xSwashRingData(); -}) Gruvin9xSwashRingData; - -PACK(typedef struct t_Gruvin9xFlightModeData_v102 { - int8_t trim[4]; // -125..125 => trim value, 127 => use trim of phase 0, -128, -127, -126 => use trim of phases 1|2|3|4 instead - int8_t swtch; // swtch of phase[0] is not used - char name[6]; - uint8_t fadeIn:4; - uint8_t fadeOut:4; - - operator FlightModeData(); - t_Gruvin9xFlightModeData_v102() { memset(this, 0, sizeof(t_Gruvin9xFlightModeData_v102)); } -}) Gruvin9xFlightModeData_v102; - - -PACK(typedef struct t_Gruvin9xFlightModeData_v106 { - int8_t trim[4]; // -500..500 => trim value, 501 => use trim of phase 0, 502, 503, 504 => use trim of phases 1|2|3|4 instead - int8_t trim_ext:8; // 2 less significant extra bits per trim (10bits trims) - int8_t swtch; // swtch of phase[0] is not used - char name[6]; - uint8_t fadeIn:4; - uint8_t fadeOut:4; - - operator FlightModeData(); - t_Gruvin9xFlightModeData_v106() { memset(this, 0, sizeof(t_Gruvin9xFlightModeData_v106)); } -}) Gruvin9xFlightModeData_v106; - -PACK(typedef struct t_Gruvin9xTimerData { - int8_t mode:7; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw - uint8_t dir:1; // 0=>Count Down, 1=>Count Up - uint16_t val; - - operator TimerData(); - t_Gruvin9xTimerData() { memset(this, 0, sizeof(t_Gruvin9xTimerData)); } -}) Gruvin9xTimerData; - -#define G9X_MAX_FLIGHT_MODES 5 -#define G9X_MAX_MIXERS 32 -#define G9X_MAX_EXPOS 14 -#define G9X_MAX_CURVE5 8 -#define G9X_MAX_CURVE9 8 - -#define G9X_NUM_CHNOUT 16 // number of real output channels CH1-CH16 -#define G9X_NUM_CSW 12 // number of custom switches -#define G9X_NUM_FSW 12 // number of functions assigned to switches - -// TODO -PACK(typedef struct t_Gruvin9xModelData_v102 { - char name[10]; // 10 must be first for eeLoadModelName - Gruvin9xTimerData timer1; - uint8_t protocol:3; - int8_t ppmNCH:3; - uint8_t thrTrim:1; // Enable Throttle Trim - uint8_t thrExpo:1; // Enable Throttle Expo - uint8_t trimInc:3; // Trim Increments - uint8_t spare1:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Gruvin9xTimerData timer2; - Gruvin9xMixData mixData[G9X_MAX_MIXERS]; - Gruvin9xLimitData limitData[G9X_NUM_CHNOUT]; - Gruvin9xExpoData expoData[G9X_MAX_EXPOS]; - int8_t curves5[G9X_MAX_CURVE5][5]; - int8_t curves9[G9X_MAX_CURVE9][9]; - Gruvin9xLogicalSwitchData logicalSw[G9X_NUM_CSW]; - Gruvin9xSafetySwData safetySw[G9X_NUM_CHNOUT]; - Gruvin9xSwashRingData swashR; - Gruvin9xFlightModeData_v102 flightModeData[G9X_MAX_FLIGHT_MODES]; - Gruvin9xFrSkyData frsky; - - operator ModelData(); - t_Gruvin9xModelData_v102() { memset(this, 0, sizeof(t_Gruvin9xModelData_v102)); } - -}) Gruvin9xModelData_v102; - -PACK(typedef struct t_Gruvin9xModelData_v103 { - char name[10]; // 10 must be first for eeLoadModelName - Gruvin9xTimerData timer1; - uint8_t protocol:3; - int8_t ppmNCH:3; - uint8_t thrTrim:1; // Enable Throttle Trim - uint8_t thrExpo:1; // Enable Throttle Expo - uint8_t trimInc:3; // Trim Increments - uint8_t spare1:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Gruvin9xTimerData timer2; - Gruvin9xMixData mixData[G9X_MAX_MIXERS]; - Gruvin9xLimitData limitData[G9X_NUM_CHNOUT]; - Gruvin9xExpoData expoData[G9X_MAX_EXPOS]; - int8_t curves5[G9X_MAX_CURVE5][5]; - int8_t curves9[G9X_MAX_CURVE9][9]; - Gruvin9xLogicalSwitchData logicalSw[G9X_NUM_CSW]; - Gruvin9xSafetySwData safetySw[G9X_NUM_CHNOUT]; - Gruvin9xSwashRingData swashR; - Gruvin9xFlightModeData_v102 flightModeData[G9X_MAX_FLIGHT_MODES]; - Gruvin9xFrSkyData frsky; - - operator ModelData(); - t_Gruvin9xModelData_v103() { memset(this, 0, sizeof(t_Gruvin9xModelData_v103)); } - -}) Gruvin9xModelData_v103; - -PACK(typedef struct t_Gruvin9xModelData_v105 { - char name[10]; // 10 must be first for eeLoadModelName - Gruvin9xTimerData timer1; - uint8_t protocol:3; - int8_t ppmNCH:3; - uint8_t thrTrim:1; // Enable Throttle Trim - uint8_t thrExpo:1; // Enable Throttle Expo - uint8_t trimInc:3; // Trim Increments - uint8_t spare1:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Gruvin9xTimerData timer2; - Gruvin9xMixData mixData[G9X_MAX_MIXERS]; - Gruvin9xLimitData limitData[G9X_NUM_CHNOUT]; - Gruvin9xExpoData expoData[G9X_MAX_EXPOS]; - int8_t curves5[G9X_MAX_CURVE5][5]; - int8_t curves9[G9X_MAX_CURVE9][9]; - Gruvin9xLogicalSwitchData logicalSw[G9X_NUM_CSW]; - Gruvin9xSafetySwData safetySw[G9X_NUM_CHNOUT]; - Gruvin9xCustomFunctionData customFn[G9X_NUM_FSW]; - Gruvin9xSwashRingData swashR; - Gruvin9xFlightModeData_v102 flightModeData[G9X_MAX_FLIGHT_MODES]; - int16_t subtrim[NUM_STICKS]; - Gruvin9xFrSkyData frsky; - - operator ModelData(); - t_Gruvin9xModelData_v105() { memset(this, 0, sizeof(t_Gruvin9xModelData_v105)); } -}) Gruvin9xModelData_v105; - -PACK(typedef struct t_Gruvin9xModelData_v106 { - char name[10]; // 10 must be first for eeLoadModelName - Gruvin9xTimerData timer1; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t thrExpo:1; // Enable Throttle Expo - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Gruvin9xTimerData timer2; - Gruvin9xMixData mixData[G9X_MAX_MIXERS]; - Gruvin9xLimitData limitData[G9X_NUM_CHNOUT]; - Gruvin9xExpoData expoData[G9X_MAX_EXPOS]; - int8_t curves5[G9X_MAX_CURVE5][5]; - int8_t curves9[G9X_MAX_CURVE9][9]; - Gruvin9xLogicalSwitchData logicalSw[G9X_NUM_CSW]; - Gruvin9xSafetySwData safetySw[G9X_NUM_CHNOUT]; - Gruvin9xCustomFunctionData customFn[G9X_NUM_FSW]; - Gruvin9xSwashRingData swashR; - Gruvin9xFlightModeData_v106 flightModeData[G9X_MAX_FLIGHT_MODES]; - Gruvin9xFrSkyData frsky; - - operator ModelData(); - t_Gruvin9xModelData_v106() { memset(this, 0, sizeof(t_Gruvin9xModelData_v106)); } -}) Gruvin9xModelData_v106; - -typedef Gruvin9xModelData_v106 Gruvin9xModelData; - -#endif diff --git a/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp b/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp deleted file mode 100644 index 2e5fd93d3..000000000 --- a/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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 -#include "gruvin9xinterface.h" -#include "gruvin9xeeprom.h" -#include "rlefile.h" -#include "appdata.h" - -#define FILE_TYP_GENERAL 1 -#define FILE_TYP_MODEL 2 - -#define FILE_GENERAL 0 -#define FILE_MODEL(n) (1+n) - -Gruvin9xInterface::Gruvin9xInterface(BoardEnum board): -EEPROMInterface(board), -efile(new RleFile()) -{ -} - -Gruvin9xInterface::~Gruvin9xInterface() -{ - delete efile; -} - -const char * Gruvin9xInterface::getName() -{ - if (board == BOARD_STOCK) - return "Gruvin9x"; - else - return "Gruvin9x v4"; -} - -const int Gruvin9xInterface::getEEpromSize() -{ - if (board == BOARD_STOCK) { - QString avrMCU = g.mcu(); - if (avrMCU==QString("m128")) { - return EESIZE_STOCK*2; - } - return EESIZE_STOCK; - } else { - return EESIZE_GRUVIN9X; - } -} - -const int Gruvin9xInterface::getMaxModels() -{ - return 16; -} - -template -void Gruvin9xInterface::loadModel(ModelData &model, unsigned int stickMode, int version) -{ - T _model; - if ((version == 2 && efile->readRlc2((uint8_t*)&_model, sizeof(T))) || - (version == 1 && efile->readRlc1((uint8_t*)&_model, sizeof(T)))) { - model = _model; - if (stickMode) { - applyStickModeToModel(model, stickMode); - } - } - else { - model.clear(); - } -} - -template -bool Gruvin9xInterface::loadGeneral(GeneralSettings &settings, int version) -{ - T _settings; - if ((version == 2 && efile->readRlc2((uint8_t*)&_settings, sizeof(T))) || - (version == 1 && efile->readRlc1((uint8_t*)&_settings, sizeof(T)))) { - settings = _settings; - return true; - } - - std::cerr << "error when loading general settings"; - return false; -} - -unsigned long Gruvin9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) -{ - std::bitset errors; - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); -} - - -unsigned long Gruvin9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) -{ - std::cout << "trying " << getName() << " import... "; - - std::bitset errors; - - if (size != this->getEEpromSize()) { - std::cout << "wrong size\n"; - errors.set(WRONG_SIZE); - return errors.to_ulong(); - } - - if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { - std::cout << "wrong file system\n"; - errors.set(WRONG_FILE_SYSTEM); - return errors.to_ulong(); - } - - efile->openRd(FILE_GENERAL); - - uint8_t version; - if (efile->readRlc2(&version, 1) != 1) { - std::cout << "no\n"; - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); - } - - if (version == 0) { - efile->openRd(FILE_GENERAL); - if (efile->readRlc1(&version, 1) != 1) { - std::cout << "no\n"; - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); - } - } - - std::cout << "version " << (unsigned int)version << " "; - - switch(version) { - case 5: - case 100: - case 101: - case 102: - case 103: - case 104: - case 105: - // subtrims(16bits) + function switches added - case 106: - // trims(10bits), no subtrims - break; - default: - std::cout << "not gruvin9x\n"; - errors.set(NOT_GRUVIN9X); - return errors.to_ulong(); - } - - efile->openRd(FILE_GENERAL); - if (version == 5) { - if (!loadGeneral(radioData.generalSettings, 1)) { - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); - } - } - else if (version < 104) { - if (!loadGeneral(radioData.generalSettings)) { - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); - } - } - else if (version <= 106) { - if (!loadGeneral(radioData.generalSettings)) { - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); - } - } - else { - std::cout << "ko\n"; - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); - } - - for (int i=0; iopenRd(FILE_MODEL(i)); - if (version == 5) { - loadModel(radioData.models[i], radioData.generalSettings.stickMode+1, 1); - } - else if (version < 103) { - loadModel(radioData.models[i], radioData.generalSettings.stickMode+1); - } - else if (version == 103) { - loadModel(radioData.models[i], radioData.generalSettings.stickMode+1); - } - else if (version == 105) { - loadModel(radioData.models[i], radioData.generalSettings.stickMode+1); - } - else if (version == 106) { - loadModel(radioData.models[i], radioData.generalSettings.stickMode+1); - } - else { - std::cout << "ko\n"; - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); - } - } - - std::cout << "ok\n"; - errors.set(ALL_OK); - return errors.to_ulong(); -} - -unsigned long Gruvin9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) -{ - std::bitset errors; - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); -} - -int Gruvin9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) -{ - std::cout << "NO!\n"; - // TODO an error - - return 0; -} - -int Gruvin9xInterface::getSize(const ModelData & model) -{ - return 0; -} - -int Gruvin9xInterface::getSize(const GeneralSettings & settings) -{ - return 0; -} - -int Gruvin9xInterface::isAvailable(PulsesProtocol proto, int port) -{ - switch (proto) { - case PULSES_PPM: - case PULSES_SILV_A: - case PULSES_SILV_B: - case PULSES_SILV_C: - case PULSES_CTP1009: - case PULSES_DSM2: - return 1; - default: - return 0; - } -} diff --git a/companion/src/firmwares/gruvin9x/gruvin9xinterface.h b/companion/src/firmwares/gruvin9x/gruvin9xinterface.h deleted file mode 100644 index 152cd5862..000000000 --- a/companion/src/firmwares/gruvin9x/gruvin9xinterface.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ -#ifndef gruvin9x_interface_h -#define gruvin9x_interface_h - -#include "eeprominterface.h" - -class RleFile; - -class Gruvin9xInterface : public EEPROMInterface -{ - - public: - - Gruvin9xInterface(BoardEnum board); - - virtual ~Gruvin9xInterface(); - - virtual const char * getName(); - - virtual const int getEEpromSize(); - - virtual const int getMaxModels(); - - virtual unsigned long load(RadioData &, const uint8_t *eeprom, int size); - - - virtual unsigned long loadBackup(RadioData &, uint8_t *eeprom,int esize, int index); - - virtual unsigned long loadxml(RadioData &radioData, QDomDocument &doc); - - virtual int save(uint8_t *eeprom, RadioData &radioData, uint32_t variant=0, uint8_t version=0); - - virtual int getSize(const ModelData &); - - virtual int getSize(const GeneralSettings & settings); - - virtual int isAvailable(PulsesProtocol proto, int port=0); - - protected: - - template - void loadModel(ModelData &model, unsigned int stickMode=0, int version=2); - - template - bool loadGeneral(GeneralSettings &settings, int version=2); - - RleFile *efile; - -}; - -#endif diff --git a/companion/src/firmwares/opentx/open9xGruvin9xeeprom.cpp b/companion/src/firmwares/opentx/open9xGruvin9xeeprom.cpp deleted file mode 100644 index dc7575d1f..000000000 --- a/companion/src/firmwares/opentx/open9xGruvin9xeeprom.cpp +++ /dev/null @@ -1,838 +0,0 @@ -#include -#include -#include "helpers.h" -#include "open9xGruvin9xeeprom.h" -#include -#include - -extern void getEEPROMZString(char *dst, const char *src, int size); -extern RawSwitch open9xStockToSwitch(int8_t sw); - -t_Open9xGruvin9xFlightModeData_v207::operator FlightModeData () -{ - FlightModeData c9x; - for (int i=0; i> (2*i)) & 0x03); - c9x.swtch = open9xStockToSwitch(swtch); - getEEPROMZString(c9x.name, name, sizeof(name)); - c9x.fadeIn = fadeIn; - c9x.fadeOut = fadeOut; - for (int i=0; i<2; i++) - c9x.rotaryEncoders[i] = rotaryEncoders[i]; - return c9x; -} - -t_Open9xGruvin9xFlightModeData_v208::operator FlightModeData () -{ - FlightModeData c9x; - for (int i=0; i= LS_FN_VPOS && c9x.func <= LS_FN_ANEG) || c9x.func >= LS_FN_EQUAL) { - c9x.val1 = open9xV4207ToSource(v1).toValue(); - } - - if (c9x.func >= LS_FN_EQUAL) { - c9x.val2 = open9xV4207ToSource(v2).toValue(); - } - - if (c9x.func >= LS_FN_AND && c9x.func <= LS_FN_XOR) { - c9x.val1 = open9xStockToSwitch(v1).toValue(); - c9x.val2 = open9xStockToSwitch(v2).toValue(); - } - - return c9x; -} - -Open9xGruvin9xLogicalSwitchData_v209::operator LogicalSwitchData () -{ - LogicalSwitchData c9x; - c9x.func = func; - c9x.val1 = v1; - c9x.val2 = v2; - - if ((c9x.func >= LS_FN_VPOS && c9x.func <= LS_FN_ANEG) || c9x.func >= LS_FN_EQUAL) { - c9x.val1 = open9xV4209ToSource(v1).toValue(); - } - - if (c9x.func >= LS_FN_EQUAL && c9x.func <= LS_FN_ELESS) { - c9x.val2 = open9xV4209ToSource(v2).toValue(); - } - - if (c9x.func >= LS_FN_AND && c9x.func <= LS_FN_XOR) { - c9x.val1 = open9xStockToSwitch(v1).toValue(); - c9x.val2 = open9xStockToSwitch(v2).toValue(); - } - - return c9x; -} - -t_Open9xGruvin9xCustomFunctionData_v203::operator CustomFunctionData () -{ - CustomFunctionData c9x; - c9x.swtch = open9xStockToSwitch(swtch); - if (func < 16) { - c9x.func = (AssignFunc)(func); - c9x.enabled=param & 0x01; - c9x.param = (param>>1)<<1; - } - else { - c9x.param = param; - if (func <= 20) - c9x.func = (AssignFunc)(func); - else if (func == 21) - c9x.func = FuncInstantTrim; - else if (func == 22) - c9x.func = FuncPlaySound; - else if (func == 23) - c9x.func = FuncPlayHaptic; - else if (func == 24) - c9x.func = FuncReset; - else if (func == 25) - c9x.func = FuncVario; - else if (func == 26) - c9x.func = FuncPlayPrompt; - else if (func == 27) - c9x.func = FuncPlayValue; - else if (func == 28) - c9x.func = FuncLogs; - else if (func == 29) - c9x.func = FuncBacklight; - else if (func >= 30 && func <= 34) - c9x.func = AssignFunc(FuncAdjustGV1 + func - 30); - else - c9x.clear(); - } - return c9x; -} - -t_Open9xGruvin9xCustomFunctionData_v210::operator CustomFunctionData () -{ - CustomFunctionData c9x; - c9x.swtch = open9xStockToSwitch(swtch); - c9x.param = param; - if (func < 22) { - c9x.func = (AssignFunc)(func); - c9x.enabled = delay; - } else { - if (func == 22) - c9x.func = FuncPlaySound; - else if (func == 23) - c9x.func = FuncPlayHaptic; - else if (func == 24) - c9x.func = FuncReset; - else if (func == 25) - c9x.func = FuncVario; - else if (func == 26) - c9x.func = FuncPlayPrompt; - else if (func == 27) - c9x.func = FuncPlayValue; - else if (func == 28) - c9x.func = FuncLogs; - else - c9x.clear(); - } - return c9x; -} - -t_Open9xGruvin9xSwashRingData_v208::operator SwashRingData () -{ - SwashRingData c9x; - c9x.elevatorWeight = invertELE ? -100 : 100; - c9x.aileronWeight = invertAIL ? -100 : 100; - c9x.collectiveWeight = invertCOL ? -100 : 100; - c9x.type = type; - c9x.collectiveSource = open9xV4207ToSource(collectiveSource); - c9x.value = value; - return c9x; -} - -t_Open9xGruvin9xSwashRingData_v209::operator SwashRingData () -{ - SwashRingData c9x; - c9x.elevatorWeight = invertELE ? -100 : 100; - c9x.aileronWeight = invertAIL ? -100 : 100; - c9x.collectiveWeight = invertCOL ? -100 : 100; - c9x.type = type; - c9x.collectiveSource = open9xV4209ToSource(collectiveSource); - c9x.value = value; - return c9x; -} - -t_Open9xGruvin9xModelData_v207::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<16; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - return c9x; -} - -t_Open9xGruvin9xModelData_v208::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<16; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.frsky.varioSource = varioSource; - c9x.frsky.varioCenterMax = varioSpeedUpMin; - c9x.frsky.varioCenterMin = varioSpeedDownMin; - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - for (int i=0; i<16; i++) { - c9x.limitData[i].ppmCenter = servoCenter[i]; - } - return c9x; -} - -t_Open9xGruvin9xModelData_v209::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<16; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.frsky.varioSource = varioSource; - c9x.frsky.varioCenterMax = varioSpeedUpMin; - c9x.frsky.varioCenterMin = varioSpeedDownMin; - c9x.switchWarningStates = switchWarningStates; - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - for (int i=0; i<16; i++) { - c9x.limitData[i].ppmCenter = servoCenter[i]; - } - return c9x; -} - -t_Open9xGruvin9xModelData_v210::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - for (int i=0; i<8; i++) { - CurveInfo crvinfo = curveinfo(this, i); - c9x.curves[i].type = (crvinfo.custom ? CurveData::CURVE_TYPE_CUSTOM : CurveData::CURVE_TYPE_STANDARD); - c9x.curves[i].count = crvinfo.points; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - for (int i=0; i<8; i++) { - CurveInfo crvinfo = curveinfo(this, i); - c9x.curves[i].type = (crvinfo.custom ? CurveData::CURVE_TYPE_CUSTOM : CurveData::CURVE_TYPE_STANDARD); - c9x.curves[i].count = crvinfo.points; - for (int j=0; j - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ - -#ifndef open9xGruvin9xeeprom_h -#define open9xGruvin9xeeprom_h - -#define O9X_V4_MAX_CSFUNCOLD 13 -#define O9X_V4_MAX_CSFUNC 15 - -#include "open9xStockeeprom.h" - -PACK(typedef struct t_Open9xGruvin9xFlightModeData_v207 { - int8_t trim[4]; // -500..500 => trim value, 501 => use trim of phase 0, 502, 503, 504 => use trim of phases 1|2|3|4 instead - int8_t trim_ext:8; // 2 less significant extra bits per trim (10bits trims) - int8_t swtch; // swtch of phase[0] is not used - char name[6]; - uint8_t fadeIn:4; - uint8_t fadeOut:4; - int16_t rotaryEncoders[2]; - operator FlightModeData(); - t_Open9xGruvin9xFlightModeData_v207() { memset(this, 0, sizeof(t_Open9xGruvin9xFlightModeData_v207)); } -}) Open9xGruvin9xFlightModeData_v207; - -PACK(typedef struct t_Open9xGruvin9xFlightModeData_v208 { - int16_t trim[4]; // -500..500 => trim value, 501 => use trim of phase 0, 502, 503, 504 => use trim of phases 1|2|3|4 instead - int8_t swtch; // swtch of phase[0] is not used - char name[6]; - uint8_t fadeIn:4; - uint8_t fadeOut:4; - int16_t rotaryEncoders[2]; - operator FlightModeData(); - t_Open9xGruvin9xFlightModeData_v208() { memset(this, 0, sizeof(t_Open9xGruvin9xFlightModeData_v208)); } -}) Open9xGruvin9xFlightModeData_v208; - -PACK(typedef struct t_Open9xGruvin9xMixData_v207 { - uint8_t destCh:4; // 0, 1..C9X_NUM_CHNOUT - int8_t phase:4; // -5=!FP4, 0=normal, 5=FP4 - int8_t weight; - int8_t swtch:6; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - int8_t curve:6; - uint8_t mixWarn:2; // mixer warning - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - uint16_t srcRaw:7; // - uint16_t differential:7; - uint16_t carryTrim:2; - int8_t sOffset; - - operator MixData(); - t_Open9xGruvin9xMixData_v207() { memset(this, 0, sizeof(t_Open9xGruvin9xMixData_v207)); } -}) Open9xGruvin9xMixData_v207; - -PACK(typedef struct t_Open9xGruvin9xMixData_v209 { - uint8_t destCh:4; // 0, 1..C9X_NUM_CHNOUT - int8_t phase:4; // -5=!FP4, 0=normal, 5=FP4 - int8_t weight; - int8_t swtch:6; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - int8_t curve:6; - uint8_t mixWarn:2; // mixer warning - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - uint16_t srcRaw:6; // - int16_t differential:7; - int16_t carryTrim:3; - int8_t sOffset; - - operator MixData(); - t_Open9xGruvin9xMixData_v209() { memset(this, 0, sizeof(t_Open9xGruvin9xMixData_v209)); } -}) Open9xGruvin9xMixData_v209; - -PACK(typedef struct t_Open9xGruvin9xMixData_v211 { - uint8_t destCh:4; // 0, 1..C9X_NUM_CHNOUT - uint8_t curveMode:1; // O=curve, 1=differential - uint8_t noExpo:1; - uint8_t spare:2; - int8_t weight; - int8_t swtch:6; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - uint8_t phases:5; - int8_t carryTrim:3; - uint8_t srcRaw:6; - uint8_t mixWarn:2; // mixer warning - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; - uint8_t speedDown:4; - int8_t curveParam; - int8_t sOffset; - - operator MixData(); - t_Open9xGruvin9xMixData_v211() { memset(this, 0, sizeof(t_Open9xGruvin9xMixData_v211)); } -}) Open9xGruvin9xMixData_v211; - -PACK(typedef struct t_Open9xGruvin9xLogicalSwitchData_v207 { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; - - operator LogicalSwitchData(); - t_Open9xGruvin9xLogicalSwitchData_v207() { memset(this, 0, sizeof(t_Open9xGruvin9xLogicalSwitchData_v207)); } - int8_t fromSource(RawSource source); - RawSource toSource(int8_t value); -}) Open9xGruvin9xLogicalSwitchData_v207; - -PACK(typedef struct t_Open9xGruvin9xLogicalSwitchData_v209 { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; - - operator LogicalSwitchData(); - t_Open9xGruvin9xLogicalSwitchData_v209() { memset(this, 0, sizeof(t_Open9xGruvin9xLogicalSwitchData_v209)); } - int8_t fromSource(RawSource source); - RawSource toSource(int8_t value); -}) Open9xGruvin9xLogicalSwitchData_v209; - -PACK(typedef struct t_Open9xGruvin9xCustomFunctionData_v203 { // Function Switches data - int8_t swtch; // input - uint8_t func; - uint8_t param; - - operator CustomFunctionData(); - t_Open9xGruvin9xCustomFunctionData_v203() { memset(this, 0, sizeof(t_Open9xGruvin9xCustomFunctionData_v203)); } -}) Open9xGruvin9xCustomFunctionData_v203; - -PACK(typedef struct t_Open9xGruvin9xCustomFunctionData_v210 { // Function Switches data - int8_t swtch; // input - uint8_t func:5; - uint8_t delay:3; - uint8_t param; - - operator CustomFunctionData(); - t_Open9xGruvin9xCustomFunctionData_v210() { memset(this, 0, sizeof(t_Open9xGruvin9xCustomFunctionData_v210)); } -}) Open9xGruvin9xCustomFunctionData_v210; - -PACK(typedef struct t_Open9xGruvin9xSwashRingData_v208 { // Swash Ring data - uint8_t invertELE:1; - uint8_t invertAIL:1; - uint8_t invertCOL:1; - uint8_t type:5; - uint8_t collectiveSource; - uint8_t value; - - operator SwashRingData(); - t_Open9xGruvin9xSwashRingData_v208() { memset(this, 0, sizeof(t_Open9xGruvin9xSwashRingData_v208)); } -}) Open9xGruvin9xSwashRingData_v208; - -PACK(typedef struct t_Open9xGruvin9xSwashRingData_v209 { // Swash Ring data - uint8_t invertELE:1; - uint8_t invertAIL:1; - uint8_t invertCOL:1; - uint8_t type:5; - uint8_t collectiveSource; - uint8_t value; - - operator SwashRingData(); - t_Open9xGruvin9xSwashRingData_v209() { memset(this, 0, sizeof(t_Open9xGruvin9xSwashRingData_v209)); } -}) Open9xGruvin9xSwashRingData_v209; - -PACK(typedef struct t_Open9xGruvin9xModelData_v207 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t spare1:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xGruvin9xMixData_v207 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xGruvin9xLogicalSwitchData_v207 logicalSw[12]; - Open9xCustomFunctionData_v203 customFn[16]; - Open9xGruvin9xSwashRingData_v208 swashR; - Open9xGruvin9xFlightModeData_v207 flightModeData[5]; - Open9xFrSkyData_v205 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t frskyLines[4]; - uint16_t frskyLinesXtra; - - operator ModelData(); - t_Open9xGruvin9xModelData_v207() { memset(this, 0, sizeof(t_Open9xGruvin9xModelData_v207)); } -}) Open9xGruvin9xModelData_v207; - -PACK(typedef struct t_Open9xGruvin9xModelData_v208 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xGruvin9xMixData_v207 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xGruvin9xLogicalSwitchData_v207 logicalSw[12]; - Open9xGruvin9xCustomFunctionData_v203 customFn[16]; - Open9xGruvin9xSwashRingData_v208 swashR; - Open9xGruvin9xFlightModeData_v208 flightModeData[5]; - Open9xFrSkyData_v208 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t frskyLines[4]; - uint16_t frskyLinesXtra; - int8_t servoCenter[16]; - - uint8_t varioSource:3; - uint8_t varioSpeedUpMin:5; // if increment in 0.2m/s = 3.0m/s max - uint8_t varioSpeedDownMin; - - operator ModelData(); - t_Open9xGruvin9xModelData_v208() { memset(this, 0, sizeof(t_Open9xGruvin9xModelData_v208)); } -}) Open9xGruvin9xModelData_v208; - -PACK(typedef struct t_Open9xGruvin9xModelData_v209 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xGruvin9xMixData_v209 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xGruvin9xLogicalSwitchData_v209 logicalSw[12]; - Open9xGruvin9xCustomFunctionData_v203 customFn[16]; - Open9xGruvin9xSwashRingData_v209 swashR; - Open9xGruvin9xFlightModeData_v208 flightModeData[5]; - Open9xFrSkyData_v208 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t frskyLines[4]; - uint16_t frskyLinesXtra; - int8_t servoCenter[16]; - - uint8_t varioSource:3; - uint8_t varioSpeedUpMin:5; // if increment in 0.2m/s = 3.0m/s max - uint8_t varioSpeedDownMin; - uint8_t switchWarningStates; - - operator ModelData(); - t_Open9xGruvin9xModelData_v209() { memset(this, 0, sizeof(t_Open9xGruvin9xModelData_v209)); } -}) Open9xGruvin9xModelData_v209; - -PACK(typedef struct t_Open9xGruvin9xModelData_v210 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xGruvin9xMixData_v209 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves[8]; - int8_t points[112-8]; - Open9xGruvin9xLogicalSwitchData_v209 logicalSw[12]; - Open9xGruvin9xCustomFunctionData_v210 customFn[16]; - Open9xGruvin9xSwashRingData_v209 swashR; - Open9xGruvin9xFlightModeData_v208 flightModeData[5]; - - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - - int8_t servoCenter[16]; - - uint8_t switchWarningStates; - - Open9xFrSkyData_v210 frsky; - - operator ModelData(); - t_Open9xGruvin9xModelData_v210() { memset(this, 0, sizeof(t_Open9xGruvin9xModelData_v210)); } -}) Open9xGruvin9xModelData_v210; - -PACK(typedef struct t_Open9xGruvin9xModelData_v211 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare1:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xGruvin9xMixData_v211 mixData[32]; - Open9xLimitData_v211 limitData[16]; - Open9xExpoData_v211 expoData[14]; - int8_t curves[8]; - int8_t points[112-8]; - Open9xGruvin9xLogicalSwitchData_v209 logicalSw[12]; - Open9xGruvin9xCustomFunctionData_v210 customFn[16]; - Open9xGruvin9xSwashRingData_v209 swashR; - Open9xGruvin9xFlightModeData_v208 flightModeData[5]; - - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t switchWarningStates; - - Open9xFrSkyData_v210 frsky; - Open9xTimerDataExtra timersXtra[2]; - - operator ModelData(); - t_Open9xGruvin9xModelData_v211() { memset(this, 0, sizeof(t_Open9xGruvin9xModelData_v211)); } -}) Open9xGruvin9xModelData_v211; - -#endif diff --git a/companion/src/firmwares/opentx/open9xSky9xeeprom.cpp b/companion/src/firmwares/opentx/open9xSky9xeeprom.cpp deleted file mode 100644 index b9348afb7..000000000 --- a/companion/src/firmwares/opentx/open9xSky9xeeprom.cpp +++ /dev/null @@ -1,1126 +0,0 @@ -#include -#include -#include "helpers.h" -#include "open9xSky9xeeprom.h" -#include -#include - -extern void getEEPROMZString(char *dst, const char *src, int size); - -RawSwitch open9xArmToSwitch(int8_t sw) -{ - uint8_t swa = abs(sw); - if (swa == 0) - return RawSwitch(SWITCH_TYPE_NONE); - else if (swa <= 9) - return RawSwitch(SWITCH_TYPE_SWITCH, sw); - else if (swa <= 9+32) - return RawSwitch(SWITCH_TYPE_VIRTUAL, sw > 0 ? sw-9 : sw+9); - else if (sw == 42) - return RawSwitch(SWITCH_TYPE_ON); - else if (sw == 84) - return RawSwitch(SWITCH_TYPE_ON); - else if (sw == -42) - return RawSwitch(SWITCH_TYPE_OFF); - else if (swa <= 42+9) - return RawSwitch(SWITCH_TYPE_SWITCH, sw > 0 ? sw-42 : sw+42); - else - return RawSwitch(SWITCH_TYPE_VIRTUAL, sw > 0 ? sw-42-9 : sw+42+9); -} - -RawSource open9xArm208ToSource(int8_t value) -{ - if (value == 0) { - return RawSource(SOURCE_TYPE_NONE); - } - else if (value <= 7) { - return RawSource(SOURCE_TYPE_STICK, value - 1); - } - else if (value == 8) { - return RawSource(SOURCE_TYPE_MAX); - } - /* else if (value == 9) { - return RawSource(SOURCE_TYPE_3POS); - } */ - else if (value <= 12) { - return RawSource(SOURCE_TYPE_CYC, value-10); - } - else if (value <= 20) { - return RawSource(SOURCE_TYPE_PPM, value-13); - } - else if (value <= 52) { - return RawSource(SOURCE_TYPE_CH, value-21); - } - else { - return RawSource(SOURCE_TYPE_TELEMETRY, value-52); - } -} - -RawSource open9xArm209ToSource(int8_t value) -{ - if (value == 0) { - return RawSource(SOURCE_TYPE_NONE); - } - else if (value <= 7) { - return RawSource(SOURCE_TYPE_STICK, value - 1); - } - else if (value <= 11) { - return RawSource(SOURCE_TYPE_TRIM, value - 8); - } - else if (value == 12) { - return RawSource(SOURCE_TYPE_MAX); - } - /* else if (value == 13) { - return RawSource(SOURCE_TYPE_3POS); - } */ - else if (value <= 16) { - return RawSource(SOURCE_TYPE_CYC, value-14); - } - else if (value <= 24) { - return RawSource(SOURCE_TYPE_PPM, value-17); - } - else if (value <= 56) { - return RawSource(SOURCE_TYPE_CH, value-25); - } - else { - return RawSource(SOURCE_TYPE_TELEMETRY, value-56); - } -} - -RawSource open9xArm210ToSource(int8_t value) -{ - if (value == 0) { - return RawSource(SOURCE_TYPE_NONE); - } - else if (value <= 7) { - return RawSource(SOURCE_TYPE_STICK, value - 1); - } - else if (value == 8) { - return RawSource(SOURCE_TYPE_ROTARY_ENCODER, value - 8); - } - else if (value <= 12) { - return RawSource(SOURCE_TYPE_TRIM, value - 9); - } - else if (value == 13) { - return RawSource(SOURCE_TYPE_MAX); - } - /* else if (value == 14) { - return RawSource(SOURCE_TYPE_3POS); - } */ - else if (value <= 17) { - return RawSource(SOURCE_TYPE_CYC, value-15); - } - else if (value <= 25) { - return RawSource(SOURCE_TYPE_PPM, value-18); - } - else if (value <= 57) { - return RawSource(SOURCE_TYPE_CH, value-26); - } - else { - return RawSource(SOURCE_TYPE_TELEMETRY, value-57); - } -} - -t_Open9xArmTimerData_v202::operator TimerData () -{ - TimerData c9x; -/* - if (mode <= -42) - c9x.mode = TimerMode(TMRMODE_FIRST_NEG_SWITCH+(mode+22)); - else if (mode <= -1) - c9x.mode = TimerMode(TMRMODE_FIRST_NEG_SWITCH+(mode+1)); - else if (mode < 5) - c9x.mode = TimerMode(mode); - else if (mode < 5+41) - c9x.mode = TimerMode(TMRMODE_FIRST_SWITCH+(mode-5)); - else - c9x.mode = TimerMode(TMRMODE_FIRST_SWITCH+(mode-5-21)); -*/ - c9x.val = val; - c9x.persistent = false; - return c9x; -} - -t_Open9xArmExpoData_v208::operator ExpoData () -{ - ExpoData c9x; - c9x.mode = mode; - c9x.chn = chn; - - if (expo!=0 && curve!=0) { - EEPROMWarnings.push_back(::QObject::tr("Simultaneous usage of expo and curves is no longer supported")); - } - else { - if (curve == 0) { - c9x.curve = CurveReference(CurveReference::CURVE_REF_EXPO, expo); - } - else { - // TODO - } - } - c9x.swtch = open9xArmToSwitch(swtch); - if (phase<0) { - c9x.flightModes= 1 << (-phase -1); - } else if (phase==0) { - c9x.flightModes=0; - } else { - c9x.flightModes=63; - c9x.flightModes &= ~(1 << (phase -1)); - } - c9x.weight = weight; - return c9x; -} - -t_Open9xArmExpoData_v210::operator ExpoData () -{ - ExpoData c9x; - c9x.mode = mode; - c9x.chn = chn; - - if (expo!=0 && curve!=0) { - EEPROMWarnings.push_back(::QObject::tr("Simultaneous usage of expo and curves is no longer supported")); - } - else { - if (curve == 0) { - c9x.curve = CurveReference(CurveReference::CURVE_REF_EXPO, expo); - } - else { - // TODO - } - } - c9x.swtch = open9xArmToSwitch(swtch); - if (phase<0) { - c9x.flightModes= 1 << (-phase -1); - } - else if (phase==0) { - c9x.flightModes=0; - } - else { - c9x.flightModes=63; - c9x.flightModes &= ~(1 << (phase -1)); - } - c9x.weight = weight; - getEEPROMZString(c9x.name, name, sizeof(name)); - return c9x; -} - -t_Open9xArmExpoData_v212::operator ExpoData () -{ - ExpoData c9x; - c9x.mode = mode; - c9x.chn = chn; - - // TODO c9x.curveMode=curveMode; - // c9x.curveParam=curveParam; - c9x.swtch = open9xArmToSwitch(swtch); - c9x.flightModes= phases; - c9x.weight = weight; - getEEPROMZString(c9x.name, name, sizeof(name)); - return c9x; -} - -t_Open9xArmFlightModeData_v208::operator FlightModeData () -{ - FlightModeData c9x; - for (int i=0; i= LS_FN_VPOS && c9x.func <= LS_FN_ANEG) || c9x.func >= LS_FN_EQUAL) { - c9x.val1 = open9xArm208ToSource(v1).toValue(); - } - - if (c9x.func >= LS_FN_EQUAL) { - c9x.val2 = open9xArm208ToSource(v2).toValue(); - } - - if (c9x.func >= LS_FN_AND && c9x.func <= LS_FN_XOR) { - c9x.val1 = open9xArmToSwitch(v1).toValue(); - c9x.val2 = open9xArmToSwitch(v2).toValue(); - } - - return c9x; -} - -t_Open9xArmLogicalSwitchData_v209::operator LogicalSwitchData () -{ - LogicalSwitchData c9x; - c9x.func = func; - c9x.val1 = v1; - c9x.val2 = v2; - - if ((c9x.func >= LS_FN_VPOS && c9x.func <= LS_FN_ANEG) || c9x.func >= LS_FN_EQUAL) { - c9x.val1 = open9xArm209ToSource(v1).toValue(); - } - - if (c9x.func >= LS_FN_EQUAL) { - c9x.val2 = open9xArm209ToSource(v2).toValue(); - } - - if (c9x.func >= LS_FN_AND && c9x.func <= LS_FN_XOR) { - c9x.val1 = open9xArmToSwitch(v1).toValue(); - c9x.val2 = open9xArmToSwitch(v2).toValue(); - } - - return c9x; -} - -t_Open9xArmLogicalSwitchData_v210::operator LogicalSwitchData () -{ - LogicalSwitchData c9x; - c9x.func = func; - c9x.val1 = v1; - c9x.val2 = v2; - c9x.delay = delay; - c9x.duration = duration; - - if ((c9x.func >= LS_FN_VPOS && c9x.func <= LS_FN_ANEG) || c9x.func >= LS_FN_EQUAL) { - c9x.val1 = open9xArm210ToSource(v1).toValue(); - } - - if (c9x.func >= LS_FN_EQUAL && c9x.func <= LS_FN_ELESS) { - c9x.val2 = open9xArm210ToSource(v2).toValue(); - } - - if (c9x.func >= LS_FN_AND && c9x.func <= LS_FN_XOR) { - c9x.val1 = open9xArmToSwitch(v1).toValue(); - c9x.val2 = open9xArmToSwitch(v2).toValue(); - } - - return c9x; -} - -t_Open9xArmCustomFunctionData_v208::operator CustomFunctionData () -{ - CustomFunctionData c9x; - c9x.swtch = open9xArmToSwitch(swtch); - c9x.func = (AssignFunc)(func); - if (c9x.func <= FuncOverrideCH32) { - c9x.enabled=param & 0x01; - c9x.param = (param>>1)<<1; - } - else { - if ((c9x.func == FuncPlayValue || c9x.func == FuncVolume) && param > 7) { - param+=2; - } - c9x.param = param; - } - return c9x; -} - -t_Open9xArmCustomFunctionData_v210::operator CustomFunctionData () -{ - CustomFunctionData c9x; - c9x.swtch = open9xArmToSwitch(swtch); - c9x.func = (AssignFunc)(func); - uint32_t value = *((uint32_t *)param); - if (c9x.func <= FuncInstantTrim) { - c9x.enabled = value & 0x01; - c9x.param = (value>>1)<<1; - } - else { - if (c9x.func == FuncPlayPrompt || c9x.func == FuncBackgroundMusic) { - memcpy(c9x.paramarm, param, sizeof(c9x.paramarm)); - } - else { - if ((c9x.func == FuncPlayValue || c9x.func == FuncVolume) && value > 7) { - value+=2; - } - c9x.param = value; - } - } - return c9x; -} - -t_Open9xArmCustomFunctionData_v211::operator CustomFunctionData () -{ - CustomFunctionData c9x; - c9x.swtch = open9xArmToSwitch(swtch); - c9x.func = (AssignFunc)(func); - uint32_t value = *((uint32_t *)param); - if (c9x.func <= FuncInstantTrim) { - c9x.enabled = delay & 0x01; - c9x.param = value; - } - else { - if (c9x.func == FuncPlayPrompt || c9x.func == FuncBackgroundMusic) { - memcpy(c9x.paramarm, param, sizeof(c9x.paramarm)); - } - else { - c9x.param = value; - if ((c9x.func == FuncPlayValue || c9x.func == FuncVolume || (c9x.func >= FuncAdjustGV1 && c9x.func <= FuncAdjustGVLast)) && value > 7) { - c9x.param++; - } - } - } - return c9x; -} - -t_Open9xArmSwashRingData_v208::operator SwashRingData () -{ - SwashRingData c9x; - c9x.elevatorWeight = invertELE ? -100 : 100; - c9x.aileronWeight = invertAIL ? -100 : 100; - c9x.collectiveWeight = invertCOL ? -100 : 100; - c9x.type = type; - c9x.collectiveSource = open9xArm208ToSource(collectiveSource); - c9x.value = value; - return c9x; -} - -t_Open9xArmSwashRingData_v209::operator SwashRingData () -{ - SwashRingData c9x; - c9x.elevatorWeight = invertELE ? -100 : 100; - c9x.aileronWeight = invertAIL ? -100 : 100; - c9x.collectiveWeight = invertCOL ? -100 : 100; - c9x.type = type; - c9x.collectiveSource = open9xArm209ToSource(collectiveSource); - c9x.value = value; - return c9x; -} - -t_Open9xArmSwashRingData_v210::operator SwashRingData () -{ - SwashRingData c9x; - c9x.elevatorWeight = invertELE ? -100 : 100; - c9x.aileronWeight = invertAIL ? -100 : 100; - c9x.collectiveWeight = invertCOL ? -100 : 100; - c9x.type = type; - c9x.collectiveSource = open9xArm210ToSource(collectiveSource); - c9x.value = value; - return c9x; -} - -t_Open9xArmFrSkyData_v210::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - c9x.usrProto = usrProto; - c9x.voltsSource = voltsSource; - c9x.blades = blades+2; - c9x.currentSource=currentSource; - c9x.screens[0].type = 1; - c9x.rssiAlarms[0] = rssiAlarms[0].get(0); - c9x.rssiAlarms[1] = rssiAlarms[1].get(1); - return c9x; -} - -t_Open9xArmFrSkyData_v211::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - c9x.usrProto = usrProto; - c9x.voltsSource = voltsSource; - c9x.blades = blades+2; - c9x.currentSource=currentSource; - c9x.screens[0].type = 1; - c9x.rssiAlarms[0] = rssiAlarms[0].get(0); - c9x.rssiAlarms[1] = rssiAlarms[1].get(1); - c9x.varioSource = varioSource; - c9x.varioCenterMax = varioSpeedUpMin; - c9x.varioCenterMin = varioSpeedDownMin; - - return c9x; -} - -t_Open9xArmModelData_v208::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<9; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<64; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<32; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<32; i++) - c9x.expoData[i] = expoData[i]; - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - for (int i=0; i<32; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<32; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.frsky.varioSource = varioSource; - c9x.frsky.varioCenterMax = varioSpeedUpMin; - c9x.frsky.varioCenterMin = varioSpeedDownMin; - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - for (int i=0; i<16; i++) { - c9x.limitData[i].ppmCenter = servoCenter[i]; - } - - return c9x; -} - -t_Open9xArmModelData_v209::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<9; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<64; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<32; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<32; i++) - c9x.expoData[i] = expoData[i]; - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - for (int i=0; i<32; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<32; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.frsky.varioSource = varioSource; - c9x.frsky.varioCenterMax = varioSpeedUpMin; - c9x.frsky.varioCenterMin = varioSpeedDownMin; - c9x.switchWarningStates = switchWarningStates; - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - for (int i=0; i<16; i++) { - c9x.limitData[i].ppmCenter = servoCenter[i]; - } - - return c9x; -} - -t_Open9xArmModelData_v210::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<9; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<64; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<32; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<32; i++) - c9x.expoData[i] = expoData[i]; - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - for (int i=0; i<32; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<32; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.frsky.varioSource = varioSource; - c9x.frsky.varioCenterMax = varioSpeedUpMin; - c9x.frsky.varioCenterMin = varioSpeedDownMin; - c9x.switchWarningStates = switchWarningStates; - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - for (int i=0; i<16; i++) { - c9x.limitData[i].ppmCenter = servoCenter[i]; - } - - return c9x; -} - -t_Open9xArmModelData_v211::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<9; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<64; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<32; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<32; i++) - c9x.expoData[i] = expoData[i]; - for (int i=0; i<16; i++) { - CurveInfo crvinfo = curveinfo(this, i); - c9x.curves[i].type = (crvinfo.custom ? CurveData::CURVE_TYPE_CUSTOM : CurveData::CURVE_TYPE_STANDARD); - c9x.curves[i].count = crvinfo.points; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<64; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<32; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<32; i++) - c9x.expoData[i] = expoData[i]; - for (int i=0; i<16; i++) { - CurveInfo crvinfo = curveinfo(this, i); - c9x.curves[i].type = (crvinfo.custom ? CurveData::CURVE_TYPE_CUSTOM : CurveData::CURVE_TYPE_STANDARD); - c9x.curves[i].count = crvinfo.points; - for (int j=0; j - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ - -#ifndef open9xSky9xeeprom_h -#define open9xSky9xeeprom_h - -#include "open9xStockeeprom.h" - -PACK(typedef struct t_Open9xArmTimerData_v202 { - int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw - uint16_t val; - - operator TimerData(); - t_Open9xArmTimerData_v202() { memset(this, 0, sizeof(t_Open9xArmTimerData_v202)); } -}) Open9xArmTimerData_v202; - -PACK(typedef struct t_Open9xArmExpoData_v208 { - uint8_t mode; // 0=end, 1=pos, 2=neg, 3=both - uint8_t chn; - int8_t curve; // 0=no curve, 1-6=std curves, 7-10=CV1-CV4, 11-15=CV9-CV13 - int8_t swtch; - int8_t phase; // if negPhase is 0: 0=normal, 5=FP4 if negPhase is 1: 5=!FP4 - uint8_t weight; - int8_t expo; - - operator ExpoData(); - t_Open9xArmExpoData_v208() { memset(this, 0, sizeof(t_Open9xArmExpoData_v208)); } -}) Open9xArmExpoData_v208; - -PACK(typedef struct t_Open9xArmExpoData_v210 { - uint8_t mode; // 0=end, 1=pos, 2=neg, 3=both - uint8_t chn; - int8_t curve; // 0=no curve, 1-6=std curves, 7-10=CV1-CV4, 11-15=CV9-CV13 - int8_t swtch; - int8_t phase; // if negPhase is 0: 0=normal, 5=FP4 if negPhase is 1: 5=!FP4 - uint8_t weight; - int8_t expo; - char name[6]; - uint8_t spare[4]; - - operator ExpoData(); - t_Open9xArmExpoData_v210() { memset(this, 0, sizeof(t_Open9xArmExpoData_v210)); } -}) Open9xArmExpoData_v210; - -PACK(typedef struct t_Open9xArmExpoData_v212 { - uint8_t mode; // 0=end, 1=pos, 2=neg, 3=both - uint8_t chn; - int8_t swtch; - uint16_t phases; - int8_t weight; - uint8_t curveMode; - char name[6]; - int8_t curveParam; - - operator ExpoData(); - t_Open9xArmExpoData_v212() { memset(this, 0, sizeof(t_Open9xArmExpoData_v212)); } -}) Open9xArmExpoData_v212; - -PACK(typedef struct t_Open9xArmMixData_v208 { - uint8_t destCh; // 0, 1..C9X_NUM_CHNOUT - int8_t phase; // -5=!FP4, 0=normal, 5=FP4 - int8_t weight; - int8_t swtch; - uint8_t mltpx; // multiplex method: 0 means +=, 1 means *=, 2 means := - int8_t curve; - uint8_t mixWarn; // mixer warning - uint8_t delayUp; - uint8_t delayDown; - uint8_t speedUp; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown; // 0 nichts - uint8_t srcRaw; // - int8_t differential; - uint8_t carryTrim; - int8_t sOffset; - - operator MixData(); - t_Open9xArmMixData_v208() { memset(this, 0, sizeof(t_Open9xArmMixData_v208)); } -}) Open9xArmMixData_v208; - -PACK(typedef struct t_Open9xArmMixData_v209 { - uint8_t destCh; // 0, 1..C9X_NUM_CHNOUT - int8_t phase; // -5=!FP4, 0=normal, 5=FP4 - int8_t weight; - int8_t swtch; - uint8_t mltpx; // multiplex method: 0 means +=, 1 means *=, 2 means := - int8_t curve; - uint8_t mixWarn; // mixer warning - uint8_t delayUp; - uint8_t delayDown; - uint8_t speedUp; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown; // 0 nichts - uint8_t srcRaw; // - int8_t differential; - int8_t carryTrim; - int8_t sOffset; - - operator MixData(); - t_Open9xArmMixData_v209() { memset(this, 0, sizeof(t_Open9xArmMixData_v209)); } -}) Open9xArmMixData_v209; - -PACK(typedef struct t_Open9xArmMixData_v210 { - uint8_t destCh; // 0, 1..C9X_NUM_CHNOUT - int8_t phase; // -5=!FP4, 0=normal, 5=FP4 - int8_t weight; - int8_t swtch; - uint8_t mltpx; // multiplex method: 0 means +=, 1 means *=, 2 means := - int8_t curve; - uint8_t mixWarn; // mixer warning - uint8_t delayUp; - uint8_t delayDown; - uint8_t speedUp; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown; // 0 nichts - uint8_t srcRaw; // - int8_t differential; - int8_t carryTrim; - int8_t sOffset; - char name[6]; - uint8_t spare[4]; - - operator MixData(); - t_Open9xArmMixData_v210() { memset(this, 0, sizeof(t_Open9xArmMixData_v210)); } -}) Open9xArmMixData_v210; - -PACK(typedef struct t_Open9xArmMixData_v212 { - uint8_t destCh; - uint16_t phases; - uint8_t curveMode:1; // O=curve, 1=differential - uint8_t noExpo:1; - int8_t carryTrim:3; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - uint8_t spare:1; - int8_t weight; - int8_t swtch; - int8_t curveParam; - uint8_t mixWarn; // mixer warning - uint8_t delayUp; - uint8_t delayDown; - uint8_t speedUp; - uint8_t speedDown; - uint8_t srcRaw; - int8_t sOffset; - char name[6]; - - operator MixData(); - t_Open9xArmMixData_v212() { memset(this, 0, sizeof(t_Open9xArmMixData_v212)); } -}) Open9xArmMixData_v212; - -PACK(typedef struct t_Open9xArmFlightModeData_v208 { - int16_t trim[4]; // -500..500 => trim value, 501 => use trim of phase 0, 502, 503, 504 => use trim of phases 1|2|3|4 instead - int8_t swtch; // swtch of phase[0] is not used - char name[6]; - uint8_t fadeIn:4; - uint8_t fadeOut:4; - operator FlightModeData(); - t_Open9xArmFlightModeData_v208() { memset(this, 0, sizeof(t_Open9xArmFlightModeData_v208)); } -}) Open9xArmFlightModeData_v208; - -PACK(typedef struct t_Open9xArmFlightModeData_v212 { - int16_t trim[4]; // -500..500 => trim value, 501 => use trim of phase 0, 502, 503, 504 => use trim of phases 1|2|3|4 instead - int8_t swtch; // swtch of phase[0] is not used - char name[6]; - uint8_t fadeIn:4; - uint8_t fadeOut:4; - int16_t rotaryEncoders[1]; - operator FlightModeData(); - t_Open9xArmFlightModeData_v212() { memset(this, 0, sizeof(t_Open9xArmFlightModeData_v212)); } -}) Open9xArmFlightModeData_v212; - -PACK(typedef struct t_Open9xArmLogicalSwitchData_v208 { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; - - operator LogicalSwitchData(); - t_Open9xArmLogicalSwitchData_v208() { memset(this, 0, sizeof(t_Open9xArmLogicalSwitchData_v208)); } -}) Open9xArmLogicalSwitchData_v208; - -PACK(typedef struct t_Open9xArmLogicalSwitchData_v209 { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; - - operator LogicalSwitchData(); - t_Open9xArmLogicalSwitchData_v209() { memset(this, 0, sizeof(t_Open9xArmLogicalSwitchData_v209)); } -}) Open9xArmLogicalSwitchData_v209; - -PACK(typedef struct t_Open9xArmLogicalSwitchData_v210 { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; - uint8_t delay; - uint8_t duration; - - operator LogicalSwitchData(); - t_Open9xArmLogicalSwitchData_v210() { memset(this, 0, sizeof(t_Open9xArmLogicalSwitchData_v210)); } -}) Open9xArmLogicalSwitchData_v210; - -PACK(typedef struct t_Open9xArmCustomFunctionData_v208 { // Function Switches data - int8_t swtch; // input - uint8_t func; - uint8_t param; - - operator CustomFunctionData(); - t_Open9xArmCustomFunctionData_v208() { memset(this, 0, sizeof(t_Open9xArmCustomFunctionData_v208)); } -}) Open9xArmCustomFunctionData_v208; - -PACK(typedef struct t_Open9xArmCustomFunctionData_v210 { // Function Switches data - int8_t swtch; // input - uint8_t func; - char param[6]; - - operator CustomFunctionData(); - t_Open9xArmCustomFunctionData_v210() { memset(this, 0, sizeof(t_Open9xArmCustomFunctionData_v210)); } -}) Open9xArmCustomFunctionData_v210; - -PACK(typedef struct t_Open9xArmCustomFunctionData_v211 { // Function Switches data - int8_t swtch; // input - uint8_t func; - char param[6]; - uint8_t delay; - uint8_t spare; - - operator CustomFunctionData(); - t_Open9xArmCustomFunctionData_v211() { memset(this, 0, sizeof(t_Open9xArmCustomFunctionData_v211)); } -}) Open9xArmCustomFunctionData_v211; - -PACK(typedef struct t_Open9xArmSwashRingData_v208 { // Swash Ring data - uint8_t invertELE:1; - uint8_t invertAIL:1; - uint8_t invertCOL:1; - uint8_t type:5; - uint8_t collectiveSource; - uint8_t value; - - operator SwashRingData(); - t_Open9xArmSwashRingData_v208() { memset(this, 0, sizeof(t_Open9xArmSwashRingData_v208)); } -}) Open9xArmSwashRingData_v208; - -PACK(typedef struct t_Open9xArmSwashRingData_v209 { // Swash Ring data - uint8_t invertELE:1; - uint8_t invertAIL:1; - uint8_t invertCOL:1; - uint8_t type:5; - uint8_t collectiveSource; - uint8_t value; - - operator SwashRingData(); - t_Open9xArmSwashRingData_v209() { memset(this, 0, sizeof(t_Open9xArmSwashRingData_v209)); } -}) Open9xArmSwashRingData_v209; - -PACK(typedef struct t_Open9xArmSwashRingData_v210 { // Swash Ring data - uint8_t invertELE:1; - uint8_t invertAIL:1; - uint8_t invertCOL:1; - uint8_t type:5; - uint8_t collectiveSource; - uint8_t value; - - operator SwashRingData(); - t_Open9xArmSwashRingData_v210() { memset(this, 0, sizeof(t_Open9xArmSwashRingData_v210)); } -}) Open9xArmSwashRingData_v210; - - -PACK(typedef struct t_Open9xArmFrSkyBarData_v210 { - uint8_t source; - uint8_t barMin; // minimum for bar display - uint8_t barMax; // ditto for max display (would usually = ratio) -}) Open9xArmFrSkyBarData_v210; - -PACK(typedef struct t_Open9xArmFrSkyData_v210 { - Open9xFrSkyChannelData_v208 channels[2]; - uint8_t usrProto:2; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh - uint8_t voltsSource:2; - uint8_t blades:2; - uint8_t currentSource:2; - Open9xArmFrSkyBarData_v210 bars[4]; - Open9xFrSkyRSSIAlarm rssiAlarms[2]; - uint8_t lines[4*2*2]; - uint8_t spare[4]; - - operator FrSkyData(); - t_Open9xArmFrSkyData_v210() { memset(this, 0, sizeof(t_Open9xArmFrSkyData_v210)); } -}) Open9xArmFrSkyData_v210; - -PACK(typedef struct t_Open9xArmFrSkyData_v211 { - Open9xFrSkyChannelData_v208 channels[2]; - Open9xFrSkyRSSIAlarm rssiAlarms[2]; - uint8_t usrProto; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh - uint8_t voltsSource; - uint8_t blades; // How many blades for RPMs, 0=2 blades, 1=3 blades - uint8_t currentSource; - Open9xArmFrSkyBarData_v210 bars[4]; - uint8_t lines[4*2*2]; - uint8_t varioSource; - uint8_t varioSpeedUpMin; // if increment in 0.2m/s = 3.0m/s max - uint8_t varioSpeedDownMin; - uint8_t spare[4]; - - operator FrSkyData(); - t_Open9xArmFrSkyData_v211() { memset(this, 0, sizeof(t_Open9xArmFrSkyData_v211)); } -}) Open9xArmFrSkyData_v211; - -PACK(typedef struct t_Open9xArmModelData_v208 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xArmTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xArmMixData_v208 mixData[64]; - Open9xLimitData_v201 limitData[32]; - Open9xArmExpoData_v208 expoData[32]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xArmLogicalSwitchData_v208 logicalSw[32]; - Open9xArmCustomFunctionData_v208 customFn[32]; - Open9xArmSwashRingData_v208 swashR; - Open9xArmFlightModeData_v208 flightModeData[9]; - Open9xFrSkyData_v208 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t frskyLines[4]; - uint16_t frskyLinesXtra; - int8_t servoCenter[32]; - - uint8_t varioSource:3; - uint8_t varioSpeedUpMin:5; // if increment in 0.2m/s = 3.0m/s max - uint8_t varioSpeedDownMin; - - operator ModelData(); - t_Open9xArmModelData_v208() { memset(this, 0, sizeof(t_Open9xArmModelData_v208)); } -}) Open9xArmModelData_v208; - -PACK(typedef struct t_Open9xArmModelData_v209 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xArmTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xArmMixData_v209 mixData[64]; - Open9xLimitData_v201 limitData[32]; - Open9xArmExpoData_v208 expoData[32]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xArmLogicalSwitchData_v209 logicalSw[32]; - Open9xArmCustomFunctionData_v208 customFn[32]; - Open9xArmSwashRingData_v209 swashR; - Open9xArmFlightModeData_v208 flightModeData[9]; - Open9xFrSkyData_v208 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t frskyLines[4]; - uint16_t frskyLinesXtra; - int8_t servoCenter[32]; - - uint8_t varioSource:3; - uint8_t varioSpeedUpMin:5; // if increment in 0.2m/s = 3.0m/s max - uint8_t varioSpeedDownMin; - uint8_t switchWarningStates; - - operator ModelData(); - t_Open9xArmModelData_v209() { memset(this, 0, sizeof(t_Open9xArmModelData_v209)); } -}) Open9xArmModelData_v209; - -PACK(typedef struct t_Open9xArmModelData_v210 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xArmTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xArmMixData_v210 mixData[64]; - Open9xLimitData_v201 limitData[32]; - Open9xArmExpoData_v210 expoData[32]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xArmLogicalSwitchData_v210 logicalSw[32]; - Open9xArmCustomFunctionData_v210 customFn[32]; - Open9xArmSwashRingData_v209 swashR; - Open9xArmFlightModeData_v208 flightModeData[9]; - Open9xArmFrSkyData_v210 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - int8_t servoCenter[32]; - - uint8_t varioSource:3; - uint8_t varioSpeedUpMin:5; // if increment in 0.2m/s = 3.0m/s max - uint8_t varioSpeedDownMin; - uint8_t switchWarningStates; - - operator ModelData(); - t_Open9xArmModelData_v210() { memset(this, 0, sizeof(t_Open9xArmModelData_v210)); } - -}) Open9xArmModelData_v210; - -PACK(typedef struct t_Open9xArmModelData_v211 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xArmTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xArmMixData_v210 mixData[64]; - Open9xLimitData_v201 limitData[32]; - Open9xArmExpoData_v210 expoData[32]; - int16_t curves[16]; - int8_t points[512]; - Open9xArmLogicalSwitchData_v210 logicalSw[32]; - Open9xArmCustomFunctionData_v211 customFn[32]; - Open9xArmSwashRingData_v209 swashR; - Open9xArmFlightModeData_v208 flightModeData[9]; - - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - - int8_t servoCenter[32]; - - uint8_t switchWarningStates; - - Open9xArmFrSkyData_v211 frsky; - - operator ModelData(); - t_Open9xArmModelData_v211() { memset(this, 0, sizeof(t_Open9xArmModelData_v211)); } -}) Open9xArmModelData_v211; - -PACK(typedef struct t_Open9xArmModelData_v212 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xArmTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare1:1; - int8_t ppmDelay; - uint16_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xArmMixData_v212 mixData[64]; - Open9xLimitData_v211 limitData[32]; - Open9xArmExpoData_v212 expoData[32]; - int16_t curves[16]; - int8_t points[512]; - Open9xArmLogicalSwitchData_v210 logicalSw[32]; - Open9xArmCustomFunctionData_v211 customFn[32]; - Open9xArmSwashRingData_v210 swashR; - Open9xArmFlightModeData_v212 flightModeData[9]; - - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t switchWarningStates; - - Open9xArmFrSkyData_v211 frsky; - Open9xTimerDataExtra timersXtra[2]; - - operator ModelData(); - t_Open9xArmModelData_v212() { memset(this, 0, sizeof(t_Open9xArmModelData_v212)); } -}) Open9xArmModelData_v212; - -#endif diff --git a/companion/src/firmwares/opentx/open9xStockeeprom.cpp b/companion/src/firmwares/opentx/open9xStockeeprom.cpp deleted file mode 100644 index 3762733c6..000000000 --- a/companion/src/firmwares/opentx/open9xStockeeprom.cpp +++ /dev/null @@ -1,1632 +0,0 @@ -#include -#include -#include "helpers.h" -#include "open9xStockeeprom.h" -#include -#include - -static const char specialCharsTab[] = "_-.,"; - -void DUMP(void *data, int size) -{ - for (int i=0; i='A' && c<='Z') return 1+c-'A'; - if (c>='a' && c<='z') return -1-c+'a'; - if (c>='0' && c<='9') return 27+c-'0'; - for (int8_t i=0;;i++) { - char cc = specialCharsTab[i]; - if (cc==0) return 0; - if (cc==c) return 37+i; - } -} - -#define ZCHAR_MAX 40 -char idx2char(int8_t idx) -{ - if (idx == 0) return ' '; - if (idx < 0) { - if (idx > -27) return 'a' - idx - 1; - idx = -idx; - } - if (idx < 27) return 'A' + idx - 1; - if (idx < 37) return '0' + idx - 27; - if (idx <= ZCHAR_MAX) return specialCharsTab[idx-37]; - return ' '; -} - -void setEEPROMZString(char *dst, const char *src, int size) -{ - for (int i=size-1; i>=0; i--) - dst[i] = char2idx(src[i]); -} - -void getEEPROMZString(char *dst, const char *src, int size) -{ - for (int i=size-1; i>=0; i--) - dst[i] = idx2char(src[i]); - dst[size] = '\0'; - for (int i=size-1; i>=0; i--) { - if (dst[i] == ' ') - dst[i] = '\0'; - else - break; - } -} - -RawSwitch open9xStockToSwitch(int8_t sw) -{ - uint8_t swa = abs(sw); - if (swa == 0) - return RawSwitch(SWITCH_TYPE_NONE); - else if (swa <= 9) - return RawSwitch(SWITCH_TYPE_SWITCH, sw); - else if (swa <= 21) - return RawSwitch(SWITCH_TYPE_VIRTUAL, sw > 0 ? sw-9 : sw+9); - else if (sw == 22) - return RawSwitch(SWITCH_TYPE_ON); - else if (sw == 44) - return RawSwitch(SWITCH_TYPE_ON); - else if (sw == -22) - return RawSwitch(SWITCH_TYPE_OFF); - else if (swa <= 22+9) - return RawSwitch(SWITCH_TYPE_SWITCH, sw > 0 ? sw-22 : sw+22); - else - return RawSwitch(SWITCH_TYPE_VIRTUAL, sw > 0 ? sw-22-9 : sw+22+9); -} - -t_Open9xExpoData_v201::operator ExpoData () -{ - ExpoData c9x; - c9x.mode = mode; - c9x.chn = chn; - if (expo != 0 && curve != 0) { - EEPROMWarnings.push_back(::QObject::tr("Simultaneous usage of expo and curves is no longer supported in OpenTX")); - } - else { - if (curve == 0) { - c9x.curve = CurveReference(CurveReference::CURVE_REF_EXPO, expo); - } - else { - // TODO - } - } - c9x.swtch = open9xStockToSwitch(swtch); - if (negPhase) { - c9x.flightModes = 1 << (phase -1); - } - else if (phase == 0) { - c9x.flightModes = 0; - } - else { - c9x.flightModes = 63; - c9x.flightModes &= ~(1 << (phase -1)); - } - c9x.weight = weight; - return c9x; -} - -t_Open9xExpoData_v211::operator ExpoData () -{ - ExpoData c9x; - c9x.mode = mode; - c9x.chn = chn; - // TODO c9x.curve - c9x.swtch = open9xStockToSwitch(swtch); - c9x.flightModes = phases; - c9x.weight = weight; - return c9x; -} - -t_Open9xLimitData_v201::operator LimitData () -{ - LimitData c9x; - c9x.min = 10 * (min - 100); - c9x.max = 10 * (max + 100); - c9x.revert = revert; - c9x.offset = offset; - return c9x; -} - -t_Open9xLimitData_v211::operator LimitData () -{ - LimitData c9x; - c9x.min = 10 * (min - 100); - c9x.max = 10 * (max + 100); - c9x.revert = revert; - c9x.offset = offset; - c9x.symetrical = symetrical; - c9x.ppmCenter = ppmCenter; - return c9x; -} - -t_Open9xMixData_v201::operator MixData () -{ - MixData c9x; - c9x.destCh = destCh; - c9x.weight = weight; - c9x.swtch = open9xStockToSwitch(swtch); - - if (srcRaw == 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); - } - else if (srcRaw <= 7) { - c9x.srcRaw = RawSource(SOURCE_TYPE_STICK, srcRaw-1); - } - else if (srcRaw == 8) { - c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); - } - else if (srcRaw == 9) { - if (swtch < 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, -swtch); - c9x.weight = -weight; - } - else if (swtch > 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, swtch); - } - else { - c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); - } - if (mltpx != MLTPX_REP) - c9x.swtch = RawSwitch(SWITCH_TYPE_NONE); - } - else if (srcRaw <= 12) { - c9x.srcRaw = RawSource(SOURCE_TYPE_CYC, srcRaw-10); - } - else if (srcRaw <= 20) { - c9x.srcRaw = RawSource(SOURCE_TYPE_PPM, srcRaw-13); - } - else { - c9x.srcRaw = RawSource(SOURCE_TYPE_CH, srcRaw-21); - } - - // TODO c9x.curve = curve; - c9x.delayUp = delayUp; - c9x.delayDown = delayDown; - c9x.speedUp = speedUp; - c9x.speedDown = speedDown; - c9x.carryTrim = carryTrim; - c9x.mltpx = (MltpxValue)mltpx; - c9x.mixWarn = mixWarn; - - if (phase < 0) { - c9x.flightModes = 1 << (-phase -1); - } else if (phase == 0) { - c9x.flightModes = 0; - } else { - c9x.flightModes = 63; - c9x.flightModes &= ~(1 << (phase -1)); - } - c9x.sOffset = sOffset; - return c9x; -} - -t_Open9xMixData_v203::operator MixData () -{ - MixData c9x; - c9x.destCh = destCh; - c9x.weight = weight; - c9x.swtch = open9xStockToSwitch(swtch); - - if (srcRaw == 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); - } - else if (srcRaw <= 7) { - c9x.srcRaw = RawSource(SOURCE_TYPE_STICK, srcRaw-1); - } - else if (srcRaw == 8) { - c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); - } - else if (srcRaw == 9) { - if (swtch < 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, -swtch); - c9x.weight = -weight; - } - else if (swtch > 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, swtch); - } - else { - c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); - } - if (mltpx != MLTPX_REP) - c9x.swtch = RawSwitch(SWITCH_TYPE_NONE); - } - else if (srcRaw <= 12) { - c9x.srcRaw = RawSource(SOURCE_TYPE_CYC, srcRaw-10); - } - else if (srcRaw <= 20) { - c9x.srcRaw = RawSource(SOURCE_TYPE_PPM, srcRaw-13); - } - else { - c9x.srcRaw = RawSource(SOURCE_TYPE_CH, srcRaw-21); - } - - // TODO c9x.curve = curve; - c9x.delayUp = delayUp; - c9x.delayDown = delayDown; - c9x.speedUp = speedUp; - c9x.speedDown = speedDown; - c9x.carryTrim = carryTrim; - c9x.mltpx = (MltpxValue)mltpx; - c9x.mixWarn = mixWarn; - - if (phase < 0) { - c9x.flightModes = 1 << (-phase -1); - } else if (phase == 0) { - c9x.flightModes = 0; - } else { - c9x.flightModes = 63; - c9x.flightModes &= ~(1 << (phase -1)); - } - c9x.sOffset = sOffset; - return c9x; -} - -t_Open9xMixData_v205::operator MixData () -{ - MixData c9x; - - if (srcRaw) { - c9x.destCh = destCh+1; - c9x.swtch = open9xStockToSwitch(swtch); - - if (srcRaw == 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); - } - else if (srcRaw <= 7) { - c9x.srcRaw = RawSource(SOURCE_TYPE_STICK, srcRaw-1); - } - else if (srcRaw == 8) { - c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); - } - else if (srcRaw == 9) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, 0); - } - else if (srcRaw <= 30) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, srcRaw-9); - } - else if (srcRaw <= 33) { - c9x.srcRaw = RawSource(SOURCE_TYPE_CYC, srcRaw-31); - } - else if (srcRaw <= 41) { - c9x.srcRaw = RawSource(SOURCE_TYPE_PPM, srcRaw-34); - } - else { - c9x.srcRaw = RawSource(SOURCE_TYPE_CH, srcRaw-42); - } - c9x.weight = weight; - - if (differential) { - c9x.curve = CurveReference(CurveReference::CURVE_REF_DIFF, differential*2); - } - else { - // TODO c9x.curve = curve; - } - - c9x.delayUp = delayUp; - c9x.delayDown = delayDown; - c9x.speedUp = speedUp; - c9x.speedDown = speedDown; - c9x.carryTrim = carryTrim; - c9x.mltpx = (MltpxValue)mltpx; - c9x.mixWarn = mixWarn; - - if (phase < 0) { - c9x.flightModes = 1 << (-phase -1); - } - else if (phase == 0) { - c9x.flightModes = 0; - } - else { - c9x.flightModes = 63; - c9x.flightModes &= ~(1 << (phase -1)); - } - c9x.sOffset = sOffset; - } - return c9x; -} - -t_Open9xMixData_v209::operator MixData () -{ - MixData c9x; - - if (srcRaw) { - c9x.destCh = destCh + 1; - c9x.swtch = open9xStockToSwitch(swtch); - - if (srcRaw == 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); - } - else if (srcRaw <= 7) { - c9x.srcRaw = RawSource(SOURCE_TYPE_STICK, srcRaw-1); - } - else if (srcRaw <= 11) { - c9x.srcRaw = RawSource(SOURCE_TYPE_TRIM, srcRaw-8); - } - else if (srcRaw == 12) { - c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); - } - else if (srcRaw == 13) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, 0); - } - else if (srcRaw <= 34) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, srcRaw-13); - } - else if (srcRaw <= 37) { - c9x.srcRaw = RawSource(SOURCE_TYPE_CYC, srcRaw-35); - } - else if (srcRaw <= 45) { - c9x.srcRaw = RawSource(SOURCE_TYPE_PPM, srcRaw-38); - } - else { - c9x.srcRaw = RawSource(SOURCE_TYPE_CH, srcRaw-46); - } - c9x.weight = weight; - - if (differential) { - c9x.curve = CurveReference(CurveReference::CURVE_REF_DIFF, differential*2); - } - else { - // TODO c9x.curve = curve; - } - - c9x.delayUp = delayUp; - c9x.delayDown = delayDown; - c9x.speedUp = speedUp; - c9x.speedDown = speedDown; - c9x.carryTrim = carryTrim; - c9x.mltpx = (MltpxValue)mltpx; - c9x.mixWarn = mixWarn; - - if (phase < 0) { - c9x.flightModes = 1 << (-phase -1); - } - else if (phase ==0 ) { - c9x.flightModes = 0; - } - else { - c9x.flightModes = 63; - c9x.flightModes &= ~(1 << (phase -1)); - } - c9x.sOffset = sOffset; - } - return c9x; -} - -t_Open9xMixData_v211::operator MixData () -{ - MixData c9x; - - if (srcRaw) { - c9x.destCh = destCh + 1; - c9x.swtch = open9xStockToSwitch(swtch); - - if (srcRaw == 0) { - c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); - } - else if (srcRaw <= 7) { - c9x.srcRaw = RawSource(SOURCE_TYPE_STICK, srcRaw-1); - } - else if (srcRaw <= 11) { - c9x.srcRaw = RawSource(SOURCE_TYPE_TRIM, srcRaw-8); - } - else if (srcRaw == 12) { - c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); - } - else if (srcRaw == 13) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, 0); - } - else if (srcRaw <= 34) { - c9x.srcRaw = RawSource(SOURCE_TYPE_SWITCH, srcRaw-13); - } - else if (srcRaw <= 37) { - c9x.srcRaw = RawSource(SOURCE_TYPE_CYC, srcRaw-35); - } - else if (srcRaw <= 45) { - c9x.srcRaw = RawSource(SOURCE_TYPE_PPM, srcRaw-38); - } - else { - c9x.srcRaw = RawSource(SOURCE_TYPE_CH, srcRaw-46); - } - c9x.weight = weight; - - if (curveMode==0) { - c9x.curve = CurveReference(CurveReference::CURVE_REF_DIFF, curveParam); - } - else { - // TODO c9x.curve = curve; - } - - c9x.delayUp = delayUp; - c9x.delayDown = delayDown; - c9x.speedUp = speedUp; - c9x.speedDown = speedDown; - c9x.carryTrim = carryTrim; - c9x.noExpo = noExpo; - c9x.mltpx = (MltpxValue)mltpx; - c9x.mixWarn = mixWarn; - c9x.flightModes = phases; - c9x.sOffset = sOffset; - } - return c9x; -} - -RawSource open9x208ToSource(int8_t value) -{ - if (value == 0) { - return RawSource(SOURCE_TYPE_NONE); - } - else if (value <= 7) { - return RawSource(SOURCE_TYPE_STICK, value - 1); - } - else if (value == 8) { - return RawSource(SOURCE_TYPE_MAX); - } - /* else if (value == 9) { - return RawSource(SOURCE_TYPE_3POS); - } */ - else if (value <= 12) { - return RawSource(SOURCE_TYPE_CYC, value-10); - } - else if (value <= 20) { - return RawSource(SOURCE_TYPE_PPM, value-13); - } - else if (value <= 36) { - return RawSource(SOURCE_TYPE_CH, value-21); - } - else { - return RawSource(SOURCE_TYPE_TELEMETRY, value-36); - } -} - -RawSource open9xStock209ToSource(int8_t value) -{ - if (value == 0) { - return RawSource(SOURCE_TYPE_NONE); - } - else if (value <= 7) { - return RawSource(SOURCE_TYPE_STICK, value - 1); - } - else if (value <= 11) { - return RawSource(SOURCE_TYPE_TRIM, value - 8); - } - else if (value == 12) { - return RawSource(SOURCE_TYPE_MAX); - } - /* else if (value == 13) { - return RawSource(SOURCE_TYPE_3POS); - } */ - else if (value <= 16) { - return RawSource(SOURCE_TYPE_CYC, value-14); - } - else if (value <= 24) { - return RawSource(SOURCE_TYPE_PPM, value-17); - } - else if (value <= 40) { - return RawSource(SOURCE_TYPE_CH, value-25); - } - else { - return RawSource(SOURCE_TYPE_TELEMETRY, value-40); - } -} - -Open9xLogicalSwitchData_v208::operator LogicalSwitchData () -{ - LogicalSwitchData c9x; - c9x.func = func; - c9x.val1 = v1; - c9x.val2 = v2; - - if ((c9x.func >= LS_FN_VPOS && c9x.func <= LS_FN_ANEG) || c9x.func >= LS_FN_EQUAL) { - c9x.val1 = open9x208ToSource(v1).toValue(); - } - - if (c9x.func >= LS_FN_EQUAL) { - c9x.val2 = open9x208ToSource(v2).toValue(); - } - - if (c9x.func >= LS_FN_AND && c9x.func <= LS_FN_XOR) { - c9x.val1 = open9xStockToSwitch(v1).toValue(); - c9x.val2 = open9xStockToSwitch(v2).toValue(); - } - - return c9x; -} - -Open9xLogicalSwitchData_v209::operator LogicalSwitchData () -{ - LogicalSwitchData c9x; - c9x.func = func; - c9x.val1 = v1; - c9x.val2 = v2; - - if ((c9x.func >= LS_FN_VPOS && c9x.func <= LS_FN_ANEG) || c9x.func >= LS_FN_EQUAL) { - c9x.val1 = open9xStock209ToSource(v1).toValue(); - } - - if (c9x.func >= LS_FN_EQUAL && c9x.func <= LS_FN_ELESS) { - c9x.val2 = open9xStock209ToSource(v2).toValue(); - } - - if (c9x.func >= LS_FN_AND && c9x.func <= LS_FN_XOR) { - c9x.val1 = open9xStockToSwitch(v1).toValue(); - c9x.val2 = open9xStockToSwitch(v2).toValue(); - } - - return c9x; -} - -t_Open9xCustomFunctionData_v201::operator CustomFunctionData () -{ - CustomFunctionData c9x; - c9x.swtch = open9xStockToSwitch(swtch); - c9x.func = (AssignFunc)(func+16); - return c9x; -} - -enum Functions { - FUNC_OVERRIDE_CH1, - FUNC_OVERRIDE_CH16=FUNC_OVERRIDE_CH1+15, - FUNC_TRAINER, - FUNC_TRAINER_RUD, - FUNC_TRAINER_ELE, - FUNC_TRAINER_THR, - FUNC_TRAINER_AIL, - FUNC_INSTANT_TRIM, - FUNC_PLAY_SOUND, - FUNC_HAPTIC, -#if defined(PCBV4) - FUNC_PLAY_SOMO, -#endif - FUNC_RESET, - FUNC_VARIO, -#if defined(PCBV4) - FUNC_LOGS, -#endif - FUNC_BACKLIGHT, -#if defined(DEBUG) - FUNC_TEST, // should remain the last before MAX as not added in companion -#endif - FUNC_MAX -}; - -t_Open9xCustomFunctionData_v203::operator CustomFunctionData () -{ - CustomFunctionData c9x; - c9x.swtch = open9xStockToSwitch(swtch); - if (func < 16) { - c9x.enabled = param & 0x01; - c9x.param = (param>>1) << 1; - c9x.func = (AssignFunc)(func); - } else { - c9x.param = param; - if (func <= 20) - c9x.func = (AssignFunc)(func); - else if (func == 21) - c9x.func = FuncInstantTrim; - else if (func == 22) - c9x.func = FuncPlaySound; - else if (func == 23) - c9x.func = FuncPlayHaptic; - else if (func == 24) - c9x.func = FuncReset; - else if (func == 25) - c9x.func = FuncVario; - else if (func == 26) - c9x.func = FuncBacklight; - else - c9x.clear(); - } - return c9x; -} - -t_Open9xCustomFunctionData_v210::operator CustomFunctionData () -{ - CustomFunctionData c9x; - c9x.swtch = open9xStockToSwitch(swtch); - c9x.param = param; - if (func < 22) { - c9x.enabled = delay; - c9x.func = (AssignFunc)(func); - } - else { - if (func == 22) - c9x.func = FuncPlaySound; - else if (func == 23) { - c9x.func = FuncPlayHaptic; - } - else if (func == 24) - c9x.func = FuncReset; - else if (func == 25) - c9x.func = FuncVario; - else if (func == 26) - c9x.func = FuncPlayPrompt; - else if (func == 27) { - c9x.func = FuncPlayValue; - if (param > 7) { - c9x.param += 2; - } - } else if (func == 28) - c9x.func = FuncBacklight; - else - c9x.clear(); - } - return c9x; -} - -t_Open9xSwashRingData_v208::operator SwashRingData () -{ - SwashRingData c9x; - c9x.elevatorWeight = invertELE ? -100 : 100; - c9x.aileronWeight = invertAIL ? -100 : 100; - c9x.collectiveWeight = invertCOL ? -100 : 100; - c9x.type = type; - c9x.collectiveSource = open9x208ToSource(collectiveSource); - c9x.value = value; - return c9x; -} - -t_Open9xSwashRingData_v209::operator SwashRingData () -{ - SwashRingData c9x; - c9x.elevatorWeight = invertELE ? -100 : 100; - c9x.aileronWeight = invertAIL ? -100 : 100; - c9x.collectiveWeight = invertCOL ? -100 : 100; - c9x.type = type; - c9x.collectiveSource = open9xStock209ToSource(collectiveSource); - c9x.value = value; - return c9x; -} - -t_Open9xFlightModeData_v201::operator FlightModeData () -{ - FlightModeData c9x; - for (int i=0; i> (2*i)) & 0x03); - c9x.swtch = open9xStockToSwitch(swtch); - getEEPROMZString(c9x.name, name, sizeof(name)); - c9x.fadeIn = fadeIn; - c9x.fadeOut = fadeOut; - return c9x; -} - -t_Open9xTimerData_v201::operator TimerData () -{ - TimerData c9x; - // c9x.mode = TMRMODE_OFF; - c9x.val = val; - c9x.persistent = persistent; - return c9x; -} - -t_Open9xTimerData_v202::operator TimerData () -{ - TimerData c9x; -/* - if (mode <= -22) - c9x.mode = TimerMode(TMRMODE_FIRST_NEG_SWITCH+(mode+22)); - else if (mode <= -1) - c9x.mode = TimerMode(TMRMODE_FIRST_NEG_SWITCH+(mode+1)); - else if (mode < 5) - c9x.mode = TimerMode(mode); - else if (mode < 5+21) - c9x.mode = TimerMode(TMRMODE_FIRST_SWITCH+(mode-5)); - else - c9x.mode = TimerMode(TMRMODE_FIRST_SWITCH+(mode-5-21)); -*/ - c9x.val = val; - c9x.persistent = false; - return c9x; -} - -FrSkyRSSIAlarm t_Open9xFrSkyRSSIAlarm::get(int index) -{ - FrSkyRSSIAlarm c9x; - c9x.level = (2 + index + level) % 4; - c9x.value = value + 50; - return c9x; -} - -t_Open9xFrSkyChannelData_v201::operator FrSkyChannelData () -{ - FrSkyChannelData c9x; - c9x.ratio = ratio; - c9x.alarms[0].value = alarms_value[0]; - c9x.alarms[0].level = alarms_level & 3; - c9x.alarms[0].greater = alarms_greater & 1; - c9x.alarms[1].value = alarms_value[1]; - c9x.alarms[1].level = (alarms_level >> 2) & 3; - c9x.alarms[1].greater = (alarms_greater >> 1) & 1; - c9x.type = type; - c9x.offset = offset; - return c9x; -} - -t_Open9xFrSkyChannelData_v203::operator FrSkyChannelData () -{ - FrSkyChannelData c9x; - c9x.ratio = ratio; - c9x.alarms[0].value = alarms_value[0]; - c9x.alarms[0].level = alarms_level & 3; - c9x.alarms[0].greater = alarms_greater & 1; - c9x.alarms[1].value = alarms_value[1]; - c9x.alarms[1].level = (alarms_level >> 2) & 3; - c9x.alarms[1].greater = (alarms_greater >> 1) & 1; - c9x.type = type; - c9x.offset = offset; - return c9x; -} - -t_Open9xFrSkyChannelData_v204::operator FrSkyChannelData () -{ - FrSkyChannelData c9x; - c9x.ratio = ratio; - c9x.type = type; - c9x.multiplier = multiplier; - c9x.alarms[0].value = alarms_value[0]; - c9x.alarms[0].level = alarms_level & 3; - c9x.alarms[0].greater = alarms_greater & 1; - c9x.alarms[1].value = alarms_value[1]; - c9x.alarms[1].level = (alarms_level >> 2) & 3; - c9x.alarms[1].greater = (alarms_greater >> 1) & 1; - // TODO c9x.multiplier = multiplier; - c9x.offset = offset; - return c9x; -} - -t_Open9xFrSkyChannelData_v208::operator FrSkyChannelData () -{ - FrSkyChannelData c9x; - c9x.ratio = ratio; - c9x.type = type; - c9x.multiplier = multiplier; - c9x.alarms[0].value = alarms_value[0]; - c9x.alarms[0].level = alarms_level & 3; - c9x.alarms[0].greater = alarms_greater & 1; - c9x.alarms[1].value = alarms_value[1]; - c9x.alarms[1].level = (alarms_level >> 2) & 3; - c9x.alarms[1].greater = (alarms_greater >> 1) & 1; - // TODO c9x.multiplier = multiplier; - c9x.offset = offset; - return c9x; -} - -t_Open9xFrSkyData_v201::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - return c9x; -} - -t_Open9xFrSkyData_v202::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - c9x.usrProto = usrProto; - return c9x; -} - -t_Open9xFrSkyData_v203::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - c9x.usrProto = usrProto; - return c9x; -} - -t_Open9xFrSkyBarData_v204::operator FrSkyBarData () -{ - FrSkyBarData c9x; - c9x.source = RawSource(SOURCE_TYPE_TELEMETRY, source); - c9x.barMin = barMin; - c9x.barMax = barMax; - return c9x; -} - -t_Open9xFrSkyData_v204::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - c9x.usrProto = usrProto; - c9x.blades = blades + 2; - c9x.screens[0].type = 1; - for (int i=0; i<4; i++) - c9x.screens[0].body.bars[i] = bars[i]; - return c9x; -} - -t_Open9xFrSkyData_v205::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - c9x.usrProto = usrProto; - c9x.blades = blades + 2; - c9x.screens[0].type = 1; - for (int i=0; i<4; i++) - c9x.screens[0].body.bars[i] = bars[i]; - c9x.rssiAlarms[0] = rssiAlarms[0].get(0); - c9x.rssiAlarms[1] = rssiAlarms[1].get(1); - return c9x; -} - -t_Open9xFrSkyData_v208::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - c9x.usrProto = usrProto; - c9x.voltsSource = voltsSource; - c9x.blades = blades + 2; - c9x.currentSource=currentSource; - c9x.screens[0].type = 1; - for (int i=0; i<4; i++) - c9x.screens[0].body.bars[i] = bars[i]; - c9x.rssiAlarms[0] = rssiAlarms[0].get(0); - c9x.rssiAlarms[1] = rssiAlarms[1].get(1); - return c9x; -} - -t_Open9xFrSkyData_v210::operator FrSkyData () -{ - FrSkyData c9x; - c9x.channels[0] = channels[0]; - c9x.channels[1] = channels[1]; - c9x.usrProto = usrProto; - c9x.voltsSource = voltsSource; - c9x.blades = blades + 2; - c9x.currentSource=currentSource; - - int lines_screen_index = 0; - c9x.screens[0].type = 1; - for (int i=0; i<4; i++) { - if (bars[i].source) { - c9x.screens[0].body.bars[i] = bars[i]; - lines_screen_index = 1; - } - } - - c9x.screens[lines_screen_index].type = 0; - - c9x.rssiAlarms[0] = rssiAlarms[0].get(0); - c9x.rssiAlarms[1] = rssiAlarms[1].get(1); - c9x.varioSource = varioSource; - c9x.varioCenterMax = varioSpeedUpMin; - c9x.varioCenterMin = varioSpeedDownMin; - return c9x; -} - -t_Open9xModelData_v201::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - c9x.timers[0] = timer1; - c9x.timers[1] = timer2; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<12; i++) - c9x.customFn[i] = customFn[i]; - // for (int i=0; i<16; i++) - // c9x.safetySw[i] = safetySw[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - - return c9x; -} - -t_Open9xModelData_v202::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - c9x.timers[0] = timer1; - c9x.timers[1] = timer2; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter, - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<12; i++) - c9x.customFn[i] = customFn[i]; - // for (int i=0; i<16; i++) - // c9x.safetySw[i] = safetySw[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - return c9x; -} - -t_Open9xModelData_v203::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - c9x.timers[0] = timer1; - c9x.timers[1] = timer2; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<16; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - return c9x; -} - -t_Open9xModelData_v204::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - c9x.timers[0] = timer1; - c9x.timers[1] = timer2; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<16; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.frsky.rssiAlarms[0] = frskyRssiAlarms[0].get(0); - c9x.frsky.rssiAlarms[1] = frskyRssiAlarms[1].get(1); - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - return c9x; -} - -t_Open9xModelData_v205::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc - 2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<16; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0]. modelId = modelId; - c9x.frsky.screens[1].type = 0; - return c9x; -} - -t_Open9xModelData_v208::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.trimInc = trimInc - 2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<16; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.frsky.varioSource = varioSource; - c9x.frsky.varioCenterMax = varioSpeedUpMin; - c9x.frsky.varioCenterMin = varioSpeedDownMin; - - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - c9x.frsky.screens[1].type = 0; - for (int i=0; i<16; i++) { - c9x.limitData[i].ppmCenter = servoCenter[i]; - } - return c9x; -} - -t_Open9xModelData_v209::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.trimInc = trimInc - 2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - c9x.curves[i].count = 5; - for (int j = 0; j < 5; j++) { - c9x.curves[i].points[j].x = -100 + 50 * i; - c9x.curves[i].points[j].y = curves5[i][j]; - } - } - for (int i=0; i<8; i++) { - c9x.curves[8 + i].count = 9; - for (int j = 0; j < 9; j++) { - c9x.curves[8 + i].points[j].x = -100 + 25 * i; - c9x.curves[8 + i].points[j].y = curves9[i][j]; - } - } - - for (int i=0; i<12; i++) - c9x.logicalSw[i] = logicalSw[i]; - for (int i=0; i<16; i++) - c9x.customFn[i] = customFn[i]; - c9x.swashRingData = swashR; - c9x.frsky = frsky; - c9x.frsky.varioSource = varioSource; - c9x.frsky.varioCenterMax = varioSpeedUpMin; - c9x.frsky.varioCenterMin = varioSpeedDownMin; - c9x.switchWarningStates = switchWarningStates; - - c9x.moduleData[0].ppm.frameLength = ppmFrameLength; - c9x.thrTraceSrc = thrTraceSrc; - c9x.moduleData[0].modelId = modelId; - c9x.frsky.screens[1].type = 0; - for (int i=0; i<16; i++) { - c9x.limitData[i].ppmCenter = servoCenter[i]; - } - return c9x; -} - -t_Open9xModelData_v210::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMZString(c9x.name, name, sizeof(name)); - for (int i=0; i<2; i++) - c9x.timers[i] = timers[i]; - switch(protocol) { - case 1: - c9x.moduleData[0].protocol = PULSES_PPM16; - break; - case 2: - c9x.moduleData[0].protocol = PULSES_PPMSIM; - break; - case 3: - c9x.moduleData[0].protocol = PULSES_PXX_DJT; - break; - case 4: - c9x.moduleData[0].protocol = PULSES_DSM2; - break; - default: - c9x.moduleData[0].protocol = PULSES_PPM; - break; - } - c9x.moduleData[0].channelsCount = 8 + (2 * ppmNCH); - c9x.thrTrim = thrTrim; - c9x.disableThrottleWarning=disableThrottleWarning; - c9x.trimInc = trimInc - 2; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.beepANACenter = beepANACenter; - c9x.moduleData[0].ppm.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.extendedTrims = extendedTrims; - for (int i=0; i<5; i++) { - c9x.flightModeData[i] = flightModeData[i]; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - CurveInfo crvinfo = curveinfo(this, i); - c9x.curves[i].type = (crvinfo.custom ? CurveData::CURVE_TYPE_CUSTOM : CurveData::CURVE_TYPE_STANDARD); - c9x.curves[i].count = crvinfo.points; - for (int j=0; j 500) { - c9x.flightModeData[i].trimRef[j] = c9x.flightModeData[i].trim[j] - 501; - if (c9x.flightModeData[i].trimRef[j] >= i) - c9x.flightModeData[i].trimRef[j] += 1; - c9x.flightModeData[i].trim[j] = 0; - } - } - } - for (int i=0; i<32; i++) - c9x.mixData[i] = mixData[i]; - for (int i=0; i<16; i++) - c9x.limitData[i] = limitData[i]; - for (int i=0; i<14; i++) - c9x.expoData[i] = expoData[i]; - - for (int i=0; i<8; i++) { - CurveInfo crvinfo = curveinfo(this, i); - c9x.curves[i].type = (crvinfo.custom ? CurveData::CURVE_TYPE_CUSTOM : CurveData::CURVE_TYPE_STANDARD); - c9x.curves[i].count = crvinfo.points; - for (int j=0; j - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ -#ifndef open9xstockeeprom_h -#define open9xstockeeprom_h - -#define O9X_MAX_CSFUNCOLD 13 -#define O9X_MAX_CSFUNC 15 - -#include -#include "eeprominterface.h" -#include - -int8_t open9xV4209FromSource(RawSource source); -int8_t open9xStock209FromSource(RawSource source); -RawSource open9xV4209ToSource(int8_t value); -RawSource open9xStock209ToSource(int8_t value); -int8_t open9xStockFromSwitch(const RawSwitch & sw); -RawSwitch open9xStockToSwitch(int8_t sw); - -struct CurveInfo { - int8_t *crv; - uint8_t points; - bool custom; -}; - -template -int8_t *curveaddress(T * model, uint8_t idx) -{ - return &model->points[idx==0 ? 0 : 5*idx+model->curves[idx-1]]; -} - -template -extern CurveInfo curveinfo(T * model, uint8_t idx) -{ - CurveInfo result; - result.crv = curveaddress(model, idx); - int8_t *next = curveaddress(model, idx+1); - uint8_t size = next - result.crv; - if (size % 2 == 0) { - result.points = (size / 2) + 1; - result.custom = true; - } - else { - result.points = size; - result.custom = false; - } - return result; -} - -PACK(typedef struct t_Open9xFrSkyRSSIAlarm { - uint8_t level:2; - int8_t value:6; - FrSkyRSSIAlarm get(int index); - t_Open9xFrSkyRSSIAlarm() { memset(this, 0, sizeof(t_Open9xFrSkyRSSIAlarm)); } -}) Open9xFrSkyRSSIAlarm; - -PACK(typedef struct t_Open9xExpoData_v201 { - uint8_t mode:2; // 0=end, 1=pos, 2=neg, 3=both - uint8_t chn:2; - uint8_t curve:4; // 0=no curve, 1-6=std curves, 7-10=CV1-CV4, 11-15=CV9-CV13 - int8_t swtch:5; - uint8_t phase:3; // if negPhase is 0: 0=normal, 5=FP4 if negPhase is 1: 5=!FP4 - uint8_t negPhase:1; - uint8_t weight:7; - int8_t expo; - - operator ExpoData(); - t_Open9xExpoData_v201() { memset(this, 0, sizeof(t_Open9xExpoData_v201)); } -}) Open9xExpoData_v201; - -PACK(typedef struct t_Open9xExpoData_v211 { - uint8_t mode:2; // 0=end, 1=pos, 2=neg, 3=both - int8_t swtch:6; - uint8_t chn:2; - uint8_t phases:5; - uint8_t curveMode:1; - uint8_t weight; // we have one bit spare here :) - int8_t curveParam; - - operator ExpoData(); - t_Open9xExpoData_v211() { memset(this, 0, sizeof(t_Open9xExpoData_v211)); } -}) Open9xExpoData_v211; - -PACK(typedef struct t_Open9xLimitData_v201 { - int8_t min; - int8_t max; - bool revert; - int16_t offset; - - operator LimitData(); - t_Open9xLimitData_v201() { memset(this, 0, sizeof(t_Open9xLimitData_v201)); } -}) Open9xLimitData_v201; - -PACK(typedef struct t_Open9xLimitData_v211 { - int8_t min; - int8_t max; - int8_t ppmCenter; - int16_t offset:14; - uint16_t symetrical:1; - uint16_t revert:1; - - operator LimitData(); - t_Open9xLimitData_v211() { memset(this, 0, sizeof(t_Open9xLimitData_v211)); } -}) Open9xLimitData_v211; - -PACK(typedef struct t_Open9xMixData_v201 { - uint8_t destCh:5; // 0, 1..C9X_NUM_CHNOUT - uint8_t mixWarn:3; // mixer warning - uint8_t srcRaw; // - int8_t weight; - int8_t swtch; - uint8_t curve; // 0=symmetrisch, 1=no neg, 2=no pos - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - uint8_t carryTrim:1; - uint8_t mltpx:3; // multiplex method 0=+ 1=* 2=replace - int8_t phase:4; // -5=!FP4, 0=normal, 5=FP4 - int8_t sOffset; - - operator MixData(); - t_Open9xMixData_v201() { memset(this, 0, sizeof(t_Open9xMixData_v201)); } -}) Open9xMixData_v201; - -PACK(typedef struct t_Open9xMixData_v203 { - uint8_t destCh:5; // 0, 1..C9X_NUM_CHNOUT - uint8_t mixWarn:3; // mixer warning - uint8_t srcRaw; // - int8_t weight; - int8_t swtch; - uint8_t curve; - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - uint8_t carryTrim:2; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - int8_t phase:4; // -5=!FP4, 0=normal, 5=FP4 - int8_t sOffset; - - operator MixData(); - t_Open9xMixData_v203() { memset(this, 0, sizeof(t_Open9xMixData_v203)); } -}) Open9xMixData_v203; - -PACK(typedef struct t_Open9xMixData_v205 { - uint8_t destCh:4; // 0, 1..C9X_NUM_CHNOUT - int8_t phase:4; // -5=!FP4, 0=normal, 5=FP4 - int8_t weight; - int8_t swtch:6; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - int8_t curve:6; - uint8_t mixWarn:2; // mixer warning - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - uint16_t srcRaw:7; // - int16_t differential:7; - uint16_t carryTrim:2; - int8_t sOffset; - - operator MixData(); - t_Open9xMixData_v205() { memset(this, 0, sizeof(t_Open9xMixData_v205)); } -}) Open9xMixData_v205; - -PACK(typedef struct t_Open9xMixData_v209 { - uint8_t destCh:4; // 0, 1..C9X_NUM_CHNOUT - int8_t phase:4; // -5=!FP4, 0=normal, 5=FP4 - int8_t weight; - int8_t swtch:6; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - int8_t curve:6; - uint8_t mixWarn:2; // mixer warning - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - uint16_t srcRaw:6; - int16_t differential:7; - int16_t carryTrim:3; - int8_t sOffset; - - operator MixData(); - t_Open9xMixData_v209() { memset(this, 0, sizeof(t_Open9xMixData_v209)); } -}) Open9xMixData_v209; - -PACK(typedef struct t_Open9xMixData_v211 { - uint8_t destCh:4; // 0, 1..C9X_NUM_CHNOUT - uint8_t curveMode:1; // O=curve, 1=differential - uint8_t noExpo:1; - uint8_t spare:2; - int8_t weight; - int8_t swtch:6; - uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := - uint8_t phases:5; - int8_t carryTrim:3; - uint8_t srcRaw:6; - uint8_t mixWarn:2; // mixer warning - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; - uint8_t speedDown:4; - int8_t curveParam; - int8_t sOffset; - - operator MixData(); - t_Open9xMixData_v211() { memset(this, 0, sizeof(t_Open9xMixData_v211)); } -}) Open9xMixData_v211; - -PACK(typedef struct t_Open9xLogicalSwitchData_v208 { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; - - operator LogicalSwitchData(); - t_Open9xLogicalSwitchData_v208() { memset(this, 0, sizeof(t_Open9xLogicalSwitchData_v208)); } - t_Open9xLogicalSwitchData_v208(LogicalSwitchData&); -}) Open9xLogicalSwitchData_v208; - -PACK(typedef struct t_Open9xLogicalSwitchData_v209 { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; - - operator LogicalSwitchData(); - t_Open9xLogicalSwitchData_v209() { memset(this, 0, sizeof(t_Open9xLogicalSwitchData_v209)); } -}) Open9xLogicalSwitchData_v209; - -PACK(typedef struct t_Open9xSafetySwData { // Safety Switches data - int8_t swtch; - int8_t val; - - t_Open9xSafetySwData() { memset(this, 0, sizeof(t_Open9xSafetySwData)); } -}) Open9xSafetySwData; - -PACK(typedef struct t_Open9xCustomFunctionData_v201 { // Function Switches data - int8_t swtch; // input - uint8_t func; - - operator CustomFunctionData(); - t_Open9xCustomFunctionData_v201() { memset(this, 0, sizeof(t_Open9xCustomFunctionData_v201)); } -}) Open9xCustomFunctionData_v201; - -PACK(typedef struct t_Open9xCustomFunctionData_v203 { // Function Switches data - int8_t swtch; // input - uint8_t func; - uint8_t param; - - operator CustomFunctionData(); - t_Open9xCustomFunctionData_v203() { memset(this, 0, sizeof(t_Open9xCustomFunctionData_v203)); } -}) Open9xCustomFunctionData_v203; - -PACK(typedef struct t_Open9xCustomFunctionData_v210 { // Function Switches data - int8_t swtch; // input - uint8_t func:5; - uint8_t delay:3; - uint8_t param; - - operator CustomFunctionData(); - t_Open9xCustomFunctionData_v210() { memset(this, 0, sizeof(t_Open9xCustomFunctionData_v210)); } -}) Open9xCustomFunctionData_v210; - -PACK(typedef struct t_Open9xFrSkyChannelData_v201 { - uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t type:4; // channel unit (0=volts, ...) - int8_t offset:4; // calibration offset. Signed 0.1V steps. EG. -4 to substract 0.4V - uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t alarms_level:4; - uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) - uint8_t spare:2; - uint8_t barMin; // minimum for bar display - uint8_t barMax; // ditto for max display (would usually = ratio) - - operator FrSkyChannelData(); - t_Open9xFrSkyChannelData_v201() { memset(this, 0, sizeof(t_Open9xFrSkyChannelData_v201)); } -}) Open9xFrSkyChannelData_v201; - -PACK(typedef struct t_Open9xFrSkyChannelData_v203 { - uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t type; // channel unit (0=volts, ...) - uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t alarms_level:4; - uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) - uint8_t spare:2; - uint8_t barMin:4; // minimum for bar display - uint8_t barMax:4; // ditto for max display (would usually = ratio) - int8_t offset; // calibration offset. Signed 0.1V steps. EG. -4 to substract 0.4V - - operator FrSkyChannelData(); - t_Open9xFrSkyChannelData_v203() { memset(this, 0, sizeof(t_Open9xFrSkyChannelData_v203)); } -}) Open9xFrSkyChannelData_v203; - -PACK(typedef struct t_Open9xFrSkyChannelData_v204 { - uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t type; // channel unit (0=volts, ...) - uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t alarms_level:4; - uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) - uint8_t multiplier:2; - int8_t offset; // calibration offset. Signed 0.1V steps. EG. -4 to substract 0.4V - - operator FrSkyChannelData(); - t_Open9xFrSkyChannelData_v204() { memset(this, 0, sizeof(t_Open9xFrSkyChannelData_v204)); } -}) Open9xFrSkyChannelData_v204; - -PACK(typedef struct t_Open9xFrSkyChannelData_v208 { - uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - int16_t offset:12; - uint16_t type:4; // channel unit (0=volts, ...) - uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t alarms_level:4; - uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) - uint8_t multiplier:2; - - operator FrSkyChannelData(); - t_Open9xFrSkyChannelData_v208() { memset(this, 0, sizeof(t_Open9xFrSkyChannelData_v208)); } -}) Open9xFrSkyChannelData_v208; - -PACK(typedef struct t_Open9xFrSkyData_v201 { - Open9xFrSkyChannelData_v201 channels[2]; - - operator FrSkyData(); - t_Open9xFrSkyData_v201() { memset(this, 0, sizeof(t_Open9xFrSkyData_v201)); } -}) Open9xFrSkyData_v201; - -PACK(typedef struct t_Open9xFrSkyData_v202 { - Open9xFrSkyChannelData_v201 channels[2]; - uint8_t usrProto:2; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh - uint8_t spare:6; - - operator FrSkyData(); - t_Open9xFrSkyData_v202() { memset(this, 0, sizeof(t_Open9xFrSkyData_v202)); } -}) Open9xFrSkyData_v202; - -PACK(typedef struct t_Open9xFrSkyData_v203 { - Open9xFrSkyChannelData_v203 channels[2]; - uint8_t usrProto; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh - - operator FrSkyData(); - t_Open9xFrSkyData_v203() { memset(this, 0, sizeof(t_Open9xFrSkyData_v203)); } -}) Open9xFrSkyData_v203; - -PACK(typedef struct t_Open9xFrSkyBarData_v204 { - uint16_t source:4; - uint16_t barMin:6; // minimum for bar display - uint16_t barMax:6; // ditto for max display (would usually = ratio) - - operator FrSkyBarData(); - t_Open9xFrSkyBarData_v204() { memset(this, 0, sizeof(t_Open9xFrSkyBarData_v204)); } -}) Open9xFrSkyBarData_v204; - -PACK(typedef struct t_Open9xFrSkyData_v204 { - Open9xFrSkyChannelData_v204 channels[2]; - uint8_t usrProto:3; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh - uint8_t imperial:1; - uint8_t blades:2; - uint8_t spare:2; - Open9xFrSkyBarData_v204 bars[4]; - - operator FrSkyData(); - t_Open9xFrSkyData_v204() { memset(this, 0, sizeof(t_Open9xFrSkyData_v204)); } -}) Open9xFrSkyData_v204; - -PACK(typedef struct t_Open9xFrSkyData_v205 { - Open9xFrSkyChannelData_v204 channels[2]; - uint8_t usrProto:3; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh - uint8_t imperial:1; - uint8_t blades:2; - uint8_t spare:2; - Open9xFrSkyBarData_v204 bars[4]; - Open9xFrSkyRSSIAlarm rssiAlarms[2]; - - operator FrSkyData(); - t_Open9xFrSkyData_v205() { memset(this, 0, sizeof(t_Open9xFrSkyData_v205)); } -}) Open9xFrSkyData_v205; - -PACK(typedef struct t_Open9xFrSkyData_v208 { - Open9xFrSkyChannelData_v208 channels[2]; - uint8_t usrProto:2; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh - uint8_t voltsSource:2; - uint8_t blades:2; - uint8_t currentSource:2; - Open9xFrSkyBarData_v204 bars[4]; - Open9xFrSkyRSSIAlarm rssiAlarms[2]; - - operator FrSkyData(); - t_Open9xFrSkyData_v208() { memset(this, 0, sizeof(t_Open9xFrSkyData_v208)); } -}) Open9xFrSkyData_v208; - -PACK(typedef struct t_Open9xFrSkyData_v210 { - Open9xFrSkyChannelData_v208 channels[2]; - uint8_t usrProto:2; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh - uint8_t blades:2; // How many blades for RPMs, 0=2 blades, 1=3 blades - uint8_t spare1:4; - uint8_t voltsSource:3; - uint8_t currentSource:3; - uint8_t spare2:2; - Open9xFrSkyBarData_v204 bars[4]; - Open9xFrSkyRSSIAlarm rssiAlarms[2]; - uint8_t lines[4]; - uint16_t linesXtra; - uint8_t varioSource:3; - uint8_t varioSpeedUpMin:5; // if increment in 0.2m/s = 3.0m/s max - uint8_t varioSpeedDownMin; - - operator FrSkyData(); - t_Open9xFrSkyData_v210() { memset(this, 0, sizeof(t_Open9xFrSkyData_v210)); } -}) Open9xFrSkyData_v210; - -PACK(typedef struct t_Open9xSwashRingData_v208 { // Swash Ring data - uint8_t invertELE:1; - uint8_t invertAIL:1; - uint8_t invertCOL:1; - uint8_t type:5; - uint8_t collectiveSource; - uint8_t value; - - operator SwashRingData(); - t_Open9xSwashRingData_v208() { memset(this, 0, sizeof(t_Open9xSwashRingData_v208)); } -}) Open9xSwashRingData_v208; - -PACK(typedef struct t_Open9xSwashRingData_v209 { // Swash Ring data - uint8_t invertELE:1; - uint8_t invertAIL:1; - uint8_t invertCOL:1; - uint8_t type:5; - uint8_t collectiveSource; - uint8_t value; - - operator SwashRingData(); - t_Open9xSwashRingData_v209() { memset(this, 0, sizeof(t_Open9xSwashRingData_v209)); } -}) Open9xSwashRingData_v209; - -PACK(typedef struct t_Open9xFlightModeData_v201 { - int8_t trim[4]; // -500..500 => trim value, 501 => use trim of phase 0, 502, 503, 504 => use trim of phases 1|2|3|4 instead - int8_t trim_ext:8; // 2 less significant extra bits per trim (10bits trims) - int8_t swtch; // swtch of phase[0] is not used - char name[6]; - uint8_t fadeIn:4; - uint8_t fadeOut:4; - - operator FlightModeData(); - t_Open9xFlightModeData_v201() { memset(this, 0, sizeof(t_Open9xFlightModeData_v201)); } -}) Open9xFlightModeData_v201; - -PACK(typedef struct t_Open9xTimerData_v201 { - int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw - uint16_t val:14; - uint16_t persistent:1; - uint16_t dir:1; // 0=>Count Down, 1=>Count Up - - operator TimerData(); - t_Open9xTimerData_v201() { memset(this, 0, sizeof(t_Open9xTimerData_v201)); } -}) Open9xTimerData_v201; - -PACK(typedef struct t_Open9xTimerData_v202 { - int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw - uint16_t val; - - operator TimerData(); - t_Open9xTimerData_v202() { memset(this, 0, sizeof(t_Open9xTimerData_v202)); } -}) Open9xTimerData_v202; - -PACK(typedef struct t_Open9xTimerDataExtra { - uint16_t remanent:1; - uint16_t value:15; - t_Open9xTimerDataExtra() { memset(this, 0, sizeof(t_Open9xTimerDataExtra)); } -}) Open9xTimerDataExtra; - -PACK(typedef struct t_Open9xModelData_v201 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v201 timer1; - uint8_t protocol:3; - int8_t ppmNCH:3; - uint8_t thrTrim:1; // Enable Throttle Trim - uint8_t thrExpo:1; // Enable Throttle Expo - uint8_t trimInc:3; // Trim Increments - uint8_t spare1:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xTimerData_v201 timer2; - Open9xMixData_v201 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xLogicalSwitchData_v208 logicalSw[12]; - Open9xSafetySwData safetySw[16]; - Open9xCustomFunctionData_v201 customFn[12]; - Open9xSwashRingData_v208 swashR; - Open9xFlightModeData_v201 flightModeData[5]; - Open9xFrSkyData_v201 frsky; - - operator ModelData(); - t_Open9xModelData_v201() { memset(this, 0, sizeof(t_Open9xModelData_v201)); } -}) Open9xModelData_v201; - -PACK(typedef struct t_Open9xModelData_v202 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timer1; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t spare1:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xTimerData_v202 timer2; - Open9xMixData_v201 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xLogicalSwitchData_v208 logicalSw[12]; - Open9xSafetySwData safetySw[16]; - Open9xCustomFunctionData_v201 customFn[12]; - Open9xSwashRingData_v208 swashR; - Open9xFlightModeData_v201 flightModeData[5]; - Open9xFrSkyData_v202 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - - operator ModelData(); - t_Open9xModelData_v202() { memset(this, 0, sizeof(t_Open9xModelData_v202)); } -}) Open9xModelData_v202; - -PACK(typedef struct t_Open9xModelData_v203 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timer1; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t spare1:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xTimerData_v202 timer2; - Open9xMixData_v203 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xLogicalSwitchData_v208 logicalSw[12]; - Open9xCustomFunctionData_v203 customFn[16]; - Open9xSwashRingData_v208 swashR; - Open9xFlightModeData_v201 flightModeData[5]; - Open9xFrSkyData_v202 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - - operator ModelData(); - t_Open9xModelData_v203() { memset(this, 0, sizeof(t_Open9xModelData_v203)); } -}) Open9xModelData_v203; - -PACK(typedef struct t_Open9xModelData_v204 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timer1; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t spare1:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xTimerData_v202 timer2; - Open9xMixData_v203 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xLogicalSwitchData_v208 logicalSw[12]; - Open9xCustomFunctionData_v203 customFn[16]; - Open9xSwashRingData_v208 swashR; - Open9xFlightModeData_v201 flightModeData[5]; - Open9xFrSkyData_v204 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - Open9xFrSkyRSSIAlarm frskyRssiAlarms[2]; - - operator ModelData(); - t_Open9xModelData_v204() { memset(this, 0, sizeof(t_Open9xModelData_v204)); } -}) Open9xModelData_v204; - -PACK(typedef struct t_Open9xModelData_v205 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t spare1:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xMixData_v205 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xLogicalSwitchData_v208 logicalSw[12]; - Open9xCustomFunctionData_v203 customFn[16]; - Open9xSwashRingData_v208 swashR; - Open9xFlightModeData_v201 flightModeData[5]; - Open9xFrSkyData_v205 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t frskyLines[4]; - uint16_t frskyLinesXtra; - int8_t servoCenter[16]; - - operator ModelData(); - t_Open9xModelData_v205() { memset(this, 0, sizeof(t_Open9xModelData_v205)); } -}) Open9xModelData_v205; - -PACK(typedef struct t_Open9xModelData_v208 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xMixData_v205 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xLogicalSwitchData_v208 logicalSw[12]; - Open9xCustomFunctionData_v203 customFn[16]; - Open9xSwashRingData_v208 swashR; - Open9xFlightModeData_v201 flightModeData[5]; - Open9xFrSkyData_v208 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t frskyLines[4]; - uint16_t frskyLinesXtra; - int8_t servoCenter[16]; - - uint8_t varioSource:3; - uint8_t varioSpeedUpMin:5; // if increment in 0.2m/s = 3.0m/s max - uint8_t varioSpeedDownMin; - - operator ModelData(); - t_Open9xModelData_v208() { memset(this, 0, sizeof(t_Open9xModelData_v208)); } -}) Open9xModelData_v208; - -PACK(typedef struct t_Open9xModelData_v209 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xMixData_v209 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - Open9xLogicalSwitchData_v209 logicalSw[12]; - Open9xCustomFunctionData_v203 customFn[16]; - Open9xSwashRingData_v209 swashR; - Open9xFlightModeData_v201 flightModeData[5]; - Open9xFrSkyData_v208 frsky; - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - uint8_t frskyLines[4]; - uint16_t frskyLinesXtra; - int8_t servoCenter[16]; - - uint8_t varioSource:3; - uint8_t varioSpeedUpMin:5; // if increment in 0.2m/s = 3.0m/s max - uint8_t varioSpeedDownMin; - uint8_t switchWarningStates; - - operator ModelData(); - t_Open9xModelData_v209() { memset(this, 0, sizeof(t_Open9xModelData_v209)); } -}) Open9xModelData_v209; - -PACK(typedef struct t_Open9xModelData_v210 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare2:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xMixData_v209 mixData[32]; - Open9xLimitData_v201 limitData[16]; - Open9xExpoData_v201 expoData[14]; - int8_t curves[8]; - int8_t points[112-8]; - Open9xLogicalSwitchData_v209 logicalSw[12]; - Open9xCustomFunctionData_v210 customFn[16]; - Open9xSwashRingData_v209 swashR; - Open9xFlightModeData_v201 flightModeData[5]; - - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - - int8_t servoCenter[16]; - - uint8_t switchWarningStates; - - Open9xFrSkyData_v210 frsky; - - operator ModelData(); - t_Open9xModelData_v210() { memset(this, 0, sizeof(t_Open9xModelData_v210)); } -}) Open9xModelData_v210; - -PACK(typedef struct t_Open9xModelData_v211 { - char name[10]; // 10 must be first for eeLoadModelName - Open9xTimerData_v202 timers[2]; - uint8_t protocol:3; - uint8_t thrTrim:1; // Enable Throttle Trim - int8_t ppmNCH:4; - uint8_t trimInc:3; // Trim Increments - uint8_t disableThrottleWarning:1; - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t extendedTrims:1; - uint8_t spare1:1; - int8_t ppmDelay; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - Open9xMixData_v211 mixData[32]; - Open9xLimitData_v211 limitData[16]; - Open9xExpoData_v211 expoData[14]; - int8_t curves[8]; - int8_t points[112-8]; - Open9xLogicalSwitchData_v209 logicalSw[12]; - Open9xCustomFunctionData_v210 customFn[16]; - Open9xSwashRingData_v209 swashR; - Open9xFlightModeData_v201 flightModeData[5]; - - int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments - uint8_t thrTraceSrc; - uint8_t modelId; - - uint8_t switchWarningStates; - - Open9xFrSkyData_v210 frsky; - - operator ModelData(); - t_Open9xModelData_v211() { memset(this, 0, sizeof(t_Open9xModelData_v211)); } -}) Open9xModelData_v211; - -#endif diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index b7d5eb62c..c778cc532 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -224,7 +224,7 @@ class SourcesConversionTable: public ConversionTable { } } - for (int i=0; i=215)) { // On stock we use 10bits per trim - for (int i=0; i(trimBase[i])); - for (int i=0; i(trimExt[i])); } else if (IS_ARM(board) && version >= 218) { - for (int i=0; i(phase.trim[i])); internalField.Append(new UnsignedField<5>(trimMode[i])); } } else if (IS_TARANIS(board) && version >= 216) { - for (int i=0; i(phase.trim[i])); internalField.Append(new UnsignedField<5>(trimMode[i])); } } else { - for (int i=0; i(trimBase[i])); } } @@ -849,7 +849,7 @@ class FlightModeField: public TransformedField { virtual void beforeExport() { - for (int i=0; i= 216) { if (phase.trimMode[i] < 0) trimMode[i] = TRIM_MODE_NONE; @@ -877,7 +877,7 @@ class FlightModeField: public TransformedField { virtual void afterImport() { - for (int i=0; i= 216) { if (trimMode[i] == TRIM_MODE_NONE) { phase.trimMode[i] = -1; @@ -924,9 +924,9 @@ class FlightModeField: public TransformedField { BoardEnum board; unsigned int version; int rotencCount; - int trimBase[NUM_STICKS+NUM_AUX_TRIMS]; - int trimExt[NUM_STICKS+NUM_AUX_TRIMS]; - unsigned int trimMode[NUM_STICKS+NUM_AUX_TRIMS]; + int trimBase[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS]; + int trimExt[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS]; + unsigned int trimMode[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS]; }; class MixField: public TransformedField { @@ -1164,7 +1164,7 @@ class MixField: public TransformedField { virtual void afterImport() { if (IS_TARANIS(board) && version < 216) { - if (mix.srcRaw.type == SOURCE_TYPE_STICK && mix.srcRaw.index < NUM_STICKS) { + if (mix.srcRaw.type == SOURCE_TYPE_STICK && mix.srcRaw.index < CPN_MAX_STICKS) { if (!mix.noExpo) { mix.srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, mix.srcRaw.index); } @@ -1615,8 +1615,8 @@ class CurvesField: public TransformedField { unsigned int version; int maxCurves; int maxPoints; - int _curves[C9X_MAX_CURVES]; - int _points[C9X_MAX_CURVES*C9X_MAX_POINTS*2]; + int _curves[CPN_MAX_CURVES]; + int _points[CPN_MAX_CURVES*CPN_MAX_POINTS*2]; }; class LogicalSwitchesFunctionsTable: public ConversionTable { @@ -1865,11 +1865,11 @@ class LogicalSwitchField: public TransformedField { } if (IS_TARANIS(board) && version < 216) { RawSource val1(csw.val1); - if (val1.type == SOURCE_TYPE_STICK && val1.index < NUM_STICKS) { + if (val1.type == SOURCE_TYPE_STICK && val1.index < CPN_MAX_STICKS) { csw.val1 = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, val1.index).toValue(); } RawSource val2(csw.val2); - if (val2.type == SOURCE_TYPE_STICK && val2.index < NUM_STICKS) { + if (val2.type == SOURCE_TYPE_STICK && val2.index < CPN_MAX_STICKS) { csw.val2 = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, val2.index).toValue(); } } @@ -1883,7 +1883,7 @@ class LogicalSwitchField: public TransformedField { } if (IS_TARANIS(board) && version < 216) { RawSource val1(csw.val1); - if (val1.type == SOURCE_TYPE_STICK && val1.index < NUM_STICKS) { + if (val1.type == SOURCE_TYPE_STICK && val1.index < CPN_MAX_STICKS) { csw.val1 = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, val1.index).toValue(); } } @@ -3384,7 +3384,7 @@ void OpenTxModelData::afterImport() eepromImportDebug() << QString("OpenTxModelData::afterImport()") << modelData.name; if (IS_TARANIS(board) && version < 216) { - for (unsigned int i=0; imode == INPUT_MODE_BOTH && expo->chn == i && expo->flightModes == 0 && expo->swtch.type == SWITCH_TYPE_NONE) @@ -3431,7 +3431,7 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, BoardEnum bo generalData(generalData), board(board), version(version), - inputsCount(NUM_STICKS+MAX_POTS(board, version)+MAX_SLIDERS(board)) + inputsCount(CPN_MAX_STICKS+MAX_POTS(board, version)+MAX_SLIDERS(board)) { eepromImportDebug() << QString("OpenTxGeneralData::OpenTxGeneralData(board: %1, version:%2, variant:%3)").arg(board).arg(version).arg(variant); @@ -3471,10 +3471,10 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, BoardEnum bo internalField.Append(new SignedField<8>(generalData.txVoltageCalibration)); internalField.Append(new SignedField<8>(generalData.backlightMode)); - for (int i=0; i(generalData.trainer.calib[i])); } - for (int i=0; i(generalData.trainer.mix[i].src)); internalField.Append(new UnsignedField<2>(generalData.trainer.mix[i].mode)); internalField.Append(new SignedField<8>(generalData.trainer.mix[i].weight)); @@ -3642,7 +3642,7 @@ OpenTxGeneralData::OpenTxGeneralData(GeneralSettings & generalData, BoardEnum bo for (int i=0; i(generalData.switchName[i])); } - for (int i=0; i(generalData.stickName[i])); } for (int i=0; i #include "opentxinterface.h" #include "opentxeeprom.h" -#include "open9xGruvin9xeeprom.h" -#include "open9xSky9xeeprom.h" #include "rlefile.h" #include "appdata.h" @@ -125,39 +123,6 @@ const int OpenTxEepromInterface::getMaxModels() return 16; } -template -bool OpenTxEepromInterface::loadModel(ModelData &model, uint8_t *data, int index, unsigned int stickMode) -{ - T _model; - - if (!data) { - // load from EEPROM - efile->openRd(FILE_MODEL(index)); - int sz = efile->readRlc2((uint8_t*)&_model, sizeof(T)); - if (sz) { - model = _model; - if (sz < (int)sizeof(T)) { - std::cout << " size(" << model.name << ") " << sz << " < " << (int)sizeof(T) << " "; - } - if (stickMode) { - applyStickModeToModel(model, stickMode); - } - } - else { - model.clear(); - } - } - else { - // load from SD Backup, size is stored in index - if ((unsigned int)index < sizeof(T)) - return false; - memcpy((uint8_t*)&_model, data, sizeof(T)); - model = _model; - } - - return true; -} - template bool OpenTxEepromInterface::loadModelVariant(unsigned int index, ModelData & model, uint8_t *data, unsigned int version, unsigned int variant) { @@ -211,82 +176,7 @@ bool OpenTxEepromInterface::loadModelFromByteArray(ModelData & model, const QByt bool OpenTxEepromInterface::loadModel(uint8_t version, ModelData &model, uint8_t *data, int index, unsigned int variant, unsigned int stickMode) { - if (version == 201) { - return loadModel(model, data, index, stickMode); - } - else if (version == 202) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else if (version == 203) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else if (version == 204) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else if (version == 205) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else if (board == BOARD_GRUVIN9X && version == 207) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else if (version == 208) { - if (board == BOARD_GRUVIN9X) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else if (IS_SKY9X(board)) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - } - else if (version == 209) { - if (board == BOARD_GRUVIN9X) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else if (IS_SKY9X(board)) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - } - else if (version == 210) { - if (board == BOARD_GRUVIN9X) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else if (IS_SKY9X(board)) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - } - else if (version == 211) { - if (board == BOARD_GRUVIN9X) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else if (IS_SKY9X(board)) { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - else { - return loadModel(model, data, index, 0 /*no more stick mode messed*/); - } - } - else if (version == 212) { - if (IS_SKY9X(board)) { - return loadModel(model, data, index); - } - else { - return loadModelVariant(index, model, data, version, variant); - } - } - else if (version >= 213) { - return loadModelVariant(index, model, data, version, variant); - } - - std::cout << " ko\n"; - return false; + return loadModelVariant(index, model, data, version, variant); } template @@ -607,14 +497,18 @@ int OpenTxFirmware::getCapability(Capability capability) case Timers: return (IS_ARM(board) ? 3 : 2); case TimersName: - return (HAS_LARGE_LCD(board) ? 8 : (IS_ARM(board) ? 3 : 0)); - case PermTimers: - if (IS_2560(board) || IS_ARM(board)) - return 1; + if (HAS_LARGE_LCD(board)) + return 8; + else if (IS_ARM(board)) + return 3; else return 0; + case PermTimers: + return (IS_2560(board) || IS_ARM(board)); case Pots: - if (board == BOARD_X7D) + if (IS_HORUS(board)) + return 3; + else if (board == BOARD_X7D) return 2; else if (IS_TARANIS_X9E(board)) return 4; @@ -623,7 +517,9 @@ int OpenTxFirmware::getCapability(Capability capability) else return 3; case Sliders: - if (board == BOARD_X7D) + if (IS_HORUS(board)) + return 4; + else if (board == BOARD_X7D) return 0; else if (IS_TARANIS_X9E(board)) return 4; diff --git a/companion/src/firmwares/th9x/th9xeeprom.cpp b/companion/src/firmwares/th9x/th9xeeprom.cpp deleted file mode 100644 index a2732d2d1..000000000 --- a/companion/src/firmwares/th9x/th9xeeprom.cpp +++ /dev/null @@ -1,322 +0,0 @@ -#include -#include "helpers.h" -#include "th9xeeprom.h" - -RawSwitch th9xToSwitch(int8_t sw) -{ - if (sw == 0) - return RawSwitch(SWITCH_TYPE_NONE); - else if (sw <= 9) - return RawSwitch(SWITCH_TYPE_SWITCH, sw); - else - return RawSwitch(SWITCH_TYPE_VIRTUAL, sw > 0 ? sw-9 : sw+9); -} - -t_Th9xTrainerMix::t_Th9xTrainerMix() -{ - memset(this, 0, sizeof(t_Th9xTrainerMix)); -} - -t_Th9xTrainerMix::operator TrainerMix() -{ - TrainerMix c9x; - c9x.src = srcChn; - c9x.swtch = th9xToSwitch(swtch); - c9x.weight = (25 * studWeight) / 8; - c9x.mode = mode; - return c9x; -} - -t_Th9xTrainerData::t_Th9xTrainerData() -{ - memset(this, 0, sizeof(t_Th9xTrainerData)); -} - -t_Th9xTrainerData::operator TrainerData () -{ - TrainerData c9x; - for (int i=0; i 6) { - c9x.curve.type = CurveReference::CURVE_REF_CUSTOM; - c9x.curve.value = curve - 6; - } - else if (curve > 0) { - c9x.curve.type = CurveReference::CURVE_REF_FUNC; - c9x.curve.value = curve; - } - c9x.mode = mode3; - c9x.weight = weight6; - c9x.chn = chn; - c9x.swtch = th9xToSwitch(drSw); - return c9x; -} - -t_Th9xLimitData::t_Th9xLimitData() -{ - memset(this, 0, sizeof(t_Th9xLimitData)); -} - -t_Th9xLimitData::operator LimitData () -{ - LimitData c9x; - c9x.min = 10*(min-100); - c9x.max = 10*(max+100); - c9x.revert = revert; - c9x.offset = offset; - return c9x; -} - -t_Th9xMixData::t_Th9xMixData() -{ - memset(this, 0, sizeof(t_Th9xMixData)); -} - -t_Th9xMixData::operator MixData () -{ - MixData c9x; - c9x.destCh = destCh; - if (srcRaw < 7) - c9x.srcRaw = RawSource(SOURCE_TYPE_STICK, srcRaw); - else if (srcRaw < 10) - c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); // TODO - else if (srcRaw == 10) - c9x.srcRaw = RawSource(SOURCE_TYPE_MAX); - else if (srcRaw == 11) - c9x.srcRaw = RawSource(SOURCE_TYPE_NONE); // TODO CUR - else if (srcRaw < 24) - c9x.srcRaw = RawSource(SOURCE_TYPE_CH, srcRaw-12); - else /* always true if (srcRaw < 32) */ - c9x.srcRaw = RawSource(SOURCE_TYPE_PPM, srcRaw-24); - c9x.weight = weight; - c9x.swtch = th9xToSwitch(swtch); - if (curve > 6) { - c9x.curve.type = CurveReference::CURVE_REF_CUSTOM; - c9x.curve.value = curve - 6; - } - else if (curve > 0) { - c9x.curve.type = CurveReference::CURVE_REF_FUNC; - c9x.curve.value = curve; - } - c9x.speedUp = speedUp; - c9x.speedDown = speedDown; - c9x.mltpx = (MltpxValue)mixMode; - return c9x; -} - -t_Th9xLogicalSwitchData::operator LogicalSwitchData () -{ - LogicalSwitchData c9x; - c9x.func = opCmp; - c9x.val1 = val1; - c9x.val2 = val2; - - if ((c9x.func >= LS_FN_VPOS && c9x.func <= LS_FN_ANEG) || c9x.func >= LS_FN_EQUAL) { - c9x.val1 = toSource(val1).toValue(); - } - - if (c9x.func >= LS_FN_EQUAL) { - c9x.val2 = toSource(val2).toValue(); - } - - if (c9x.func >= LS_FN_AND && c9x.func <= LS_FN_XOR) { - c9x.val1 = th9xToSwitch(val1).toValue(); - c9x.val2 = th9xToSwitch(val2).toValue(); - } - - return c9x; -} - -int8_t t_Th9xLogicalSwitchData::fromSource(RawSource source) -{ - int v1 = 0; - if (source.type == SOURCE_TYPE_STICK) - v1 = 1+source.index; - else if (source.type == SOURCE_TYPE_ROTARY_ENCODER) { - EEPROMWarnings.push_back(::QObject::tr("th9x on this board doesn't have Rotary Encoders")); - v1 = 5+source.index; - } - else if (source.type == SOURCE_TYPE_MAX) - v1 = 8; - /* else if (source.type == SOURCE_TYPE_3POS) - v1 = 9; */ - else if (source.type == SOURCE_TYPE_CYC) - v1 = 10+source.index; - else if (source.type == SOURCE_TYPE_PPM) - v1 = 13+source.index; - else if (source.type == SOURCE_TYPE_CH) - v1 = 21+source.index; - else if (source.type == SOURCE_TYPE_TELEMETRY) - v1 = 36+source.index; - return v1; -} - -RawSource t_Th9xLogicalSwitchData::toSource(int8_t value) -{ - if (value == 0) { - return RawSource(SOURCE_TYPE_NONE); - } - else if (value <= 7) { - return RawSource(SOURCE_TYPE_STICK, value - 1); - } - else if (value == 8) { - return RawSource(SOURCE_TYPE_MAX); - } - /* else if (value == 9) { - return RawSource(SOURCE_TYPE_3POS); - } */ - else if (value <= 12) { - return RawSource(SOURCE_TYPE_CYC, value-10); - } - else if (value <= 20) { - return RawSource(SOURCE_TYPE_PPM, value-13); - } - else if (value <= 36) { - return RawSource(SOURCE_TYPE_CH, value-21); - } - else { - return RawSource(SOURCE_TYPE_TELEMETRY, value-36); - } -} - -t_Th9xModelData::t_Th9xModelData() -{ - memset(this, 0, sizeof(t_Th9xModelData)); -} - -t_Th9xModelData::operator ModelData () -{ - ModelData c9x; - c9x.used = true; - getEEPROMString(c9x.name, name, sizeof(name)); - /*switch(tmrMode) { - case 1: - c9x.timers[0].mode = TMRMODE_ABS; - break; - case 2: - c9x.timers[0].mode = TMRMODE_THs; - break; - case 3: - c9x.timers[0].mode = TMRMODE_THp; - break; - default: - c9x.timers[0].mode = TMRMODE_OFF; - break; - }*/ - // c9x.timers[0].dir = tmrDir; - c9x.timers[0].val = tmrVal; - /*c9x.protocol = (Protocol)protocol; - c9x.moduleData[0].channelsCount = 8 + 2 * ppmNCH; - c9x.thrTrim = thrTrim; - c9x.trimInc = trimInc; - c9x.moduleData[0].ppm.delay = 300 + 50 * ppmDelay; - c9x.customFn[0].func = FuncTrims2Offsets; - if (trimSw) { - c9x.customFn[0].swtch = trimSw; - } - c9x.beepANACenter = beepANACenter; - c9x.pulsePol = pulsePol; - c9x.extendedLimits = extendedLimits; - c9x.swashRingData.invertELE = swashInvertELE; - c9x.swashRingData.invertAIL = swashInvertAIL; - c9x.swashRingData.invertCOL = swashInvertCOL; - c9x.swashRingData.type = swashType; - c9x.swashRingData.collectiveSource = swashCollectiveSource; - c9x.swashRingData.value = swashRingValue;*/ - for (int i=0; i - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ -#ifndef th9xeeprom_h -#define th9xeeprom_h - -#include -#include "eeprominterface.h" - -//eeprom data -#define TH9X_NUM_CHNOUT 8 -#define TH9X_MAX_EXPOS 15 -#define TH9X_MAX_MIXERS 25 -#define TH9X_MAX_SWITCHES 16 -#define TH9X_MAX_CURVES3 3 -#define TH9X_MAX_CURVES5 2 -#define TH9X_MAX_CURVES9 2 -#define TH9X_MAX_CSFUNC 13 - -#define MDVERS 6 - -#define TH9X_NUM_CSW 12 //number of custom switches -#define NUM_STICKSnPOTS 7 //number of sticks and pots - -PACK(typedef struct t_Th9xTrainerMix { - uint8_t srcChn:3; //0-7 = ch1-8 - int8_t swtch:5; - int8_t studWeight:6; - uint8_t mode:2; // off, add-mode, subst-mode - - operator TrainerMix(); - t_Th9xTrainerMix(); -}) Th9xTrainerMix; // - -PACK(typedef struct t_Th9xTrainerData { - int16_t calib[8]; - Th9xTrainerMix mix[4]; - - operator TrainerData(); - t_Th9xTrainerData(); -}) Th9xTrainerData; - -PACK(typedef struct t_Th9xGeneral { - uint8_t myVers; - int16_t calibMid[NUM_STICKSnPOTS]; - int16_t calibSpanNeg[NUM_STICKSnPOTS]; - int16_t calibSpanPos[NUM_STICKSnPOTS]; - uint8_t inactivityMin; //ge150 - uint8_t iTrimSwitch:4; //ge192 - uint8_t iTrimTme1:2; - uint8_t iTrimTme2:2; - uint8_t currModel; //0..15 - uint8_t contrast; - uint8_t vBatWarn; - int8_t txVoltageCalibration; - int8_t lightSw; - Th9xTrainerData trainer; - uint8_t adcFilt:2; - uint8_t keySpeed:2; - uint8_t thr0pos:4; - uint8_t disableThrottleWarning:1; - uint8_t disableSwitchWarning:1; - uint8_t disableMemoryWarning:1; - uint8_t beeperVal:2; - uint8_t view:3; - uint8_t stickMode:2; - uint8_t naviMode:2; - - operator GeneralSettings(); - t_Th9xGeneral(); -}) Th9xGeneral; - -/* - * ModelData - */ - -PACK(typedef struct t_Th9xExpoData { - int8_t exp5:5; - uint8_t mode3:3; //0=end 1=pos 2=neg 3=both 4=trimNeg - - int8_t weight6:6; - uint8_t chn:2; // - - int8_t drSw:5; - uint8_t curve:3; // - - operator ExpoData(); - t_Th9xExpoData(); -}) Th9xExpoData; - - -PACK(typedef struct t_Th9xLimitData { - int8_t min:7; - bool scale:1; - int8_t max:7; - bool resv:1; - bool revert:1; - int8_t offset:7; - - operator LimitData(); - t_Th9xLimitData(); -}) Th9xLimitData; - -#define MLTPX_ADD 0 -#define MLTPX_MUL 1 -#define MLTPX_REP 2 - -PACK(typedef struct t_Th9xMixData { - uint8_t destCh:4; // 1..C9X_NUM_CHNOUT,X1-X4 - uint8_t mixMode:2; // + * = - uint8_t dmy1:2; // - - uint8_t srcRaw:5; // S1-4,P1-3,max,cur,X1-X4,p1-3,T1-8 24 - uint8_t switchMode:2; // switchMode oOff\tiNeg\tiNul\tiPos - uint8_t curveNeg:1; // Cv cV - - int8_t weight; - - int8_t swtch:5; - uint8_t curve:3; // 0=off 1..7=cv1..7 - - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - - operator MixData(); - t_Th9xMixData(); -}) Th9xMixData; - -PACK(typedef struct t_Th9xLogicalSwitchData { - uint8_t sw:3; // 0..7 - uint8_t opCmp:2; // < & | ^ - uint8_t opRes:3; // 0 => 1=> 0=> !=> & | ^ - int8_t val1; - int8_t val2; - - operator LogicalSwitchData(); - t_Th9xLogicalSwitchData() { memset(this, 0, sizeof(t_Th9xLogicalSwitchData)); } - int8_t fromSource(RawSource source); - RawSource toSource(int8_t value); -}) Th9xLogicalSwitchData; - -PACK(typedef struct t_Th9xTrimData { - int8_t itrim:6; //trim index - uint8_t tmode:2; - - t_Th9xTrimData() { } -}) Th9xTrimData; - -PACK(typedef struct t_Th9xModelData { - char name[10]; // 10 must be first for eeLoadModelName - uint8_t mdVers; // 1 - uint8_t tmrMode:3; // 1 - int8_t tmrSw:5; // - uint16_t tmrVal; // 2 - uint8_t protocol:5; // 1 - uint8_t protocolPar:3; // - char res[3]; // 3 - Th9xLimitData limitData[TH9X_NUM_CHNOUT];// 3*8 - Th9xExpoData expoTab[TH9X_MAX_EXPOS]; // 5*4 -> 3*15 - Th9xMixData mixData[TH9X_MAX_MIXERS]; //0 5*25 - int8_t curves3[TH9X_MAX_CURVES3][3]; // 9 new143 - int8_t curves5[TH9X_MAX_CURVES5][5]; // 10 - int8_t curves9[TH9X_MAX_CURVES9][9]; // 18 - Th9xLogicalSwitchData switchTab[TH9X_MAX_SWITCHES];// - Th9xTrimData trimData[NUM_STICKS]; // 3*4 -> 1*4 - operator ModelData(); - t_Th9xModelData(); -}) Th9xModelData; - -#endif diff --git a/companion/src/firmwares/th9x/th9xinterface.cpp b/companion/src/firmwares/th9x/th9xinterface.cpp deleted file mode 100644 index 6e4dcf44d..000000000 --- a/companion/src/firmwares/th9x/th9xinterface.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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 -#include "th9xinterface.h" -#include "th9xeeprom.h" -#include "rlefile.h" -#include "appdata.h" - -#define FILE_TYP_GENERAL 1 -#define FILE_TYP_MODEL 2 - -#define FILE_GENERAL 0 -#define FILE_MODEL(n) (1+n) - -Th9xInterface::Th9xInterface(): -EEPROMInterface(BOARD_STOCK), -efile(new RleFile()) -{ -} - -Th9xInterface::~Th9xInterface() -{ - delete efile; -} - -const char * Th9xInterface::getName() -{ - return "Th9x"; -} - -const int Th9xInterface::getEEpromSize() -{ - QString avrMCU = g.mcu(); - if (avrMCU==QString("m128")) { - return 2*EESIZE_STOCK; - } - return EESIZE_STOCK; -} - -const int Th9xInterface::getMaxModels() -{ - return 16; -} - -unsigned long Th9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) -{ - std::bitset errors; - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); -} - -unsigned long Th9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) -{ - std::cout << "trying th9x import... "; - - std::bitset errors; - - if (size != getEEpromSize()) { - std::cout << "wrong size\n"; - errors.set(WRONG_SIZE); - return errors.to_ulong(); - } - - if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { - std::cout << "wrong file system\n"; - errors.set(WRONG_FILE_SYSTEM); - return errors.to_ulong(); - } - - efile->openRd(FILE_GENERAL); - Th9xGeneral th9xGeneral; - - if (efile->readRlc2((uint8_t*)&th9xGeneral, 1) != 1) { - std::cout << "no\n"; - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); - } - - std::cout << "version " << (unsigned int)th9xGeneral.myVers << " "; - - switch(th9xGeneral.myVers) { - case 6: - break; - default: - std::cout << "not th9x\n"; - errors.set(NOT_TH9X); - return errors.to_ulong(); - } - - efile->openRd(FILE_GENERAL); - int len = efile->readRlc2((uint8_t*)&th9xGeneral, sizeof(Th9xGeneral)); - if (len != sizeof(Th9xGeneral)) { - std::cout << "not th9x\n"; - errors.set(NOT_TH9X); - return errors.to_ulong(); - } - radioData.generalSettings = th9xGeneral; - - for (int i=0; iopenRd(FILE_MODEL(i)); - if (!efile->readRlc2((uint8_t*)&th9xModel, sizeof(Th9xModelData))) { - radioData.models[i].clear(); - } - else { - radioData.models[i] = th9xModel; - } - } - - std::cout << "ok\n"; - errors.set(ALL_OK); - return errors.to_ulong(); -} - -unsigned long Th9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) -{ - std::bitset errors; - errors.set(UNKNOWN_ERROR); - return errors.to_ulong(); -} - -int Th9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) -{ - std::cout << "NO!\n"; - // TODO a warning - - return 0; -} - -int Th9xInterface::getSize(const ModelData & model) -{ - return 0; -} - -int Th9xInterface::getSize(const GeneralSettings & settings) -{ - return 0; -} - -int Th9xInterface::isAvailable(PulsesProtocol proto, int port) -{ - switch (proto) { - case PULSES_PPM: - case PULSES_SILV_A: - case PULSES_SILV_B: - case PULSES_SILV_C: - case PULSES_CTP1009: - return 1; - default: - return 0; - } -} diff --git a/companion/src/firmwares/th9x/th9xinterface.h b/companion/src/firmwares/th9x/th9xinterface.h deleted file mode 100644 index d1be1fc8f..000000000 --- a/companion/src/firmwares/th9x/th9xinterface.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ -#ifndef th9x_interface_h -#define th9x_interface_h - -#include "eeprominterface.h" - -class RleFile; - -class Th9xInterface : public EEPROMInterface -{ - public: - - Th9xInterface(); - - virtual ~Th9xInterface(); - - virtual const char * getName(); - - virtual const int getEEpromSize(); - - virtual const int getMaxModels(); - - virtual unsigned long load(RadioData &, const uint8_t *eeprom, int size); - - virtual unsigned long loadBackup(RadioData &, uint8_t *eeprom, int esize, int index); - - virtual unsigned long loadxml(RadioData &radioData, QDomDocument &doc); - - virtual int save(uint8_t *eeprom, RadioData &radioData, uint32_t variant=0, uint8_t version=0); - - virtual int getSize(const ModelData &); - - virtual int getSize(const GeneralSettings &); - - virtual int isAvailable(PulsesProtocol proto, int port=0); - - protected: - - RleFile *efile; - -}; - -#endif diff --git a/companion/src/flasheepromdialog.cpp b/companion/src/flasheepromdialog.cpp index 2249be10a..0db04bd8b 100644 --- a/companion/src/flasheepromdialog.cpp +++ b/companion/src/flasheepromdialog.cpp @@ -58,7 +58,7 @@ void FlashEEpromDialog::updateUI() ui->patchCalibration->show(); ui->patchHardwareSettings->show(); // TODO I hardcode the number of pots here, should be dependant on the board? - if (!((calib.length()==(NUM_STICKS+3)*12) && (trainercalib.length()==16))) { + if (!((calib.length()==(CPN_MAX_STICKS+3)*12) && (trainercalib.length()==16))) { ui->patchCalibration->setDisabled(true); } if (!((DisplaySet.length()==6) && (BeeperSet.length()==4) && (HapticSet.length()==6) && (SpeakerSet.length()==6))) { @@ -181,11 +181,11 @@ bool FlashEEpromDialog::patchCalibration() int8_t txCurrentCalibration=(int8_t) g.profile[g.id()].txCurrentCalibration(); int8_t PPM_Multiplier=(int8_t) g.profile[g.id()].ppmMultiplier(); - if ((calib.length()==(NUM_STICKS+potsnum)*12) && (trainercalib.length()==16)) { + if ((calib.length()==(CPN_MAX_STICKS+potsnum)*12) && (trainercalib.length()==16)) { QString Byte; int16_t byte16; bool ok; - for (int i=0; i<(NUM_STICKS+potsnum); i++) { + for (int i=0; i<(CPN_MAX_STICKS+potsnum); i++) { Byte=calib.mid(i*12,4); byte16=(int16_t)Byte.toInt(&ok,16); if (ok) diff --git a/companion/src/generaledit/calibration.cpp b/companion/src/generaledit/calibration.cpp index cae297193..8eed38dd0 100644 --- a/companion/src/generaledit/calibration.cpp +++ b/companion/src/generaledit/calibration.cpp @@ -24,7 +24,7 @@ CalibrationPanel::CalibrationPanel(QWidget * parent, GeneralSettings & generalSe headerLabels << QObject::tr("Negative span") << QObject::tr("Mid value") << QObject::tr("Positive span"); tableWidget->setHorizontalHeaderLabels(headerLabels); - int rows = NUM_STICKS + GetCurrentFirmware()->getCapability(Pots) + GetCurrentFirmware()->getCapability(Sliders); + int rows = CPN_MAX_STICKS + GetCurrentFirmware()->getCapability(Pots) + GetCurrentFirmware()->getCapability(Sliders); tableWidget->setRowCount(rows); for(int i = 0; i < rows; ++i) { diff --git a/companion/src/generaledit/generaledit.cpp b/companion/src/generaledit/generaledit.cpp index 99354419a..18ac857b3 100644 --- a/companion/src/generaledit/generaledit.cpp +++ b/companion/src/generaledit/generaledit.cpp @@ -101,11 +101,11 @@ void GeneralEdit::on_calretrieve_PB_clicked() QString SpeakerSet = g.profile[profile_id].speaker(); QString CountrySet = g.profile[profile_id].countryCode(); - if ((calib.length()==(NUM_STICKS+potsnum)*12) && (trainercalib.length()==16)) { + if ((calib.length()==(CPN_MAX_STICKS+potsnum)*12) && (trainercalib.length()==16)) { QString Byte; int16_t byte16; bool ok; - for (int i=0; i<(NUM_STICKS+potsnum); i++) { + for (int i=0; i<(CPN_MAX_STICKS+potsnum); i++) { Byte=calib.mid(i*12,4); byte16=(int16_t)Byte.toInt(&ok,16); if (ok) generalSettings.calibMid[i]=byte16; @@ -138,14 +138,14 @@ void GeneralEdit::on_calretrieve_PB_clicked() QByteArray qba; int16_t offset; bool ok; - for (int i=0; igetCapability(Switches)); i++) { Byte=hwtypes.mid(i,1); byte16=(int16_t)Byte.toInt(&ok,16); - qba=controlNames.mid(3*(i+NUM_STICKS),3).toLatin1(); + qba=controlNames.mid(3*(i+CPN_MAX_STICKS),3).toLatin1(); if (ok) { generalSettings.switchConfig[i]=byte16; strcpy(generalSettings.switchName[i], qba.data()); @@ -155,7 +155,7 @@ void GeneralEdit::on_calretrieve_PB_clicked() for (int i=0; i<(GetCurrentFirmware()->getCapability(Pots)); i++) { Byte=hwtypes.mid(i+offset,1); byte16=(int16_t)Byte.toInt(&ok,16); - qba=controlNames.mid(3*(i+NUM_STICKS+offset),3).toLatin1(); + qba=controlNames.mid(3*(i+CPN_MAX_STICKS+offset),3).toLatin1(); if (ok) { generalSettings.potConfig[i]=byte16; strcpy(generalSettings.potName[i], qba.data()); @@ -165,7 +165,7 @@ void GeneralEdit::on_calretrieve_PB_clicked() for (int i=0; i<(GetCurrentFirmware()->getCapability(Sliders)); i++) { Byte=hwtypes.mid(i+offset,1); byte16=(int16_t)Byte.toInt(&ok,16); - qba=controlNames.mid(3*(i+NUM_STICKS+offset),3).toLatin1(); + qba=controlNames.mid(3*(i+CPN_MAX_STICKS+offset),3).toLatin1(); if (ok) { generalSettings.sliderConfig[i]=byte16; strcpy(generalSettings.sliderName[i], qba.data()); @@ -243,7 +243,7 @@ void GeneralEdit::on_calstore_PB_clicked() } } calib.clear(); - for (int i=0; i< (NUM_STICKS+potsnum); i++) { + for (int i=0; i< (CPN_MAX_STICKS+potsnum); i++) { calib.append(QString("%1").arg((uint16_t)generalSettings.calibMid[i], 4, 16, QChar('0'))); calib.append(QString("%1").arg((uint16_t)generalSettings.calibSpanNeg[i], 4, 16, QChar('0'))); calib.append(QString("%1").arg((uint16_t)generalSettings.calibSpanPos[i], 4, 16, QChar('0'))); @@ -256,7 +256,7 @@ void GeneralEdit::on_calstore_PB_clicked() g.profile[profile_id].trainerCalib( calib ); hwtypes.clear(); controlNames.clear(); - for (int i=0; igetCapability(Switches)); i++) { diff --git a/companion/src/generaledit/hardware.cpp b/companion/src/generaledit/hardware.cpp index 33cb0ebfb..e5d7f5b5d 100644 --- a/companion/src/generaledit/hardware.cpp +++ b/companion/src/generaledit/hardware.cpp @@ -34,7 +34,7 @@ void HardwarePanel::setupPotConfig(int index, QLabel *label, AutoLineEdit *name, bool enabled = false; if (IS_TARANIS_X9E(firmware->getBoard()) && index < 4) { - label->setText(RawSource(SOURCE_TYPE_STICK, index+NUM_STICKS).toString()); + label->setText(RawSource(SOURCE_TYPE_STICK, index+CPN_MAX_STICKS).toString()); enabled = true; } else if (IS_TARANIS_PLUS(firmware->getBoard()) && index < 3) { @@ -72,7 +72,7 @@ void HardwarePanel::setupSliderConfig(int index, QLabel *label, AutoLineEdit *na } if (IS_TARANIS_X9E(firmware->getBoard())) { - label->setText(RawSource(SOURCE_TYPE_STICK, index+NUM_STICKS+4).toString()); + label->setText(RawSource(SOURCE_TYPE_STICK, index+CPN_MAX_STICKS+4).toString()); } if (enabled) { diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 08f978b45..204f6ba35 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -14,7 +14,7 @@ Stopwatch gStopwatch("global"); -const QColor colors[C9X_MAX_CURVES] = { +const QColor colors[CPN_MAX_CURVES] = { QColor(0,0,127), QColor(0,127,0), QColor(127,0,0), @@ -551,11 +551,11 @@ void populateSourceCB(QComboBox *b, const RawSource & source, const GeneralSetti } if (flags & POPULATE_SOURCES) { - for (int i=0; igetCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders); i++) { + for (int i=0; igetCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders); i++) { item = RawSource(SOURCE_TYPE_STICK, i); // skip unavailable pots and sliders - if (item.isPot() && !generalSettings.isPotAvailable(i-NUM_STICKS)) continue; - if (item.isSlider() && !generalSettings.isSliderAvailable(i-NUM_STICKS-GetCurrentFirmware()->getCapability(Pots))) continue; + if (item.isPot() && !generalSettings.isPotAvailable(i-CPN_MAX_STICKS)) continue; + if (item.isSlider() && !generalSettings.isSliderAvailable(i-CPN_MAX_STICKS-GetCurrentFirmware()->getCapability(Pots))) continue; b->addItem(item.toString(model), item.toValue()); if (item == source) b->setCurrentIndex(b->count()-1); } @@ -600,7 +600,7 @@ void populateSourceCB(QComboBox *b, const RawSource & source, const GeneralSetti } if (flags & POPULATE_SOURCES) { - for (int i=0; iaddItem(item.toString(model), item.toValue()); if (item == source) b->setCurrentIndex(b->count()-1); @@ -626,7 +626,7 @@ void populateSourceCB(QComboBox *b, const RawSource & source, const GeneralSetti b->addItem(item.toString(model), item.toValue()); if (item == source) b->setCurrentIndex(b->count()-1); } - for (int i=0; isensorData[i].isAvailable()) { //this conditon must be false if we populate Global Functions where model = 0 for (int j=0; j<3; ++j) { item = RawSource(SOURCE_TYPE_TELEMETRY, 3*i+j); diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 60607a047..ffe4d421c 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -8,7 +8,7 @@ #include #include "eeprominterface.h" -extern const QColor colors[C9X_MAX_CURVES]; +extern const QColor colors[CPN_MAX_CURVES]; #define TMR_NUM_OPTION (TMRMODE_COUNT+2*9+2*GetCurrentFirmware()->getCapability(LogicalSwitches)-1) diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 57d2916bf..acd132ea6 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -1,44 +1,3 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - #include #include #include diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h index bd156756d..706628285 100644 --- a/companion/src/mainwindow.h +++ b/companion/src/mainwindow.h @@ -1,44 +1,3 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - #ifndef MAINWINDOW_H #define MAINWINDOW_H diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index fc60f8cd2..28ad8520e 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -1,44 +1,3 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - #include "mdichild.h" #include "ui_mdichild.h" #include "xmlinterface.h" diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index f5d3e4db2..94cba5a3a 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -1,44 +1,3 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - #ifndef MDICHILD_H #define MDICHILD_H diff --git a/companion/src/modeledit/curves.cpp b/companion/src/modeledit/curves.cpp index bdad1375b..310232463 100644 --- a/companion/src/modeledit/curves.cpp +++ b/companion/src/modeledit/curves.cpp @@ -156,7 +156,7 @@ Curves::Curves(QWidget * parent, ModelData & model, GeneralSettings & generalSet ui->curvesLayout2->addItem(item2,limit+1,1,1,1,0); } - for (int i=0; isetProperty("index", i); spnx[i]->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); @@ -360,7 +360,7 @@ void Curves::updateCurvePoints() spnx[i]->hide(); } } - for (int i=count; ihide(); spnx[i]->hide(); } @@ -440,7 +440,7 @@ void Curves::on_curvePoints_currentIndexChanged(int index) model->curves[currentCurve].count = numpoints; // TODO something better + reuse! - for (int i=0; icurves[currentCurve].points[i].x = (i >= numpoints-1 ? +100 : -100 + (200*i)/(numpoints-1)); model->curves[currentCurve].points[i].y = 0; } @@ -463,7 +463,7 @@ void Curves::on_curveCustom_currentIndexChanged(int index) model->curves[currentCurve].type = type; // TODO something better + reuse! - for (int i=0; icurves[currentCurve].points[i].x = (i >= numpoints-1 ? +100 : -100 + (200*i)/(numpoints-1)); model->curves[currentCurve].points[i].y = 0; } diff --git a/companion/src/modeledit/curves.h b/companion/src/modeledit/curves.h index 94077aa8d..e58331861 100644 --- a/companion/src/modeledit/curves.h +++ b/companion/src/modeledit/curves.h @@ -55,9 +55,9 @@ class Curves : public ModelPanel private: Ui::Curves *ui; int currentCurve; - bool visibleCurves[C9X_MAX_CURVES]; - QSpinBox * spnx[C9X_MAX_POINTS]; - QSpinBox * spny[C9X_MAX_POINTS]; + bool visibleCurves[CPN_MAX_CURVES]; + QSpinBox * spnx[CPN_MAX_POINTS]; + QSpinBox * spny[CPN_MAX_POINTS]; QVector templates; void setCurrentCurve(int index); void updateCurve(); diff --git a/companion/src/modeledit/customfunctions.h b/companion/src/modeledit/customfunctions.h index 94d330f22..d6da9ba3e 100644 --- a/companion/src/modeledit/customfunctions.h +++ b/companion/src/modeledit/customfunctions.h @@ -58,18 +58,18 @@ class CustomFunctionsPanel : public GenericPanel QSet tracksSet; QSet scriptsSet; int mediaPlayerCurrent; - QComboBox * fswtchSwtch[C9X_MAX_CUSTOM_FUNCTIONS]; - QComboBox * fswtchFunc[C9X_MAX_CUSTOM_FUNCTIONS]; - QCheckBox * fswtchParamGV[C9X_MAX_CUSTOM_FUNCTIONS]; - QDoubleSpinBox * fswtchParam[C9X_MAX_CUSTOM_FUNCTIONS]; - QTimeEdit * fswtchParamTime[C9X_MAX_CUSTOM_FUNCTIONS]; - QPushButton * playBT[C9X_MAX_CUSTOM_FUNCTIONS]; - QComboBox * fswtchParamT[C9X_MAX_CUSTOM_FUNCTIONS]; - QComboBox * fswtchParamArmT[C9X_MAX_CUSTOM_FUNCTIONS]; - QCheckBox * fswtchEnable[C9X_MAX_CUSTOM_FUNCTIONS]; - RepeatComboBox * fswtchRepeat[C9X_MAX_CUSTOM_FUNCTIONS]; - QComboBox * fswtchGVmode[C9X_MAX_CUSTOM_FUNCTIONS]; - QSlider * fswtchBLcolor[C9X_MAX_CUSTOM_FUNCTIONS]; + QComboBox * fswtchSwtch[CPN_MAX_CUSTOM_FUNCTIONS]; + QComboBox * fswtchFunc[CPN_MAX_CUSTOM_FUNCTIONS]; + QCheckBox * fswtchParamGV[CPN_MAX_CUSTOM_FUNCTIONS]; + QDoubleSpinBox * fswtchParam[CPN_MAX_CUSTOM_FUNCTIONS]; + QTimeEdit * fswtchParamTime[CPN_MAX_CUSTOM_FUNCTIONS]; + QPushButton * playBT[CPN_MAX_CUSTOM_FUNCTIONS]; + QComboBox * fswtchParamT[CPN_MAX_CUSTOM_FUNCTIONS]; + QComboBox * fswtchParamArmT[CPN_MAX_CUSTOM_FUNCTIONS]; + QCheckBox * fswtchEnable[CPN_MAX_CUSTOM_FUNCTIONS]; + RepeatComboBox * fswtchRepeat[CPN_MAX_CUSTOM_FUNCTIONS]; + QComboBox * fswtchGVmode[CPN_MAX_CUSTOM_FUNCTIONS]; + QSlider * fswtchBLcolor[CPN_MAX_CUSTOM_FUNCTIONS]; QMediaPlayer * mediaPlayer; int selectedFunction; diff --git a/companion/src/modeledit/expodialog.cpp b/companion/src/modeledit/expodialog.cpp index d2c7948fa..14c6e912a 100644 --- a/companion/src/modeledit/expodialog.cpp +++ b/companion/src/modeledit/expodialog.cpp @@ -78,7 +78,7 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, G ui->trimCB->hide(); } - for(int i=0; i < NUM_STICKS; i++) { + for(int i=0; i < CPN_MAX_STICKS; i++) { ui->trimCB->addItem(AnalogString(i), i+1); } ui->trimCB->setCurrentIndex(1 - ed->carryTrim); diff --git a/companion/src/modeledit/flightmodes.cpp b/companion/src/modeledit/flightmodes.cpp index 5f0988685..d01a78485 100644 --- a/companion/src/modeledit/flightmodes.cpp +++ b/companion/src/modeledit/flightmodes.cpp @@ -56,8 +56,8 @@ FlightModePanel::FlightModePanel(QWidget * parent, ModelData & model, int phaseI } // The trims - QString labels[NUM_STICKS]; - for(int i=0; i < NUM_STICKS; i++) { + QString labels[CPN_MAX_STICKS]; + for(int i=0; i < CPN_MAX_STICKS; i++) { labels[i] = AnalogString(i); } diff --git a/companion/src/modeledit/flightmodes.h b/companion/src/modeledit/flightmodes.h index 3290ebdbe..345fd933d 100644 --- a/companion/src/modeledit/flightmodes.h +++ b/companion/src/modeledit/flightmodes.h @@ -45,12 +45,12 @@ class FlightModePanel : public ModelPanel int reCount; int gvCount; QVector trimsLabel; - QLineEdit * gvNames[C9X_MAX_GVARS]; - QSpinBox * gvValues[C9X_MAX_GVARS]; - QCheckBox * gvPopups[C9X_MAX_GVARS]; - QComboBox * gvUse[C9X_MAX_GVARS]; - QSpinBox * reValues[C9X_MAX_ENCODERS]; - QComboBox * reUse[C9X_MAX_ENCODERS]; + QLineEdit * gvNames[CPN_MAX_GVARS]; + QSpinBox * gvValues[CPN_MAX_GVARS]; + QCheckBox * gvPopups[CPN_MAX_GVARS]; + QComboBox * gvUse[CPN_MAX_GVARS]; + QSpinBox * reValues[CPN_MAX_ENCODERS]; + QComboBox * reUse[CPN_MAX_ENCODERS]; QVector trimsUse; QVector trimsValue; QVector trimsSlider; diff --git a/companion/src/modeledit/inputs.cpp b/companion/src/modeledit/inputs.cpp index 3ddaaf2d6..9e0ff8133 100644 --- a/companion/src/modeledit/inputs.cpp +++ b/companion/src/modeledit/inputs.cpp @@ -9,7 +9,7 @@ InputsPanel::InputsPanel(QWidget *parent, ModelData & model, GeneralSettings & g { inputsCount = firmware->getCapability(VirtualInputs); if (inputsCount == 0) - inputsCount = NUM_STICKS; + inputsCount = CPN_MAX_STICKS; QGridLayout * exposLayout = new QGridLayout(this); @@ -58,7 +58,7 @@ void InputsPanel::update() firstLine = true; int curDest = -1; - for (int i=0; iexpoData[i]; if (md->mode==0) break; @@ -162,7 +162,7 @@ QString InputsPanel::getInputText(int dest, bool * new_ch) bool InputsPanel::gm_insertExpo(int idx) { - if (idx<0 || idx>=C9X_MAX_EXPOS || model->expoData[C9X_MAX_EXPOS-1].mode > 0) { + if (idx<0 || idx>=CPN_MAX_EXPOS || model->expoData[CPN_MAX_EXPOS-1].mode > 0) { QMessageBox::information(this, "Companion", tr("Not enough available inputs!")); return false; } @@ -184,7 +184,7 @@ void InputsPanel::gm_deleteExpo(int index) void InputsPanel::gm_openExpo(int index) { - if(index<0 || index>=C9X_MAX_EXPOS) return; + if(index<0 || index>=CPN_MAX_EXPOS) return; ExpoData mixd(model->expoData[index]); emit modified(); @@ -215,8 +215,8 @@ void InputsPanel::gm_openExpo(int index) int InputsPanel::getExpoIndex(unsigned int dch) { unsigned int i = 0; - while (model->expoData[i].chn<=dch && model->expoData[i].mode && iexpoData[i].chn<=dch && model->expoData[i].mode && i InputsPanel::createExpoListFromSelected() QList list; foreach(QListWidgetItem *item, ExposlistWidget->selectedItems()) { int idx= item->data(Qt::UserRole).toByteArray().at(0); - if(idx>=0 && idx=0 && idxC9X_MAX_EXPOS || (idx==C9X_MAX_EXPOS && dir)) return idx; + if(idx>CPN_MAX_EXPOS || (idx==CPN_MAX_EXPOS && dir)) return idx; int tdx = dir ? idx+1 : idx-1; ExpoData temp; diff --git a/companion/src/modeledit/logicalswitches.h b/companion/src/modeledit/logicalswitches.h index 7384126e3..5b2f13c0b 100644 --- a/companion/src/modeledit/logicalswitches.h +++ b/companion/src/modeledit/logicalswitches.h @@ -28,16 +28,16 @@ class LogicalSwitchesPanel : public ModelPanel void cswCut(); private: - QComboBox * csw[C9X_NUM_CSW]; - QDoubleSpinBox * cswitchValue[C9X_NUM_CSW]; - QDoubleSpinBox * cswitchOffset[C9X_NUM_CSW]; - QDoubleSpinBox * cswitchOffset2[C9X_NUM_CSW]; - QTimeEdit * cswitchTOffset[C9X_NUM_CSW]; - QComboBox * cswitchAnd[C9X_NUM_CSW]; - QDoubleSpinBox * cswitchDuration[C9X_NUM_CSW]; - QDoubleSpinBox * cswitchDelay[C9X_NUM_CSW]; - QComboBox * cswitchSource1[C9X_NUM_CSW]; - QComboBox * cswitchSource2[C9X_NUM_CSW]; + QComboBox * csw[CPN_MAX_CSW]; + QDoubleSpinBox * cswitchValue[CPN_MAX_CSW]; + QDoubleSpinBox * cswitchOffset[CPN_MAX_CSW]; + QDoubleSpinBox * cswitchOffset2[CPN_MAX_CSW]; + QTimeEdit * cswitchTOffset[CPN_MAX_CSW]; + QComboBox * cswitchAnd[CPN_MAX_CSW]; + QDoubleSpinBox * cswitchDuration[CPN_MAX_CSW]; + QDoubleSpinBox * cswitchDelay[CPN_MAX_CSW]; + QComboBox * cswitchSource1[CPN_MAX_CSW]; + QComboBox * cswitchSource2[CPN_MAX_CSW]; void setSwitchWidgetVisibility(int i); int selectedSwitch; diff --git a/companion/src/modeledit/mixerdialog.cpp b/companion/src/modeledit/mixerdialog.cpp index e3e316362..db60324e2 100644 --- a/companion/src/modeledit/mixerdialog.cpp +++ b/companion/src/modeledit/mixerdialog.cpp @@ -38,7 +38,7 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData *mixdata, G } if (!firmware->getCapability(VirtualInputs)) { - for(int i=0; i < NUM_STICKS; i++) { + for(int i=0; i < CPN_MAX_STICKS; i++) { ui->trimCB->addItem(AnalogString(i)); } } @@ -145,7 +145,7 @@ void MixerDialog::valuesChanged() QCheckBox * cb_fp[] = {ui->cb_FP0,ui->cb_FP1,ui->cb_FP2,ui->cb_FP3,ui->cb_FP4,ui->cb_FP5,ui->cb_FP6,ui->cb_FP7,ui->cb_FP8 }; md->srcRaw = RawSource(ui->sourceCB->itemData(ui->sourceCB->currentIndex()).toInt()); if (firmware->getCapability(HasNoExpo)) { - bool drVisible = (md->srcRaw.type == SOURCE_TYPE_STICK && md->srcRaw.index < NUM_STICKS); + bool drVisible = (md->srcRaw.type == SOURCE_TYPE_STICK && md->srcRaw.index < CPN_MAX_STICKS); ui->MixDR_CB->setEnabled(drVisible); ui->label_MixDR->setEnabled(drVisible); } diff --git a/companion/src/modeledit/setup.cpp b/companion/src/modeledit/setup.cpp index 5b300e068..a093fa638 100644 --- a/companion/src/modeledit/setup.cpp +++ b/companion/src/modeledit/setup.cpp @@ -594,7 +594,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge } QWidget * prevFocus = ui->image; - for (int i=0; igetCapability(Timers)) { timers[i] = new TimerPanel(this, model, model.timers[i], generalSettings, firmware, prevFocus); ui->gridLayout->addWidget(timers[i], 1+i, 1); @@ -610,7 +610,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge if (firmware->getCapability(HasTopLcd)) { ui->toplcdTimer->setField(model.toplcdTimer, this); - for (int i=0; igetCapability(Timers)) { ui->toplcdTimer->addItem(tr("Timer %1").arg(i+1), i); } @@ -631,7 +631,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge // Beep Center checkboxes prevFocus = ui->trimsDisplay; - int analogs = NUM_STICKS + firmware->getCapability(Pots) + firmware->getCapability(Sliders); + int analogs = CPN_MAX_STICKS + firmware->getCapability(Pots) + firmware->getCapability(Sliders); for (int i=0; igetCapability(RotaryEncoders); i++) { QCheckBox * checkbox = new QCheckBox(this); checkbox->setProperty("index", i); @@ -641,10 +641,10 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge centerBeepCheckboxes << checkbox; if (IS_TARANIS(board)) { RawSource src(SOURCE_TYPE_STICK, i); - if (src.isPot() && !generalSettings.isPotAvailable(i-NUM_STICKS)) { + if (src.isPot() && !generalSettings.isPotAvailable(i-CPN_MAX_STICKS)) { checkbox->hide(); } - else if (src.isSlider() && !generalSettings.isSliderAvailable(i-NUM_STICKS-firmware->getCapability(Pots))) { + else if (src.isSlider() && !generalSettings.isSliderAvailable(i-CPN_MAX_STICKS-firmware->getCapability(Pots))) { checkbox->hide(); } } @@ -702,7 +702,7 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge ui->potWarningLayout->addWidget(cb, 0, i+1); connect(cb, SIGNAL(toggled(bool)), this, SLOT(potWarningToggled(bool))); potWarningCheckboxes << cb; - if (RawSource(SOURCE_TYPE_STICK, NUM_STICKS+i).isPot()) { + if (RawSource(SOURCE_TYPE_STICK, CPN_MAX_STICKS+i).isPot()) { if (!generalSettings.isPotAvailable(i)) { cb->hide(); } @@ -736,9 +736,9 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge } if (firmware->getCapability(ModelTrainerEnable)) { - modules[C9X_NUM_MODULES] = new ModulePanel(this, model, model.moduleData[C9X_NUM_MODULES], generalSettings, firmware, -1); - ui->modulesLayout->addWidget(modules[C9X_NUM_MODULES]); - connect(modules[C9X_NUM_MODULES], SIGNAL(modified()), this, SLOT(onChildModified())); + modules[CPN_MAX_MODULES] = new ModulePanel(this, model, model.moduleData[CPN_MAX_MODULES], generalSettings, firmware, -1); + ui->modulesLayout->addWidget(modules[CPN_MAX_MODULES]); + connect(modules[CPN_MAX_MODULES], SIGNAL(modified()), this, SLOT(onChildModified())); } disableMouseScrolling(); @@ -894,7 +894,7 @@ void SetupPanel::update() for (int i=0; igetCapability(Timers); i++) timers[i]->update(); - for (int i=0; iupdate(); } diff --git a/companion/src/modeledit/setup.h b/companion/src/modeledit/setup.h index 4fd32530d..cf75d75d5 100644 --- a/companion/src/modeledit/setup.h +++ b/companion/src/modeledit/setup.h @@ -65,10 +65,10 @@ class ModulePanel : public ModelPanel void on_failsafeMode_currentIndexChanged(int value); void onFailsafeComboIndexChanged(int index); void onFailsafeSpinChanged(double value); - void on_multiProtocol_currentIndexChanged(int index); - void on_multiSubType_currentIndexChanged(int index); - void on_autoBind_stateChanged(int state); - void on_lowPower_stateChanged(int state); + void on_multiProtocol_currentIndexChanged(int index); + void on_multiSubType_currentIndexChanged(int index); + void on_autoBind_stateChanged(int state); + void on_lowPower_stateChanged(int state); private: ModuleData & module; @@ -115,8 +115,8 @@ class SetupPanel : public ModelPanel QVector startupSwitchesCheckboxes; QVector potWarningCheckboxes; QVector centerBeepCheckboxes; - ModulePanel * modules[C9X_NUM_MODULES+1]; - TimerPanel * timers[C9X_MAX_TIMERS]; + ModulePanel * modules[CPN_MAX_MODULES+1]; + TimerPanel * timers[CPN_MAX_TIMERS]; void updateStartupSwitches(); void updatePotWarnings(); void updateBeepCenter(); diff --git a/companion/src/modeledit/telemetry.cpp b/companion/src/modeledit/telemetry.cpp index 9f997a47b..9593a9030 100644 --- a/companion/src/modeledit/telemetry.cpp +++ b/companion/src/modeledit/telemetry.cpp @@ -628,13 +628,13 @@ void populateTelemetrySourcesComboBox(AutoComboBox * cb, const ModelData * model { cb->clear(); if (negative) { - for (int i=-C9X_MAX_SENSORS; i<0; ++i) { + for (int i=-CPN_MAX_SENSORS; i<0; ++i) { if (model->sensorData[-i-1].isAvailable()) cb->addItem(QObject::tr("-%1").arg(model->sensorData[-i-1].label), i); } } cb->addItem("---", 0); - for (int i=1; i<=C9X_MAX_SENSORS; ++i) { + for (int i=1; i<=CPN_MAX_SENSORS; ++i) { if (model->sensorData[i-1].isAvailable()) cb->addItem(model->sensorData[i-1].label, i); } @@ -720,7 +720,7 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin if (IS_ARM(firmware->getBoard())) { ui->A1GB->hide(); ui->A2GB->hide(); - for (int i=0; isensorsLayout->addWidget(panel); sensorPanels[i] = panel; @@ -782,7 +782,7 @@ void TelemetryPanel::update() } if (IS_ARM(firmware->getBoard())) { - for (int i=0; iupdate(); } for (int i=0; igetCapability(TelemetryCustomScreens); i++) { @@ -827,7 +827,7 @@ void TelemetryPanel::setup() } /*if (IS_ARM(firmware->getBoard())) { - for (int i=0; i, model, generalSettings, firmware); ui->sensorsLayout->addWidget(panel); sensorPanels[i] = panel; diff --git a/companion/src/modeledit/telemetry.h b/companion/src/modeledit/telemetry.h index 066bdaa9c..b3b9f44b0 100644 --- a/companion/src/modeledit/telemetry.h +++ b/companion/src/modeledit/telemetry.h @@ -134,7 +134,7 @@ class TelemetryPanel : public ModelPanel Ui::Telemetry *ui; TelemetryAnalog * analogs[4]; TelemetryCustomScreen * telemetryCustomScreens[4]; - TelemetrySensorPanel * sensorPanels[C9X_MAX_SENSORS]; + TelemetrySensorPanel * sensorPanels[CPN_MAX_SENSORS]; void setup(); void telBarUpdate(); diff --git a/companion/src/modelslist.cpp b/companion/src/modelslist.cpp index 0cfb942c2..cf07ec2c7 100644 --- a/companion/src/modelslist.cpp +++ b/companion/src/modelslist.cpp @@ -1,44 +1,3 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - #include "modelslist.h" #include "mdichild.h" #include "helpers.h" @@ -52,7 +11,7 @@ class DragDropHeader { } bool general_settings; uint8_t models_count; - uint8_t models[C9X_MAX_MODELS]; + uint8_t models[CPN_MAX_MODELS]; }; ModelsListWidget::ModelsListWidget(QWidget *parent): diff --git a/companion/src/modelslist.h b/companion/src/modelslist.h index 8014a1ae4..047997dd9 100644 --- a/companion/src/modelslist.h +++ b/companion/src/modelslist.h @@ -1,44 +1,3 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - #ifndef MODELSLIST_H #define MODELSLIST_H @@ -48,7 +7,7 @@ struct CurrentSelection { QListWidgetItem *current_item; - bool selected[C9X_MAX_MODELS+1]; + bool selected[CPN_MAX_MODELS+1]; }; class ModelsListWidget : public QListWidget diff --git a/companion/src/multimodelprinter.cpp b/companion/src/multimodelprinter.cpp index 3e7a6ebfe..0394eb870 100644 --- a/companion/src/multimodelprinter.cpp +++ b/companion/src/multimodelprinter.cpp @@ -247,7 +247,7 @@ QString MultiModelPrinter::printFlightModes() columns.append("" + tr("Switch") + ""); columns.append("" + tr("Fade IN") + ""); columns.append("" + tr("Fade OUT") + ""); - for (int i=0; i" + AnalogString(i) + " trim"); } columns.append(""); @@ -262,7 +262,7 @@ QString MultiModelPrinter::printFlightModes() columns.append(""); COMPARE(model->flightModeData[i].fadeOut); columns.append(""); - for (int k=0; k"); COMPARE(modelPrinter->printTrim(i, k)); columns.append(""); diff --git a/companion/src/multimodelprinter.h b/companion/src/multimodelprinter.h index fa1c19f33..bc823fc95 100644 --- a/companion/src/multimodelprinter.h +++ b/companion/src/multimodelprinter.h @@ -1,58 +1,58 @@ -#ifndef _MULTIMODELPRINTER_H -#define _MULTIMODELPRINTER_H - -#include -#include -#include "eeprominterface.h" -#include "modelprinter.h" - -class MultiModelPrinter: public QObject -{ - Q_OBJECT - - public: - MultiModelPrinter(Firmware * firmware); - virtual ~MultiModelPrinter(); - - void setModel(int idx, const ModelData & model); - QString print(QTextDocument * document); - - protected: - class MultiColumns { - public: - MultiColumns(int count); - ~MultiColumns(); - bool isEmpty(); - QString print(); - void append(const QString & str); - void appendTitle(const QString & name); - void append(int idx, const QString & str); - template void append(int idx, T val); - void beginCompare(); - void endCompare(const QString & color = "grey"); - private: - int count; - QString * columns; - QString * compareColumns; - }; - - Firmware * firmware; - GeneralSettings defaultSettings; - QVector models; // TODO const - QVector modelPrinters; - - QString printTitle(const QString & label); - QString printSetup(); - QString printHeliSetup(); - QString printFlightModes(); - QString printLimits(); - QString printInputs(); - QString printMixers(); - QString printCurves(QTextDocument * document); - QString printGvars(); - QString printLogicalSwitches(); - QString printCustomFunctions(); - QString printTelemetry(); -}; - -#endif // _MULTIMODELPRINTER_H +#ifndef _MULTIMODELPRINTER_H +#define _MULTIMODELPRINTER_H + +#include +#include +#include "eeprominterface.h" +#include "modelprinter.h" + +class MultiModelPrinter: public QObject +{ + Q_OBJECT + + public: + MultiModelPrinter(Firmware * firmware); + virtual ~MultiModelPrinter(); + + void setModel(int idx, const ModelData & model); + QString print(QTextDocument * document); + + protected: + class MultiColumns { + public: + MultiColumns(int count); + ~MultiColumns(); + bool isEmpty(); + QString print(); + void append(const QString & str); + void appendTitle(const QString & name); + void append(int idx, const QString & str); + template void append(int idx, T val); + void beginCompare(); + void endCompare(const QString & color = "grey"); + private: + int count; + QString * columns; + QString * compareColumns; + }; + + Firmware * firmware; + GeneralSettings defaultSettings; + QVector models; // TODO const + QVector modelPrinters; + + QString printTitle(const QString & label); + QString printSetup(); + QString printHeliSetup(); + QString printFlightModes(); + QString printLimits(); + QString printInputs(); + QString printMixers(); + QString printCurves(QTextDocument * document); + QString printGvars(); + QString printLogicalSwitches(); + QString printCustomFunctions(); + QString printTelemetry(); +}; + +#endif // _MULTIMODELPRINTER_H diff --git a/companion/src/printdialog.cpp b/companion/src/printdialog.cpp index 08b9faecc..c46afdad2 100644 --- a/companion/src/printdialog.cpp +++ b/companion/src/printdialog.cpp @@ -1,95 +1,95 @@ -#include "printdialog.h" -#include "ui_printdialog.h" -#include "helpers.h" -#include -#include - -// #if !defined WIN32 && defined __GNUC__ -// #include -// #endif - -PrintDialog::PrintDialog(QWidget *parent, Firmware * firmware, GeneralSettings & generalSettings, ModelData & model, const QString & filename) : - QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), - firmware(firmware), - generalSettings(generalSettings), - model(model), - printfilename(filename), - ui(new Ui::PrintDialog), - multimodelprinter(firmware) -{ - ui->setupUi(this); - setWindowIcon(CompanionIcon("print.png")); - setWindowTitle(model.name); - multimodelprinter.setModel(0, model); - ui->textEdit->setHtml(multimodelprinter.print(ui->textEdit->document())); - if (!printfilename.isEmpty()) { - printToFile(); - QTimer::singleShot(0, this, SLOT(autoClose())); - } -} - -void PrintDialog::closeEvent(QCloseEvent *event) -{ -} - -PrintDialog::~PrintDialog() -{ - delete ui; -} - -void PrintDialog::on_printButton_clicked() -{ - QPrinter printer; - printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter); - QPrintDialog *dialog = new QPrintDialog(&printer, this); - dialog->setWindowTitle(tr("Print Document")); - if (dialog->exec() != QDialog::Accepted) - return; - ui->textEdit->print(&printer); -} - -void PrintDialog::on_printFileButton_clicked() -{ - QString fn = QFileDialog::getSaveFileName(this,tr("Select PDF output file"),QString(),tr("ODF files (*.odt);;PDF Files(*.pdf);;HTML-Files (*.htm *.html);;All Files (*)")); - if (fn.isEmpty()) - return; - if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".pdf", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) ) - fn += ".pdf"; // default - if (fn.endsWith(".pdf", Qt::CaseInsensitive)) { - QPrinter printer; - printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setColorMode(QPrinter::Color); - printer.setOutputFileName(fn); - ui->textEdit->print(&printer); - } - else { - QTextDocumentWriter writer(fn); - writer.write(ui->textEdit->document()); - } -} - -void PrintDialog::printToFile() -{ - if (printfilename.isEmpty()) - return; - if (! (printfilename.endsWith(".odt", Qt::CaseInsensitive) || printfilename.endsWith(".pdf", Qt::CaseInsensitive) || printfilename.endsWith(".htm", Qt::CaseInsensitive) || printfilename.endsWith(".html", Qt::CaseInsensitive)) ) - printfilename += ".pdf"; // default - if (printfilename.endsWith(".pdf", Qt::CaseInsensitive)) { - QPrinter printer; - printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setColorMode(QPrinter::Color); - printer.setOutputFileName(printfilename); - ui->textEdit->print(&printer); - } - else { - QTextDocumentWriter writer(printfilename); - writer.write(ui->textEdit->document()); - } -} - -void PrintDialog::autoClose() -{ - this->close(); -} +#include "printdialog.h" +#include "ui_printdialog.h" +#include "helpers.h" +#include +#include + +// #if !defined WIN32 && defined __GNUC__ +// #include +// #endif + +PrintDialog::PrintDialog(QWidget *parent, Firmware * firmware, GeneralSettings & generalSettings, ModelData & model, const QString & filename) : + QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint), + firmware(firmware), + generalSettings(generalSettings), + model(model), + printfilename(filename), + ui(new Ui::PrintDialog), + multimodelprinter(firmware) +{ + ui->setupUi(this); + setWindowIcon(CompanionIcon("print.png")); + setWindowTitle(model.name); + multimodelprinter.setModel(0, model); + ui->textEdit->setHtml(multimodelprinter.print(ui->textEdit->document())); + if (!printfilename.isEmpty()) { + printToFile(); + QTimer::singleShot(0, this, SLOT(autoClose())); + } +} + +void PrintDialog::closeEvent(QCloseEvent *event) +{ +} + +PrintDialog::~PrintDialog() +{ + delete ui; +} + +void PrintDialog::on_printButton_clicked() +{ + QPrinter printer; + printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter); + QPrintDialog *dialog = new QPrintDialog(&printer, this); + dialog->setWindowTitle(tr("Print Document")); + if (dialog->exec() != QDialog::Accepted) + return; + ui->textEdit->print(&printer); +} + +void PrintDialog::on_printFileButton_clicked() +{ + QString fn = QFileDialog::getSaveFileName(this,tr("Select PDF output file"),QString(),tr("ODF files (*.odt);;PDF Files(*.pdf);;HTML-Files (*.htm *.html);;All Files (*)")); + if (fn.isEmpty()) + return; + if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".pdf", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) ) + fn += ".pdf"; // default + if (fn.endsWith(".pdf", Qt::CaseInsensitive)) { + QPrinter printer; + printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setColorMode(QPrinter::Color); + printer.setOutputFileName(fn); + ui->textEdit->print(&printer); + } + else { + QTextDocumentWriter writer(fn); + writer.write(ui->textEdit->document()); + } +} + +void PrintDialog::printToFile() +{ + if (printfilename.isEmpty()) + return; + if (! (printfilename.endsWith(".odt", Qt::CaseInsensitive) || printfilename.endsWith(".pdf", Qt::CaseInsensitive) || printfilename.endsWith(".htm", Qt::CaseInsensitive) || printfilename.endsWith(".html", Qt::CaseInsensitive)) ) + printfilename += ".pdf"; // default + if (printfilename.endsWith(".pdf", Qt::CaseInsensitive)) { + QPrinter printer; + printer.setPageMargins(10.0,10.0,10.0,10.0,printer.Millimeter); + printer.setOutputFormat(QPrinter::PdfFormat); + printer.setColorMode(QPrinter::Color); + printer.setOutputFileName(printfilename); + ui->textEdit->print(&printer); + } + else { + QTextDocumentWriter writer(printfilename); + writer.write(ui->textEdit->document()); + } +} + +void PrintDialog::autoClose() +{ + this->close(); +} diff --git a/companion/src/printdialog.h b/companion/src/printdialog.h index bd64bde7c..6c96cf3f6 100644 --- a/companion/src/printdialog.h +++ b/companion/src/printdialog.h @@ -1,39 +1,39 @@ -#ifndef _PRINTDIALOG_H -#define _PRINTDIALOG_H - -#include -#include "eeprominterface.h" -#include "multimodelprinter.h" - -namespace Ui { - class PrintDialog; -} - -class PrintDialog : public QDialog -{ - Q_OBJECT - - public: - PrintDialog(QWidget * parent, Firmware * firmware, GeneralSettings & generalSettings, ModelData & model, const QString & filename=""); - ~PrintDialog(); - void closeEvent(QCloseEvent * event); - - Firmware * firmware; - GeneralSettings & generalSettings; - ModelData & model; - - QString printfilename; - - protected: - Ui::PrintDialog *ui; - MultiModelPrinter multimodelprinter; // TODO multimodelPrinter - - void printToFile(); - - private slots: - void on_printButton_clicked(); - void on_printFileButton_clicked(); - void autoClose(); -}; - -#endif // _PRINTDIALOG_H +#ifndef _PRINTDIALOG_H +#define _PRINTDIALOG_H + +#include +#include "eeprominterface.h" +#include "multimodelprinter.h" + +namespace Ui { + class PrintDialog; +} + +class PrintDialog : public QDialog +{ + Q_OBJECT + + public: + PrintDialog(QWidget * parent, Firmware * firmware, GeneralSettings & generalSettings, ModelData & model, const QString & filename=""); + ~PrintDialog(); + void closeEvent(QCloseEvent * event); + + Firmware * firmware; + GeneralSettings & generalSettings; + ModelData & model; + + QString printfilename; + + protected: + Ui::PrintDialog *ui; + MultiModelPrinter multimodelprinter; // TODO multimodelPrinter + + void printToFile(); + + private slots: + void on_printButton_clicked(); + void on_printFileButton_clicked(); + void autoClose(); +}; + +#endif // _PRINTDIALOG_H diff --git a/companion/src/process_copy.cpp b/companion/src/process_copy.cpp index e0a53d100..586150c6d 100644 --- a/companion/src/process_copy.cpp +++ b/companion/src/process_copy.cpp @@ -1,71 +1,71 @@ -#include "process_copy.h" -#include "progresswidget.h" -#include -#include -#include -#include - -#define BLKSIZE 512 - -CopyProcess::CopyProcess(const QString &source, const QString &destination, ProgressWidget *progress): -progress(progress), -source(source), -destination(destination), -result(true) -{ -} - -bool CopyProcess::run() -{ - progress->lock(true); - // progress->setInfo(tr("Copying file...")); - - QEventLoop loop; - connect(this, SIGNAL(finished()), &loop, SLOT(quit())); - QTimer::singleShot(500, this, SLOT(onTimer())); - loop.exec(); - - return result; -} - -void CopyProcess::onTimer() -{ - char buf[BLKSIZE]; - - QFile sourceFile(source); - int blocks = (sourceFile.size() + BLKSIZE - 1) / BLKSIZE; - progress->setMaximum(blocks-1); - - if (sourceFile.open(QIODevice::ReadOnly)) { - QFile destinationFile(destination); - if (destinationFile.open(QIODevice::ReadWrite)) { - // progress->addText(tr("Writing file: ")); - for (int i=0; isetValue(i); - } - else { - QMessageBox::warning(NULL, tr("Error"), tr("Write error")); - result = false; - break; - } - } - destinationFile.close(); - } - else { - QMessageBox::warning(NULL, tr("Error"),tr("Cannot write %1 (reason: %2)").arg(destinationFile.fileName()).arg(sourceFile.errorString())); - result = false; - } - } - else { - QMessageBox::warning(NULL, tr("Error"),tr("Cannot open %1 (reason: %2)").arg(sourceFile.fileName()).arg(sourceFile.errorString())); - result = false; - } - - sourceFile.close(); - - progress->lock(false); - emit finished(); -} +#include "process_copy.h" +#include "progresswidget.h" +#include +#include +#include +#include + +#define BLKSIZE 512 + +CopyProcess::CopyProcess(const QString &source, const QString &destination, ProgressWidget *progress): +progress(progress), +source(source), +destination(destination), +result(true) +{ +} + +bool CopyProcess::run() +{ + progress->lock(true); + // progress->setInfo(tr("Copying file...")); + + QEventLoop loop; + connect(this, SIGNAL(finished()), &loop, SLOT(quit())); + QTimer::singleShot(500, this, SLOT(onTimer())); + loop.exec(); + + return result; +} + +void CopyProcess::onTimer() +{ + char buf[BLKSIZE]; + + QFile sourceFile(source); + int blocks = (sourceFile.size() + BLKSIZE - 1) / BLKSIZE; + progress->setMaximum(blocks-1); + + if (sourceFile.open(QIODevice::ReadOnly)) { + QFile destinationFile(destination); + if (destinationFile.open(QIODevice::ReadWrite)) { + // progress->addText(tr("Writing file: ")); + for (int i=0; isetValue(i); + } + else { + QMessageBox::warning(NULL, tr("Error"), tr("Write error")); + result = false; + break; + } + } + destinationFile.close(); + } + else { + QMessageBox::warning(NULL, tr("Error"),tr("Cannot write %1 (reason: %2)").arg(destinationFile.fileName()).arg(sourceFile.errorString())); + result = false; + } + } + else { + QMessageBox::warning(NULL, tr("Error"),tr("Cannot open %1 (reason: %2)").arg(sourceFile.fileName()).arg(sourceFile.errorString())); + result = false; + } + + sourceFile.close(); + + progress->lock(false); + emit finished(); +} diff --git a/companion/src/process_copy.h b/companion/src/process_copy.h index ad41d3c15..f67b1f8b2 100644 --- a/companion/src/process_copy.h +++ b/companion/src/process_copy.h @@ -1,31 +1,31 @@ -#ifndef COPYPROCESS_H_ -#define COPYPROCESS_H_ - -#include -#include -#include - -class ProgressWidget; - -class CopyProcess : public QObject -{ - Q_OBJECT - -public: - CopyProcess(const QString &source, const QString &destination, ProgressWidget *progress); - bool run(); - -signals: - void finished(); - -protected slots: - void onTimer(); - -protected: - ProgressWidget *progress; - const QString source; - const QString destination; - bool result; -}; - -#endif // COPYPROCESS_H_ +#ifndef COPYPROCESS_H_ +#define COPYPROCESS_H_ + +#include +#include +#include + +class ProgressWidget; + +class CopyProcess : public QObject +{ + Q_OBJECT + +public: + CopyProcess(const QString &source, const QString &destination, ProgressWidget *progress); + bool run(); + +signals: + void finished(); + +protected slots: + void onTimer(); + +protected: + ProgressWidget *progress; + const QString source; + const QString destination; + bool result; +}; + +#endif // COPYPROCESS_H_ diff --git a/companion/src/process_flash.cpp b/companion/src/process_flash.cpp index a57c3c02c..4290caea1 100644 --- a/companion/src/process_flash.cpp +++ b/companion/src/process_flash.cpp @@ -1,302 +1,302 @@ -#include "process_flash.h" -#include "progresswidget.h" -#include -#include -#include -#include "eeprominterface.h" -//#include "firmwareinterface.h" - -#if defined WIN32 || !defined __GNUC__ -#include -#include -#include -#define sleep(x) Sleep(x*1000) -#else -#include -#include "mountlist.h" -#endif - -FlashProcess::FlashProcess(const QString &cmd, const QStringList &args, ProgressWidget *progress): -progress(progress), -cmd(cmd), -args(args), -process(new QProcess(this)), -hasErrors(false), -lfuse(0), -hfuse(0), -efuse(0), -flashPhase(READING) -#if !__GNUC__ -, killTimer(NULL) -#endif -{ - connect(process, SIGNAL(started()),this, SLOT(onStarted())); - connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadyReadStandardOutput())); - connect(process, SIGNAL(readyReadStandardError()), this, SLOT(onReadyReadStandardError())); - connect(process, SIGNAL(finished(int)), this, SLOT(onFinished(int))); -} - -FlashProcess::~FlashProcess() -{ -#if !__GNUC__ - delete killTimer; -#endif -} - -bool FlashProcess::run() -{ - if (!QFile::exists(cmd)) { - QMessageBox::critical(NULL, "Companion", tr("Executable %1 not found").arg(cmd)); - return false; - } - -#if !__GNUC__ - if (cmd.toLower().contains("sam-ba")) { - killTimer = new QTimer(this); - connect(killTimer, SIGNAL(timeout()), this, SLOT(onKillTimerElapsed())); - killTimer->start(2000); - } -#endif - - QEventLoop loop; - connect(this, SIGNAL(finished()), &loop, SLOT(quit())); - process->start(cmd, args); - loop.exec(); - - return true; -} - -void FlashProcess::onStarted() -{ - progress->lock(true); - progress->addText(cmd + " " + args.join(" ")); - progress->addSeparator(); -} - -# if !__GNUC__ -bool killProcessByName(const char *szProcessToKill) -{ - HANDLE hProcessSnap; - HANDLE hProcess; - PROCESSENTRY32 pe32; - DWORD dwPriorityClass; - - hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // Takes a snapshot of all the processes - - if (hProcessSnap == INVALID_HANDLE_VALUE) { - return false; - } - - pe32.dwSize = sizeof(PROCESSENTRY32); - - if (!Process32First(hProcessSnap, &pe32)) { - CloseHandle(hProcessSnap); - return false; - } - - do { - if (!strcmp(pe32.szExeFile,szProcessToKill)) { // checks if process at current position has the name of to be killed app - hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID); // gets handle to process - TerminateProcess(hProcess, 0); // Terminate process by handle - CloseHandle(hProcess); // close the handle - } - } while (Process32Next(hProcessSnap, &pe32)); // gets next member of snapshot - - CloseHandle(hProcessSnap); // closes the snapshot handle - return true; -} -#endif - -void FlashProcess::onKillTimerElapsed() -{ -# if !__GNUC__ - // trick to accelerate SAM-BA startup - killProcessByName("tasklist.exe"); -#endif -} - -void FlashProcess::analyseStandardOutput(const QString &text) -{ - currStdoutLine.append(text); - if (currStdoutLine.contains("size = ")) { - int pos = currStdoutLine.lastIndexOf("size = "); - QString temp = currStdoutLine.mid(pos+7); - pos = temp.lastIndexOf("\n"); - int size = temp.left(pos).toInt(); - progress->setMaximum(size/2048); - } - if (currStdoutLine.contains("\n")) { - int nlPos = currStdoutLine.lastIndexOf("\n"); - currStdoutLine = currStdoutLine.mid(nlPos+1); - } - if (!currStdoutLine.isEmpty()) { - if (currStdoutLine.at(0) == QChar('.')) { - int pos = currStdoutLine.lastIndexOf("."); - progress->setValue(pos); - } - else if (currStdoutLine.startsWith("Starting upload: [")) { - int pos = (currStdoutLine.lastIndexOf("#")-19)*100/256; - progress->setValue(pos); - } - } - - if (text.contains("Complete ")) { -#if !__GNUC__ - delete killTimer; - killTimer = NULL; -#endif - int start = text.indexOf("Complete "); - int end = text.indexOf("%"); - if (start > 0) { - start += 9; - int value = text.mid(start, end-start).toInt(); - progress->setValue(value); - } - } - - if (text.contains(":010000")) { - // contains fuse info - QStringList stl = text.split(":01000000"); - foreach (QString t, stl) { - bool ok = false; - if (!lfuse) lfuse = t.left(2).toInt(&ok, 16); - if (!hfuse && !ok) hfuse = t.left(2).toInt(&ok, 16); - if (!efuse && !ok) efuse = t.left(2).toInt(&ok, 16); - } - } - - if (text.contains("-E-")) { - hasErrors = true; - } -} - -void FlashProcess::analyseStandardError(const QString &text) -{ - currStderrLine.append(text); - if (currStderrLine.contains("#")) { - QString avrflashPhase = currStderrLine.left(1).toLower(); - if (avrflashPhase == "w") { - flashPhase = WRITING; - progress->setInfo(tr("Writing...")); - progress->setValue(2 * currStderrLine.count("#")); - } - else if (avrflashPhase == "r") { - if (flashPhase == READING) { - progress->setInfo(tr("Reading...")); - } - else { - flashPhase = VERIFYING; - progress->setInfo(tr("Verifying...")); - } - progress->setValue(2 * currStderrLine.count("#")); - } - } - - if (currStderrLine.contains("\n")) { - int nlPos = currStderrLine.lastIndexOf("\n"); - currStderrLine = currStderrLine.mid(nlPos+1); - } - - if ((text.contains("-E-") && !text.contains("-E- No receive file name")) || - text.contains("No DFU capable USB device found")) { - hasErrors = true; - } -} - -void FlashProcess::onReadyReadStandardOutput() -{ - QString text = QString(process->readAllStandardOutput()); - progress->addText(text); - analyseStandardOutput(text); -} - -void FlashProcess::onReadyReadStandardError() -{ - QString text = QString(process->readAllStandardError()); - progress->addText(text); - analyseStandardError(text); -} - -void FlashProcess::errorWizard() -{ - QString output = progress->getText(); - - if (output.contains("avrdude: Expected signature for")) { // wrong signature - int pos = output.indexOf("avrdude: Device signature = "); - bool fwexist = false; - QString DeviceStr = tr("unknown"); - QString FwStr = ""; - - if (pos > 0) { - QString DeviceId = output.mid(pos+28, 8); - if (DeviceId=="0x1e9602") { - DeviceStr = "Atmega 64"; - FwStr="\n" + tr("ie: OpenTX for 9X board or OpenTX for 9XR board"); - fwexist = true; - } - else if (DeviceId=="0x1e9702") { - DeviceStr = "Atmega 128"; - FwStr="\n" + tr("ie: OpenTX for M128 / 9X board or OpenTX for 9XR board with M128 chip"); - fwexist = true; - } - else if (DeviceId=="0x1e9703") { - DeviceStr = "Atmega 1280"; - } - else if (DeviceId=="0x1e9704") { - DeviceStr = "Atmega 1281"; - } - else if (DeviceId=="0x1e9801") { - DeviceStr = "Atmega 2560"; - FwStr="\n" + tr("ie: OpenTX for Gruvin9X board"); - fwexist = true; - } - else if (DeviceId=="0x1e9802") { - DeviceStr = "Atmega 2561"; - } - } - if (fwexist==false) { - QMessageBox::warning(NULL, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease check advanced burn options to set the correct cpu type.").arg(DeviceStr)); - } - else { - Firmware *firmware = GetCurrentFirmware(); - QMessageBox::warning(NULL, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease select an appropriate firmware type to program it.").arg(DeviceStr)+FwStr+tr("\nYou are currently using:\n %1").arg(firmware->getName())); - } - } - else if (output.contains("No DFU capable USB device found")){ -#if defined WIN32 || !defined __GNUC__ - QMessageBox::warning(NULL, "Companion - Tip of the day", tr("Your radio does not seem connected to USB or the driver is not installed!!!\n\nPlease use ZADIG to properly install the driver.")); -#else - QMessageBox::warning(NULL, "Companion - Tip of the day", tr("Your radio does not seem connected to USB or the driver is not initialized!!!.")); -#endif - } -} - -void FlashProcess::onFinished(int code=0) -{ - progress->addSeparator(); - if (code==1 && cmd.toLower().contains("sam-ba")) { - code = 0; - } - if (code) { - progress->setInfo(tr("Flashing done (exit code = %1)").arg(code)); - if (cmd.toLower().contains("avrdude") || cmd.toLower().contains("dfu")) { - errorWizard(); - } - } - else if (hasErrors) { - progress->setInfo(tr("Flashing done with errors")); - } - if (lfuse || hfuse || efuse) { - addReadFuses(); - } - progress->setValue(progress->maximum()); - progress->lock(false); - emit finished(); -} - -void FlashProcess::addReadFuses() -{ - progress->addSeparator(); - progress->addText(tr("FUSES: Low=%1 High=%2 Ext=%3").arg(lfuse, 2, 16, QChar('0')).arg(hfuse, 2, 16, QChar('0')).arg(efuse, 2, 16, QChar('0'))); - progress->addSeparator(); -} +#include "process_flash.h" +#include "progresswidget.h" +#include +#include +#include +#include "eeprominterface.h" +//#include "firmwareinterface.h" + +#if defined WIN32 || !defined __GNUC__ +#include +#include +#include +#define sleep(x) Sleep(x*1000) +#else +#include +#include "mountlist.h" +#endif + +FlashProcess::FlashProcess(const QString &cmd, const QStringList &args, ProgressWidget *progress): +progress(progress), +cmd(cmd), +args(args), +process(new QProcess(this)), +hasErrors(false), +lfuse(0), +hfuse(0), +efuse(0), +flashPhase(READING) +#if !__GNUC__ +, killTimer(NULL) +#endif +{ + connect(process, SIGNAL(started()),this, SLOT(onStarted())); + connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadyReadStandardOutput())); + connect(process, SIGNAL(readyReadStandardError()), this, SLOT(onReadyReadStandardError())); + connect(process, SIGNAL(finished(int)), this, SLOT(onFinished(int))); +} + +FlashProcess::~FlashProcess() +{ +#if !__GNUC__ + delete killTimer; +#endif +} + +bool FlashProcess::run() +{ + if (!QFile::exists(cmd)) { + QMessageBox::critical(NULL, "Companion", tr("Executable %1 not found").arg(cmd)); + return false; + } + +#if !__GNUC__ + if (cmd.toLower().contains("sam-ba")) { + killTimer = new QTimer(this); + connect(killTimer, SIGNAL(timeout()), this, SLOT(onKillTimerElapsed())); + killTimer->start(2000); + } +#endif + + QEventLoop loop; + connect(this, SIGNAL(finished()), &loop, SLOT(quit())); + process->start(cmd, args); + loop.exec(); + + return true; +} + +void FlashProcess::onStarted() +{ + progress->lock(true); + progress->addText(cmd + " " + args.join(" ")); + progress->addSeparator(); +} + +# if !__GNUC__ +bool killProcessByName(const char *szProcessToKill) +{ + HANDLE hProcessSnap; + HANDLE hProcess; + PROCESSENTRY32 pe32; + DWORD dwPriorityClass; + + hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); // Takes a snapshot of all the processes + + if (hProcessSnap == INVALID_HANDLE_VALUE) { + return false; + } + + pe32.dwSize = sizeof(PROCESSENTRY32); + + if (!Process32First(hProcessSnap, &pe32)) { + CloseHandle(hProcessSnap); + return false; + } + + do { + if (!strcmp(pe32.szExeFile,szProcessToKill)) { // checks if process at current position has the name of to be killed app + hProcess = OpenProcess(PROCESS_TERMINATE,0, pe32.th32ProcessID); // gets handle to process + TerminateProcess(hProcess, 0); // Terminate process by handle + CloseHandle(hProcess); // close the handle + } + } while (Process32Next(hProcessSnap, &pe32)); // gets next member of snapshot + + CloseHandle(hProcessSnap); // closes the snapshot handle + return true; +} +#endif + +void FlashProcess::onKillTimerElapsed() +{ +# if !__GNUC__ + // trick to accelerate SAM-BA startup + killProcessByName("tasklist.exe"); +#endif +} + +void FlashProcess::analyseStandardOutput(const QString &text) +{ + currStdoutLine.append(text); + if (currStdoutLine.contains("size = ")) { + int pos = currStdoutLine.lastIndexOf("size = "); + QString temp = currStdoutLine.mid(pos+7); + pos = temp.lastIndexOf("\n"); + int size = temp.left(pos).toInt(); + progress->setMaximum(size/2048); + } + if (currStdoutLine.contains("\n")) { + int nlPos = currStdoutLine.lastIndexOf("\n"); + currStdoutLine = currStdoutLine.mid(nlPos+1); + } + if (!currStdoutLine.isEmpty()) { + if (currStdoutLine.at(0) == QChar('.')) { + int pos = currStdoutLine.lastIndexOf("."); + progress->setValue(pos); + } + else if (currStdoutLine.startsWith("Starting upload: [")) { + int pos = (currStdoutLine.lastIndexOf("#")-19)*100/256; + progress->setValue(pos); + } + } + + if (text.contains("Complete ")) { +#if !__GNUC__ + delete killTimer; + killTimer = NULL; +#endif + int start = text.indexOf("Complete "); + int end = text.indexOf("%"); + if (start > 0) { + start += 9; + int value = text.mid(start, end-start).toInt(); + progress->setValue(value); + } + } + + if (text.contains(":010000")) { + // contains fuse info + QStringList stl = text.split(":01000000"); + foreach (QString t, stl) { + bool ok = false; + if (!lfuse) lfuse = t.left(2).toInt(&ok, 16); + if (!hfuse && !ok) hfuse = t.left(2).toInt(&ok, 16); + if (!efuse && !ok) efuse = t.left(2).toInt(&ok, 16); + } + } + + if (text.contains("-E-")) { + hasErrors = true; + } +} + +void FlashProcess::analyseStandardError(const QString &text) +{ + currStderrLine.append(text); + if (currStderrLine.contains("#")) { + QString avrflashPhase = currStderrLine.left(1).toLower(); + if (avrflashPhase == "w") { + flashPhase = WRITING; + progress->setInfo(tr("Writing...")); + progress->setValue(2 * currStderrLine.count("#")); + } + else if (avrflashPhase == "r") { + if (flashPhase == READING) { + progress->setInfo(tr("Reading...")); + } + else { + flashPhase = VERIFYING; + progress->setInfo(tr("Verifying...")); + } + progress->setValue(2 * currStderrLine.count("#")); + } + } + + if (currStderrLine.contains("\n")) { + int nlPos = currStderrLine.lastIndexOf("\n"); + currStderrLine = currStderrLine.mid(nlPos+1); + } + + if ((text.contains("-E-") && !text.contains("-E- No receive file name")) || + text.contains("No DFU capable USB device found")) { + hasErrors = true; + } +} + +void FlashProcess::onReadyReadStandardOutput() +{ + QString text = QString(process->readAllStandardOutput()); + progress->addText(text); + analyseStandardOutput(text); +} + +void FlashProcess::onReadyReadStandardError() +{ + QString text = QString(process->readAllStandardError()); + progress->addText(text); + analyseStandardError(text); +} + +void FlashProcess::errorWizard() +{ + QString output = progress->getText(); + + if (output.contains("avrdude: Expected signature for")) { // wrong signature + int pos = output.indexOf("avrdude: Device signature = "); + bool fwexist = false; + QString DeviceStr = tr("unknown"); + QString FwStr = ""; + + if (pos > 0) { + QString DeviceId = output.mid(pos+28, 8); + if (DeviceId=="0x1e9602") { + DeviceStr = "Atmega 64"; + FwStr="\n" + tr("ie: OpenTX for 9X board or OpenTX for 9XR board"); + fwexist = true; + } + else if (DeviceId=="0x1e9702") { + DeviceStr = "Atmega 128"; + FwStr="\n" + tr("ie: OpenTX for M128 / 9X board or OpenTX for 9XR board with M128 chip"); + fwexist = true; + } + else if (DeviceId=="0x1e9703") { + DeviceStr = "Atmega 1280"; + } + else if (DeviceId=="0x1e9704") { + DeviceStr = "Atmega 1281"; + } + else if (DeviceId=="0x1e9801") { + DeviceStr = "Atmega 2560"; + FwStr="\n" + tr("ie: OpenTX for Gruvin9X board"); + fwexist = true; + } + else if (DeviceId=="0x1e9802") { + DeviceStr = "Atmega 2561"; + } + } + if (fwexist==false) { + QMessageBox::warning(NULL, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease check advanced burn options to set the correct cpu type.").arg(DeviceStr)); + } + else { + Firmware *firmware = GetCurrentFirmware(); + QMessageBox::warning(NULL, "Companion - Tip of the day", tr("Your radio uses a %1 CPU!!!\n\nPlease select an appropriate firmware type to program it.").arg(DeviceStr)+FwStr+tr("\nYou are currently using:\n %1").arg(firmware->getName())); + } + } + else if (output.contains("No DFU capable USB device found")){ +#if defined WIN32 || !defined __GNUC__ + QMessageBox::warning(NULL, "Companion - Tip of the day", tr("Your radio does not seem connected to USB or the driver is not installed!!!\n\nPlease use ZADIG to properly install the driver.")); +#else + QMessageBox::warning(NULL, "Companion - Tip of the day", tr("Your radio does not seem connected to USB or the driver is not initialized!!!.")); +#endif + } +} + +void FlashProcess::onFinished(int code=0) +{ + progress->addSeparator(); + if (code==1 && cmd.toLower().contains("sam-ba")) { + code = 0; + } + if (code) { + progress->setInfo(tr("Flashing done (exit code = %1)").arg(code)); + if (cmd.toLower().contains("avrdude") || cmd.toLower().contains("dfu")) { + errorWizard(); + } + } + else if (hasErrors) { + progress->setInfo(tr("Flashing done with errors")); + } + if (lfuse || hfuse || efuse) { + addReadFuses(); + } + progress->setValue(progress->maximum()); + progress->lock(false); + emit finished(); +} + +void FlashProcess::addReadFuses() +{ + progress->addSeparator(); + progress->addText(tr("FUSES: Low=%1 High=%2 Ext=%3").arg(lfuse, 2, 16, QChar('0')).arg(hfuse, 2, 16, QChar('0')).arg(efuse, 2, 16, QChar('0'))); + progress->addSeparator(); +} diff --git a/companion/src/process_flash.h b/companion/src/process_flash.h index 39f12f86e..309522b22 100644 --- a/companion/src/process_flash.h +++ b/companion/src/process_flash.h @@ -1,53 +1,53 @@ -#ifndef FLASHPROCESS_H_ -#define FLASHPROCESS_H_ - -#include -#include -#include - -class ProgressWidget; -class QProcess; -class QTimer; - -class FlashProcess : public QObject -{ - Q_OBJECT - -public: - FlashProcess(const QString &cmd, const QStringList &args, ProgressWidget *progress); - ~FlashProcess(); - bool run(); - -signals: - void finished(); - -protected slots: - void onStarted(); - void onReadyReadStandardOutput(); - void onReadyReadStandardError(); - void onFinished(int); - void onKillTimerElapsed(); - -protected: - void analyseStandardOutput(const QString &text); - void analyseStandardError(const QString &text); - void errorWizard(); - void addReadFuses(); - ProgressWidget *progress; - const QString cmd; - const QStringList args; - QProcess *process; - bool hasErrors; - QString currStdoutLine; - QString currStderrLine; - unsigned int lfuse; - unsigned int hfuse; - unsigned int efuse; - enum FlashPhase { READING, WRITING, VERIFYING }; - FlashPhase flashPhase; -#if !__GNUC__ - QTimer *killTimer; -#endif -}; - -#endif // FLASHPROCESS_H_ +#ifndef FLASHPROCESS_H_ +#define FLASHPROCESS_H_ + +#include +#include +#include + +class ProgressWidget; +class QProcess; +class QTimer; + +class FlashProcess : public QObject +{ + Q_OBJECT + +public: + FlashProcess(const QString &cmd, const QStringList &args, ProgressWidget *progress); + ~FlashProcess(); + bool run(); + +signals: + void finished(); + +protected slots: + void onStarted(); + void onReadyReadStandardOutput(); + void onReadyReadStandardError(); + void onFinished(int); + void onKillTimerElapsed(); + +protected: + void analyseStandardOutput(const QString &text); + void analyseStandardError(const QString &text); + void errorWizard(); + void addReadFuses(); + ProgressWidget *progress; + const QString cmd; + const QStringList args; + QProcess *process; + bool hasErrors; + QString currStdoutLine; + QString currStderrLine; + unsigned int lfuse; + unsigned int hfuse; + unsigned int efuse; + enum FlashPhase { READING, WRITING, VERIFYING }; + FlashPhase flashPhase; +#if !__GNUC__ + QTimer *killTimer; +#endif +}; + +#endif // FLASHPROCESS_H_ diff --git a/companion/src/progresswidget.cpp b/companion/src/progresswidget.cpp index 472af5ca9..a3862be38 100644 --- a/companion/src/progresswidget.cpp +++ b/companion/src/progresswidget.cpp @@ -1,120 +1,120 @@ -#include "progresswidget.h" -#include "ui_progresswidget.h" -#include "appdata.h" -#include -#include -#include - -ProgressWidget::ProgressWidget(QWidget *parent): -QWidget(parent), -ui(new Ui::ProgressWidget) -{ - ui->setupUi(this); - ui->info->hide(); - ui->checkBox->hide(); - ui->textEdit->hide(); - -#ifdef __APPLE__ - QFont newFont("Courier", 13); - ui->textEdit->setFont(newFont); - ui->textEdit->setAttribute(Qt::WA_MacNormalSize); -#elif defined WIN32 || !defined __GNUC__ - QFont newFont("Courier", 9); - ui->textEdit->setFont(newFont); -#endif -} - -ProgressWidget::~ProgressWidget() -{ - delete ui; -} - -void ProgressWidget::stop() -{ - emit stopped(); -} - -void ProgressWidget::forceOpen() -{ - ui->checkBox->hide(); - ui->textEdit->show(); -} - -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) -{ - ui->checkBox->setVisible(true); - - if (g.outputDisplayDetails()) { - ui->checkBox->setChecked(true); - ui->textEdit->setVisible(true); - } - - 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); - cursor.insertText(text); - - if (atEnd) { - ui->textEdit->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum); - } -} - -QString ProgressWidget::getText() -{ - return ui->textEdit->toPlainText(); -} - -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::on_checkBox_toggled(bool checked) -{ - g.outputDisplayDetails(checked); - ui->textEdit->setVisible(checked); - QTimer::singleShot(0, this, SLOT(shrink())); -} - -void ProgressWidget::lock(bool lock) -{ - emit locked(lock); -} - -void ProgressWidget::shrink() -{ - emit detailsToggled(); -} - - +#include "progresswidget.h" +#include "ui_progresswidget.h" +#include "appdata.h" +#include +#include +#include + +ProgressWidget::ProgressWidget(QWidget *parent): +QWidget(parent), +ui(new Ui::ProgressWidget) +{ + ui->setupUi(this); + ui->info->hide(); + ui->checkBox->hide(); + ui->textEdit->hide(); + +#ifdef __APPLE__ + QFont newFont("Courier", 13); + ui->textEdit->setFont(newFont); + ui->textEdit->setAttribute(Qt::WA_MacNormalSize); +#elif defined WIN32 || !defined __GNUC__ + QFont newFont("Courier", 9); + ui->textEdit->setFont(newFont); +#endif +} + +ProgressWidget::~ProgressWidget() +{ + delete ui; +} + +void ProgressWidget::stop() +{ + emit stopped(); +} + +void ProgressWidget::forceOpen() +{ + ui->checkBox->hide(); + ui->textEdit->show(); +} + +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) +{ + ui->checkBox->setVisible(true); + + if (g.outputDisplayDetails()) { + ui->checkBox->setChecked(true); + ui->textEdit->setVisible(true); + } + + 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); + cursor.insertText(text); + + if (atEnd) { + ui->textEdit->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum); + } +} + +QString ProgressWidget::getText() +{ + return ui->textEdit->toPlainText(); +} + +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::on_checkBox_toggled(bool checked) +{ + g.outputDisplayDetails(checked); + ui->textEdit->setVisible(checked); + QTimer::singleShot(0, this, SLOT(shrink())); +} + +void ProgressWidget::lock(bool lock) +{ + emit locked(lock); +} + +void ProgressWidget::shrink() +{ + emit detailsToggled(); +} + + diff --git a/companion/src/progresswidget.h b/companion/src/progresswidget.h index 19d4500cd..d27dcaed4 100644 --- a/companion/src/progresswidget.h +++ b/companion/src/progresswidget.h @@ -1,42 +1,42 @@ -#ifndef PROGRESS_WIDGET_H_ -#define PROGRESS_WIDGET_H_ - -#include - -namespace Ui { - class ProgressWidget; -} - -class ProgressWidget : public QWidget -{ - Q_OBJECT - - public: - explicit ProgressWidget(QWidget *parent); - ~ProgressWidget(); - void lock(bool lock); - void addText(const QString &text); - QString getText(); - void setInfo(const QString &text); - void setMaximum(int value); - int maximum(); - void setValue(int value); - void setProgressColor(const QColor &color); - void addSeparator(); - void forceOpen(); - void stop(); - - signals: - void detailsToggled(); - void locked(bool); - void stopped(); - - protected slots: - void on_checkBox_toggled(bool checked); - void shrink(); - - private: - Ui::ProgressWidget *ui; -}; - -#endif // PROGRESS_WIDGET_H_ +#ifndef PROGRESS_WIDGET_H_ +#define PROGRESS_WIDGET_H_ + +#include + +namespace Ui { + class ProgressWidget; +} + +class ProgressWidget : public QWidget +{ + Q_OBJECT + + public: + explicit ProgressWidget(QWidget *parent); + ~ProgressWidget(); + void lock(bool lock); + void addText(const QString &text); + QString getText(); + void setInfo(const QString &text); + void setMaximum(int value); + int maximum(); + void setValue(int value); + void setProgressColor(const QColor &color); + void addSeparator(); + void forceOpen(); + void stop(); + + signals: + void detailsToggled(); + void locked(bool); + void stopped(); + + protected slots: + void on_checkBox_toggled(bool checked); + void shrink(); + + private: + Ui::ProgressWidget *ui; +}; + +#endif // PROGRESS_WIDGET_H_ diff --git a/companion/src/simulation/simulatorimport.h b/companion/src/simulation/simulatorimport.h index 21087c618..f6a2488ca 100644 --- a/companion/src/simulation/simulatorimport.h +++ b/companion/src/simulation/simulatorimport.h @@ -29,15 +29,15 @@ telemetryStreaming = 20; #ifdef SETVALUES_IMPORT #undef SETVALUES_IMPORT -for (int i=0; i t LIMIT(t mi, t x, t ma) { return std::min(std::max(mi, x), ma struct TxInputs { - int sticks[NUM_STICKS]; /* lh lv rv rh */ - int pots[C9X_NUM_POTS]; - int switches[C9X_NUM_SWITCHES]; - bool keys[C9X_NUM_KEYS]; + int sticks[CPN_MAX_STICKS]; /* lh lv rv rh */ + int pots[CPN_MAX_POTS]; + int switches[CPN_MAX_SWITCHES]; + bool keys[CPN_MAX_KEYS]; bool rotenc; bool trims[12]; }; @@ -41,16 +41,16 @@ class TxOutputs { public: TxOutputs() { memset(this, 0, sizeof(TxOutputs)); } - int chans[C9X_NUM_CHNOUT]; - bool vsw[C9X_NUM_CSW]; - int gvars[C9X_MAX_FLIGHT_MODES][C9X_MAX_GVARS]; + int chans[CPN_MAX_CHNOUT]; + bool vsw[CPN_MAX_CSW]; + int gvars[CPN_MAX_FLIGHT_MODES][CPN_MAX_GVARS]; unsigned int beep; // uint8_t phase; }; struct Trims { - int values[NUM_STICKS]; /* lh lv rv rh */ + int values[CPN_MAX_STICKS]; /* lh lv rv rh */ bool extended; }; diff --git a/companion/src/simulator.cpp b/companion/src/simulator.cpp index 2694ddae9..3a297095e 100644 --- a/companion/src/simulator.cpp +++ b/companion/src/simulator.cpp @@ -1,44 +1,3 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial Usage -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - #include #include #include diff --git a/companion/src/splashlabel.h b/companion/src/splashlabel.h index 32ff65019..d03b80e1e 100644 --- a/companion/src/splashlabel.h +++ b/companion/src/splashlabel.h @@ -1,18 +1,3 @@ -/* - * Author - Bertrand Songis - * - * Based on th9x -> http://code.google.com/p/th9x/ - * - * 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. - * - */ #ifndef SPLASHLABEL_H #define SPLASHLABEL_H diff --git a/companion/src/storage/xmlinterface.cpp b/companion/src/storage/xmlinterface.cpp index 94fd58b84..ba2f57bf7 100644 --- a/companion/src/storage/xmlinterface.cpp +++ b/companion/src/storage/xmlinterface.cpp @@ -152,7 +152,7 @@ void saveModel(ModelData & m, model & xm) phases xphases; phases::phase_sequence & phases_sequence (xphases.phase()); - for (int i=0; i #include "eeprominterface.h" #include "wizarddata.h" diff --git a/companion/src/wizarddata.h b/companion/src/wizarddata.h index ee70984fd..2e0632636 100644 --- a/companion/src/wizarddata.h +++ b/companion/src/wizarddata.h @@ -1,17 +1,3 @@ -/* - * Author - Kjell Kernen - * - * 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. - * - */ - #ifndef WIZARDDATA_H #define WIZARDDATA_H diff --git a/companion/src/wizarddialog.cpp b/companion/src/wizarddialog.cpp index ecede5dd7..0a03ed122 100644 --- a/companion/src/wizarddialog.cpp +++ b/companion/src/wizarddialog.cpp @@ -1,17 +1,3 @@ -/* - * Author - Kjell Kernen - * - * 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 "wizarddialog.h" #include "wizarddata.h" #include "helpers.h" diff --git a/companion/src/wizarddialog.h b/companion/src/wizarddialog.h index dff5c99db..eca411701 100644 --- a/companion/src/wizarddialog.h +++ b/companion/src/wizarddialog.h @@ -1,17 +1,3 @@ -/* - * Author - Kjell Kernen - * - * 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. - * - */ - #ifndef WIZARDDIALOG_H #define WIZARDDIALOG_H @@ -31,7 +17,7 @@ class WizardDialog : public QWizard void showHelp(); }; -class StandardPage: public QWizardPage +class StandardPage: public QWizardPage { Q_OBJECT @@ -57,7 +43,7 @@ class StandardPage: public QWizardPage int nextId() const; }; -class ModelSelectionPage: public StandardPage +class ModelSelectionPage: public StandardPage { Q_OBJECT public: @@ -71,7 +57,7 @@ private: int nextId() const; }; -class WingtypeSelectionPage: public StandardPage +class WingtypeSelectionPage: public StandardPage { Q_OBJECT public: @@ -82,7 +68,7 @@ private: int nextId() const; }; -class TailSelectionPage: public StandardPage +class TailSelectionPage: public StandardPage { Q_OBJECT public: @@ -94,7 +80,7 @@ private: int nextId() const; }; -class FlybarSelectionPage: public StandardPage +class FlybarSelectionPage: public StandardPage { Q_OBJECT public: