5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 #include "eeprominterface.h"
27 #include <QTableWidget>
28 #include <QGridLayout>
31 #include <QElapsedTimer>
32 #include <QStandardItemModel>
34 extern const QColor colors
[CPN_MAX_CURVES
];
36 #define TMR_NUM_OPTION (TMRMODE_COUNT+2*9+2*getCurrentFirmware()->getCapability(LogicalSwitches)-1)
38 //convert from mode 1 to mode generalSettings.stickMode
39 //NOTICE! => 1..4 -> 1..4
40 #define CONVERT_MODE(x) (((x)<=4) ? modn12x3[generalSettings.stickMode][((x)-1)] : (x))
43 #define CH(x) (SRC_CH1+(x)-1-(SRC_SWC-SRC_3POS))
44 #define CV(x) (CURVE_BASE+(x)-1)
46 #define CURVE5(x) ((x)-1)
47 #define CURVE9(x) (MAX_CURVE5+(x)-1)
53 #define TRIM_MODE_NONE 0x1F // 0b11111
57 class CompanionIcon
: public QIcon
{
59 CompanionIcon(const QString
&baseimage
);
62 class GVarGroup
: public QObject
{
67 GVarGroup(QCheckBox
* weightGV
, QAbstractSpinBox
* weightSB
, QComboBox
* weightCB
, int & weight
, const ModelData
& model
, const int deflt
, const int mini
, const int maxi
, const double step
=1.0, bool allowGVars
=true);
73 void gvarCBChanged(int);
78 QAbstractSpinBox
*weightSB
;
87 #define HIDE_DIFF 0x01
88 #define HIDE_EXPO 0x02
89 #define HIDE_NEGATIVE_CURVES 0x04
91 class CurveGroup
: public QObject
{
96 CurveGroup(QComboBox
*curveTypeCB
, QCheckBox
*curveGVarCB
, QComboBox
*curveValueCB
, QSpinBox
*curveValueSB
, CurveReference
& curve
, const ModelData
& model
, unsigned int flags
=0);
100 void gvarCBChanged(int);
101 void typeChanged(int);
102 void valuesChanged();
105 QComboBox
*curveTypeCB
;
106 QCheckBox
*curveGVarCB
;
107 QComboBox
*curveValueCB
;
108 QSpinBox
*curveValueSB
;
109 CurveReference
& curve
;
110 const ModelData
& model
;
117 #define POPULATE_NONE (1<<0)
118 #define POPULATE_SOURCES (1<<1)
119 #define POPULATE_TRIMS (1<<2)
120 #define POPULATE_SWITCHES (1<<3)
121 #define POPULATE_GVARS (1<<4)
122 #define POPULATE_TELEMETRY (1<<5)
123 #define POPULATE_TELEMETRYEXT (1<<6)
124 #define POPULATE_VIRTUAL_INPUTS (1<<7)
125 #define POPULATE_SCRIPT_OUTPUTS (1<<8)
127 #define GVARS_VARIANT 0x0001
128 #define FRSKY_VARIANT 0x0002
132 void addRawSourceItems(QStandardItemModel
* itemModel
, const RawSourceType
& type
, int count
, const GeneralSettings
* const generalSettings
= NULL
,
133 const ModelData
* const model
= NULL
, const int start
= 0, const QList
<int> exclude
= QList
<int>());
134 QStandardItemModel
* getRawSourceItemModel(const GeneralSettings
* const generalSettings
= NULL
, const ModelData
* const model
= NULL
, unsigned int flags
= 0);
136 void populateGvarUseCB(QComboBox
*b
, unsigned int phase
);
137 void populateGVCB(QComboBox
& b
, int value
, const ModelData
& model
);
138 QString
getAdjustmentString(int16_t val
, const ModelData
* model
= NULL
, bool sign
= false);
140 void populateFileComboBox(QComboBox
* b
, const QSet
<QString
> & set
, const QString
& current
);
141 void getFileComboBoxValue(QComboBox
* b
, char * dest
, int length
);
142 } // namespace Helpers
144 // TODO : move to Helpers namespace
146 QString
image2qstring(QImage image
);
147 int findmult(float value
, float base
);
150 QString
getFrSkyAlarmType(int alarm
);
151 QString
getFrSkyUnits(int units
);
152 QString
getFrSkyProtocol(int protocol
);
153 QString
getFrSkyMeasure(int units
);
154 QString
getFrSkySrc(int index
);
156 void startSimulation(QWidget
* parent
, RadioData
& radioData
, int modelIdx
);
158 // Format a pixmap to fit on the current firmware
159 QPixmap
makePixMap(const QImage
& image
);
161 int version2index(const QString
& version
);
162 const QString
index2version(int index
);
164 class QTimeS
: public QTime
167 QTimeS(int s
) { int h
= s
/3600; s
%= 3600; int m
= s
/60; s
%=60; setHMS(h
, m
, s
); }
168 QTimeS(const QTime
& q
) : QTime(q
) {}
169 int seconds() const { return hour()*3600 + minute()*60 + second(); }
172 bool qunlink(const QString
& fileName
);
174 QString
generateProcessUniqueTempFileName(const QString
& fileName
);
175 bool isTempFileName(const QString
& fileName
);
177 QString
getSoundsPath(const GeneralSettings
&generalSettings
);
178 QSet
<QString
> getFilesSet(const QString
&path
, const QStringList
&filter
, int maxLen
);
180 bool caseInsensitiveLessThan(const QString
&s1
, const QString
&s2
);
186 GpsCoord(): latitude(0), longitude(0) {}
187 double latitude
; // Precede South latitudes and West longitudes with a minus sign. Latitudes range from -90 to 90.
188 double longitude
; // Longitudes range from -180 to 180.
191 class GpsGlitchFilter
194 GpsGlitchFilter() : lastValid(false), glitchCount(0) {}
195 bool isGlitch(GpsCoord coord
);
204 class GpsLatLonFilter
208 bool isValid(GpsCoord coord
);
217 GpsCoord
extractGpsCoordinates(const QString
& position
);
222 TableLayout(QWidget
* parent
, int rowCount
, const QStringList
& headerLabels
);
225 void addWidget(int row
, int column
, QWidget
* widget
);
226 void addLayout(int row
, int column
, QLayout
* layout
);
228 void resizeColumnsToContents();
229 void setColumnWidth(int col
, int width
);
230 void pushRowsUp(int row
);
233 #if defined(TABLE_LAYOUT)
234 QTableWidget
* tableWidget
;
236 QGridLayout
* gridWidget
;
244 Stopwatch(const QString
& name
) :
245 name(name
), total(0) {
256 qint64 elapsed
= timer
.restart();
258 qDebug() << name
<< QString("%1 ms [%2 ms]").arg(elapsed
).arg(total
);
261 void report(const QString
& text
) {
262 qint64 elapsed
= timer
.restart();
264 qDebug() << name
<< text
<< QString("%1 ms [%2 ms]").arg(elapsed
).arg(total
);
273 extern Stopwatch gStopwatch
;
275 #endif // _HELPERS_H_