6#include <QtCore/QVariant>
8APMFlightModesComponentController::APMFlightModesComponentController(QObject *parent)
10 , _simpleModeFact(parameterExists(-1, _simpleParamName) ? getParameterFact(-1, _simpleParamName) : nullptr)
11 , _superSimpleModeFact(parameterExists(-1, _superSimpleParamName) ? getParameterFact(-1, _superSimpleParamName) : nullptr)
12 , _simpleModesSupported(_simpleModeFact && _superSimpleModeFact)
14 const bool arduRoverFirmware = parameterExists(-1, QStringLiteral(
"MODE1"));
15 _modeParamPrefix = arduRoverFirmware ? QStringLiteral(
"MODE") : QStringLiteral(
"FLTMODE");
16 _modeChannelParam = arduRoverFirmware ? QStringLiteral(
"MODE_CH") : QStringLiteral(
"FLTMODE_CH");
18 for (
int i = 0; i < _cFltModes; i++) {
19 _simpleModeEnabled.append(QVariant(
false));
20 _superSimpleModeEnabled.append(QVariant(
false));
23 if (_simpleModesSupported) {
24 _setupSimpleModeEnabled();
26 const uint8_t simpleModeValue =
static_cast<uint8_t
>(_simpleModeFact->rawValue().toUInt());
27 const uint8_t superSimpleModeValue =
static_cast<uint8_t
>(_superSimpleModeFact->rawValue().toUInt());
28 if ((simpleModeValue == 0) && (superSimpleModeValue == 0)) {
29 _simpleMode = SimpleModeStandard;
30 }
else if ((simpleModeValue == _allSimpleBits) && (superSimpleModeValue == 0)) {
31 _simpleMode = SimpleModeSimple;
32 }
else if ((simpleModeValue == 0) && (superSimpleModeValue == _allSimpleBits)) {
33 _simpleMode = SimpleModeSuperSimple;
35 _simpleMode = SimpleModeCustom;
41 QStringList usedParams;
42 for (
int i = 1; i < 7; i++) {
43 usedParams << QStringLiteral(
"%1%2").arg(_modeParamPrefix).arg(i);
49 for (
int i = 0; i < _cChannelOptions; i++) {
50 _rgChannelOptionEnabled.append(QVariant(
false));
56void APMFlightModesComponentController::channelValuesChanged(QVector<int> channelValues)
58 int flightModeChannel = 4;
64 if (flightModeChannel >=
static_cast<int>(channelValues.size())) {
68 _activeFlightMode = 0;
69 int channelValue = channelValues[flightModeChannel];
70 if (channelValue != -1) {
72 static constexpr const int rgThreshold[] = { 1230, 1360, 1490, 1620, 1749 };
73 for (
size_t i = 0; i < std::size(rgThreshold); i++) {
74 if (channelValue <= rgThreshold[
static_cast<size_t>(i)]) {
75 _activeFlightMode =
static_cast<int>(i) + 1;
81 _activeFlightMode = 6;
86 for (
int i = 0; i < _cChannelOptions; i++) {
87 _rgChannelOptionEnabled[i] = QVariant(
false);
88 channelValue = channelValues[i + 5];
89 if (channelValue > 1800) {
90 _rgChannelOptionEnabled[i] = QVariant(
true);
96void APMFlightModesComponentController::_updateSimpleParamsFromSimpleMode()
98 int newSimpleModeValue = 0;
99 int newSuperSimpleModeValue = 0;
101 if (_simpleMode == SimpleModeSimple) {
102 newSimpleModeValue = _allSimpleBits;
103 }
else if (_simpleMode == SimpleModeSuperSimple) {
104 newSuperSimpleModeValue = _allSimpleBits;
107 for (
int i = 0; i < _cFltModes; i++) {
108 _simpleModeEnabled[i] =
false;
109 _superSimpleModeEnabled[i] =
false;
114 _simpleModeFact->setRawValue(newSimpleModeValue);
115 _superSimpleModeFact->setRawValue(newSuperSimpleModeValue);
118void APMFlightModesComponentController::setSimpleMode(
int fltModeIndex,
bool enabled)
120 if (fltModeIndex < _cFltModes) {
121 uint8_t mode =
static_cast<uint8_t
>(_simpleModeFact->rawValue().toInt());
123 mode |= 1 << fltModeIndex;
125 mode &= ~(1 << fltModeIndex);
127 _simpleModeFact->setRawValue(mode);
131void APMFlightModesComponentController::setSuperSimpleMode(
int fltModeIndex,
bool enabled)
133 if (fltModeIndex < _cFltModes) {
134 uint8_t mode =
static_cast<uint8_t
>(_superSimpleModeFact->rawValue().toInt());
136 mode |= 1 << fltModeIndex;
138 mode &= ~(1 << fltModeIndex);
140 _superSimpleModeFact->setRawValue(mode);
144void APMFlightModesComponentController::_setupSimpleModeEnabled()
146 const uint8_t simpleMode =
static_cast<uint8_t
>(_simpleModeFact->rawValue().toUInt());
147 const uint8_t superSimpleMode =
static_cast<uint8_t
>(_superSimpleModeFact->rawValue().toUInt());
149 for (
int i = 0; i < _cFltModes; i++) {
150 const uint8_t bitSet =
static_cast<uint8_t
>(1 << i);
151 _simpleModeEnabled[i] = !!(simpleMode & bitSet);
152 _superSimpleModeEnabled[i] = !!(superSimpleMode & bitSet);
void channelOptionEnabledChanged()
void simpleModeChanged(int simpleMode)
void superSimpleModeEnabledChanged()
void activeFlightModeChanged(int activeFlightMode)
void simpleModeEnabledChanged()
Used for handling missing Facts from C++ code.
static constexpr int defaultComponentId
void rcChannelsChanged(QVector< int > channelValues)