Make TX volatge for simu more flexible (#7124)
[opentx.git] / companion / src / firmwares / logicalswitchdata.cpp
blob457fc01038f8b41d6f756ff840ff79420fdd6d52
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "logicalswitchdata.h"
23 #include "radiodata.h"
24 #include "radiodataconversionstate.h"
25 #include "rawsource.h"
26 #include "rawswitch.h"
28 bool LogicalSwitchData::isEmpty() const
30 return (func == 0);
33 CSFunctionFamily LogicalSwitchData::getFunctionFamily() const
35 if (func == LS_FN_EDGE)
36 return LS_FAMILY_EDGE;
37 else if (func == LS_FN_TIMER)
38 return LS_FAMILY_TIMER;
39 else if (func == LS_FN_STICKY)
40 return LS_FAMILY_STICKY;
41 else if (func < LS_FN_AND || func > LS_FN_ELESS)
42 return LS_FAMILY_VOFS;
43 else if (func < LS_FN_EQUAL)
44 return LS_FAMILY_VBOOL;
45 else
46 return LS_FAMILY_VCOMP;
49 unsigned int LogicalSwitchData::getRangeFlags() const
51 int f = 0;
53 if (func == LS_FN_DPOS || func == LS_FN_DAPOS)
54 f |= RANGE_DELTA_FUNCTION;
56 if (func == LS_FN_DAPOS || func == LS_FN_APOS || func == LS_FN_ANEG)
57 f |= RANGE_ABS_FUNCTION;
59 return f;
62 QString LogicalSwitchData::funcToString() const
64 switch (func) {
65 case LS_FN_OFF:
66 return tr("---");
67 case LS_FN_VPOS:
68 return tr("a>x");
69 case LS_FN_VNEG:
70 return tr("a<x");
71 case LS_FN_APOS:
72 return tr("|a|>x");
73 case LS_FN_ANEG:
74 return tr("|a|<x");
75 case LS_FN_AND:
76 return tr("AND");
77 case LS_FN_OR:
78 return tr("OR");
79 case LS_FN_XOR:
80 return tr("XOR");
81 case LS_FN_EQUAL:
82 return tr("a=b");
83 case LS_FN_NEQUAL:
84 return tr("a!=b");
85 case LS_FN_GREATER:
86 return tr("a>b");
87 case LS_FN_LESS:
88 return tr("a<b");
89 case LS_FN_EGREATER:
90 return tr("a>=b");
91 case LS_FN_ELESS:
92 return tr("a<=b");
93 case LS_FN_DPOS:
94 return tr("d>=x");
95 case LS_FN_DAPOS:
96 return tr("|d|>=x");
97 case LS_FN_VEQUAL:
98 return tr("a=x");
99 case LS_FN_VALMOSTEQUAL:
100 return tr("a~x");
101 case LS_FN_TIMER:
102 return tr("Timer");
103 case LS_FN_STICKY:
104 return tr("Sticky");
105 case LS_FN_EDGE:
106 return tr("Edge");
107 default:
108 return tr("Unknown");
112 QString LogicalSwitchData::nameToString(int index) const
114 return RadioData::getElementName(tr("L"), index + 1, NULL, true);
117 void LogicalSwitchData::convert(RadioDataConversionState & cstate)
119 cstate.setComponent(tr("LSW"), 7);
120 cstate.setSubComp(RawSwitch(SWITCH_TYPE_VIRTUAL, cstate.subCompIdx + 1).toString(cstate.fromType, cstate.fromGS(), cstate.fromModel()));
121 CSFunctionFamily family = getFunctionFamily();
122 switch(family) {
123 case LS_FAMILY_VOFS:
124 val1 = RawSource(val1).convert(cstate.withComponentField("V1")).toValue();
125 break;
126 case LS_FAMILY_STICKY:
127 case LS_FAMILY_VBOOL:
128 val1 = RawSwitch(val1).convert(cstate.withComponentField("V1")).toValue();
129 val2 = RawSwitch(val2).convert(cstate.withComponentField("V2")).toValue();
130 break;
131 case LS_FAMILY_EDGE:
132 val1 = RawSwitch(val1).convert(cstate.withComponentField("V1")).toValue();
133 break;
134 case LS_FAMILY_VCOMP:
135 val1 = RawSource(val1).convert(cstate.withComponentField("V1")).toValue();
136 val2 = RawSource(val2).convert(cstate.withComponentField("V2")).toValue();
137 break;
138 default:
139 break;
142 andsw = RawSwitch(andsw).convert(cstate.withComponentField("AND")).toValue();