1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-14 11:59:50 +03:00

Input scale now added in Companion. I have broken all getStep / getMin /

getMax / getOffset used for custom switches and telemetry bars.
Everything needs to be tested again ...
This commit is contained in:
Bertrand Songis 2014-01-28 15:43:52 +01:00
parent 30b8a7e14b
commit f41f1a3f7b
16 changed files with 308 additions and 495 deletions

View file

@ -1300,13 +1300,13 @@ void compareDialog::printFrSky()
if (fd1->screens[0].type==fd2->screens[0].type) if (fd1->screens[0].type==fd2->screens[0].type)
color=getColor1(fd1->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].source); color=getColor1(fd1->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].source);
str.append("<td align=\"Center\"><font color="+color+">"+getFrSkySrc(fd1->screens[0].body.bars[i].source)+"</font></td>"); str.append("<td align=\"Center\"><font color="+color+">"+getFrSkySrc(fd1->screens[0].body.bars[i].source)+"</font></td>");
value1=getBarValue(fd1->screens[0].body.bars[i].source,fd1->screens[0].body.bars[i].barMin,fd1); // TODO value1 = getBarValue(fd1->screens[0].body.bars[i].source,fd1->screens[0].body.bars[i].barMin,fd1);
value2=getBarValue(fd2->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].barMin,fd2); // TODO value2 = getBarValue(fd2->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].barMin,fd2);
if (fd1->screens[0].type==fd2->screens[0].type) if (fd1->screens[0].type==fd2->screens[0].type)
color=getColor1(value1,value2); color=getColor1(value1,value2);
str.append("<td align=\"Right\"><font color="+color+">"+QString::number(value1)+"</td>"); str.append("<td align=\"Right\"><font color="+color+">"+QString::number(value1)+"</td>");
value1=getBarValue(fd1->screens[0].body.bars[i].source,fd1->screens[0].body.bars[i].barMax,fd1); // TODO value1=getBarValue(fd1->screens[0].body.bars[i].source,fd1->screens[0].body.bars[i].barMax,fd1);
value2=getBarValue(fd2->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].barMax,fd2); // TODO value2=getBarValue(fd2->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].barMax,fd2);
if (fd1->screens[0].type==fd2->screens[0].type) if (fd1->screens[0].type==fd2->screens[0].type)
color=getColor1(value1,value2); color=getColor1(value1,value2);
str.append("<td align=\"Right\"><font color="+color+">"+QString::number(value1)+"</td></tr>"); str.append("<td align=\"Right\"><font color="+color+">"+QString::number(value1)+"</td></tr>");
@ -1418,13 +1418,13 @@ void compareDialog::printFrSky()
if (fd1->screens[0].type==fd2->screens[0].type) if (fd1->screens[0].type==fd2->screens[0].type)
color=getColor2(fd1->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].source); color=getColor2(fd1->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].source);
str.append("<td align=\"Center\"><font color="+color+">"+getFrSkySrc(fd2->screens[0].body.bars[i].source)+"</font></td>"); str.append("<td align=\"Center\"><font color="+color+">"+getFrSkySrc(fd2->screens[0].body.bars[i].source)+"</font></td>");
value1=getBarValue(fd1->screens[0].body.bars[i].source,fd1->screens[0].body.bars[i].barMin,fd1); // TODO value1=getBarValue(fd1->screens[0].body.bars[i].source,fd1->screens[0].body.bars[i].barMin,fd1);
value2=getBarValue(fd2->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].barMin,fd2); // TODO value2=getBarValue(fd2->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].barMin,fd2);
if (fd1->screens[0].type==fd2->screens[0].type) if (fd1->screens[0].type==fd2->screens[0].type)
color=getColor2(value1,value2); color=getColor2(value1,value2);
str.append("<td align=\"Right\"><font color="+color+">"+QString::number(value2)+"</font></td>"); str.append("<td align=\"Right\"><font color="+color+">"+QString::number(value2)+"</font></td>");
value1=getBarValue(fd1->screens[0].body.bars[i].source,fd1->screens[0].body.bars[i].barMax,fd1); // TODO value1=getBarValue(fd1->screens[0].body.bars[i].source,fd1->screens[0].body.bars[i].barMax,fd1);
value2=getBarValue(fd2->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].barMax,fd2); // TODO value2=getBarValue(fd2->screens[0].body.bars[i].source,fd2->screens[0].body.bars[i].barMax,fd2);
if (fd1->screens[0].type==fd2->screens[0].type) if (fd1->screens[0].type==fd2->screens[0].type)
color=getColor2(value1,value2); color=getColor2(value1,value2);
str.append("<td align=\"Right\"><font color="+color+">"+QString::number(value2)+"</font></td></tr>"); str.append("<td align=\"Right\"><font color="+color+">"+QString::number(value2)+"</font></td></tr>");

View file

@ -37,146 +37,124 @@ void getEEPROMString(char *dst, const char *src, int size)
} }
} }
int RawSource::getDecimals(const ModelData & Model) RawSourceRange RawSource::getRange()
{ {
if(type==SOURCE_TYPE_TELEMETRY) { RawSourceRange result;
switch (index) {
case TELEMETRY_SOURCE_A1: int board = GetEepromInterface()->getBoard();
case TELEMETRY_SOURCE_A2:
return (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].type==0 ? 2: 0);
case TELEMETRY_SOURCE_CELL:
return 2;
case TELEMETRY_SOURCE_CELLS_SUM:
case TELEMETRY_SOURCE_VFAS:
case TELEMETRY_SOURCE_CURRENT:
return 1;
default:
return 0;
}
}
return 0;
}
double RawSource::getMin(const ModelData & Model)
{
switch (type) { switch (type) {
case SOURCE_TYPE_TELEMETRY: case SOURCE_TYPE_TELEMETRY:
switch (index) { switch (index) {
/*case TELEMETRY_SOURCE_NONE:
case TELEMETRY_SOURCE_TX_BATT: case TELEMETRY_SOURCE_TX_BATT:
result.step = 0.1;
result.decimals = 1;
result.max = 25.5;
break;
case TELEMETRY_SOURCE_TIMER1: case TELEMETRY_SOURCE_TIMER1:
case TELEMETRY_SOURCE_TIMER2: case TELEMETRY_SOURCE_TIMER2:
return 0; */ result.step = IS_TARANIS(board) ? 1 : 3;
case TELEMETRY_SOURCE_A1: result.max = 765;
case TELEMETRY_SOURCE_A2: break;
if (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].type==0) {
return (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].offset*Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio)/2550.0;
}
else {
return (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].offset*Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio)/255.0;
}
case TELEMETRY_SOURCE_ALT:
case TELEMETRY_SOURCE_GPS_ALT:
return -500;
case TELEMETRY_SOURCE_T1:
case TELEMETRY_SOURCE_T2:
return -30;
default:
return 0;
}
break;
default:
return (Model.extendedLimits ? -125 :-100);
}
}
double RawSource::getMax(const ModelData & Model)
{
switch (type) {
case SOURCE_TYPE_TELEMETRY:
switch (index) {
case TELEMETRY_SOURCE_TIMER1:
case TELEMETRY_SOURCE_TIMER2:
return 765;
case TELEMETRY_SOURCE_RSSI_TX: case TELEMETRY_SOURCE_RSSI_TX:
case TELEMETRY_SOURCE_RSSI_RX: case TELEMETRY_SOURCE_RSSI_RX:
return 100; result.max = 100;
break;
case TELEMETRY_SOURCE_A1: case TELEMETRY_SOURCE_A1:
case TELEMETRY_SOURCE_A2: case TELEMETRY_SOURCE_A2:
if (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].type==0) { if (model) {
return (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio-(Model.frsky.channels[index-TELEMETRY_SOURCE_A1].offset*Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio)/255.0)/10; if (model->frsky.channels[index-TELEMETRY_SOURCE_A1].type==0) {
} else { result.step = (model->frsky.channels[index-TELEMETRY_SOURCE_A1].ratio / 2550.0);
return Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio-(Model.frsky.channels[index-TELEMETRY_SOURCE_A1].offset*Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio)/255.0; result.min = (model->frsky.channels[index-TELEMETRY_SOURCE_A1].offset * model->frsky.channels[index-TELEMETRY_SOURCE_A1].ratio) / 2550.0;
result.max = model->frsky.channels[index-TELEMETRY_SOURCE_A1].ratio - (model->frsky.channels[index-TELEMETRY_SOURCE_A1].offset * model->frsky.channels[index-TELEMETRY_SOURCE_A1].ratio) / 2550.0;
result.decimals = 2;
// result.offset = result.min;
}
else {
result.step = (model->frsky.channels[index-TELEMETRY_SOURCE_A1].ratio / 255.0);
result.min = (model->frsky.channels[index-TELEMETRY_SOURCE_A1].offset *model->frsky.channels[index-TELEMETRY_SOURCE_A1].ratio) / 255.0;
result.max = model->frsky.channels[index-TELEMETRY_SOURCE_A1].ratio - (model->frsky.channels[index-TELEMETRY_SOURCE_A1].offset * model->frsky.channels[index-TELEMETRY_SOURCE_A1].ratio) / 255.0;
result.decimals = 0;
// result.offset = result.min;
}
} }
break;
case TELEMETRY_SOURCE_ALT: case TELEMETRY_SOURCE_ALT:
case TELEMETRY_SOURCE_GPS_ALT: case TELEMETRY_SOURCE_GPS_ALT:
return 1540; result.step = IS_TARANIS(board) ? 1 : 8;
case TELEMETRY_SOURCE_RPM: result.min = -500;
return 12750; result.max = 1540;
case TELEMETRY_SOURCE_FUEL: // result.offset = 524;
return 100; break;
case TELEMETRY_SOURCE_T1: case TELEMETRY_SOURCE_T1:
case TELEMETRY_SOURCE_T2: case TELEMETRY_SOURCE_T2:
return 225; result.min = -30;
result.max = 225;
// result.offset = 98;
break;
case TELEMETRY_SOURCE_RPM:
result.step = IS_TARANIS(board) ? 1 : 50;
result.max = 12750;
// result.offset = 6400;
break;
case TELEMETRY_SOURCE_FUEL:
result.max = 100;
break;
case TELEMETRY_SOURCE_SPEED: case TELEMETRY_SOURCE_SPEED:
return 944; result.step = IS_TARANIS(board) ? 1 : 4;
result.max = 944;
// result.offset = 474;
if (model && !model->frsky.imperial) {
result.step *= 1.852;
result.max *= 1.852;
}
break;
case TELEMETRY_SOURCE_DIST: case TELEMETRY_SOURCE_DIST:
return 2040; result.step = IS_TARANIS(board) ? 1 : 8;
result.max = 2040;
// result.offset = 1024;
break;
case TELEMETRY_SOURCE_CELL: case TELEMETRY_SOURCE_CELL:
return 5.1; result.step = IS_TARANIS(board) ? 0.01 : 0.02;
result.max = 5.1;
result.decimals = 2;
// result.offset = 2.56;
break;
case TELEMETRY_SOURCE_CELLS_SUM: case TELEMETRY_SOURCE_CELLS_SUM:
case TELEMETRY_SOURCE_VFAS: case TELEMETRY_SOURCE_VFAS:
return 25.5; result.step = 0.1;
result.max = 25.5;
result.decimals = 1;
break;
case TELEMETRY_SOURCE_CURRENT: case TELEMETRY_SOURCE_CURRENT:
return 127.5; result.step = IS_TARANIS(board) ? 0.1 : 0.5;
result.max = 127.5;
result.decimals = 1;
break;
case TELEMETRY_SOURCE_CONSUMPTION: case TELEMETRY_SOURCE_CONSUMPTION:
return 5100; result.step = IS_TARANIS(board) ? 1 : 20;
result.max = 5100;
break;
case TELEMETRY_SOURCE_POWER: case TELEMETRY_SOURCE_POWER:
return 1275; result.step = IS_TARANIS(board) ? 1 : 5;
result.max = 1275;
break;
default: default:
return 125; result.max = 125;
break;
} }
break; break;
default: default:
return (Model.extendedLimits ? 125 :100); result.max = (model && model->extendedLimits ? 125 : 100);
result.min = - result.max;
break;
} }
return result;
} }
double RawSource::getOffset(const ModelData & Model) #if 0
{
if (type==SOURCE_TYPE_TELEMETRY) {
switch (index) {
case TELEMETRY_SOURCE_A1:
case TELEMETRY_SOURCE_A2:
if (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].type==0) {
return (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].offset*Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio)/2550.0;
}
else {
return (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].offset*Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio)/255.0;
}
case TELEMETRY_SOURCE_ALT:
case TELEMETRY_SOURCE_GPS_ALT:
return 524;
case TELEMETRY_SOURCE_RPM:
return 6400;
case TELEMETRY_SOURCE_FUEL:
return 0;
case TELEMETRY_SOURCE_T1:
case TELEMETRY_SOURCE_T2:
return 98;
case TELEMETRY_SOURCE_SPEED:
return 474;
case TELEMETRY_SOURCE_DIST:
return 1024;
case TELEMETRY_SOURCE_CELL:
return 2.56;
default:
return 0;
}
}
return 0;
}
int RawSource::getRawOffset(const ModelData & Model) int RawSource::getRawOffset(const ModelData & Model)
{ {
switch (type) { switch (type) {
@ -202,51 +180,7 @@ int RawSource::getRawOffset(const ModelData & Model)
return 0; return 0;
} }
} }
#endif
double RawSource::getStep(const ModelData & Model)
{
switch (type) {
case SOURCE_TYPE_TELEMETRY:
switch (index) {
case TELEMETRY_SOURCE_TIMER1:
case TELEMETRY_SOURCE_TIMER2:
return 3;
case TELEMETRY_SOURCE_A1:
case TELEMETRY_SOURCE_A2:
if (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].type==0) {
return (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio/2550.0);
}
else {
return (Model.frsky.channels[index-TELEMETRY_SOURCE_A1].ratio/255.0);
}
case TELEMETRY_SOURCE_ALT:
case TELEMETRY_SOURCE_GPS_ALT:
return 8;
case TELEMETRY_SOURCE_RPM:
return 50;
case TELEMETRY_SOURCE_SPEED:
return 4;
case TELEMETRY_SOURCE_DIST:
return 8;
case TELEMETRY_SOURCE_CELL:
return 0.02;
case TELEMETRY_SOURCE_CELLS_SUM:
case TELEMETRY_SOURCE_VFAS:
return 0.1;
case TELEMETRY_SOURCE_CURRENT:
return 0.5;
case TELEMETRY_SOURCE_CONSUMPTION:
return 20;
case TELEMETRY_SOURCE_POWER:
return 5;
default:
return 1;
}
break;
default:
return 1;
}
}
QString AnalogString(int index) QString AnalogString(int index)
{ {

View file

@ -283,6 +283,30 @@ class ModelData;
QString AnalogString(int index); QString AnalogString(int index);
QString RotaryEncoderString(int index); QString RotaryEncoderString(int index);
class RawSourceRange
{
public:
RawSourceRange():
decimals(0),
min(0.0),
max(0.0),
step(1.0),
offset(0.0)
{
}
float getValue(int value) {
return round(float(value) * step);
}
int decimals;
double min;
double max;
double step;
double offset;
};
class RawSource { class RawSource {
public: public:
RawSource(): RawSource():
@ -313,17 +337,16 @@ class RawSource {
QString toString(); QString toString();
int getDecimals(const ModelData & Model); RawSourceRange getRange();
double getMin(const ModelData & Model);
double getMax(const ModelData & Model);
double getStep(const ModelData & Model);
double getOffset(const ModelData & Model);
int getRawOffset(const ModelData & Model);
bool operator== ( const RawSource& other) { bool operator == ( const RawSource & other) {
return (this->type == other.type) && (this->index == other.index); return (this->type == other.type) && (this->index == other.index);
} }
bool operator != ( const RawSource & other) {
return (this->type != other.type) || (this->index != other.index);
}
RawSourceType type; RawSourceType type;
int index; int index;
const ModelData * model; const ModelData * model;
@ -982,7 +1005,6 @@ enum Capability {
GvarsAreNamed, GvarsAreNamed,
GvarsFlightPhases, GvarsFlightPhases,
GvarsHaveSources, GvarsHaveSources,
GvarsAsSources,
GvarsName, GvarsName,
NoTelemetryProtocol, NoTelemetryProtocol,
TelemetryCSFields, TelemetryCSFields,

View file

@ -282,7 +282,6 @@ int Er9xInterface::getCapability(const Capability capability)
case Gvars: case Gvars:
return 7; return 7;
case GvarsHaveSources: case GvarsHaveSources:
case GvarsAsSources:
return 1; return 1;
case GetThrSwitch: case GetThrSwitch:
return DSW_THR; return DSW_THR;

View file

@ -318,7 +318,6 @@ int Ersky9xInterface::getCapability(const Capability capability)
case MaxVolume: case MaxVolume:
return 23; return 23;
case GvarsHaveSources: case GvarsHaveSources:
case GvarsAsSources:
return 1; return 1;
case TelemetryMaxMultiplier: case TelemetryMaxMultiplier:
return 2; return 2;

View file

@ -201,7 +201,7 @@ class SourcesConversionTable: public ConversionTable {
if (!(flags & FLAG_NOTELEMETRY)) { if (!(flags & FLAG_NOTELEMETRY)) {
if (release21March2013) { if (release21March2013) {
if ((board != BOARD_STOCK && (board!=BOARD_M128 || version<215)) || (variant & GVARS_VARIANT)) { if ((board != BOARD_STOCK && (board!=BOARD_M128 || version<215)) || (variant & GVARS_VARIANT)) {
for (int i=0; i<5; i++) for (int i=0; i<MAX_GVARS(board, version); i++)
addConversion(RawSource(SOURCE_TYPE_GVAR, i), val++); addConversion(RawSource(SOURCE_TYPE_GVAR, i), val++);
} }
} }

View file

@ -175,6 +175,7 @@ QString getFuncName(unsigned int val)
} }
} }
// TODO should be a toString() method in CustoSwData ...
QString getCustomSwitchStr(CustomSwData * customSw, const ModelData & model) QString getCustomSwitchStr(CustomSwData * customSw, const ModelData & model)
{ {
QString result = ""; QString result = "";
@ -189,7 +190,8 @@ QString getCustomSwitchStr(CustomSwData * customSw, const ModelData & model)
result = QString("TIM(%1 , %2)").arg(ValToTim(customSw->val1)).arg(ValToTim(customSw->val2)); result = QString("TIM(%1 , %2)").arg(ValToTim(customSw->val1)).arg(ValToTim(customSw->val2));
break; break;
case CS_FAMILY_VOFS: { case CS_FAMILY_VOFS: {
RawSource source = RawSource(customSw->val1); RawSource source = RawSource(customSw->val1, &model);
RawSourceRange range = source.getRange();
if (customSw->val1) if (customSw->val1)
result += source.toString(); result += source.toString();
else else
@ -204,7 +206,7 @@ QString getCustomSwitchStr(CustomSwData * customSw, const ModelData & model)
result += " &gt; "; result += " &gt; ";
else if (customSw->func == CS_FN_ANEG || customSw->func == CS_FN_VNEG) else if (customSw->func == CS_FN_ANEG || customSw->func == CS_FN_VNEG)
result += " &lt; "; result += " &lt; ";
result += QString::number(source.getStep(model) * (customSw->val2 + source.getRawOffset(model)) + source.getOffset(model)); result += QString::number(range.step * (customSw->val2 /*TODO+ source.getRawOffset(model)*/) + range.offset);
break; break;
} }
case CS_FAMILY_VBOOL: case CS_FAMILY_VBOOL:
@ -1313,109 +1315,6 @@ QString getFrSkySrc(int index)
return RawSource(SOURCE_TYPE_TELEMETRY, index-1).toString(); return RawSource(SOURCE_TYPE_TELEMETRY, index-1).toString();
} }
/*
1,2) Timer1/Timer2 0:765
3,4) TX/RX
5) A1 range
6) A2 range
7) ALT 0-1020
8)RPM 0-12750
9FUEL 0-100%
10) T1 -30-225
11) T2 -30-225
12) spd 0-510
13) dist 0-2040
14)GAlt 0-1020
15) cell 0-5.1
16) Cels 0 25.5
17) Vfas 0 25.5
18) Curr 0 127.5
19) Cnsp 0 5100
20) Powr 0 1275
21) AccX 0 2.55
22) AccY 0 2.55
23) AccZ 0 2.55
24) Hdg 0 255
25) VSpd 0 2.55
26) A1- A1 range
27) A2- A2 range
28) Alt- 0 255
29) Alt+ 0 255
30) Rpm+ 0 255
31) T1+ 0 255 (s????)
32) T2+ 0 255 (e????)
33) Spd+ 0 255 (ILG???)
34) Dst+ 0 255 (v ????)
35) Cur+ 0 25.5 (A)
1.852
*/
float getBarValue(int barId, int value, FrSkyData *fd)
{
switch (barId-1) {
case TELEMETRY_SOURCE_TX_BATT:
return value/10.0;
case TELEMETRY_SOURCE_TIMER1:
case TELEMETRY_SOURCE_TIMER2:
return (3*value);
case TELEMETRY_SOURCE_RSSI_TX:
case TELEMETRY_SOURCE_RSSI_RX:
case TELEMETRY_SOURCE_FUEL:
return std::min(100, value);
case TELEMETRY_SOURCE_A1:
case TELEMETRY_SOURCE_A1_MIN:
if (fd->channels[0].type==0)
return ((fd->channels[0].ratio*value/255.0)+fd->channels[0].offset)/10;
else
return ((fd->channels[0].ratio*value/255.0)+fd->channels[0].offset);
case TELEMETRY_SOURCE_A2:
case TELEMETRY_SOURCE_A2_MIN:
if (fd->channels[1].type==0)
return ((fd->channels[1].ratio*value/255.0)+fd->channels[1].offset)/10;
else
return ((fd->channels[1].ratio*value/255.0)+fd->channels[1].offset);
case TELEMETRY_SOURCE_ALT:
case TELEMETRY_SOURCE_GPS_ALT:
case TELEMETRY_SOURCE_ALT_MAX:
case TELEMETRY_SOURCE_ALT_MIN:
return (8*value)-500;
case TELEMETRY_SOURCE_RPM:
case TELEMETRY_SOURCE_RPM_MAX:
return value * 50;
case TELEMETRY_SOURCE_T1:
case TELEMETRY_SOURCE_T2:
case TELEMETRY_SOURCE_T1_MAX:
case TELEMETRY_SOURCE_T2_MAX:
return value - 30.0;
case TELEMETRY_SOURCE_CELL:
return value*2.0/100;
case TELEMETRY_SOURCE_CELLS_SUM:
case TELEMETRY_SOURCE_VFAS:
return value/10.0;
case TELEMETRY_SOURCE_HDG:
return std::min(359, value*2);
case TELEMETRY_SOURCE_DIST_MAX:
case TELEMETRY_SOURCE_DIST:
return value * 8;
case TELEMETRY_SOURCE_CURRENT_MAX:
case TELEMETRY_SOURCE_CURRENT:
return value/2.0;
case TELEMETRY_SOURCE_POWER:
return value*5;
case TELEMETRY_SOURCE_CONSUMPTION:
return value * 20;
case TELEMETRY_SOURCE_SPEED:
case TELEMETRY_SOURCE_SPEED_MAX:
if (fd->imperial==1)
return value;
else
return value*1.852;
default:
return value;
}
}
QString getTrimInc(ModelData * g_model) QString getTrimInc(ModelData * g_model)
{ {
switch (g_model->trimInc) { switch (g_model->trimInc) {

View file

@ -137,7 +137,7 @@ QString getFrSkyUnits(int units);
QString getFrSkyProtocol(int protocol); QString getFrSkyProtocol(int protocol);
QString getFrSkyMeasure(int units); QString getFrSkyMeasure(int units);
QString getFrSkySrc(int index); QString getFrSkySrc(int index);
float getBarValue(int barId, int value, FrSkyData *fd);
float c9xexpou(float point, float coeff); float c9xexpou(float point, float coeff);
float ValToTim(int value); float ValToTim(int value);
int TimToVal(float value); int TimToVal(float value);

View file

@ -146,36 +146,43 @@ void CustomSwitchesPanel::edited()
{ {
case (CS_FAMILY_VOFS): case (CS_FAMILY_VOFS):
if (model.customSw[i].val1 != cswitchSource1[i]->itemData(cswitchSource1[i]->currentIndex()).toInt()) { if (model.customSw[i].val1 != cswitchSource1[i]->itemData(cswitchSource1[i]->currentIndex()).toInt()) {
source=RawSource(model.customSw[i].val1); source = RawSource(model.customSw[i].val1, &model);
model.customSw[i].val1 = cswitchSource1[i]->itemData(cswitchSource1[i]->currentIndex()).toInt(); model.customSw[i].val1 = cswitchSource1[i]->itemData(cswitchSource1[i]->currentIndex()).toInt();
RawSource newSource = RawSource(model.customSw[i].val1); RawSource newSource = RawSource(model.customSw[i].val1, &model);
if (newSource.type == SOURCE_TYPE_TELEMETRY) { if (newSource.type == SOURCE_TYPE_TELEMETRY) {
if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].func<CS_FN_VEQUAL) { if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].func<CS_FN_VEQUAL) {
model.customSw[i].val2 = 0; model.customSw[i].val2 = 0;
} else { }
else {
model.customSw[i].val2 = -128; model.customSw[i].val2 = -128;
} }
} else { }
else {
RawSourceRange range = source.getRange();
if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].func<CS_FN_VEQUAL) { if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].func<CS_FN_VEQUAL) {
model.customSw[i].val2 = (cswitchOffset[i]->value()/source.getStep(model)); model.customSw[i].val2 = (cswitchOffset[i]->value() / range.step);
} else { }
model.customSw[i].val2 = ((cswitchOffset[i]->value()-source.getOffset(model))/source.getStep(model))-source.getRawOffset(model); else {
model.customSw[i].val2 = (cswitchOffset[i]->value() - range.offset) / range.step/* TODO - source.getRawOffset(model)*/;
} }
} }
setSwitchWidgetVisibility(i); setSwitchWidgetVisibility(i);
} else { }
source=RawSource(model.customSw[i].val1); else {
source = RawSource(model.customSw[i].val1, &model);
RawSourceRange range = source.getRange();
if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].func<CS_FN_VEQUAL) { if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].func<CS_FN_VEQUAL) {
model.customSw[i].val2 = (cswitchOffset[i]->value()/source.getStep(model)); model.customSw[i].val2 = (cswitchOffset[i]->value() / range.step);
cswitchOffset[i]->setValue(model.customSw[i].val2*source.getStep(model)); cswitchOffset[i]->setValue(model.customSw[i].val2*range.step);
} else { }
model.customSw[i].val2 = ((cswitchOffset[i]->value()-source.getOffset(model))/source.getStep(model))-source.getRawOffset(model); else {
cswitchOffset[i]->setValue((model.customSw[i].val2 +source.getRawOffset(model))*source.getStep(model)+source.getOffset(model)); model.customSw[i].val2 = ((cswitchOffset[i]->value()-range.offset)/range.step)/* TODO - source.getRawOffset(model)*/;
cswitchOffset[i]->setValue((model.customSw[i].val2 /* + TODO source.getRawOffset(model)*/)*range.step+range.offset);
} }
} }
break; break;
case (CS_FAMILY_TIMERS): { case (CS_FAMILY_TIMERS): {
value=cswitchOffset[i]->value(); value = cswitchOffset[i]->value();
newval=TimToVal(value); newval=TimToVal(value);
if (newval>model.customSw[i].val2) { if (newval>model.customSw[i].val2) {
if (value >=60) { if (value >=60) {
@ -246,7 +253,9 @@ void CustomSwitchesPanel::edited()
void CustomSwitchesPanel::setSwitchWidgetVisibility(int i) void CustomSwitchesPanel::setSwitchWidgetVisibility(int i)
{ {
RawSource source = RawSource(model.customSw[i].val1); RawSource source = RawSource(model.customSw[i].val1, &model);
RawSourceRange range = source.getRange();
switch (getCSFunctionFamily(model.customSw[i].func)) switch (getCSFunctionFamily(model.customSw[i].func))
{ {
case CS_FAMILY_VOFS: case CS_FAMILY_VOFS:
@ -255,16 +264,16 @@ void CustomSwitchesPanel::setSwitchWidgetVisibility(int i)
cswitchValue[i]->setVisible(false); cswitchValue[i]->setVisible(false);
cswitchOffset[i]->setVisible(true); cswitchOffset[i]->setVisible(true);
populateSourceCB(cswitchSource1[i], source, model, POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | POPULATE_TELEMETRY | (GetEepromInterface()->getCapability(GvarsInCS) ? POPULATE_GVARS : 0)); populateSourceCB(cswitchSource1[i], source, model, POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_TRIMS | POPULATE_SWITCHES | POPULATE_TELEMETRY | (GetEepromInterface()->getCapability(GvarsInCS) ? POPULATE_GVARS : 0));
cswitchOffset[i]->setDecimals(source.getDecimals(model)); cswitchOffset[i]->setDecimals(range.decimals);
cswitchOffset[i]->setSingleStep(source.getStep(model)); cswitchOffset[i]->setSingleStep(range.step);
if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].func<CS_FN_VEQUAL) { if (model.customSw[i].func>CS_FN_ELESS && model.customSw[i].func<CS_FN_VEQUAL) {
cswitchOffset[i]->setMinimum(source.getStep(model)*-127); cswitchOffset[i]->setMinimum(range.step*-127);
cswitchOffset[i]->setMaximum(source.getStep(model)*127); cswitchOffset[i]->setMaximum(range.step*127);
cswitchOffset[i]->setValue(source.getStep(model)*model.customSw[i].val2); cswitchOffset[i]->setValue(range.step*model.customSw[i].val2);
} else { } else {
cswitchOffset[i]->setMinimum(source.getMin(model)); cswitchOffset[i]->setMinimum(range.min);
cswitchOffset[i]->setMaximum(source.getMax(model)); cswitchOffset[i]->setMaximum(range.max);
cswitchOffset[i]->setValue(source.getStep(model)*(model.customSw[i].val2+source.getRawOffset(model))+source.getOffset(model)); cswitchOffset[i]->setValue(range.step*(model.customSw[i].val2/* TODO+source.getRawOffset(model)*/)+range.offset);
} }
break; break;
case CS_FAMILY_VBOOL: case CS_FAMILY_VBOOL:

View file

@ -48,7 +48,7 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, i
ui->sideLabel->hide(); ui->sideLabel->hide();
ui->sideCB->hide(); ui->sideCB->hide();
ui->inputName->setMaxLength(4); ui->inputName->setMaxLength(4);
populateSourceCB(ui->sourceCB, ed->srcRaw, model, POPULATE_SOURCES | POPULATE_SWITCHES | POPULATE_TRIMS | (GetEepromInterface()->getCapability(GvarsAsSources) ? POPULATE_GVARS : 0)); populateSourceCB(ui->sourceCB, ed->srcRaw, model, POPULATE_SOURCES | POPULATE_SWITCHES | POPULATE_TRIMS | POPULATE_TELEMETRY);
ui->sourceCB->removeItem(0); ui->sourceCB->removeItem(0);
} }
else { else {
@ -56,8 +56,6 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, i
ui->inputName->hide(); ui->inputName->hide();
ui->sourceLabel->hide(); ui->sourceLabel->hide();
ui->sourceCB->hide(); ui->sourceCB->hide();
ui->scaleLabel->hide();
ui->scaleSB->hide();
ui->trimLabel->hide(); ui->trimLabel->hide();
ui->trimCB->hide(); ui->trimCB->hide();
} }
@ -83,13 +81,15 @@ ExpoDialog::ExpoDialog(QWidget *parent, ModelData & model, ExpoData *expoData, i
ui->lineName->setValidator(new QRegExpValidator(rx, this)); ui->lineName->setValidator(new QRegExpValidator(rx, this));
ui->lineName->setText(ed->name); ui->lineName->setText(ed->name);
updateScale();
valuesChanged(); valuesChanged();
connect(ui->lineName,SIGNAL(editingFinished()), this, SLOT(valuesChanged())); connect(ui->lineName, SIGNAL(editingFinished()), this, SLOT(valuesChanged()));
connect(ui->sourceCB,SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged())); connect(ui->sourceCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));
connect(ui->trimCB,SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged())); connect(ui->scale, SIGNAL(editingFinished()), this, SLOT(valuesChanged()));
connect(ui->switchesCB,SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged())); connect(ui->trimCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));
connect(ui->sideCB,SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged())); connect(ui->switchesCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));
connect(ui->sideCB, SIGNAL(currentIndexChanged(int)), this, SLOT(valuesChanged()));
for (int i=0; i<9; i++) { for (int i=0; i<9; i++) {
connect(cb_fp[i], SIGNAL(toggled(bool)), this, SLOT(valuesChanged())); connect(cb_fp[i], SIGNAL(toggled(bool)), this, SLOT(valuesChanged()));
} }
@ -103,23 +103,35 @@ ExpoDialog::~ExpoDialog()
delete ui; delete ui;
} }
void ExpoDialog::changeEvent(QEvent *e) void ExpoDialog::updateScale()
{ {
QDialog::changeEvent(e); if (GetEepromInterface()->getCapability(VirtualInputs) && ed->srcRaw.type == SOURCE_TYPE_TELEMETRY) {
switch (e->type()) { RawSourceRange range = ed->srcRaw.getRange();
case QEvent::LanguageChange: ui->scaleLabel->show();
ui->retranslateUi(this); ui->scale->show();
break; ui->scale->setDecimals(range.decimals);
default: ui->scale->setMinimum(range.min);
break; ui->scale->setMaximum(range.max);
} ui->scale->setValue(round(range.step * ed->scale));
}
else {
ui->scaleLabel->hide();
ui->scale->hide();
}
} }
void ExpoDialog::valuesChanged() void ExpoDialog::valuesChanged()
{ {
QCheckBox * cb_fp[] = {ui->cb_FP0,ui->cb_FP1,ui->cb_FP2,ui->cb_FP3,ui->cb_FP4,ui->cb_FP5,ui->cb_FP6,ui->cb_FP7,ui->cb_FP8 }; QCheckBox * cb_fp[] = {ui->cb_FP0,ui->cb_FP1,ui->cb_FP2,ui->cb_FP3,ui->cb_FP4,ui->cb_FP5,ui->cb_FP6,ui->cb_FP7,ui->cb_FP8 };
ed->srcRaw = RawSource(ui->sourceCB->itemData(ui->sourceCB->currentIndex()).toInt()); RawSource srcRaw = RawSource(ui->sourceCB->itemData(ui->sourceCB->currentIndex()).toInt());
if (ed->srcRaw != srcRaw) {
ed->srcRaw = srcRaw;
updateScale();
}
RawSourceRange range = srcRaw.getRange();
ed->scale = round(float(ui->scale->value()) / range.step);
ed->carryTrim = 1 - ui->trimCB->currentIndex(); ed->carryTrim = 1 - ui->trimCB->currentIndex();
ed->swtch = RawSwitch(ui->switchesCB->itemData(ui->switchesCB->currentIndex()).toInt()); ed->swtch = RawSwitch(ui->switchesCB->itemData(ui->switchesCB->currentIndex()).toInt());
ed->mode = ui->sideCB->currentIndex() + 1; ed->mode = ui->sideCB->currentIndex() + 1;
@ -173,5 +185,5 @@ void ExpoDialog::valuesChanged()
void ExpoDialog::shrink() void ExpoDialog::shrink()
{ {
resize(0,0); resize(0, 0);
} }

View file

@ -18,7 +18,7 @@ class ExpoDialog : public QDialog {
~ExpoDialog(); ~ExpoDialog();
protected: protected:
void changeEvent(QEvent *e); void updateScale();
private slots: private slots:
void valuesChanged(); void valuesChanged();

View file

@ -330,7 +330,7 @@ If blank then the input is considered to be &quot;ON&quot; all the time.</string
</spacer> </spacer>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QDoubleSpinBox" name="scaleSB"> <widget class="QDoubleSpinBox" name="scale">
<property name="whatsThis"> <property name="whatsThis">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
@ -441,6 +441,32 @@ p, li { white-space: pre-wrap; }
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>inputName</tabstop>
<tabstop>lineName</tabstop>
<tabstop>sourceCB</tabstop>
<tabstop>scale</tabstop>
<tabstop>trimCB</tabstop>
<tabstop>weightGV</tabstop>
<tabstop>weightSB</tabstop>
<tabstop>weightCB</tabstop>
<tabstop>curveTypeCB</tabstop>
<tabstop>curveGVarCB</tabstop>
<tabstop>curveValueCB</tabstop>
<tabstop>curveValueSB</tabstop>
<tabstop>cb_FP0</tabstop>
<tabstop>cb_FP1</tabstop>
<tabstop>cb_FP2</tabstop>
<tabstop>cb_FP3</tabstop>
<tabstop>cb_FP4</tabstop>
<tabstop>cb_FP5</tabstop>
<tabstop>cb_FP6</tabstop>
<tabstop>cb_FP7</tabstop>
<tabstop>cb_FP8</tabstop>
<tabstop>switchesCB</tabstop>
<tabstop>sideCB</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources> <resources>
<include location="../companion.qrc"/> <include location="../companion.qrc"/>
</resources> </resources>

View file

@ -20,7 +20,7 @@ MixerDialog::MixerDialog(QWidget *parent, ModelData & model, MixData *mixdata, i
else else
this->setWindowTitle(tr("DEST -> CH%1%2").arg(md->destCh/10).arg(md->destCh%10)); this->setWindowTitle(tr("DEST -> CH%1%2").arg(md->destCh/10).arg(md->destCh%10));
populateSourceCB(ui->sourceCB, md->srcRaw, model, POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_SWITCHES | POPULATE_TRIMS | (GetEepromInterface()->getCapability(GvarsAsSources) ? POPULATE_GVARS : 0)); populateSourceCB(ui->sourceCB, md->srcRaw, model, POPULATE_SOURCES | POPULATE_VIRTUAL_INPUTS | POPULATE_SWITCHES | POPULATE_TRIMS);
ui->sourceCB->removeItem(0); ui->sourceCB->removeItem(0);
int limit = GetEepromInterface()->getCapability(OffsetWeight); int limit = GetEepromInterface()->getCapability(OffsetWeight);

View file

@ -530,44 +530,27 @@ void TelemetryPanel::setup()
int screen = j/4; int screen = j/4;
int field = j%4; int field = j%4;
populateCustomScreenFieldCB(barsCB[j], model.frsky.screens[screen].body.bars[field].source, false, model.frsky.usrProto); populateCustomScreenFieldCB(barsCB[j], model.frsky.screens[screen].body.bars[field].source, false, model.frsky.usrProto);
switch (model.frsky.screens[screen].body.bars[field].source-1) { RawSource source = RawSource(SOURCE_TYPE_TELEMETRY, model.frsky.screens[screen].body.bars[field].source, &model);
case TELEMETRY_SOURCE_TX_BATT: RawSourceRange range = source.getRange();
case TELEMETRY_SOURCE_A1: minSB[j]->setDecimals(range.decimals);
case TELEMETRY_SOURCE_A1_MIN: minSB[j]->setMinimum(range.min);
case TELEMETRY_SOURCE_A2: minSB[j]->setMaximum(range.max);
case TELEMETRY_SOURCE_A2_MIN: minSB[j]->setSingleStep(range.step);
case TELEMETRY_SOURCE_CELLS_SUM: minSB[j]->setValue(range.getValue(model.frsky.screens[screen].body.bars[field].barMin));
case TELEMETRY_SOURCE_VFAS: maxSB[j]->setDecimals(range.decimals);
case TELEMETRY_SOURCE_CURRENT_MAX: maxSB[j]->setMinimum(range.min);
case TELEMETRY_SOURCE_CURRENT: maxSB[j]->setMaximum(range.max);
minSB[j]->setDecimals(1); maxSB[j]->setSingleStep(range.step);
maxSB[j]->setDecimals(1); maxSB[j]->setValue(range.getValue(255 - model.frsky.screens[screen].body.bars[field].barMax));
break;
case TELEMETRY_SOURCE_CELL:
minSB[j]->setDecimals(2);
maxSB[j]->setDecimals(2);
break;
default:
minSB[j]->setDecimals(0);
maxSB[j]->setDecimals(0);
}
minSB[j]->setMinimum(getBarValue(model.frsky.screens[screen].body.bars[field].source, 0, &model.frsky));
minSB[j]->setMaximum(getBarValue(model.frsky.screens[screen].body.bars[field].source, 255, &model.frsky));
minSB[j]->setSingleStep(getBarStep(model.frsky.screens[screen].body.bars[field].source));
minSB[j]->setValue(getBarValue(model.frsky.screens[screen].body.bars[field].source, model.frsky.screens[screen].body.bars[field].barMin, &model.frsky));
maxSB[j]->setMinimum(getBarValue(model.frsky.screens[screen].body.bars[field].source, 0, &model.frsky));
maxSB[j]->setMaximum(getBarValue(model.frsky.screens[screen].body.bars[field].source, 255, &model.frsky));
maxSB[j]->setSingleStep(getBarStep(model.frsky.screens[screen].body.bars[field].source));
maxSB[j]->setValue(getBarValue(model.frsky.screens[screen].body.bars[field].source, (255-model.frsky.screens[screen].body.bars[field].barMax), &model.frsky));
if (model.frsky.screens[screen].body.bars[field].source==0 || model.frsky.screens[screen].type==0) { if (model.frsky.screens[screen].body.bars[field].source==0 || model.frsky.screens[screen].type==0) {
minSB[j]->setDisabled(true); minSB[j]->setDisabled(true);
maxSB[j]->setDisabled(true); maxSB[j]->setDisabled(true);
} }
connect(barsCB[j],SIGNAL(currentIndexChanged(int)),this,SLOT(telBarCBcurrentIndexChanged(int))); connect(barsCB[j], SIGNAL(currentIndexChanged(int)), this, SLOT(telBarCBcurrentIndexChanged(int)));
connect(maxSB[j],SIGNAL(editingFinished()),this,SLOT(telMaxSBeditingFinished())); connect(maxSB[j], SIGNAL(editingFinished()), this, SLOT(telMaxSBeditingFinished()));
connect(minSB[j],SIGNAL(editingFinished()),this,SLOT(telMinSBeditingFinished())); connect(minSB[j], SIGNAL(editingFinished()), this, SLOT(telMinSBeditingFinished()));
} }
lock=false; lock=false;
} }
@ -770,14 +753,16 @@ void TelemetryPanel::telBarUpdate()
int screen=i/4; int screen=i/4;
index=barsCB[i]->currentIndex(); index=barsCB[i]->currentIndex();
if (index==TELEMETRY_SOURCE_A1 || index==TELEMETRY_SOURCE_A1 || index==TELEMETRY_SOURCE_A1_MIN || index==TELEMETRY_SOURCE_A2_MIN) { if (index==TELEMETRY_SOURCE_A1 || index==TELEMETRY_SOURCE_A1 || index==TELEMETRY_SOURCE_A1_MIN || index==TELEMETRY_SOURCE_A2_MIN) {
minSB[i]->setMinimum(getBarValue(index, 0, &model.frsky)); RawSource source = RawSource(SOURCE_TYPE_TELEMETRY, index, &model);
minSB[i]->setMaximum(getBarValue(index, 255, &model.frsky)); RawSourceRange range = source.getRange();
minSB[i]->setSingleStep(getBarStep(index)); minSB[i]->setMinimum(range.min);
maxSB[i]->setMinimum(getBarValue(index, 0, &model.frsky)); minSB[i]->setMaximum(range.max);
maxSB[i]->setMaximum(getBarValue(index, 255, &model.frsky)); minSB[i]->setSingleStep(range.step);
maxSB[i]->setSingleStep(getBarStep(index)); maxSB[i]->setMinimum(range.min);
minSB[i]->setValue(getBarValue(index, model.frsky.screens[screen].body.bars[i%4].barMin, &model.frsky)); maxSB[i]->setMaximum(range.max);
maxSB[i]->setValue(getBarValue(index, 255-model.frsky.screens[screen].body.bars[i%4].barMax, &model.frsky)); maxSB[i]->setSingleStep(range.step);
minSB[i]->setValue(range.getValue(model.frsky.screens[screen].body.bars[i%4].barMin));
maxSB[i]->setValue(range.getValue(255 - model.frsky.screens[screen].body.bars[i%4].barMax));
} }
} }
lock=false; lock=false;
@ -785,116 +770,110 @@ void TelemetryPanel::telBarUpdate()
void TelemetryPanel::ScreenTypeCBcurrentIndexChanged(int index) void TelemetryPanel::ScreenTypeCBcurrentIndexChanged(int index)
{ {
if (lock) return; if (!lock) {
lock = true;
QComboBox *comboBox = qobject_cast<QComboBox*>(sender()); QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
int screen = comboBox->objectName().right(1).toInt() -1; int screen = comboBox->objectName().right(1).toInt() -1;
lock=true; model.frsky.screens[screen].type = index;
model.frsky.screens[screen].type=index;
for (int i=0; i<3; i++) { for (int i=0; i<3; i++) {
bool isNum = (model.frsky.screens[i].type==0); bool isNum = (model.frsky.screens[i].type==0);
barsGB[i]->setVisible(!isNum); barsGB[i]->setVisible(!isNum);
numsGB[i]->setVisible(isNum); numsGB[i]->setVisible(isNum);
} }
lock = false;
lock=false;
emit modified(); emit modified();
}
} }
void TelemetryPanel::telBarCBcurrentIndexChanged(int index) void TelemetryPanel::telBarCBcurrentIndexChanged(int index)
{ {
if (lock) return; if (!lock) {
lock = true;
QComboBox *comboBox = qobject_cast<QComboBox*>(sender()); QComboBox *comboBox = qobject_cast<QComboBox*>(sender());
int screenId = comboBox->objectName().mid(8,1).toInt() - 1; int screenId = comboBox->objectName().mid(8,1).toInt() - 1;
int barId = comboBox->objectName().mid(10,1).toInt() - 1; int barId = comboBox->objectName().mid(10,1).toInt() - 1;
int bar=barId+screenId*4; int bar=barId+screenId*4;
model.frsky.screens[screenId].body.bars[barId].source=index; model.frsky.screens[screenId].body.bars[barId].source=index;
lock=true;
if (index==0) { if (index==0) {
model.frsky.screens[screenId].body.bars[barId].barMin=0; model.frsky.screens[screenId].body.bars[barId].barMin=0;
model.frsky.screens[screenId].body.bars[barId].barMax=0; model.frsky.screens[screenId].body.bars[barId].barMax=0;
minSB[bar]->setDisabled(true); minSB[bar]->setDisabled(true);
maxSB[bar]->setDisabled(true); maxSB[bar]->setDisabled(true);
} else { }
else {
minSB[bar]->setEnabled(true); minSB[bar]->setEnabled(true);
maxSB[bar]->setEnabled(true); maxSB[bar]->setEnabled(true);
} }
switch (index-1) { RawSource source = RawSource(SOURCE_TYPE_TELEMETRY, index-1, &model);
case TELEMETRY_SOURCE_TX_BATT: RawSourceRange range = source.getRange();
case TELEMETRY_SOURCE_A1: minSB[bar]->setDecimals(range.decimals);
case TELEMETRY_SOURCE_A1_MIN: minSB[bar]->setMinimum(range.min);
case TELEMETRY_SOURCE_A2: minSB[bar]->setMaximum(range.max);
case TELEMETRY_SOURCE_A2_MIN: minSB[bar]->setSingleStep(range.step);
case TELEMETRY_SOURCE_CELLS_SUM: maxSB[bar]->setDecimals(range.decimals);
case TELEMETRY_SOURCE_VFAS: maxSB[bar]->setMinimum(range.min);
case TELEMETRY_SOURCE_CURRENT_MAX: maxSB[bar]->setMaximum(range.max);
case TELEMETRY_SOURCE_CURRENT: maxSB[bar]->setSingleStep(range.step);
minSB[bar]->setDecimals(1); minSB[bar]->setValue(range.getValue(model.frsky.screens[screenId].body.bars[barId].barMin));
maxSB[bar]->setDecimals(1); maxSB[bar]->setValue(range.getValue(255 - model.frsky.screens[screenId].body.bars[barId].barMax));
break; lock = false;
case TELEMETRY_SOURCE_CELL:
minSB[bar]->setDecimals(2);
maxSB[bar]->setDecimals(2);
break;
default:
minSB[bar]->setDecimals(0);
maxSB[bar]->setDecimals(0);
}
minSB[bar]->setMinimum(getBarValue(index, 0, &model.frsky));
minSB[bar]->setMaximum(getBarValue(index, 255, &model.frsky));
minSB[bar]->setSingleStep(getBarStep(index));
maxSB[bar]->setMinimum(getBarValue(index, 0, &model.frsky));
maxSB[bar]->setMaximum(getBarValue(index, 255, &model.frsky));
maxSB[bar]->setSingleStep(getBarStep(index));
minSB[bar]->setValue(getBarValue(index, model.frsky.screens[screenId].body.bars[barId].barMin, &model.frsky));
maxSB[bar]->setValue(getBarValue(index, 255-model.frsky.screens[screenId].body.bars[barId].barMax, &model.frsky));
lock=false;
emit modified(); emit modified();
}
} }
void TelemetryPanel::telMinSBeditingFinished() void TelemetryPanel::telMinSBeditingFinished()
{ {
if (lock) return; if (!lock) {
lock = true;
QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(sender()); QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(sender());
int screenId = spinBox->objectName().mid(8,1).toInt() - 1; int screenId = spinBox->objectName().mid(8,1).toInt() - 1;
int barId = spinBox->objectName().right(1).toInt() - 1; int barId = spinBox->objectName().right(1).toInt() - 1;
int minId = barId+screenId*4; int minId = barId+screenId*4;
lock=true; RawSource source = RawSource(SOURCE_TYPE_TELEMETRY, model.frsky.screens[screenId].body.bars[barId].source, &model);
RawSourceRange range = source.getRange();
if (model.frsky.screens[screenId].body.bars[barId].source==TELEMETRY_SOURCE_A1 || model.frsky.screens[screenId].body.bars[barId].source==TELEMETRY_SOURCE_A1_MIN) { if (model.frsky.screens[screenId].body.bars[barId].source==TELEMETRY_SOURCE_A1 || model.frsky.screens[screenId].body.bars[barId].source==TELEMETRY_SOURCE_A1_MIN) {
model.frsky.screens[screenId].body.bars[barId].barMin=round((minSB[minId]->value()-analogs[0]->ui->CalibSB->value())/getBarStep(model.frsky.screens[screenId].body.bars[barId].source)); model.frsky.screens[screenId].body.bars[barId].barMin = round((minSB[minId]->value()-analogs[0]->ui->CalibSB->value())/range.step);
} else if (model.frsky.screens[screenId].body.bars[minId].source==TELEMETRY_SOURCE_A2 || model.frsky.screens[screenId].body.bars[minId].source==TELEMETRY_SOURCE_A2_MIN) {
model.frsky.screens[screenId].body.bars[barId].barMin=round((minSB[minId]->value()-analogs[1]->ui->CalibSB->value())/getBarStep(model.frsky.screens[screenId].body.bars[barId].source));
} else {
model.frsky.screens[screenId].body.bars[barId].barMin=round((minSB[minId]->value()-getBarValue(model.frsky.screens[screenId].body.bars[barId].source, 0, &model.frsky))/getBarStep(model.frsky.screens[screenId].body.bars[barId].source));
} }
spinBox->setValue(getBarValue(model.frsky.screens[screenId].body.bars[barId].source, model.frsky.screens[screenId].body.bars[barId].barMin, &model.frsky)); else if (model.frsky.screens[screenId].body.bars[minId].source==TELEMETRY_SOURCE_A2 || model.frsky.screens[screenId].body.bars[minId].source==TELEMETRY_SOURCE_A2_MIN) {
model.frsky.screens[screenId].body.bars[barId].barMin = round((minSB[minId]->value()-analogs[1]->ui->CalibSB->value())/range.step);
}
else {
model.frsky.screens[screenId].body.bars[barId].barMin = round((minSB[minId]->value()-range.getValue(0))/range.step);
}
spinBox->setValue(range.getValue(model.frsky.screens[screenId].body.bars[barId].barMin));
if (maxSB[minId]->value()<minSB[minId]->value()) { if (maxSB[minId]->value()<minSB[minId]->value()) {
model.frsky.screens[screenId].body.bars[minId].barMax=(255-model.frsky.screens[screenId].body.bars[barId].barMin+1); model.frsky.screens[screenId].body.bars[minId].barMax = (255-model.frsky.screens[screenId].body.bars[barId].barMin+1);
maxSB[minId]->setValue(getBarValue(model.frsky.screens[screenId].body.bars[barId].source, 255-model.frsky.screens[screenId].body.bars[barId].barMax, &model.frsky)); maxSB[minId]->setValue(range.getValue(255 - model.frsky.screens[screenId].body.bars[barId].barMax));
} }
maxSB[minId]->setMinimum(getBarValue(model.frsky.screens[screenId].body.bars[barId].source, (model.frsky.screens[screenId].body.bars[barId].barMin+1), &model.frsky)); maxSB[minId]->setMinimum(range.getValue((model.frsky.screens[screenId].body.bars[barId].barMin+1)));
lock=false;
lock = false;
emit modified(); emit modified();
}
} }
void TelemetryPanel::telMaxSBeditingFinished() void TelemetryPanel::telMaxSBeditingFinished()
{ {
if (lock) return; if (!lock) {
QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(sender()); QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox*>(sender());
int screenId = spinBox->objectName().mid(8,1).toInt() - 1; int screenId = spinBox->objectName().mid(8,1).toInt() - 1;
int barId = spinBox->objectName().right(1).toInt() - 1; int barId = spinBox->objectName().right(1).toInt() - 1;
lock=true; lock = true;
RawSource source = RawSource(SOURCE_TYPE_TELEMETRY, model.frsky.screens[screenId].body.bars[barId].source, &model);
RawSourceRange range = source.getRange();
if (model.frsky.screens[screenId].body.bars[barId].source==5) { if (model.frsky.screens[screenId].body.bars[barId].source==5) {
model.frsky.screens[screenId].body.bars[barId].barMax = (255-round((spinBox->value()-analogs[0]->ui->CalibSB->value())/getBarStep(model.frsky.screens[screenId].body.bars[barId].source))); model.frsky.screens[screenId].body.bars[barId].barMax = (255-round((spinBox->value()-analogs[0]->ui->CalibSB->value())/range.step));
} else if (model.frsky.screens[screenId].body.bars[barId].source==6) {
model.frsky.screens[screenId].body.bars[barId].barMax = (255-round((spinBox->value()-analogs[1]->ui->CalibSB->value())/getBarStep(model.frsky.screens[screenId].body.bars[barId].source)));
} else {
model.frsky.screens[screenId].body.bars[barId].barMax = (255-round((spinBox->value()-getBarValue(model.frsky.screens[screenId].body.bars[barId].source, 0, &model.frsky))/getBarStep(model.frsky.screens[screenId].body.bars[barId].source) ));
} }
spinBox->setValue(getBarValue(model.frsky.screens[screenId].body.bars[barId].source, (255-model.frsky.screens[screenId].body.bars[barId].barMax), &model.frsky)); else if (model.frsky.screens[screenId].body.bars[barId].source==6) {
lock=false; model.frsky.screens[screenId].body.bars[barId].barMax = (255-round((spinBox->value()-analogs[1]->ui->CalibSB->value())/range.step));
}
else {
model.frsky.screens[screenId].body.bars[barId].barMax = (255-round((spinBox->value()-range.getValue(0))/range.step));
}
spinBox->setValue(range.getValue(255-model.frsky.screens[screenId].body.bars[barId].barMax));
lock = false;
emit modified(); emit modified();
}
} }
void TelemetryPanel::customFieldEdited() void TelemetryPanel::customFieldEdited()
@ -902,7 +881,7 @@ void TelemetryPanel::customFieldEdited()
if (!lock) { if (!lock) {
lock = true; lock = true;
int cols=GetEepromInterface()->getCapability(TelemetryColsCSFields); int cols = GetEepromInterface()->getCapability(TelemetryColsCSFields);
if (cols==0) cols=2; if (cols==0) cols=2;
for (int i=0; i<GetEepromInterface()->getCapability(TelemetryCSFields); i++) { for (int i=0; i<GetEepromInterface()->getCapability(TelemetryCSFields); i++) {
@ -913,74 +892,9 @@ void TelemetryPanel::customFieldEdited()
model.frsky.screens[screen].body.lines[r].source[c]=csf[i]->currentIndex(); model.frsky.screens[screen].body.lines[r].source[c]=csf[i]->currentIndex();
} }
} }
emit modified();
lock = false; lock = false;
emit modified();
} }
} }
float TelemetryPanel::getBarStep(int barId)
{
switch (barId-1) {
case TELEMETRY_SOURCE_TX_BATT:
return 0.1;
break;
case TELEMETRY_SOURCE_TIMER1:
case TELEMETRY_SOURCE_TIMER2:
return 3;
break;
case TELEMETRY_SOURCE_A1:
case TELEMETRY_SOURCE_A1_MIN:
return (analogs[0]->ui->RatioSB->value()/255);
break;
case TELEMETRY_SOURCE_A2:
case TELEMETRY_SOURCE_A2_MIN:
return (analogs[1]->ui->RatioSB->value()/255);
break;
case TELEMETRY_SOURCE_ALT:
case TELEMETRY_SOURCE_GPS_ALT:
case TELEMETRY_SOURCE_ALT_MAX:
case TELEMETRY_SOURCE_ALT_MIN:
return 8;
break;
case TELEMETRY_SOURCE_RPM:
case TELEMETRY_SOURCE_RPM_MAX:
return 50;
break;
case TELEMETRY_SOURCE_CELLS_SUM:
case TELEMETRY_SOURCE_VFAS:
return 0.1;
break;
case TELEMETRY_SOURCE_CELL:
return 0.02;
break;
case TELEMETRY_SOURCE_HDG:
return 2;
break;
case TELEMETRY_SOURCE_DIST:
case TELEMETRY_SOURCE_DIST_MAX:
return 8;
break;
case TELEMETRY_SOURCE_CURRENT_MAX:
case TELEMETRY_SOURCE_CURRENT:
return 0.5;
break;
case TELEMETRY_SOURCE_POWER:
return 5;
break;
case TELEMETRY_SOURCE_CONSUMPTION:
return 20;
break;
case TELEMETRY_SOURCE_SPEED:
case TELEMETRY_SOURCE_SPEED_MAX:
if (model.frsky.imperial==1) {
return 1;
} else {
return 1.852;
}
break;
default:
return 1;
break;
}
}

View file

@ -94,7 +94,6 @@ class TelemetryPanel : public ModelPanel
QComboBox* csf[36]; QComboBox* csf[36];
void setup(); void setup();
float getBarStep(int barId);
void telBarUpdate(); void telBarUpdate();
}; };

View file

@ -834,7 +834,7 @@ void printDialog::printFrSky()
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
if (fd->screens[j].body.bars[i].source!=0) if (fd->screens[j].body.bars[i].source!=0)
tc++; tc++;
str.append("<tr><td align=\"Center\"><b>"+QString::number(i+1,10)+"</b></td><td align=\"Center\"><b>"+getFrSkySrc(fd->screens[j].body.bars[i].source)+"</b></td><td align=\"Right\"><b>"+(fd->screens[j].body.bars[i].source>0 ? QString::number(getBarValue(fd->screens[j].body.bars[i].source, fd->screens[j].body.bars[i].barMin,fd)):"----")+"</b></td><td align=\"Right\"><b>"+(fd->screens[j].body.bars[i].source>0 ? QString::number(getBarValue(fd->screens[j].body.bars[i].source,(255-fd->screens[j].body.bars[i].barMax),fd)) :"----")+"</b></td></tr>"); // TODO str.append("<tr><td align=\"Center\"><b>"+QString::number(i+1,10)+"</b></td><td align=\"Center\"><b>"+getFrSkySrc(fd->screens[j].body.bars[i].source)+"</b></td><td align=\"Right\"><b>"+(fd->screens[j].body.bars[i].source>0 ? QString::number(getBarValue(fd->screens[j].body.bars[i].source, fd->screens[j].body.bars[i].barMin,fd)):"----")+"</b></td><td align=\"Right\"><b>"+(fd->screens[j].body.bars[i].source>0 ? QString::number(getBarValue(fd->screens[j].body.bars[i].source,(255-fd->screens[j].body.bars[i].barMax),fd)) :"----")+"</b></td></tr>");
} }
str.append("</table>"); str.append("</table>");
} }