Telemetry refactoring - Fixes #1634

This commit is contained in:
bsongis
2014-11-08 12:06:42 +01:00
parent 7d8ca6931b
commit 88d9691d16
105 changed files with 5789 additions and 3449 deletions
+3 -5
View File
@@ -97,6 +97,7 @@ add_custom_command(
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/../..
${PROJECT_SOURCE_DIR}/shared
${SIMU_SRC_DIRECTORY}
${RADIO_SRC_DIRECTORY}
${RADIO_SRC_DIRECTORY}/fonts/std
@@ -104,6 +105,7 @@ include_directories(
${XSD_INCLUDE_DIR}
)
add_subdirectory(shared)
add_subdirectory(modeledit)
add_subdirectory(generaledit)
add_subdirectory(simulation)
@@ -167,8 +169,6 @@ set(companion_SRCS
qcustomplot.cpp
wizarddata.cpp
wizarddialog.cpp
foldersync.cpp
hexspinbox.cpp
)
set(companion_MOC_HDRS
@@ -191,10 +191,8 @@ set(companion_MOC_HDRS
mainwindow.h
radionotfound.h
qcustomplot.h
qautocombobox.h
helpers.h
wizarddialog.h
hexspinbox.h
)
set(companion_UIS
@@ -284,7 +282,7 @@ ELSE( )
ADD_EXECUTABLE( ${PROJECT_NAME} WIN32 ${companion_SRCS} ${companion_QM} )
ENDIF( )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} generaledit modeledit simulation common ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY} ${XERCESC_LIBRARY} ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${PHONON_LIBS} )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} generaledit modeledit simulation common shared ${QT_LIBRARIES} ${QT_QTMAIN_LIBRARY} ${XERCESC_LIBRARY} ${PTHREAD_LIBRARY} ${SDL_LIBRARY} ${PHONON_LIBS} )
############# Standalone simu ###############
+284 -183
View File
@@ -92,6 +92,74 @@ QString getGVarString(int16_t val, bool sign)
}
}
void SensorData::updateUnit()
{
if (type == TYPE_CALCULATED) {
if (formula == FORMULA_CONSUMPTION)
unit = UNIT_MAH;
}
}
QString SensorData::unitString() const
{
switch (unit) {
case UNIT_VOLTS:
return QObject::tr("V");
case UNIT_AMPS:
return QObject::tr("A");
case UNIT_MILLIAMPS:
return QObject::tr("mA");
case UNIT_KTS:
return QObject::tr("kts");
case UNIT_METERS_PER_SECOND:
return QObject::tr("m/s");
case UNIT_KMH:
return QObject::tr("km/h");
case UNIT_MPH:
return QObject::tr("mph");
case UNIT_METERS:
return QObject::tr("m");
case UNIT_FEET:
return QObject::tr("f");
case UNIT_CELSIUS:
return QObject::tr("°C");
case UNIT_FAHRENHEIT:
return QObject::tr("%F");
case UNIT_PERCENT:
return QObject::tr("%");
case UNIT_MAH:
return QObject::tr("mAh");
case UNIT_WATTS:
return QObject::tr("W");
case UNIT_DBM:
return QObject::tr("dB");
case UNIT_RPMS:
return QObject::tr("rpms");
case UNIT_G:
return QObject::tr("g");
case UNIT_DEGREE:
return QObject::tr("°");
case UNIT_HOURS:
return QObject::tr("hours");
case UNIT_MINUTES:
return QObject::tr("minutes");
case UNIT_SECONDS:
return QObject::tr("seconds");
case UNIT_CELLS:
return QObject::tr("V");
default:
return "";
}
}
bool RawSource::isTimeBased() const
{
if (IS_ARM(GetCurrentFirmware()->getBoard()))
return false;
else
return (type==SOURCE_TYPE_TELEMETRY && (index==TELEMETRY_SOURCE_TX_TIME || index==TELEMETRY_SOURCE_TIMER1 || index==TELEMETRY_SOURCE_TIMER2 || index==TELEMETRY_SOURCE_TIMER3));
}
RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSettings & settings, unsigned int flags) const
{
RawSourceRange result;
@@ -106,192 +174,208 @@ RawSourceRange RawSource::getRange(const ModelData * model, const GeneralSetting
switch (type) {
case SOURCE_TYPE_TELEMETRY:
if (singleprec) {
result.offset = -DBL_MAX;
}
switch (index) {
case TELEMETRY_SOURCE_TX_BATT:
result.step = 0.1;
result.decimals = 1;
result.max = 25.5;
result.unit = QObject::tr("V");
break;
case TELEMETRY_SOURCE_TX_TIME:
result.step = 1;
result.max = 24*60 - 1;
break;
case TELEMETRY_SOURCE_TIMER1:
case TELEMETRY_SOURCE_TIMER2:
case TELEMETRY_SOURCE_TIMER3:
result.step = singleprec ? 5 : 1;
result.max = singleprec ? 255*5 : 60*60;
result.unit = QObject::tr("s");
break;
case TELEMETRY_SOURCE_RSSI_TX:
case TELEMETRY_SOURCE_RSSI_RX:
result.max = 100;
if (singleprec) result.offset = 128;
break;
case TELEMETRY_SOURCE_A1_MIN:
case TELEMETRY_SOURCE_A2_MIN:
case TELEMETRY_SOURCE_A3_MIN:
case TELEMETRY_SOURCE_A4_MIN:
if (model) result = model->frsky.channels[index-TELEMETRY_SOURCE_A1_MIN].getRange();
break;
case TELEMETRY_SOURCE_A1:
case TELEMETRY_SOURCE_A2:
case TELEMETRY_SOURCE_A3:
case TELEMETRY_SOURCE_A4:
if (model) result = model->frsky.channels[index-TELEMETRY_SOURCE_A1].getRange();
break;
case TELEMETRY_SOURCE_ALT:
case TELEMETRY_SOURCE_ALT_MIN:
case TELEMETRY_SOURCE_ALT_MAX:
case TELEMETRY_SOURCE_GPS_ALT:
result.step = singleprec ? 8 : 1;
result.min = -500;
result.max = singleprec ? 1540 : 3000;
if (firmware->getCapability(Imperial) || settings.imperial) {
result.step = (result.step * 105) / 32;
result.min = (result.min * 105) / 32;
result.max = (result.max * 105) / 32;
result.unit = QObject::tr("ft");
}
else {
result.unit = QObject::tr("m");
}
break;
case TELEMETRY_SOURCE_T1:
case TELEMETRY_SOURCE_T1_MAX:
case TELEMETRY_SOURCE_T2:
case TELEMETRY_SOURCE_T2_MAX:
result.min = -30;
result.max = 225;
result.unit = QObject::trUtf8("°C");
break;
case TELEMETRY_SOURCE_HDG:
result.step = singleprec ? 2 : 1;
result.max = 360;
if (singleprec) result.offset = 256;
result.unit = QObject::trUtf8("°");
break;
case TELEMETRY_SOURCE_RPM:
case TELEMETRY_SOURCE_RPM_MAX:
result.step = singleprec ? 50 : 1;
result.max = singleprec ? 12750 : 30000;
break;
case TELEMETRY_SOURCE_FUEL:
result.max = 100;
result.unit = QObject::tr("%");
break;
case TELEMETRY_SOURCE_ASPEED:
case TELEMETRY_SOURCE_ASPEED_MAX:
result.decimals = 1;
result.step = singleprec ? 2.0 : 0.1;
result.max = singleprec ? (2*255) : 2000;
if (firmware->getCapability(Imperial) || settings.imperial) {
result.step *= 1.150779;
result.max *= 1.150779;
result.unit = QObject::tr("mph");
}
else {
result.step *= 1.852;
result.max *= 1.852;
result.unit = QObject::tr("km/h");
}
break;
case TELEMETRY_SOURCE_SPEED:
case TELEMETRY_SOURCE_SPEED_MAX:
result.step = singleprec ? 2 : 1;
result.max = singleprec ? (2*255) : 2000;
if (firmware->getCapability(Imperial) || settings.imperial) {
result.step *= 1.150779;
result.max *= 1.150779;
result.unit = QObject::tr("mph");
}
else {
result.step *= 1.852;
result.max *= 1.852;
result.unit = QObject::tr("km/h");
}
break;
case TELEMETRY_SOURCE_VERTICAL_SPEED:
result.step = 0.1;
result.min = singleprec ? -12.5 : -300.0;
result.max = singleprec ? 13.0 : 300.0;
result.decimals = 1;
result.unit = QObject::tr("m/s");
break;
case TELEMETRY_SOURCE_DTE:
result.max = 30000;
break;
case TELEMETRY_SOURCE_DIST:
case TELEMETRY_SOURCE_DIST_MAX:
result.step = singleprec ? 8 : 1;
result.max = singleprec ? 2040 : 10000;
result.unit = QObject::tr("m");
break;
case TELEMETRY_SOURCE_CELL:
case TELEMETRY_SOURCE_CELL_MIN:
result.step = singleprec ? 0.02 : 0.01;
result.max = 5.1;
result.decimals = 2;
result.unit = QObject::tr("V");
break;
case TELEMETRY_SOURCE_CELLS_SUM:
case TELEMETRY_SOURCE_CELLS_MIN:
case TELEMETRY_SOURCE_VFAS:
case TELEMETRY_SOURCE_VFAS_MIN:
result.step = 0.1;
result.max = singleprec ? 25.5 : 100.0;
result.decimals = 1;
result.unit = QObject::tr("V");
break;
case TELEMETRY_SOURCE_CURRENT:
case TELEMETRY_SOURCE_CURRENT_MAX:
result.step = singleprec ? 0.5 : 0.1;
result.max = singleprec ? 127.5 : 200.0;
result.decimals = 1;
result.unit = QObject::tr("A");
break;
case TELEMETRY_SOURCE_CONSUMPTION:
result.step = singleprec ? 100 : 1;
result.max = singleprec ? 25500 : 30000;
result.unit = QObject::tr("mAh");
break;
case TELEMETRY_SOURCE_POWER:
case TELEMETRY_SOURCE_POWER_MAX:
result.step = singleprec ? 5 : 1;
result.max = singleprec ? 1275 : 2000;
result.unit = QObject::tr("W");
break;
case TELEMETRY_SOURCE_ACCX:
case TELEMETRY_SOURCE_ACCY:
case TELEMETRY_SOURCE_ACCZ:
if (IS_ARM(board)) {
div_t qr = div(index, 3);
const SensorData & sensor = model->sensorData[qr.quot];
if (sensor.prec == 2)
result.step = 0.01;
result.decimals = 2;
result.max = singleprec ? 2.55 : 10.00;
result.min = singleprec ? 0 : -10.00;
result.unit = QObject::tr("g");
break;
default:
result.max = 125;
break;
else if (sensor.prec == 1)
result.step = 0.1;
else
result.step = 1;
result.min = -30000 * result.step;
result.max = +30000 * result.step;
result.decimals = sensor.prec;
result.unit = sensor.unitString();
}
if (singleprec && result.offset==-DBL_MAX) {
result.offset = result.max - (127*result.step);
}
if (flags & (RANGE_DELTA_FUNCTION|RANGE_DELTA_ABS_FUNCTION)) {
else {
if (singleprec) {
result.offset = 0;
result.min = result.step * -127;
result.max = result.step * 127;
result.offset = -DBL_MAX;
}
else {
result.min = -result.max;
switch (index) {
case TELEMETRY_SOURCE_TX_BATT:
result.step = 0.1;
result.decimals = 1;
result.max = 25.5;
result.unit = QObject::tr("V");
break;
case TELEMETRY_SOURCE_TX_TIME:
result.step = 1;
result.max = 24*60 - 1;
break;
case TELEMETRY_SOURCE_TIMER1:
case TELEMETRY_SOURCE_TIMER2:
case TELEMETRY_SOURCE_TIMER3:
result.step = singleprec ? 5 : 1;
result.max = singleprec ? 255*5 : 60*60;
result.unit = QObject::tr("s");
break;
case TELEMETRY_SOURCE_RSSI_TX:
case TELEMETRY_SOURCE_RSSI_RX:
result.max = 100;
if (singleprec) result.offset = 128;
break;
case TELEMETRY_SOURCE_A1_MIN:
case TELEMETRY_SOURCE_A2_MIN:
case TELEMETRY_SOURCE_A3_MIN:
case TELEMETRY_SOURCE_A4_MIN:
if (model) result = model->frsky.channels[index-TELEMETRY_SOURCE_A1_MIN].getRange();
break;
case TELEMETRY_SOURCE_A1:
case TELEMETRY_SOURCE_A2:
case TELEMETRY_SOURCE_A3:
case TELEMETRY_SOURCE_A4:
if (model) result = model->frsky.channels[index-TELEMETRY_SOURCE_A1].getRange();
break;
case TELEMETRY_SOURCE_ALT:
case TELEMETRY_SOURCE_ALT_MIN:
case TELEMETRY_SOURCE_ALT_MAX:
case TELEMETRY_SOURCE_GPS_ALT:
result.step = singleprec ? 8 : 1;
result.min = -500;
result.max = singleprec ? 1540 : 3000;
if (firmware->getCapability(Imperial) || settings.imperial) {
result.step = (result.step * 105) / 32;
result.min = (result.min * 105) / 32;
result.max = (result.max * 105) / 32;
result.unit = QObject::tr("ft");
}
else {
result.unit = QObject::tr("m");
}
break;
case TELEMETRY_SOURCE_T1:
case TELEMETRY_SOURCE_T1_MAX:
case TELEMETRY_SOURCE_T2:
case TELEMETRY_SOURCE_T2_MAX:
result.min = -30;
result.max = 225;
result.unit = QObject::trUtf8("°C");
break;
case TELEMETRY_SOURCE_HDG:
result.step = singleprec ? 2 : 1;
result.max = 360;
if (singleprec) result.offset = 256;
result.unit = QObject::trUtf8("°");
break;
case TELEMETRY_SOURCE_RPM:
case TELEMETRY_SOURCE_RPM_MAX:
result.step = singleprec ? 50 : 1;
result.max = singleprec ? 12750 : 30000;
break;
case TELEMETRY_SOURCE_FUEL:
result.max = 100;
result.unit = QObject::tr("%");
break;
case TELEMETRY_SOURCE_ASPEED:
case TELEMETRY_SOURCE_ASPEED_MAX:
result.decimals = 1;
result.step = singleprec ? 2.0 : 0.1;
result.max = singleprec ? (2*255) : 2000;
if (firmware->getCapability(Imperial) || settings.imperial) {
result.step *= 1.150779;
result.max *= 1.150779;
result.unit = QObject::tr("mph");
}
else {
result.step *= 1.852;
result.max *= 1.852;
result.unit = QObject::tr("km/h");
}
break;
case TELEMETRY_SOURCE_SPEED:
case TELEMETRY_SOURCE_SPEED_MAX:
result.step = singleprec ? 2 : 1;
result.max = singleprec ? (2*255) : 2000;
if (firmware->getCapability(Imperial) || settings.imperial) {
result.step *= 1.150779;
result.max *= 1.150779;
result.unit = QObject::tr("mph");
}
else {
result.step *= 1.852;
result.max *= 1.852;
result.unit = QObject::tr("km/h");
}
break;
case TELEMETRY_SOURCE_VERTICAL_SPEED:
result.step = 0.1;
result.min = singleprec ? -12.5 : -300.0;
result.max = singleprec ? 13.0 : 300.0;
result.decimals = 1;
result.unit = QObject::tr("m/s");
break;
case TELEMETRY_SOURCE_DTE:
result.max = 30000;
break;
case TELEMETRY_SOURCE_DIST:
case TELEMETRY_SOURCE_DIST_MAX:
result.step = singleprec ? 8 : 1;
result.max = singleprec ? 2040 : 10000;
result.unit = QObject::tr("m");
break;
case TELEMETRY_SOURCE_CELL:
case TELEMETRY_SOURCE_CELL_MIN:
result.step = singleprec ? 0.02 : 0.01;
result.max = 5.1;
result.decimals = 2;
result.unit = QObject::tr("V");
break;
case TELEMETRY_SOURCE_CELLS_SUM:
case TELEMETRY_SOURCE_CELLS_MIN:
case TELEMETRY_SOURCE_VFAS:
case TELEMETRY_SOURCE_VFAS_MIN:
result.step = 0.1;
result.max = singleprec ? 25.5 : 100.0;
result.decimals = 1;
result.unit = QObject::tr("V");
break;
case TELEMETRY_SOURCE_CURRENT:
case TELEMETRY_SOURCE_CURRENT_MAX:
result.step = singleprec ? 0.5 : 0.1;
result.max = singleprec ? 127.5 : 200.0;
result.decimals = 1;
result.unit = QObject::tr("A");
break;
case TELEMETRY_SOURCE_CONSUMPTION:
result.step = singleprec ? 100 : 1;
result.max = singleprec ? 25500 : 30000;
result.unit = QObject::tr("mAh");
break;
case TELEMETRY_SOURCE_POWER:
case TELEMETRY_SOURCE_POWER_MAX:
result.step = singleprec ? 5 : 1;
result.max = singleprec ? 1275 : 2000;
result.unit = QObject::tr("W");
break;
case TELEMETRY_SOURCE_ACCX:
case TELEMETRY_SOURCE_ACCY:
case TELEMETRY_SOURCE_ACCZ:
result.step = 0.01;
result.decimals = 2;
result.max = singleprec ? 2.55 : 10.00;
result.min = singleprec ? 0 : -10.00;
result.unit = QObject::tr("g");
break;
default:
result.max = 125;
break;
}
if (singleprec && result.offset==-DBL_MAX) {
result.offset = result.max - (127*result.step);
}
if (flags & (RANGE_DELTA_FUNCTION|RANGE_DELTA_ABS_FUNCTION)) {
if (singleprec) {
result.offset = 0;
result.min = result.step * -127;
result.max = result.step * 127;
}
else {
result.min = -result.max;
}
}
}
break;
@@ -340,6 +424,10 @@ QString RawSource::toString(const ModelData * model)
QObject::tr("TrmR"), QObject::tr("TrmE"), QObject::tr("TrmT"), QObject::tr("TrmA")
};
static const QString special[] = {
QObject::tr("Batt"), QObject::tr("Time"), QObject::tr("Timer1"), QObject::tr("Timer2"), QObject::tr("Timer3"),
};
static const QString telemetry[] = {
QObject::tr("Batt"), QObject::tr("Time"), QObject::tr("Timer1"), QObject::tr("Timer2"), QObject::tr("Timer3"),
QObject::tr("SWR"), QObject::tr("RSSI Tx"), QObject::tr("RSSI Rx"),
@@ -365,6 +453,7 @@ QString RawSource::toString(const ModelData * model)
if (index<0) {
return QObject::tr("----");
}
switch (type) {
case SOURCE_TYPE_VIRTUAL_INPUT:
{
@@ -394,8 +483,18 @@ QString RawSource::toString(const ModelData * model)
return QObject::tr("TR%1").arg(index+1);
case SOURCE_TYPE_CH:
return QObject::tr("CH%1").arg(index+1);
case SOURCE_TYPE_SPECIAL:
return CHECK_IN_ARRAY(special, index);
case SOURCE_TYPE_TELEMETRY:
return CHECK_IN_ARRAY(telemetry, index);
if (IS_ARM(GetEepromInterface()->getBoard())) {
div_t qr = div(index, 3);
QString result = QString(model ? model->sensorData[qr.quot].label : QString("[T%1]").arg(qr.quot+1));
if (qr.rem) result += qr.rem == 1 ? "-" : "+";
return result;
}
else {
return CHECK_IN_ARRAY(telemetry, index);
}
case SOURCE_TYPE_GVAR:
return QObject::tr("GV%1").arg(index+1);
default:
@@ -1168,6 +1267,8 @@ void ModelData::clear()
timers[i].clear();
swashRingData.clear();
frsky.clear();
for (int i=0; i<C9X_MAX_SENSORS; i++)
sensorData[i].clear();
}
bool ModelData::isempty()
+102 -6
View File
@@ -301,6 +301,7 @@ enum RawSourceType {
SOURCE_TYPE_PPM,
SOURCE_TYPE_CH,
SOURCE_TYPE_GVAR,
SOURCE_TYPE_SPECIAL,
SOURCE_TYPE_TELEMETRY,
MAX_SOURCE_TYPE
};
@@ -373,9 +374,7 @@ class RawSource {
return (this->type != other.type) || (this->index != other.index);
}
bool isTimeBased() const {
return (type==SOURCE_TYPE_TELEMETRY && (index==TELEMETRY_SOURCE_TX_TIME || index==TELEMETRY_SOURCE_TIMER1 || index==TELEMETRY_SOURCE_TIMER2 || index==TELEMETRY_SOURCE_TIMER3));
}
bool isTimeBased() const;
RawSourceType type;
int index;
@@ -788,9 +787,8 @@ class FrSkyData {
unsigned int usrProto;
int blades;
unsigned int voltsSource;
bool altitudeDisplayed;
unsigned int altitudeSource;
unsigned int currentSource;
unsigned int FrSkyGpsAlt;
FrSkyScreenData screens[4];
FrSkyRSSIAlarm rssiAlarms[2];
unsigned int varioSource;
@@ -873,6 +871,103 @@ class ScriptData {
void clear() { memset(this, 0, sizeof(ScriptData)); }
};
#define C9X_MAX_SENSORS 32
class SensorData {
public:
enum
{
TYPE_CUSTOM,
TYPE_CALCULATED
};
enum
{
FORMULA_ADD,
FORMULA_AVERAGE,
FORMULA_MIN,
FORMULA_MAX,
FORMULA_MULTIPLY,
FORMULA_CELL,
FORMULA_CONSUMPTION,
FORMULA_DIST
};
enum {
UNIT_RAW,
UNIT_VOLTS,
UNIT_AMPS,
UNIT_MILLIAMPS,
UNIT_KTS,
UNIT_METERS_PER_SECOND,
UNIT_KMH,
UNIT_MPH,
UNIT_METERS,
UNIT_FEET,
UNIT_CELSIUS,
UNIT_FAHRENHEIT,
UNIT_PERCENT,
UNIT_MAH,
UNIT_WATTS,
UNIT_DBM,
UNIT_RPMS,
UNIT_G,
UNIT_DEGREE,
UNIT_HOURS,
UNIT_MINUTES,
UNIT_SECONDS,
// FrSky format used for these fields, could be another format in the future
UNIT_CELLS,
UNIT_DATETIME,
UNIT_GPS,
UNIT_GPS_LONGITUDE,
UNIT_GPS_LATITUDE,
UNIT_GPS_LONGITUDE_EW,
UNIT_GPS_LATITUDE_NS,
UNIT_DATETIME_YEAR,
UNIT_DATETIME_DAY_MONTH,
UNIT_DATETIME_HOUR_MIN,
UNIT_DATETIME_SEC
};
SensorData() { clear(); }
unsigned int type; // custom / formula
unsigned int id;
unsigned int instance;
unsigned int persistentValue;
unsigned int formula;
char label[4+1];
unsigned int unit;
unsigned int prec;
unsigned int inputFlags;
bool logs;
bool persistent;
// for custom sensors
unsigned int ratio;
unsigned int offset;
// for consumption
unsigned int amps;
// for cell
unsigned int source;
unsigned int index;
// for calculations
unsigned int sources[4];
// for GPS dist
unsigned int gps;
unsigned int alt;
bool isAvailable() const { return type==TYPE_CALCULATED || id!=0 || instance!=0; }
void updateUnit();
QString unitString() const;
void clear() { memset(this, 0, sizeof(SensorData)); }
};
class ModelData {
public:
ModelData();
@@ -930,6 +1025,8 @@ class ModelData {
ScriptData scriptData[C9X_MAX_SCRIPTS];
SensorData sensorData[C9X_MAX_SENSORS];
void clear();
bool isempty();
void setDefaultInputs(const GeneralSettings & settings);
@@ -1143,7 +1240,6 @@ enum Capability {
TelemetryCustomScreensFieldsPerLine,
TelemetryTimeshift,
TelemetryMaxMultiplier,
HasAltitudeSel,
HasVario,
HasVarioSink,
HasFailsafe,
@@ -466,7 +466,6 @@ t_Er9xModelData::operator ModelData ()
c9x.frsky = frsky;
c9x.frsky.usrProto=FrSkyUsrProto;
c9x.frsky.FrSkyGpsAlt=FrSkyGpsAlt;
return c9x;
}
@@ -594,7 +594,6 @@ t_Ersky9xModelData_v10::operator ModelData ()
c9x.frsky = frsky;
c9x.frsky.usrProto=FrSkyUsrProto;
c9x.frsky.FrSkyGpsAlt=FrSkyGpsAlt;
return c9x;
}
@@ -705,23 +704,10 @@ t_Ersky9xModelData_v11::operator ModelData ()
for (int i=0; i<ERSKY9X_NUM_CSW_V11; i++)
c9x.logicalSw[i] = logicalSw[i];
// for (int i=0; i<ERSKY9X_NUM_CHNOUT_V11; i++)
// c9x.safetySw[i] = safetySw[i];
c9x.frsky = frsky;
c9x.frsky.usrProto=FrSkyUsrProto;
c9x.frsky.FrSkyGpsAlt=FrSkyGpsAlt;
// for (int i=0; i<8; i++) {
// c9x.frskyalarms[i].frskyAlarmLimit=frskyAlarms.alarmData[i].frskyAlarmLimit;
// c9x.frskyalarms[i].frskyAlarmSound=frskyAlarms.alarmData[i].frskyAlarmSound;
// c9x.frskyalarms[i].frskyAlarmType=frskyAlarms.alarmData[i].frskyAlarmType;
// }
// for (int i=0; i<8; i++) {
// c9x.customdisplay[i]=customDisplayIndex[i];
// }
for (int i=0; i<5;i++) {
c9x.flightModeData[0].gvars[i]=gvars[i].gvar;
// c9x.gvsource[i]=gvars[i].gvsource;
}
return c9x;
}
@@ -104,6 +104,7 @@ namespace Open9xSky9x {
#include "radio/src/templates.cpp"
#include "radio/src/translations.cpp"
#include "radio/src/fonts.cpp"
#include "radio/src/telemetry/telemetry.cpp"
#include "radio/src/telemetry/frsky.cpp"
#include "radio/src/telemetry/frsky_sport.cpp"
#include "radio/src/telemetry/frsky_d.cpp"
@@ -118,6 +118,7 @@ inline int geteepromsize() {
#define SDCARD
#include "radio/src/translations.cpp"
#include "radio/src/fonts.cpp"
#include "radio/src/telemetry/telemetry.cpp"
#include "radio/src/telemetry/frsky.cpp"
#include "radio/src/telemetry/frsky_sport.cpp"
#include "radio/src/telemetry/frsky_d.cpp"
+233 -71
View File
@@ -24,6 +24,7 @@
#define MAX_CUSTOM_FUNCTIONS(board, version) (IS_ARM(board) ? (version >= 216 ? 64 : 32) : (IS_DBLEEPROM(board, version) ? 24 : 16))
#define MAX_CURVES(board, version) (IS_ARM(board) ? ((IS_TARANIS(board) && version >= 216) ? 32 : 16) : 8)
#define MAX_GVARS(board, version) ((IS_ARM(board) && version >= 216) ? 9 : 5)
#define MAX_SENSORS(board, version) (IS_TARANIS(board) ? 32 : 16)
#define NUM_PPM_INPUTS(board, version) ((IS_ARM(board) && version >= 216) ? 16 : 8)
#define IS_AFTER_RELEASE_21_MARCH_2013(board, version) (version >= 214 || (!IS_ARM(board) && version >= 213))
@@ -268,32 +269,46 @@ class SourcesConversionTable: public ConversionTable {
addConversion(RawSource(SOURCE_TYPE_CH, i), val++);
if (!(flags & FLAG_NOTELEMETRY)) {
if (afterrelease21March2013) {
if ((board != BOARD_STOCK && (board!=BOARD_M128 || version<215)) || (variant & GVARS_VARIANT)) {
for (int i=0; i<MAX_GVARS(board, version); i++)
addConversion(RawSource(SOURCE_TYPE_GVAR, i), val++);
}
if (IS_ARM(board) && version >= 217) {
for (int i=0; i<MAX_GVARS(board, version); i++)
addConversion(RawSource(SOURCE_TYPE_GVAR, i), val++);
addConversion(RawSource(SOURCE_TYPE_SPECIAL, 0), val++); // BATT
addConversion(RawSource(SOURCE_TYPE_SPECIAL, 1), val++); // TIME
val += 5;
addConversion(RawSource(SOURCE_TYPE_SPECIAL, 2), val++); // Timer1
addConversion(RawSource(SOURCE_TYPE_SPECIAL, 3), val++); // Timer2
addConversion(RawSource(SOURCE_TYPE_SPECIAL, 4), val++); // Timer3
for (int i=0; i<C9X_MAX_SENSORS*3; ++i)
addConversion(RawSource(SOURCE_TYPE_TELEMETRY, i), val++);
}
else {
if (afterrelease21March2013) {
if ((board != BOARD_STOCK && (board!=BOARD_M128 || version<215)) || (variant & GVARS_VARIANT)) {
for (int i=0; i<MAX_GVARS(board, version); i++)
addConversion(RawSource(SOURCE_TYPE_GVAR, i), val++);
}
}
for (int i=0; i<TELEMETRY_SOURCE_ACC; i++) {
if (version < 216) {
if (i==TELEMETRY_SOURCE_TX_TIME || i==TELEMETRY_SOURCE_SWR || i==TELEMETRY_SOURCE_A3 || i==TELEMETRY_SOURCE_A4 || i==TELEMETRY_SOURCE_ASPEED || i==TELEMETRY_SOURCE_DTE || i==TELEMETRY_SOURCE_CELL_MIN || i==TELEMETRY_SOURCE_CELLS_MIN || i==TELEMETRY_SOURCE_VFAS_MIN)
continue;
}
if (!IS_ARM(board)) {
if (i==TELEMETRY_SOURCE_TX_TIME || i==TELEMETRY_SOURCE_SWR || i==TELEMETRY_SOURCE_A3 || i==TELEMETRY_SOURCE_A4 || i==TELEMETRY_SOURCE_A3_MIN || i==TELEMETRY_SOURCE_A4_MIN)
continue;
}
addConversion(RawSource(SOURCE_TYPE_TELEMETRY, i), val++);
if (version >= 216 && IS_ARM(board)) {
if (i==TELEMETRY_SOURCE_RSSI_RX)
val += 1;
if (i==TELEMETRY_SOURCE_TX_TIME)
val += 5;
if (i==TELEMETRY_SOURCE_DTE)
val += 5;
if (i==TELEMETRY_SOURCE_POWER_MAX)
val += 5;
for (int i=0; i<TELEMETRY_SOURCE_ACC; i++) {
if (version < 216) {
if (i==TELEMETRY_SOURCE_TX_TIME || i==TELEMETRY_SOURCE_SWR || i==TELEMETRY_SOURCE_A3 || i==TELEMETRY_SOURCE_A4 || i==TELEMETRY_SOURCE_ASPEED || i==TELEMETRY_SOURCE_DTE || i==TELEMETRY_SOURCE_CELL_MIN || i==TELEMETRY_SOURCE_CELLS_MIN || i==TELEMETRY_SOURCE_VFAS_MIN)
continue;
}
if (!IS_ARM(board)) {
if (i==TELEMETRY_SOURCE_TX_TIME || i==TELEMETRY_SOURCE_SWR || i==TELEMETRY_SOURCE_A3 || i==TELEMETRY_SOURCE_A4 || i==TELEMETRY_SOURCE_A3_MIN || i==TELEMETRY_SOURCE_A4_MIN)
continue;
}
addConversion(RawSource(SOURCE_TYPE_TELEMETRY, i), val++);
if (version >= 216 && IS_ARM(board)) {
if (i==TELEMETRY_SOURCE_RSSI_RX)
val += 1;
if (i==TELEMETRY_SOURCE_TX_TIME)
val += 5;
if (i==TELEMETRY_SOURCE_DTE)
val += 5;
if (i==TELEMETRY_SOURCE_POWER_MAX)
val += 5;
}
}
}
}
@@ -874,14 +889,14 @@ class MixField: public TransformedField {
internalField.Append(new UnsignedField<1>((unsigned int &)mix.carryTrim));
internalField.Append(new UnsignedField<4>(mix.mixWarn));
internalField.Append(new SignedField<16>(_weight));
internalField.Append(new SourceField<10>(mix.srcRaw, board, version, FLAG_NOTELEMETRY));
internalField.Append(new SignedField<14>(_offset));
internalField.Append(new SwitchField<8>(mix.swtch, board, version));
internalField.Append(new CurveReferenceField(mix.curve, board, version));
internalField.Append(new UnsignedField<8>(mix.delayUp));
internalField.Append(new UnsignedField<8>(mix.delayDown));
internalField.Append(new UnsignedField<8>(mix.speedUp));
internalField.Append(new UnsignedField<8>(mix.speedDown));
internalField.Append(new SourceField<8>(mix.srcRaw, board, version, FLAG_NOTELEMETRY));
internalField.Append(new SignedField<16>(_offset));
internalField.Append(new ZCharField<8>(mix.name));
}
else if (IS_ARM(board) && version >= 217) {
@@ -1134,7 +1149,30 @@ class InputField: public TransformedField {
board(board),
version(version)
{
if (IS_TARANIS(board) && version >= 216) {
if (IS_TARANIS(board) && version >= 217) {
internalField.Append(new SourceField<10>(expo.srcRaw, board, version, 0));
internalField.Append(new UnsignedField<14>(expo.scale, "Scale"));
internalField.Append(new UnsignedField<8>(expo.chn, "Channel"));
internalField.Append(new SwitchField<8>(expo.swtch, board, version));
internalField.Append(new UnsignedField<16>(expo.phases));
internalField.Append(new SignedField<8>(_weight, "Weight"));
internalField.Append(new SignedField<6>(expo.carryTrim, "CarryTrim"));
internalField.Append(new UnsignedField<2>(expo.mode, "Mode"));
internalField.Append(new ZCharField<8>(expo.name));
internalField.Append(new SignedField<8>(_offset, "Offset"));
internalField.Append(new CurveReferenceField(expo.curve, board, version));
}
else if (IS_ARM(board) && version >= 216) {
internalField.Append(new UnsignedField<2>(expo.mode, "Mode"));
internalField.Append(new UnsignedField<3>(expo.chn, "Channel"));
internalField.Append(new BoolField<2>(_curveMode));
internalField.Append(new UnsignedField<9>(expo.phases, "Phases"));
internalField.Append(new SwitchField<8>(expo.swtch, board, version));
internalField.Append(new SignedField<8>(_weight, "Weight"));
internalField.Append(new ZCharField<6>(expo.name));
internalField.Append(new SignedField<8>(_curveParam));
}
else if (IS_TARANIS(board) && version >= 216) {
internalField.Append(new SourceField<8>(expo.srcRaw, board, version, 0));
internalField.Append(new UnsignedField<16>(expo.scale, "Scale"));
internalField.Append(new UnsignedField<8>(expo.chn, "Channel"));
@@ -1305,11 +1343,11 @@ class LimitField: public StructField {
if (IS_TARANIS(board) && version >= 217) {
Append(new ConversionField< SignedField<11> >(limit.min, exportLimitValue<1000>, importLimitValue<1000>));
Append(new ConversionField< SignedField<11> >(limit.max, exportLimitValue<-1000>, importLimitValue<-1000>));
Append(new SignedField<10>(limit.ppmCenter));
Append(new ConversionField< SignedField<11> >(limit.offset, exportLimitValue<0>, importLimitValue<0>));
Append(new SignedField<11>(limit.ppmCenter));
Append(new BoolField<1>(limit.symetrical));
Append(new BoolField<1>(limit.revert));
Append(new SpareBitsField<2>());
Append(new SpareBitsField<3>());
Append(new SignedField<8>(limit.curve.value));
if (HAS_LARGE_LCD(board)) {
Append(new ZCharField<6>(limit.name));
@@ -1591,22 +1629,44 @@ class LogicalSwitchField: public TransformedField {
v2(0),
v3(0)
{
if (IS_ARM(board) && version >= 216) {
if (IS_ARM(board) && version >= 217) {
internalField.Append(new ConversionField< UnsignedField<6> >(csw.func, &functionsConversionTable, "Function"));
internalField.Append(new SignedField<10>(v1));
internalField.Append(new SignedField<16>(v2));
internalField.Append(new SignedField<16>(v3));
}
else if (IS_ARM(board) && version >= 216) {
internalField.Append(new SignedField<8>(v1));
internalField.Append(new SignedField<16>(v2));
internalField.Append(new SignedField<16>(v3));
internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function"));
}
else if (IS_ARM(board) && version >= 216) {
internalField.Append(new SignedField<8>(v1));
internalField.Append(new SignedField<16>(v2));
internalField.Append(new SignedField<16>(v3));
internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function"));
}
else if (IS_ARM(board) && version >= 215) {
internalField.Append(new SignedField<16>(v1));
internalField.Append(new SignedField<16>(v2));
internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function"));
}
else if (IS_ARM(board)) {
internalField.Append(new SignedField<8>(v1));
internalField.Append(new SignedField<8>(v2));
internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function"));
}
else {
internalField.Append(new SignedField<8>(v1));
internalField.Append(new SignedField<8>(v2));
if (version >= 213)
internalField.Append(new ConversionField< UnsignedField<4> >(csw.func, &functionsConversionTable, "Function"));
else
internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function"));
}
if (IS_ARM(board)) {
internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function"));
int scale = (version >= 216 ? 0 : 5);
internalField.Append(new ConversionField< UnsignedField<8> >(csw.delay, 0, scale));
internalField.Append(new ConversionField< UnsignedField<8> >(csw.duration, 0, scale));
@@ -1616,12 +1676,8 @@ class LogicalSwitchField: public TransformedField {
}
else {
if (version >= 213) {
internalField.Append(new ConversionField< UnsignedField<4> >(csw.func, &functionsConversionTable, "Function"));
internalField.Append(new ConversionField< UnsignedField<4> >((unsigned int &)csw.andsw, andswitchesConversionTable, "AND switch"));
}
else {
internalField.Append(new ConversionField< UnsignedField<8> >(csw.func, &functionsConversionTable, "Function"));
}
}
}
@@ -2286,28 +2342,48 @@ class FrskyScreenField: public DataField {
version(version)
{
for (int i=0; i<4; i++) {
bars.Append(new TelemetrySourceField<8>(screen.body.bars[i].source, board, version));
bars.Append(new UnsignedField<8>(screen.body.bars[i].barMin));
bars.Append(new UnsignedField<8>(screen.body.bars[i].barMax));
if (IS_ARM(board) && version >= 217) {
if (IS_TARANIS(board))
bars.Append(new TelemetrySourceField<16>(screen.body.bars[i].source, board, version));
else
bars.Append(new TelemetrySourceField<8>(screen.body.bars[i].source, board, version));
bars.Append(new UnsignedField<16>(screen.body.bars[i].barMin));
bars.Append(new UnsignedField<16>(screen.body.bars[i].barMax));
}
else {
bars.Append(new TelemetrySourceField<8>(screen.body.bars[i].source, board, version));
bars.Append(new UnsignedField<8>(screen.body.bars[i].barMin));
bars.Append(new UnsignedField<8>(screen.body.bars[i].barMax));
}
}
int columns = (IS_TARANIS(board) ? 3 : 2);
for (int i=0; i<4; i++) {
for (int j=0; j<columns; j++) {
numbers.Append(new TelemetrySourceField<8>(screen.body.lines[i].source[j], board, version));
}
}
if (!IS_TARANIS(board)) {
for (int i=0; i<4; i++) {
numbers.Append(new SpareBitsField<8>());
if (IS_TARANIS(board) && version >= 217)
numbers.Append(new TelemetrySourceField<16>(screen.body.lines[i].source[j], board, version));
else
numbers.Append(new TelemetrySourceField<8>(screen.body.lines[i].source[j], board, version));
}
}
none.Append(new SpareBitsField<12*8>());
if (!IS_TARANIS(board)) {
if (IS_ARM(board))
numbers.Append(new SpareBitsField<12*8>());
else
numbers.Append(new SpareBitsField<4*8>());
}
if (version >= 217) {
if (IS_TARANIS(board))
none.Append(new SpareBitsField<24*8>());
else
none.Append(new SpareBitsField<20*8>());
}
if (IS_TARANIS(board) && version >= 217) {
script.Append(new CharField<8>(screen.body.script.filename));
script.Append(new SpareBitsField<32>());
script.Append(new SpareBitsField<16*8>());
}
}
@@ -2440,29 +2516,35 @@ class FrskyField: public StructField {
rssiConversionTable[1] = RSSIConversionTable(1);
if (IS_ARM(board)) {
for (int i=0; i<((version >= 216) ? 4 : 2); i++) {
Append(new UnsignedField<8>(frsky.channels[i].ratio, "Ratio"));
Append(new SignedField<12>(frsky.channels[i].offset, "Offset"));
Append(new UnsignedField<4>(frsky.channels[i].type, "Type"));
for (int j=0; j<2; j++)
Append(new UnsignedField<8>(frsky.channels[i].alarms[j].value, "Alarm value"));
for (int j=0; j<2; j++)
Append(new UnsignedField<2>(frsky.channels[i].alarms[j].level));
for (int j=0; j<2; j++)
Append(new UnsignedField<1>(frsky.channels[i].alarms[j].greater));
Append(new SpareBitsField<2>());
Append(new UnsignedField<8>(frsky.channels[i].multiplier, 0, 5, "Multiplier"));
}
Append(new UnsignedField<8>(frsky.usrProto));
if (version >= 216) {
Append(new ConversionField< UnsignedField<7> >(frsky.voltsSource, &telemetryVoltsSourceConversionTable, "Volts Source"));
Append(new BoolField<1>(frsky.altitudeDisplayed));
if (version >= 217) {
Append(new UnsignedField<8>(frsky.voltsSource, "Volts Source"));
Append(new UnsignedField<8>(frsky.altitudeSource, "Altitude Source"));
}
else {
Append(new ConversionField< UnsignedField<8> >(frsky.voltsSource, &telemetryVoltsSourceConversionTable, "Volts Source"));
for (int i=0; i<((version >= 216) ? 4 : 2); i++) {
Append(new UnsignedField<8>(frsky.channels[i].ratio, "Ratio"));
Append(new SignedField<12>(frsky.channels[i].offset, "Offset"));
Append(new UnsignedField<4>(frsky.channels[i].type, "Type"));
for (int j=0; j<2; j++)
Append(new UnsignedField<8>(frsky.channels[i].alarms[j].value, "Alarm value"));
for (int j=0; j<2; j++)
Append(new UnsignedField<2>(frsky.channels[i].alarms[j].level));
for (int j=0; j<2; j++)
Append(new UnsignedField<1>(frsky.channels[i].alarms[j].greater));
Append(new SpareBitsField<2>());
Append(new UnsignedField<8>(frsky.channels[i].multiplier, 0, 5, "Multiplier"));
}
Append(new UnsignedField<8>(frsky.usrProto));
if (version >= 216) {
Append(new ConversionField< UnsignedField<7> >(frsky.voltsSource, &telemetryVoltsSourceConversionTable, "Volts Source"));
Append(new SpareBitsField<1>());
}
else {
Append(new ConversionField< UnsignedField<8> >(frsky.voltsSource, &telemetryVoltsSourceConversionTable, "Volts Source"));
}
Append(new ConversionField< SignedField<8> >(frsky.blades, -2));
Append(new ConversionField< UnsignedField<8> >(frsky.currentSource, &telemetryCurrentSourceConversionTable, "Current Source"));
}
Append(new ConversionField< SignedField<8> >(frsky.blades, -2));
Append(new ConversionField< UnsignedField<8> >(frsky.currentSource, &telemetryCurrentSourceConversionTable, "Current Source"));
if (version >= 217) {
for (int i=0; i<4; i++) {
@@ -2491,7 +2573,7 @@ class FrskyField: public StructField {
Append(new ConversionField< UnsignedField<2> >(frsky.rssiAlarms[i].level, &rssiConversionTable[i], "RSSI"));
Append(new ConversionField< SignedField<6> >(frsky.rssiAlarms[i].value, -45+i*3));
}
if (version >= 216) {
if (version == 216) {
Append(new BoolField<1>(frsky.mAhPersistent));
Append(new UnsignedField<15>(frsky.storedMah));
Append(new SignedField<8>(frsky.fasOffset));
@@ -2555,6 +2637,80 @@ class MavlinkField: public StructField {
}
};
class SensorField: public TransformedField {
public:
SensorField(SensorData & sensor, BoardEnum board, unsigned int version):
TransformedField(internalField),
internalField("Sensor"),
sensor(sensor),
_param(0)
{
internalField.Append(new UnsignedField<16>(_id, "id/persistentValue"));
internalField.Append(new UnsignedField<8>(_instance, "instance/formula"));
internalField.Append(new ZCharField<4>(sensor.label));
internalField.Append(new UnsignedField<1>(sensor.type, "type"));
internalField.Append(new UnsignedField<5>(sensor.unit, "unit"));
internalField.Append(new UnsignedField<2>(sensor.prec, "prec"));
internalField.Append(new UnsignedField<2>(sensor.inputFlags, "inputFlags"));
internalField.Append(new BoolField<1>(sensor.logs));
internalField.Append(new BoolField<1>(sensor.persistent));
internalField.Append(new SpareBitsField<4>());
internalField.Append(new UnsignedField<32>(_param, "param"));
}
virtual void beforeExport()
{
if (sensor.type == SensorData::TYPE_CUSTOM) {
_id = sensor.id;
_instance = sensor.instance;
_param = (sensor.ratio) + (sensor.offset << 16);
}
else {
_id = sensor.persistentValue;
_instance = sensor.formula;
if (sensor.formula == SensorData::FORMULA_CELL)
_param = (sensor.source) + (sensor.index << 8);
else if (sensor.formula == SensorData::FORMULA_ADD || sensor.formula == SensorData::FORMULA_MULTIPLY || sensor.formula == SensorData::FORMULA_MIN || sensor.formula == SensorData::FORMULA_MAX)
_param = (sensor.sources[0]) + (sensor.sources[1] << 8) + (sensor.sources[2] << 16) + (sensor.sources[3] << 24);
else if (sensor.formula == SensorData::FORMULA_DIST)
_param = (sensor.gps) + (sensor.alt << 8);
else if (sensor.formula == SensorData::FORMULA_CONSUMPTION)
_param = (sensor.amps);
}
}
virtual void afterImport()
{
if (sensor.type == SensorData::TYPE_CUSTOM) {
sensor.id = _id;
sensor.instance = _instance;
}
else {
sensor.persistentValue = _id;
sensor.formula = _instance;
if (sensor.formula == SensorData::FORMULA_CELL)
(sensor.source = _sources[0], sensor.index = _sources[1]);
else if (sensor.formula == SensorData::FORMULA_ADD || sensor.formula == SensorData::FORMULA_MULTIPLY || sensor.formula == SensorData::FORMULA_MIN || sensor.formula == SensorData::FORMULA_MAX)
for (int i=0; i<4; ++i)
sensor.sources[i] = _sources[i];
else if (sensor.formula == SensorData::FORMULA_DIST)
(sensor.gps = _sources[0], sensor.alt = _sources[1]);
else if (sensor.formula == SensorData::FORMULA_CONSUMPTION)
sensor.amps = _sources[0];
}
}
protected:
StructField internalField;
SensorData & sensor;
unsigned int _id;
unsigned int _instance;
union {
unsigned int _param;
uint8_t _sources[4];
};
};
int exportPpmDelay(int delay) { return (delay - 300) / 50; }
int importPpmDelay(int delay) { return 300 + 50 * delay; }
@@ -2587,12 +2743,12 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigne
for (int i=0; i<MAX_TIMERS(board, version); i++) {
internalField.Append(new SwitchField<8>(modelData.timers[i].mode, board, version, true));
if (IS_ARM(board) && version >= 217) {
internalField.Append(new UnsignedField<24>(modelData.timers[i].val));
internalField.Append(new SignedField<24>(modelData.timers[i].pvalue));
internalField.Append(new UnsignedField<2>(modelData.timers[i].countdownBeep));
internalField.Append(new BoolField<1>(modelData.timers[i].minuteBeep));
internalField.Append(new UnsignedField<2>(modelData.timers[i].persistent));
internalField.Append(new SpareBitsField<3>());
internalField.Append(new UnsignedField<24>(modelData.timers[i].val));
internalField.Append(new SignedField<24>(modelData.timers[i].pvalue));
if (IS_TARANIS(board))
internalField.Append(new ZCharField<8>(modelData.timers[i].name));
else
@@ -2637,7 +2793,7 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigne
if (IS_TARANIS(board) || (IS_ARM(board) && version >= 216)) {
internalField.Append(new BoolField<1>(modelData.noGlobalFunctions));
internalField.Append(new SpareBitsField<4>());
internalField.Append(new SpareBitsField<3>());
}
else {
internalField.Append(new ConversionField< SignedField<4> >(modelData.moduleData[0].channelsCount, &channelsConversionTable, "Channels number", ::QObject::tr("OpenTX doesn't allow this number of channels")));
@@ -2802,9 +2958,15 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigne
}
}
if (IS_ARM(board) && version >= 216) {
if (IS_ARM(board) && version == 216) {
internalField.Append(new SpareBitsField<16>());
}
if (IS_ARM(board) && version >= 217) {
for (int i=0; i<MAX_SENSORS(board, version); ++i) {
internalField.Append(new SensorField(modelData.sensorData[i], board, version));
}
}
}
void OpenTxModelData::beforeExport()
@@ -556,7 +556,7 @@ int OpenTxFirmware::getCapability(const Capability capability)
case GvarsFlightModes:
return ((IS_ARM(board) || board==BOARD_GRUVIN9X) ? 1 : 0);
case Mixes:
return (IS_ARM(board) ? 64 : 32);
return (IS_TARANIS(board) ? 64 : (IS_ARM(board) ? 60 : 32));
case OffsetWeight:
return (IS_ARM(board) ? 500 : 245);
case Timers:
@@ -575,8 +575,10 @@ int OpenTxFirmware::getCapability(const Capability capability)
case SwitchesPositions:
return (IS_TARANIS(board) ? 22 : 9);
case CustomFunctions:
if (IS_ARM(board))
if (IS_TARANIS(board))
return 64;
else if (IS_ARM(board))
return 60;
else if (board==BOARD_GRUVIN9X||board==BOARD_M128)
return 24;
else
@@ -9,6 +9,7 @@
#include "trainer.h"
#include "calibration.h"
#include "../modeledit/customfunctions.h"
#include "verticalscrollarea.h"
GeneralEdit::GeneralEdit(QWidget * parent, RadioData & radioData, FirmwareInterface * firmware) :
QDialog(parent),
+1 -1
View File
@@ -3,7 +3,7 @@
#include <QDialog>
#include "eeprominterface.h"
#include "helpers.h"
#include "genericpanel.h"
namespace Ui {
class GeneralEdit;
+19 -117
View File
@@ -616,7 +616,25 @@ void populateSourceCB(QComboBox *b, const RawSource & source, const ModelData *
}
}
if (flags & POPULATE_TELEMETRYEXT) {
if (IS_ARM(GetCurrentFirmware()->getBoard())) {
if ((flags & POPULATE_TELEMETRY) || (flags & POPULATE_TELEMETRYEXT)) {
for (int i=0; i<5; ++i) {
item = RawSource(SOURCE_TYPE_SPECIAL, i);
b->addItem(item.toString(model), item.toValue());
if (item == source) b->setCurrentIndex(b->count()-1);
}
for (int i=0; i<C9X_MAX_SENSORS; ++i) {
if (model->sensorData[i].isAvailable()) {
for (int j=0; j<3; ++j) {
item = RawSource(SOURCE_TYPE_TELEMETRY, 3*i+j);
b->addItem(item.toString(model), item.toValue());
if (item == source) b->setCurrentIndex(b->count()-1);
}
}
}
}
}
else if (flags & POPULATE_TELEMETRYEXT) {
for (int i=0; i<TELEMETRY_SOURCE_ACC; i++) {
if (i==TELEMETRY_SOURCE_RSSI_TX && IS_TARANIS(board))
continue;
@@ -1001,119 +1019,3 @@ QString generateProcessUniqueTempFileName(const QString & fileName)
sanitizedFileName.remove('/');
return QDir::tempPath() + QString("/%1-").arg(QCoreApplication::applicationPid()) + sanitizedFileName;
}
GenericPanel::GenericPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, FirmwareInterface * firmware):
QWidget(parent),
model(model),
generalSettings(generalSettings),
firmware(firmware),
lock(false)
{
}
GenericPanel::~GenericPanel()
{
}
void GenericPanel::update()
{
}
void GenericPanel::addLabel(QGridLayout * gridLayout, QString text, int col, bool minimize)
{
QLabel *label = new QLabel(this);
label->setFrameShape(QFrame::Panel);
label->setFrameShadow(QFrame::Raised);
label->setMidLineWidth(0);
label->setAlignment(Qt::AlignCenter);
label->setMargin(5);
label->setText(text);
if (!minimize)
label->setMinimumWidth(100);
gridLayout->addWidget(label, 0, col, 1, 1);
}
void GenericPanel::addEmptyLabel(QGridLayout * gridLayout, int col)
{
QLabel *label = new QLabel(this);
label->setText("");
gridLayout->addWidget(label, 0, col, 1, 1);
}
void GenericPanel::addHSpring(QGridLayout * gridLayout, int col, int row)
{
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
gridLayout->addItem(spacer, row, col);
}
void GenericPanel::addVSpring(QGridLayout * gridLayout, int col, int row)
{
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
gridLayout->addItem(spacer, row, col);
}
void GenericPanel::addDoubleSpring(QGridLayout * gridLayout, int col, int row)
{
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding );
gridLayout->addItem(spacer, row, col);
}
bool GenericPanel::eventFilter(QObject *object, QEvent * event)
{
QWidget * widget = qobject_cast<QWidget*>(object);
if (widget) {
if (event->type() == QEvent::Wheel) {
if (widget->focusPolicy() == Qt::WheelFocus) {
event->accept();
return false;
}
else {
event->ignore();
return true;
}
}
else if (event->type() == QEvent::FocusIn) {
widget->setFocusPolicy(Qt::WheelFocus);
}
else if (event->type() == QEvent::FocusOut) {
widget->setFocusPolicy(Qt::StrongFocus);
}
}
return QWidget::eventFilter(object, event);
}
void GenericPanel::disableMouseScrolling()
{
Q_FOREACH(QComboBox * cb, findChildren<QComboBox*>()) {
cb->installEventFilter(this);
cb->setFocusPolicy(Qt::StrongFocus);
}
Q_FOREACH(QAbstractSpinBox * sb, findChildren<QAbstractSpinBox*>()) {
sb->installEventFilter(this);
sb->setFocusPolicy(Qt::StrongFocus);
}
Q_FOREACH(QSlider * slider, findChildren<QSlider*>()) {
slider->installEventFilter(this);
slider->setFocusPolicy(Qt::StrongFocus);
}
}
VerticalScrollArea::VerticalScrollArea(QWidget * parent, GenericPanel * panel):
QScrollArea(parent),
panel(panel),
parent(parent)
{
setWidgetResizable(true);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setWidget(panel);
panel->installEventFilter(this);
}
bool VerticalScrollArea::eventFilter(QObject *o, QEvent *e)
{
if (o == panel && e->type() == QEvent::Resize) {
setMinimumWidth(panel->minimumSizeHint().width() + verticalScrollBar()->width());
}
return false;
}
-43
View File
@@ -153,47 +153,4 @@ int qunlink(const QString & fileName);
QString generateProcessUniqueTempFileName(const QString & fileName);
class GenericPanel : public QWidget
{
Q_OBJECT
friend class QUnsignedAutoComboBox;
public:
GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, FirmwareInterface * firmware);
virtual ~GenericPanel();
signals:
void modified();
public slots:
virtual void update();
protected:
ModelData * model;
GeneralSettings & generalSettings;
FirmwareInterface * firmware;
bool lock;
void addLabel(QGridLayout * gridLayout, QString text, int col, bool mimimize=false);
void addEmptyLabel(QGridLayout * gridLayout, int col);
void addHSpring(QGridLayout *, int col, int row);
void addVSpring(QGridLayout *, int col, int row);
void addDoubleSpring(QGridLayout *, int col, int row);
virtual bool eventFilter(QObject *obj, QEvent *event);
void disableMouseScrolling();
};
class VerticalScrollArea : public QScrollArea
{
public:
VerticalScrollArea(QWidget * parent, GenericPanel * panel);
protected:
virtual bool eventFilter(QObject *o, QEvent *e);
private:
GenericPanel * panel;
QWidget * parent;
};
#endif // HELPERS_H
+1
View File
@@ -41,6 +41,7 @@ set(modeledit_UIS
flightmode.ui
telemetry_analog.ui
telemetry_customscreen.ui
telemetry_sensor.ui
)
foreach(name ${modeledit_NAMES})
-2
View File
@@ -194,11 +194,9 @@ void Channels::symlimitsEdited()
void Channels::nameEdited()
{
if (!lock) {
lock = true;
QLineEdit *le = qobject_cast<QLineEdit*>(sender());
int index = le->property("index").toInt();
strcpy(model->limitData[index].name, le->text().toAscii());
lock = false;
emit modified();
}
}
+1
View File
@@ -2,6 +2,7 @@
#define CURVES_H
#include "modeledit.h"
#include "eeprominterface.h"
#include <QSpinBox>
namespace Ui {
@@ -2,6 +2,7 @@
#define CUSTOMFUNCTIONS_H
#include "modeledit.h"
#include "eeprominterface.h"
#include <QLabel>
#include <QCheckBox>
#include <QComboBox>
+1
View File
@@ -2,6 +2,7 @@
#define FLIGHTMODES_H
#include "modeledit.h"
#include "eeprominterface.h"
#include <QVector>
#include <QLabel>
#include <QTabWidget>
@@ -2,6 +2,7 @@
#define CUSTOMSWITCHES_H
#include "modeledit.h"
#include "eeprominterface.h"
#include <QComboBox>
#include <QDoubleSpinBox>
#include <QTimeEdit>
+2 -1
View File
@@ -1,4 +1,5 @@
#include "modeledit.h"
#include "../helpers.h"
#include "ui_modeledit.h"
#include "setup.h"
#include "heli.h"
@@ -7,7 +8,7 @@
#include "mixes.h"
#include "channels.h"
#include "curves.h"
#include "../helpers.h"
#include "verticalscrollarea.h"
#include "logicalswitches.h"
#include "customfunctions.h"
#include "telemetry.h"
+3 -1
View File
@@ -2,7 +2,9 @@
#define MODELEDIT_H
#include <QDialog>
#include "helpers.h"
#include "genericpanel.h"
class RadioData;
namespace Ui {
class ModelEdit;
+2 -2
View File
@@ -34,14 +34,14 @@ TimerPanel::TimerPanel(QWidget *parent, ModelData & model, TimerData & timer, Ge
ui->persistentValue->hide();
}
ui->countdownBeep->setField(&timer.countdownBeep, this);
ui->countdownBeep->setField(timer.countdownBeep, this);
ui->countdownBeep->addItem(tr("Silent"), 0);
ui->countdownBeep->addItem(tr("Beeps"), 1);
if (IS_ARM(board) || IS_2560(board)) {
ui->countdownBeep->addItem(tr("Voice"), 2);
}
ui->persistent->setField(&timer.persistent, this);
ui->persistent->setField(timer.persistent, this);
ui->persistent->addItem(tr("Not persistent"), 0);
ui->persistent->addItem(tr("Persistent (flight)"), 1);
ui->persistent->addItem(tr("Persistent (manual reset)"), 2);
+1
View File
@@ -2,6 +2,7 @@
#define SETUP_H
#include "modeledit.h"
#include "eeprominterface.h"
#include <QVector>
#include <QCheckBox>
#include <QSlider>
+5 -5
View File
@@ -9,7 +9,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>626</width>
<width>675</width>
<height>33</height>
</rect>
</property>
@@ -57,7 +57,7 @@
</widget>
</item>
<item>
<widget class="QUnsignedAutoComboBox" name="countdownBeep"/>
<widget class="AutoComboBox" name="countdownBeep"/>
</item>
<item>
<widget class="QCheckBox" name="minuteBeep">
@@ -67,7 +67,7 @@
</widget>
</item>
<item>
<widget class="QUnsignedAutoComboBox" name="persistent"/>
<widget class="AutoComboBox" name="persistent"/>
</item>
<item>
<widget class="QLabel" name="persistentValue">
@@ -93,9 +93,9 @@
</widget>
<customwidgets>
<customwidget>
<class>QUnsignedAutoComboBox</class>
<class>AutoComboBox</class>
<extends>QComboBox</extends>
<header>qautocombobox.h</header>
<header>autocombobox.h</header>
</customwidget>
</customwidgets>
<resources/>
+234 -77
View File
@@ -2,6 +2,7 @@
#include "ui_telemetry.h"
#include "ui_telemetry_analog.h"
#include "ui_telemetry_customscreen.h"
#include "ui_telemetry_sensor.h"
#include "helpers.h"
#include "appdata.h"
@@ -469,6 +470,169 @@ void TelemetryCustomScreen::barMaxChanged(double value)
}
}
TelemetrySensorPanel::TelemetrySensorPanel(QWidget *parent, SensorData & sensor, ModelData & model, GeneralSettings & generalSettings, FirmwareInterface * firmware):
ModelPanel(parent, model, generalSettings, firmware),
ui(new Ui::TelemetrySensor),
sensor(sensor),
lock(false)
{
ui->setupUi(this);
ui->id->setField(sensor.id);
ui->instance->setField(sensor.instance);
ui->ratio->setField(sensor.ratio);
ui->offset->setField(sensor.offset);
ui->inputFlags->setField(sensor.inputFlags);
ui->logs->setField(sensor.logs);
ui->persistent->setField(sensor.persistent);
ui->gpsSensor->setField(sensor.gps);
ui->altSensor->setField(sensor.alt);
ui->ampsSensor->setField(sensor.amps);
ui->cellsSensor->setField(sensor.source);
ui->source1->setField(sensor.sources[0]);
ui->source2->setField(sensor.sources[1]);
ui->source3->setField(sensor.sources[2]);
ui->source4->setField(sensor.sources[3]);
update();
}
TelemetrySensorPanel::~TelemetrySensorPanel()
{
delete ui;
}
void TelemetrySensorPanel::update()
{
bool precDisplayed = false;
bool gpsFieldsDisplayed = false;
bool cellsFieldsDisplayed = false;
bool consFieldsDisplayed = false;
bool ratioFieldsDisplayed = false;
bool sources12FieldsDisplayed = false;
bool sources34FieldsDisplayed = false;
lock = true;
ui->name->setText(sensor.label);
ui->type->setCurrentIndex(sensor.type);
ui->unit->setCurrentIndex(sensor.unit);
ui->prec->setValue(sensor.prec);
if (sensor.type == SensorData::TYPE_CALCULATED) {
sensor.updateUnit();
ui->idLabel->hide();
ui->id->hide();
ui->instanceLabel->hide();
ui->instance->hide();
ui->formula->show();
ui->formula->setCurrentIndex(sensor.formula);
precDisplayed = (sensor.formula < SensorData::FORMULA_CELL);
gpsFieldsDisplayed = (sensor.formula == SensorData::FORMULA_DIST);
cellsFieldsDisplayed = (sensor.formula == SensorData::FORMULA_CELL);
consFieldsDisplayed = (sensor.formula == SensorData::FORMULA_CONSUMPTION);
sources12FieldsDisplayed = (sensor.formula <= SensorData::FORMULA_MULTIPLY);
sources34FieldsDisplayed = (sensor.formula < SensorData::FORMULA_MULTIPLY);
updateSourcesComboBox(ui->source1);
updateSourcesComboBox(ui->source2);
updateSourcesComboBox(ui->source3);
updateSourcesComboBox(ui->source4);
updateSourcesComboBox(ui->gpsSensor);
updateSourcesComboBox(ui->altSensor);
updateSourcesComboBox(ui->ampsSensor);
}
else {
ui->idLabel->show();
ui->id->show();
ui->instanceLabel->show();
ui->instance->show();
ui->formula->hide();
ratioFieldsDisplayed = (sensor.unit != SensorData::UNIT_GPS && sensor.unit != SensorData::UNIT_DATETIME);
ui->offset->setDecimals(sensor.prec);
precDisplayed = (sensor.unit != SensorData::UNIT_GPS && sensor.unit != SensorData::UNIT_DATETIME);
}
ui->ratioLabel->setVisible(ratioFieldsDisplayed);
ui->ratio->setVisible(ratioFieldsDisplayed);
ui->offsetLabel->setVisible(ratioFieldsDisplayed);
ui->offset->setVisible(ratioFieldsDisplayed);
ui->precLabel->setVisible(precDisplayed);
ui->prec->setVisible(precDisplayed);
ui->unit->setVisible(precDisplayed);
ui->gpsSensorLabel->setVisible(gpsFieldsDisplayed);
ui->gpsSensor->setVisible(gpsFieldsDisplayed);
ui->altSensorLabel->setVisible(gpsFieldsDisplayed);
ui->altSensor->setVisible(gpsFieldsDisplayed);
ui->ampsSensorLabel->setVisible(consFieldsDisplayed);
ui->ampsSensor->setVisible(consFieldsDisplayed);
ui->cellsSensorLabel->setVisible(cellsFieldsDisplayed);
ui->cellsSensor->setVisible(cellsFieldsDisplayed);
ui->cellsIndex->setVisible(cellsFieldsDisplayed);
ui->source1->setVisible(sources12FieldsDisplayed);
ui->source2->setVisible(sources12FieldsDisplayed);
ui->source3->setVisible(sources34FieldsDisplayed);
ui->source4->setVisible(sources34FieldsDisplayed);
lock = false;
}
void populateTelemetrySourcesComboBox(AutoComboBox * cb, const ModelData * model)
{
cb->clear();
cb->addItem("---", 0);
for (int i=0; i<C9X_MAX_SENSORS; ++i) {
if (model->sensorData[i].isAvailable())
cb->addItem(model->sensorData[i].label, i+1);
}
}
void TelemetrySensorPanel::updateSourcesComboBox(AutoComboBox * cb)
{
populateTelemetrySourcesComboBox(cb, model);
}
void TelemetrySensorPanel::on_name_editingFinished()
{
if (!lock) {
strcpy(sensor.label, ui->name->text().toAscii());
update();
emit modified();
}
}
void TelemetrySensorPanel::on_type_currentIndexChanged(int index)
{
if (!lock) {
sensor.type = index;
update();
emit modified();
}
}
void TelemetrySensorPanel::on_formula_currentIndexChanged(int index)
{
if (!lock) {
sensor.formula = index;
update();
emit modified();
}
}
void TelemetrySensorPanel::on_unit_currentIndexChanged(int index)
{
if (!lock) {
sensor.unit = index;
update();
emit modified();
}
}
void TelemetrySensorPanel::on_prec_editingFinished()
{
if (!lock) {
sensor.prec = ui->prec->value();
update();
emit modified();
}
}
/******************************************************/
TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettings & generalSettings, FirmwareInterface * firmware):
@@ -494,26 +658,31 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
ui->telemetryProtocol->hide();
}
analogs[0] = new TelemetryAnalog(this, model.frsky.channels[0], model, generalSettings, firmware);
ui->A1Layout->addWidget(analogs[0]);
connect(analogs[0], SIGNAL(modified()), this, SLOT(onAnalogModified()));
analogs[1] = new TelemetryAnalog(this, model.frsky.channels[1], model, generalSettings, firmware);
ui->A2Layout->addWidget(analogs[1]);
connect(analogs[1], SIGNAL(modified()), this, SLOT(onAnalogModified()));
if (IS_ARM(firmware->getBoard())) {
analogs[2] = new TelemetryAnalog(this, model.frsky.channels[2], model, generalSettings, firmware);
ui->A3Layout->addWidget(analogs[2]);
connect(analogs[2], SIGNAL(modified()), this, SLOT(onAnalogModified()));
analogs[3] = new TelemetryAnalog(this, model.frsky.channels[3], model, generalSettings, firmware);
ui->A4Layout->addWidget(analogs[3]);
connect(analogs[3], SIGNAL(modified()), this, SLOT(onAnalogModified()));
ui->A1GB->hide();
ui->A2GB->hide();
for (int i=0; i<C9X_MAX_SENSORS; ++i) {
TelemetrySensorPanel * panel = new TelemetrySensorPanel(this, model.sensorData[i], model, generalSettings, firmware);
ui->sensorsLayout->addWidget(panel);
sensorPanels[i] = panel;
}
}
else {
ui->A3GB->hide();
ui->A4GB->hide();
ui->sensorsGB->hide();
analogs[0] = new TelemetryAnalog(this, model.frsky.channels[0], model, generalSettings, firmware);
ui->A1Layout->addWidget(analogs[0]);
connect(analogs[0], SIGNAL(modified()), this, SLOT(onAnalogModified()));
analogs[1] = new TelemetryAnalog(this, model.frsky.channels[1], model, generalSettings, firmware);
ui->A2Layout->addWidget(analogs[1]);
connect(analogs[1], SIGNAL(modified()), this, SLOT(onAnalogModified()));
}
if (IS_TARANIS(firmware->getBoard())) {
ui->voltsSource->setField(model.frsky.voltsSource);
ui->altitudeSource->setField(model.frsky.altitudeSource);
}
else {
ui->topbarGB->hide();
}
for (int i=0; i<firmware->getCapability(TelemetryCustomScreens); i++) {
@@ -522,11 +691,6 @@ TelemetryPanel::TelemetryPanel(QWidget *parent, ModelData & model, GeneralSettin
telemetryCustomScreens[i] = tab;
}
if (IS_ARM(firmware->getBoard())) {
ui->bladesCount->setMinimum(1);
ui->bladesCount->setMaximum(128);
}
disableMouseScrolling();
setup();
@@ -547,6 +711,15 @@ void TelemetryPanel::update()
ui->telemetryProtocol->setEnabled(false);
ui->telemetryProtocol->setCurrentIndex(0);
}
populateTelemetrySourcesComboBox(ui->voltsSource, model);
populateTelemetrySourcesComboBox(ui->altitudeSource, model);
}
if (IS_ARM(firmware->getBoard())) {
for (int i=0; i<C9X_MAX_SENSORS; ++i) {
sensorPanels[i]->update();
}
}
}
@@ -569,19 +742,13 @@ void TelemetryPanel::setup()
ui->rssiAlarm2Label->setText(tr("Critical Alarm"));
}
if (!firmware->getCapability(HasAltitudeSel)) {
ui->AltitudeGPS_ChkB->hide();
}
else {
ui->AltitudeGPS_ChkB->setChecked(model->frsky.FrSkyGpsAlt);
}
if (IS_TARANIS(firmware->getBoard())) {
ui->AltitudeToolbar_ChkB->setChecked(model->frsky.altitudeDisplayed);
}
else {
ui->AltitudeToolbar_ChkB->hide();
}
/*if (IS_ARM(firmware->getBoard())) {
for (int i=0; i<C9X_MAX_SENSORS; ++i) {
TelemetrySensorPanel * panel = new TelemetrySensorPanel(this, model->, model, generalSettings, firmware);
ui->sensorsLayout->addWidget(panel);
sensorPanels[i] = panel;
}
}*/
int varioCap = firmware->getCapability(HasVario);
if (!varioCap) {
@@ -610,7 +777,7 @@ void TelemetryPanel::setup()
ui->varioLimitCenterMin_DSB->setValue((model->frsky.varioCenterMin/10.0)-0.5);
}
ui->altimetryGB->setVisible(firmware->getCapability(HasAltitudeSel) || firmware->getCapability(HasVario)),
ui->altimetryGB->setVisible(firmware->getCapability(HasVario)),
ui->frskyProtoCB->setDisabled(firmware->getCapability(NoTelemetryProtocol));
if (firmware->getCapability(Telemetry) & TM_HASWSHH) {
@@ -621,33 +788,35 @@ void TelemetryPanel::setup()
}
ui->variousGB->hide();
if (!(firmware->getCapability(HasFasOffset)) && !(firmware_id.contains("fasoffset"))) {
ui->fasOffset_label->hide();
ui->fasOffset_DSB->hide();
}
else {
ui->fasOffset_DSB->setValue(model->frsky.fasOffset/10.0);
ui->variousGB->show();
}
if (!(firmware->getCapability(HasMahPersistent))) {
ui->mahCount_label->hide();
ui->mahCount_SB->hide();
ui->mahCount_ChkB->hide();
}
else {
if (model->frsky.mAhPersistent) {
ui->mahCount_ChkB->setChecked(true);
ui->mahCount_SB->setValue(model->frsky.storedMah);
if (!IS_ARM(firmware->getBoard())) {
if (!(firmware->getCapability(HasFasOffset)) && !(firmware_id.contains("fasoffset"))) {
ui->fasOffset_label->hide();
ui->fasOffset_DSB->hide();
}
else {
ui->mahCount_SB->setDisabled(true);
ui->fasOffset_DSB->setValue(model->frsky.fasOffset/10.0);
ui->variousGB->show();
}
ui->variousGB->show();
}
ui->frskyProtoCB->setCurrentIndex(model->frsky.usrProto);
ui->bladesCount->setValue(model->frsky.blades);
if (!(firmware->getCapability(HasMahPersistent))) {
ui->mahCount_label->hide();
ui->mahCount_SB->hide();
ui->mahCount_ChkB->hide();
}
else {
if (model->frsky.mAhPersistent) {
ui->mahCount_ChkB->setChecked(true);
ui->mahCount_SB->setValue(model->frsky.storedMah);
}
else {
ui->mahCount_SB->setDisabled(true);
}
ui->variousGB->show();
}
ui->frskyProtoCB->setCurrentIndex(model->frsky.usrProto);
ui->bladesCount->setValue(model->frsky.blades);
}
populateVoltsSource();
populateCurrentSource();
@@ -658,8 +827,8 @@ void TelemetryPanel::setup()
void TelemetryPanel::populateVarioSource()
{
QUnsignedAutoComboBox * cb = ui->varioSourceCB;
cb->setField(&model->frsky.varioSource, this);
AutoComboBox * cb = ui->varioSourceCB;
cb->setField(model->frsky.varioSource, this);
if (!IS_TARANIS(firmware->getBoard())) {
cb->addItem(tr("Alti"), TELEMETRY_VARIO_SOURCE_ALTI);
cb->addItem(tr("Alti+"), TELEMETRY_VARIO_SOURCE_ALTI_PLUS);
@@ -674,8 +843,8 @@ void TelemetryPanel::populateVarioSource()
void TelemetryPanel::populateVoltsSource()
{
QUnsignedAutoComboBox * cb = ui->frskyVoltCB;
cb->setField(&model->frsky.voltsSource, this);
AutoComboBox * cb = ui->frskyVoltCB;
cb->setField(model->frsky.voltsSource, this);
cb->addItem(tr("A1"), TELEMETRY_VOLTS_SOURCE_A1);
cb->addItem(tr("A2"), TELEMETRY_VOLTS_SOURCE_A2);
if (IS_ARM(firmware->getBoard())) {
@@ -688,8 +857,8 @@ void TelemetryPanel::populateVoltsSource()
void TelemetryPanel::populateCurrentSource()
{
QUnsignedAutoComboBox * cb = ui->frskyCurrentCB;
cb->setField(&model->frsky.currentSource, this);
AutoComboBox * cb = ui->frskyCurrentCB;
cb->setField(model->frsky.currentSource, this);
cb->addItem(tr("---"), TELEMETRY_CURRENT_SOURCE_NONE);
cb->addItem(tr("A1"), TELEMETRY_CURRENT_SOURCE_A1);
cb->addItem(tr("A2"), TELEMETRY_CURRENT_SOURCE_A2);
@@ -749,18 +918,6 @@ void TelemetryPanel::on_rssiAlarm2SB_editingFinished()
emit modified();
}
void TelemetryPanel::on_AltitudeGPS_ChkB_toggled(bool checked)
{
model->frsky.FrSkyGpsAlt = checked;
emit modified();
}
void TelemetryPanel::on_AltitudeToolbar_ChkB_toggled(bool checked)
{
model->frsky.altitudeDisplayed = checked;
emit modified();
}
void TelemetryPanel::on_varioLimitMin_DSB_editingFinished()
{
model->frsky.varioMin = round(ui->varioLimitMin_DSB->value()+10);
+30 -2
View File
@@ -2,13 +2,17 @@
#define TELEMETRY_H
#include "modeledit.h"
#include "eeprominterface.h"
#include <QGroupBox>
#include <QComboBox>
#include <QDoubleSpinBox>
class AutoComboBox;
namespace Ui {
class TelemetryAnalog;
class TelemetryCustomScreen;
class TelemetrySensor;
class Telemetry;
}
@@ -74,6 +78,31 @@ class TelemetryCustomScreen: public ModelPanel
QDoubleSpinBox * maxSB[4];
};
class TelemetrySensorPanel: public ModelPanel
{
Q_OBJECT
public:
TelemetrySensorPanel(QWidget *parent, SensorData & sensor, ModelData & model, GeneralSettings & generalSettings, FirmwareInterface * firmware);
~TelemetrySensorPanel();
void update();
protected slots:
void on_name_editingFinished();
void on_type_currentIndexChanged(int index);
void on_formula_currentIndexChanged(int index);
void on_unit_currentIndexChanged(int index);
void on_prec_editingFinished();
protected:
void updateSourcesComboBox(AutoComboBox * cb);
private:
Ui::TelemetrySensor * ui;
SensorData & sensor;
bool lock;
};
class TelemetryPanel : public ModelPanel
{
Q_OBJECT
@@ -88,12 +117,10 @@ class TelemetryPanel : public ModelPanel
void onAnalogModified();
void on_frskyProtoCB_currentIndexChanged(int index);
void on_bladesCount_editingFinished();
void on_AltitudeToolbar_ChkB_toggled(bool checked);
void on_rssiAlarm1CB_currentIndexChanged(int index);
void on_rssiAlarm2CB_currentIndexChanged(int index);
void on_rssiAlarm1SB_editingFinished();
void on_rssiAlarm2SB_editingFinished();
void on_AltitudeGPS_ChkB_toggled(bool checked);
void on_varioLimitMin_DSB_editingFinished();
void on_varioLimitMax_DSB_editingFinished();
void on_varioLimitCenterMin_DSB_editingFinished();
@@ -106,6 +133,7 @@ class TelemetryPanel : public ModelPanel
Ui::Telemetry *ui;
TelemetryAnalog * analogs[4];
TelemetryCustomScreen * telemetryCustomScreens[4];
TelemetrySensorPanel * sensorPanels[C9X_MAX_SENSORS];
void setup();
void telBarUpdate();
File diff suppressed because it is too large Load Diff
@@ -2,20 +2,12 @@
<ui version="4.0">
<class>TelemetryCustomScreen</class>
<widget class="QWidget" name="TelemetryCustomScreen">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>650</width>
<height>393</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5" stretch="0,0,1">
<layout class="QHBoxLayout" name="screenScript" stretch="0,0,1">
<item>
<widget class="QLabel" name="screenTypeLabel">
<property name="sizePolicy">
@@ -87,59 +79,55 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="screenNums">
<layout class="QGridLayout" name="screenNumsLayout"/>
</widget>
</item>
<item>
<widget class="QGroupBox" name="screenBars">
<layout class="QGridLayout" name="screenBarsLayout" columnstretch="1,0,1,0">
<item row="0" column="1">
<widget class="QLabel" name="label_266">
<property name="text">
<string>Min</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_265">
<property name="text">
<string>Source</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_267">
<property name="text">
<string>Gauge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_268">
<property name="text">
<string>Max</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
<widget class="QGroupBox" name="screenBars">
<layout class="QGridLayout" name="screenBarsLayout" columnstretch="1,0,1,0">
<item row="0" column="1">
<widget class="QLabel" name="label_266">
<property name="text">
<string>Min</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_265">
<property name="text">
<string>Source</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_267">
<property name="text">
<string>Gauge</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_268">
<property name="text">
<string>Max</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="screenNums">
<layout class="QGridLayout" name="screenNumsLayout"/>
</widget>
</item>
</layout>
</widget>
+594
View File
@@ -0,0 +1,594 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TelemetrySensor</class>
<widget class="QWidget" name="TelemetrySensor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>2790</width>
<height>67</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0,0,0,1,1,1,1,0,0,1,0,1,0,1,1,1,1,1,1,0,1,0,1,0,1,1,0,1">
<property name="leftMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="name">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>4</number>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="type">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Custom</string>
</property>
</item>
<item>
<property name="text">
<string>Formula</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="idLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Id</string>
</property>
</widget>
</item>
<item>
<widget class="AutoHexSpinBox" name="id">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="instanceLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Instance</string>
</property>
</widget>
</item>
<item>
<widget class="AutoDoubleSpinBox" name="instance">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>255.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="formula">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Add</string>
</property>
</item>
<item>
<property name="text">
<string>Average</string>
</property>
</item>
<item>
<property name="text">
<string>Min</string>
</property>
</item>
<item>
<property name="text">
<string>Max</string>
</property>
</item>
<item>
<property name="text">
<string>Multiply</string>
</property>
</item>
<item>
<property name="text">
<string>Cell</string>
</property>
</item>
<item>
<property name="text">
<string>Consumption</string>
</property>
</item>
<item>
<property name="text">
<string>Dist</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="cellsSensorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cells Sensor :</string>
</property>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="cellsSensor">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>---</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="cellsIndex">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="gpsSensorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>GPS Sensor :</string>
</property>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="gpsSensor">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>---</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="altSensorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Alt. Sensor :</string>
</property>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="altSensor">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>---</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="ampsSensorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Amps Sensor :</string>
</property>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="ampsSensor">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>---</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="source1">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>---</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="source2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>---</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="source3">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>---</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="source4">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>---</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="unit">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Raw (-)</string>
</property>
</item>
<item>
<property name="text">
<string>Voltage (V)</string>
</property>
</item>
<item>
<property name="text">
<string>Current (A)</string>
</property>
</item>
<item>
<property name="text">
<string>Current (mA)</string>
</property>
</item>
<item>
<property name="text">
<string>Speed (kts)</string>
</property>
</item>
<item>
<property name="text">
<string>Speed (m/s)</string>
</property>
</item>
<item>
<property name="text">
<string>Speed (km/h)</string>
</property>
</item>
<item>
<property name="text">
<string>Speed (miles/h)</string>
</property>
</item>
<item>
<property name="text">
<string>Meters (m)</string>
</property>
</item>
<item>
<property name="text">
<string>Feet (f)</string>
</property>
</item>
<item>
<property name="text">
<string>Temp (°C)</string>
</property>
</item>
<item>
<property name="text">
<string>Temp (°F)</string>
</property>
</item>
<item>
<property name="text">
<string>Percentage (%)</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="precLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Precision</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="prec">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>2.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ratioLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Range</string>
</property>
</widget>
</item>
<item>
<widget class="AutoDoubleSpinBox" name="ratio">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>3000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="offsetLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Offset</string>
</property>
</widget>
</item>
<item>
<widget class="AutoDoubleSpinBox" name="offset">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>2</number>
</property>
<property name="minimum">
<double>-12.800000000000001</double>
</property>
<property name="maximum">
<double>12.699999999999999</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="AutoComboBox" name="inputFlags">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>---</string>
</property>
</item>
<item>
<property name="text">
<string>Auto Offset</string>
</property>
</item>
<item>
<property name="text">
<string>Filtered</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="AutoCheckBox" name="logs">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Logs</string>
</property>
</widget>
</item>
<item>
<widget class="AutoCheckBox" name="persistent">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Persistent</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>AutoDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>autodoublespinbox.h</header>
</customwidget>
<customwidget>
<class>AutoComboBox</class>
<extends>QComboBox</extends>
<header>autocombobox.h</header>
</customwidget>
<customwidget>
<class>AutoCheckBox</class>
<extends>QCheckBox</extends>
<header>autocheckbox.h</header>
</customwidget>
<customwidget>
<class>AutoHexSpinBox</class>
<extends>QSpinBox</extends>
<header>autohexspinbox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
+22
View File
@@ -0,0 +1,22 @@
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
set(shared_SRCS
foldersync.cpp
genericpanel.cpp
hexspinbox.cpp
verticalscrollarea.cpp
)
set(shared_HDRS
autocheckbox.h
autocombobox.h
autodoublespinbox.h
autohexspinbox.h
genericpanel.h
hexspinbox.h
verticalscrollarea.h
)
qt4_wrap_cpp(shared_SRCS ${shared_HDRS})
add_library(shared ${shared_SRCS})
+54
View File
@@ -0,0 +1,54 @@
#ifndef AUTOCHECKBOX_H_
#define AUTOCHECKBOX_H_
#include <QCheckBox>
#include "modeledit/modeledit.h"
class AutoCheckBox: public QCheckBox
{
Q_OBJECT
public:
explicit AutoCheckBox(QWidget *parent = 0):
QCheckBox(parent),
field(NULL),
panel(NULL),
lock(false)
{
connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
}
void setField(bool & field, ModelPanel * panel=NULL)
{
this->field = &field;
this->panel = panel;
updateValue();
}
void updateValue()
{
lock = true;
if (field) {
setChecked((int)*field);
}
lock = false;
}
protected slots:
void onToggled(bool checked)
{
if (field && !lock) {
*field = checked;
if (panel) {
emit panel->modified();
}
}
}
protected:
bool * field;
ModelPanel * panel;
bool lock;
};
#endif /* AUTOCHECKBOX_H_ */
@@ -1,15 +1,15 @@
#ifndef QAUTOCOMBOBOX_H_
#define QAUTOCOMBOBOX_H_
#ifndef AUTOCOMBOBOX_H_
#define AUTOCOMBOBOX_H_
#include <QComboBox>
#include "modeledit/modeledit.h"
class QUnsignedAutoComboBox: public QComboBox
class AutoComboBox: public QComboBox
{
Q_OBJECT
public:
explicit QUnsignedAutoComboBox(QWidget *parent = 0):
explicit AutoComboBox(QWidget *parent = 0):
QComboBox(parent),
field(NULL),
panel(NULL),
@@ -18,19 +18,32 @@ class QUnsignedAutoComboBox: public QComboBox
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
}
void clear()
{
lock = true;
QComboBox::clear();
lock = false;
}
void addItem(const QString & item, unsigned int value)
{
lock = true;
QComboBox::addItem(item, value);
if (field && *field==value)
if (field && *field==value) {
setCurrentIndex(count()-1);
}
lock = false;
}
void setField(unsigned int * field, ModelPanel * panel=NULL)
void setField(unsigned int & field, ModelPanel * panel=NULL)
{
this->field = field;
this->field = &field;
this->panel = panel;
for (int i=0; i<count(); ++i) {
setItemData(i, i);
if ((int)field == i)
setCurrentIndex(i);
}
}
protected slots:
@@ -50,4 +63,4 @@ class QUnsignedAutoComboBox: public QComboBox
bool lock;
};
#endif /* QAUTOCOMBOBOX_H_ */
#endif /* AUTOCOMBOBOX_H_ */
+78
View File
@@ -0,0 +1,78 @@
#ifndef AUTODOUBLESPINBOX_H_
#define AUTODOUBLESPINBOX_H_
#include <QDoubleSpinBox>
#include "modeledit/modeledit.h"
class AutoDoubleSpinBox: public QDoubleSpinBox
{
Q_OBJECT
public:
explicit AutoDoubleSpinBox(QWidget *parent = 0):
QDoubleSpinBox(parent),
field(NULL),
panel(NULL),
lock(false)
{
connect(this, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double)));
}
void setField(int & field, ModelPanel * panel=NULL)
{
this->field = &field;
this->panel = panel;
updateValue();
}
void setField(unsigned int & field, ModelPanel * panel=NULL)
{
this->field = (int *)&field;
this->panel = panel;
updateValue();
}
void updateValue()
{
if (field) {
setValue(float(*field)/multiplier());
}
}
void setDecimals(int prec)
{
QDoubleSpinBox::setDecimals(prec);
updateValue();
}
protected:
int multiplier()
{
switch (decimals()) {
case 1:
return 10;
case 2:
return 100;
default:
return 1;
}
}
protected slots:
void onValueChanged(double value)
{
if (field && !lock) {
*field = value * multiplier();
if (panel) {
emit panel->modified();
}
}
}
protected:
int * field;
ModelPanel * panel;
bool lock;
};
#endif /* AUTODOUBLESPINBOX_H_ */
+52
View File
@@ -0,0 +1,52 @@
#ifndef AUTOHEXSPINBOX_H_
#define AUTOHEXSPINBOX_H_
#include "hexspinbox.h"
#include "modeledit/modeledit.h"
class AutoHexSpinBox: public HexSpinBox
{
Q_OBJECT
public:
explicit AutoHexSpinBox(QWidget *parent = 0):
HexSpinBox(parent),
field(NULL),
panel(NULL),
lock(false)
{
connect(this, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
}
void setField(unsigned int & field, ModelPanel * panel=NULL)
{
this->field = &field;
this->panel = panel;
updateValue();
}
void updateValue()
{
if (field) {
setValue(*field);
}
}
protected slots:
void onValueChanged(int value)
{
if (field && !lock) {
*field = value;
if (panel) {
emit panel->modified();
}
}
}
protected:
unsigned int * field;
ModelPanel * panel;
bool lock;
};
#endif /* AUTOHEXSPINBOX_H_ */
+104
View File
@@ -0,0 +1,104 @@
#include "genericpanel.h"
#include <QComboBox>
#include <QEvent>
#include <QLabel>
#include <QGridLayout>
#include <QSpacerItem>
GenericPanel::GenericPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, FirmwareInterface * firmware):
QWidget(parent),
model(model),
generalSettings(generalSettings),
firmware(firmware),
lock(false)
{
}
GenericPanel::~GenericPanel()
{
}
void GenericPanel::update()
{
}
void GenericPanel::addLabel(QGridLayout *gridLayout, const QString &text, int col, bool minimize)
{
QLabel *label = new QLabel(this);
label->setFrameShape(QFrame::Panel);
label->setFrameShadow(QFrame::Raised);
label->setMidLineWidth(0);
label->setAlignment(Qt::AlignCenter);
label->setMargin(5);
label->setText(text);
if (!minimize)
label->setMinimumWidth(100);
gridLayout->addWidget(label, 0, col, 1, 1);
}
void GenericPanel::addEmptyLabel(QGridLayout * gridLayout, int col)
{
QLabel *label = new QLabel(this);
label->setText("");
gridLayout->addWidget(label, 0, col, 1, 1);
}
void GenericPanel::addHSpring(QGridLayout * gridLayout, int col, int row)
{
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
gridLayout->addItem(spacer, row, col);
}
void GenericPanel::addVSpring(QGridLayout * gridLayout, int col, int row)
{
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
gridLayout->addItem(spacer, row, col);
}
void GenericPanel::addDoubleSpring(QGridLayout * gridLayout, int col, int row)
{
QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding );
gridLayout->addItem(spacer, row, col);
}
bool GenericPanel::eventFilter(QObject *object, QEvent * event)
{
QWidget * widget = qobject_cast<QWidget*>(object);
if (widget) {
if (event->type() == QEvent::Wheel) {
if (widget->focusPolicy() == Qt::WheelFocus) {
event->accept();
return false;
}
else {
event->ignore();
return true;
}
}
else if (event->type() == QEvent::FocusIn) {
widget->setFocusPolicy(Qt::WheelFocus);
}
else if (event->type() == QEvent::FocusOut) {
widget->setFocusPolicy(Qt::StrongFocus);
}
}
return QWidget::eventFilter(object, event);
}
void GenericPanel::disableMouseScrolling()
{
Q_FOREACH(QComboBox * cb, findChildren<QComboBox*>()) {
cb->installEventFilter(this);
cb->setFocusPolicy(Qt::StrongFocus);
}
Q_FOREACH(QAbstractSpinBox * sb, findChildren<QAbstractSpinBox*>()) {
sb->installEventFilter(this);
sb->setFocusPolicy(Qt::StrongFocus);
}
Q_FOREACH(QSlider * slider, findChildren<QSlider*>()) {
slider->installEventFilter(this);
slider->setFocusPolicy(Qt::StrongFocus);
}
}
+45
View File
@@ -0,0 +1,45 @@
#ifndef GENERICPANEL_H_
#define GENERICPANEL_H_
#include <QWidget>
class ModelData;
class GeneralSettings;
class FirmwareInterface;
class QGridLayout;
class QString;
class GenericPanel : public QWidget
{
Q_OBJECT
friend class AutoComboBox;
friend class AutoDoubleSpinBox;
friend class AutoCheckBox;
friend class AutoHexSpinBox;
public:
GenericPanel(QWidget *parent, ModelData * model, GeneralSettings & generalSettings, FirmwareInterface * firmware);
virtual ~GenericPanel();
signals:
void modified();
public slots:
virtual void update();
protected:
ModelData * model;
GeneralSettings & generalSettings;
FirmwareInterface * firmware;
bool lock;
void addLabel(QGridLayout * gridLayout, const QString &text, int col, bool mimimize=false);
void addEmptyLabel(QGridLayout * gridLayout, int col);
void addHSpring(QGridLayout *, int col, int row);
void addVSpring(QGridLayout *, int col, int row);
void addDoubleSpring(QGridLayout *, int col, int row);
virtual bool eventFilter(QObject *obj, QEvent *event);
void disableMouseScrolling();
};
#endif
+23
View File
@@ -0,0 +1,23 @@
#include "verticalscrollarea.h"
#include "genericpanel.h"
#include <QEvent>
#include <QScrollBar>
VerticalScrollArea::VerticalScrollArea(QWidget * parent, GenericPanel * panel):
QScrollArea(parent),
panel(panel),
parent(parent)
{
setWidgetResizable(true);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setWidget(panel);
panel->installEventFilter(this);
}
bool VerticalScrollArea::eventFilter(QObject *o, QEvent *e)
{
if (o == panel && e->type() == QEvent::Resize) {
setMinimumWidth(panel->minimumSizeHint().width() + verticalScrollBar()->width());
}
return false;
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef VERTICALSCROLLAREA_H_
#define VERTICALSCROLLAREA_H_
#include <QScrollArea>
class GenericPanel;
class VerticalScrollArea : public QScrollArea
{
public:
VerticalScrollArea(QWidget * parent, GenericPanel * panel);
protected:
virtual bool eventFilter(QObject *o, QEvent *e);
private:
GenericPanel * panel;
QWidget * parent;
};
#endif