Fix doc path
[opentx.git] / companion / src / firmwares / multiprotocols.cpp
blob7cb12379f4e3aae4433b24a9d6495e58c7840628
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 <QObject>
23 #include "multiprotocols.h"
24 #include "radiodata.h"
26 #define STR_MULTI_SUBTYPE QT_TRANSLATE_NOOP("Multiprotocols", "Subtype")
27 #define STR_MULTI_VIDFREQ QT_TRANSLATE_NOOP("Multiprotocols", "Video TX frequency")
28 #define STR_MULTI_RFTUNE QT_TRANSLATE_NOOP("Multiprotocols", "CC2500 frequency fine tune")
29 #define STR_MULTI_TELEMETRY QT_TRANSLATE_NOOP("Multiprotocols", "Telemetry")
30 #define STR_MULTI_RFPOWER QT_TRANSLATE_NOOP("Multiprotocols", "Radio output power")
31 #define STR_MULTI_SERVOFREQ QT_TRANSLATE_NOOP("Multiprotocols", "Servo output frequency")
32 #define STR_MULTI_OPTION QT_TRANSLATE_NOOP("Multiprotocols", "Option value")
33 #define STR_MULTI_DEFAULT QT_TRANSLATE_NOOP("Multiprotocols", "DEFAULT")
35 static const QStringList STR_SUBTYPE_CUSTOM ({
36 STR_MULTI_SUBTYPE " 0", STR_MULTI_SUBTYPE " 1", STR_MULTI_SUBTYPE " 2", STR_MULTI_SUBTYPE " 3",
37 STR_MULTI_SUBTYPE " 4", STR_MULTI_SUBTYPE " 5", STR_MULTI_SUBTYPE " 6", STR_MULTI_SUBTYPE " 7"
38 });
39 static const QStringList STR_SUBTYPE_FLYSKY {"Standard", "V9x9", "V6x6", "V912", "CX20"};
40 static const QStringList STR_SUBTYPE_HUBSAN {"H107", "H301", "H501"};
41 static const QStringList STR_SUBTYPE_FRSKY {"D16", "D8", "D16 8ch", "V8", "D16 EU-LBT", "D16 EU-LBT 8ch"};
42 static const QStringList STR_SUBTYPE_HISKY {"Standard", "HK310"};
43 static const QStringList STR_SUBTYPE_V2X2 {"Standard", "JXD506"};
44 static const QStringList STR_SUBTYPE_DSM {"DSM2 22ms", "DSM2 11ms", "DSMX 22ms", "DSMX 11ms"};
45 static const QStringList STR_SUBTYPE_YD717 {"Standard", "Skywalker", "Syma X4", "XINXUN", "NIHUI"};
46 static const QStringList STR_SUBTYPE_KN {"WLtoys", "FeiLun"};
47 static const QStringList STR_SUBTYPE_SYMAX {"Standard", "Syma X5C"};
48 static const QStringList STR_SUBTYPE_SLT {"V1 (6 Channel)", "V2 (8 Channel)", "Q100", "Q200", "MR100"};
49 static const QStringList STR_SUBTYPE_CX10 {"Green", "Blue", "DM007", "-", "JC3015a", "JC3015b", "MK33041"};
50 static const QStringList STR_SUBTYPE_CG023 {"Standard", "YD829"};
51 static const QStringList STR_SUBTYPE_BAYANG {"Standard", "H8S3D", "X16 AH", "IRDRONE", "DHD D4"};
52 static const QStringList STR_SUBTYPE_MT99 {"MT99", "H7", "YZ", "LS", "FY805"};
53 static const QStringList STR_SUBTYPE_MJXQ {"WLH08", "X600", "X800", "H26D", "E010", "H26WH", "Phoenix"};
54 static const QStringList STR_SUBTYPE_FY326 {"Standard", "FY319"};
55 static const QStringList STR_SUBTYPE_HONTAI {"Standard", "JJRC X1", "X5C1 Clone", "FQ777_951"};
56 static const QStringList STR_SUBTYPE_AFHDS2A {"PWM and IBUS", "PPM and IBUS", "PWM and SBUS", "PPM and SBUS"};
57 static const QStringList STR_SUBTYPE_Q2X2 {"Q222", "Q242", "Q282"};
58 static const QStringList STR_SUBTYPE_WK2x01 {"WK2801", "WK2401", "W6_5_1", "W6_6_1", "W6_HEL", "W6_HEL_I"};
59 static const QStringList STR_SUBTYPE_Q303 {"Standard", "CX35", "CX10D", "CX10WD"};
60 static const QStringList STR_SUBTYPE_CABELL {"Cabell V3", "Cab V3 Telem", "-", "-", "-", "-", "Set FailSafe", "Unbind"};
61 static const QStringList STR_SUBTYPE_H83D {"H8 Mini 3D", "H20H", "H20 Mini", "H30 Mini"};
62 static const QStringList STR_SUBTYPE_CORONA {"Corona V1", "Corona V2", "Flydream V3"};
63 static const QStringList STR_SUBTYPE_HITEC {"Optima", "Optima Hub Telem", "Minima"};
64 static const QStringList STR_SUBTYPE_BUGS_MINI {"Standard", "Bugs 3H"};
65 static const QStringList STR_SUBTYPE_E01X {"E012", "E015", "E016H"};
66 static const QStringList STR_SUBTYPE_GD00X {"GD V1", "GD V2"};
67 static const QStringList STR_SUBTYPE_REDPINE {"Fast", "Slow"};
68 static const QStringList STR_SUBTYPE_POTENSIC {"A20 Firefly", " - "};
70 static const QStringList NO_SUBTYPE {STR_MULTI_DEFAULT};
73 // Table is designed to be shared with gui_common_arm.cpp
75 const Multiprotocols multiProtocols {
76 {MM_RF_PROTO_FLYSKY, 4, false, STR_SUBTYPE_FLYSKY, nullptr},
77 {MM_RF_PROTO_HUBSAN, 2, false, STR_SUBTYPE_HUBSAN, STR_MULTI_VIDFREQ},
78 {MM_RF_PROTO_FRSKY, 5, false, STR_SUBTYPE_FRSKY, STR_MULTI_RFTUNE},
79 {MM_RF_PROTO_HISKY, 1, false, STR_SUBTYPE_HISKY, nullptr},
80 {MM_RF_PROTO_V2X2, 1, false, STR_SUBTYPE_V2X2, nullptr},
81 {MM_RF_PROTO_DSM2, 3, false, STR_SUBTYPE_DSM, nullptr},
82 {MM_RF_PROTO_YD717, 4, false, STR_SUBTYPE_YD717, nullptr},
83 {MM_RF_PROTO_KN, 1, false, STR_SUBTYPE_KN, nullptr},
84 {MM_RF_PROTO_SYMAX, 1, false, STR_SUBTYPE_SYMAX, nullptr},
85 {MM_RF_PROTO_SLT, 4, false, STR_SUBTYPE_SLT, nullptr},
86 {MM_RF_PROTO_CX10, 6, false, STR_SUBTYPE_CX10, nullptr},
87 {MM_RF_PROTO_CG023, 1, false, STR_SUBTYPE_CG023, nullptr},
88 {MM_RF_PROTO_BAYANG, 4, false, STR_SUBTYPE_BAYANG, STR_MULTI_TELEMETRY},
89 {MM_RF_PROTO_MT99XX, 4, false, STR_SUBTYPE_MT99, nullptr},
90 {MM_RF_PROTO_MJXQ, 6, false, STR_SUBTYPE_MJXQ, STR_MULTI_RFTUNE},
91 {MM_RF_PROTO_FY326, 1, false, STR_SUBTYPE_FY326, nullptr},
92 {MM_RF_PROTO_SFHSS, 0, true, NO_SUBTYPE, STR_MULTI_RFTUNE},
93 {MM_RF_PROTO_HONTAI, 3, false, STR_SUBTYPE_HONTAI, nullptr},
94 {MM_RF_PROTO_OLRS, 0, false, NO_SUBTYPE, STR_MULTI_RFPOWER},
95 {MM_RF_PROTO_FS_AFHDS2A, 3, true, STR_SUBTYPE_AFHDS2A, STR_MULTI_SERVOFREQ},
96 {MM_RF_PROTO_Q2X2, 2, false, STR_SUBTYPE_Q2X2, nullptr},
97 {MM_RF_PROTO_WK_2X01, 5, false, STR_SUBTYPE_WK2x01, nullptr},
98 {MM_RF_PROTO_Q303, 3, false, STR_SUBTYPE_Q303, nullptr},
99 {MM_RF_PROTO_CABELL, 7, false, STR_SUBTYPE_CABELL, STR_MULTI_OPTION},
100 {MM_RF_PROTO_H83D, 3, false, STR_SUBTYPE_H83D, nullptr},
101 {MM_RF_PROTO_CORONA, 2, false, STR_SUBTYPE_CORONA, STR_MULTI_RFTUNE},
102 {MM_RF_PROTO_HITEC, 2, false, STR_SUBTYPE_HITEC, STR_MULTI_RFTUNE},
103 {MM_RF_PROTO_BUGS_MINI, 1, false, STR_SUBTYPE_BUGS_MINI, nullptr},
104 {MM_RF_PROTO_E01X, 2, false, STR_SUBTYPE_E01X, nullptr},
105 {MM_RF_PROTO_V911S, 0, false, NO_SUBTYPE, STR_MULTI_RFTUNE},
106 {MM_RF_PROTO_GD00X, 1, false, STR_SUBTYPE_GD00X, STR_MULTI_RFTUNE},
107 {MM_RF_PROTO_KF606, 0, false, NO_SUBTYPE, STR_MULTI_RFTUNE},
108 {MM_RF_PROTO_REDPINE, 1, false, STR_SUBTYPE_REDPINE, STR_MULTI_RFTUNE},
109 {MM_RF_PROTO_POTENSIC, 1, false, STR_SUBTYPE_POTENSIC, nullptr},
110 {MM_RF_CUSTOM_SELECTED, 7, true, STR_SUBTYPE_CUSTOM, STR_MULTI_OPTION},
112 // Sentinel and default for protocols not listed above (MM_RF_CUSTOM is 0xff)
113 {0xfe, 0, false, NO_SUBTYPE, nullptr}
116 int Multiprotocols::MultiProtocolDefinition::getOptionMin() const {
117 if (optionsstr == STR_MULTI_RFPOWER)
118 return -1;
119 else if (optionsstr == STR_MULTI_SERVOFREQ)
120 return 0;
121 else
122 return -128;
125 int Multiprotocols::MultiProtocolDefinition::getOptionMax() const {
126 if (optionsstr == STR_MULTI_RFPOWER)
127 return 7;
128 else if (optionsstr == STR_MULTI_SERVOFREQ)
129 return 70;
130 else
131 return 127;
134 const Multiprotocols::MultiProtocolDefinition & Multiprotocols::getProtocol(int protocol) const {
135 for (const Multiprotocols::MultiProtocolDefinition & proto: protocols)
136 if (proto.protocol == protocol)
137 return proto;
139 // Protocol not found, return the default (last) proto
140 Q_ASSERT(protocols.rbegin()->protocol == 0xfe);
141 return *protocols.rbegin();
144 // static
145 QString Multiprotocols::protocolToString(int protocol, bool custom)
147 static const QStringList strings({
148 "FlySky", "Hubsan", "FrSky", "Hisky", "V2x2", "DSM", "Devo", "YD717", "KN", "SymaX", "SLT", "CX10", "CG023",
149 "Bayang", "ESky", "MT99XX", "MJXQ", "Shenqi", "FY326", "SFHSS", "J6 PRO","FQ777","Assan","Hontai","Open LRS",
150 "FlySky AFHDS2A", "Q2x2", "Walkera", "Q303", "GW008", "DM002", "Cabell", "ESky 150", "H8 3D", "Corona", "CFlie",
151 "Hitec", "Wfly", "Bugs", "Bugs Mini", "Traxxas", "NCC-1701-A", "E01X", "WL Heli V911S", "GD00X", "Volantex V761",
152 "KFPlan KF606", "Redpine", "Potensic"
155 if (protocol == MM_RF_CUSTOM_SELECTED || custom)
156 return tr("Custom - proto %1)").arg(protocol);
157 else
158 return strings.value(protocol, CPN_STR_UNKNOWN_ITEM);
161 // static
162 QString Multiprotocols::subTypeToString(int protocol, unsigned subType)
164 return tr(qPrintable(multiProtocols.getProtocol(protocol).subTypeStrings.value(subType, CPN_STR_UNKNOWN_ITEM)));