7#include <QtCore/QSettings>
19 _calDefaultMinValue = 1000;
20 _calDefaultMaxValue = 2000;
21 _calCenterPoint= ((_calDefaultMaxValue - _calDefaultMinValue) / 2.0f) + _calDefaultMinValue;
22 _calRoughCenterDelta = 50;
26 int valueRange = _calDefaultMaxValue - _calDefaultMinValue;
27 _calValidMinValue = _calDefaultMinValue + (valueRange * 0.3f);
28 _calValidMaxValue = _calDefaultMaxValue - (valueRange * 0.3f);
33 _revParamFormat =
"RC%1_REVERSED";
34 _revParamIsBool =
true;
37 _revParamFormat =
"RC%1_REV";
38 _revParamIsBool =
false;
72bool RadioComponentController::_channelReversedParamValue(
int channel)
76 if (_revParamIsBool) {
77 return paramFact->
rawValue().toBool();
80 float floatReversed = paramFact->
rawValue().toFloat(&convertOk);
85 return floatReversed == -1.0f;
92void RadioComponentController::_setChannelReversedParamValue(
int channel,
bool reversed)
96 if (_revParamIsBool) {
104void RadioComponentController::_saveStoredCalibrationValues()
113 const QString minTpl(
"RC%1_MIN");
114 const QString maxTpl(
"RC%1_MAX");
115 const QString trimTpl(
"RC%1_TRIM");
118 for (
int chan = 0; chan<
_chanMax; chan++) {
120 const int oneBasedChannel = chan + 1;
128 paramFact->
setRawValue(
static_cast<float>(info->channelTrim));
132 paramFact->
setRawValue(
static_cast<float>(info->channelMin));
136 paramFact->
setRawValue(
static_cast<float>(info->channelMax));
145 reversed = info->channelReversed;
147 reversed = !info->channelReversed;
149 _setChannelReversedParamValue(chan, reversed);
154 for (
size_t stickFunctionIndex = 0; stickFunctionIndex <
stickFunctionMaxRadio; stickFunctionIndex++) {
155 int32_t paramChannel;
164 QString paramName = _stickFunctionToParamName(
static_cast<StickFunction>(stickFunctionIndex));
167 if (paramFact && paramFact->
rawValue().toInt() != paramChannel) {
184 _readStoredCalibrationValues();
187void RadioComponentController::_readStoredCalibrationValues()
191 for (
int i = 0; i <
_chanMax; i++) {
202 const QString minTpl(
"RC%1_MIN");
203 const QString maxTpl(
"RC%1_MAX");
204 const QString trimTpl(
"RC%1_TRIM");
206 for (
int i = 0; i <
_chanMax; ++i) {
211 info->channelMin = 1100;
212 info->channelMax = 1900;
213 info->channelReversed =
false;
219 info->channelTrim = paramFact->
rawValue().toInt();
224 info->channelMin = paramFact->
rawValue().toInt();
232 info->channelReversed = _channelReversedParamValue(i);
236 int32_t paramChannel;
238 QString paramName = _stickFunctionToParamName(
static_cast<StickFunction>(i));
241 paramChannel = paramFact->
rawValue().toInt();
243 if (paramChannel > 0 && paramChannel <=
_chanMax) {
255 static const QHash<StickFunction, QString> rgStickFunctionParamsPX4({
262 static const QHash<StickFunction, QString> rgStickFunctionParamsAPM({
269 const auto &rgStickFunctionParams =
_vehicle->
px4Firmware() ? rgStickFunctionParamsPX4 : rgStickFunctionParamsAPM;
271 if (!rgStickFunctionParams.contains(function)) {
272 qCWarning(RadioComponentControllerLog) <<
"Internal Error: Invalid stick function";
276 return rgStickFunctionParams.value(function);
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Q_INVOKABLE Fact * getParameterFact(int componentId, const QString &name, bool reportMissing=true) const
Q_INVOKABLE bool parameterExists(int componentId, const QString &name) const
A Fact is used to hold a single value within the system.
void setRawValue(const QVariant &value)
QVariant rawValue() const
Value after translation.
static constexpr int defaultComponentId
Controller class for RC Transmitter calibration.
Q_INVOKABLE void crsfBindMode()
void start() final override
~RadioComponentController()
void throttleReversedCalFailure()
Signalled to indicate cal failure due to reversed throttle.
Q_INVOKABLE void spektrumBindMode(int mode)
Abstract base class for calibrating RC and Joystick controller.
void _validateAndAdjustCalibrationValues()
StickFunction
These identify the various controls functions. They are also used as indices into the _rgFunctioInfo ...
static constexpr int _chanMax
A set of information associated with a radio channel.
void _clampedChannelValuesChanged(QVector< int > channelValues)
virtual Q_INVOKABLE void start()
ChannelInfo _rgChannelInfo[_chanMax]
Information associated with each rc channel.
int _rgFunctionChannelMapping[stickFunctionMax]
Maps from StickFunction to channel index. _chanMax indicates channel not set for this function.
int _chanCount
Number of actual rc channels available.
void _signalAllAttitudeValueChanges()
MAV_TYPE vehicleType() const
void rcChannelsClampedChanged(QVector< int > channelValues)
void pairRX(int rxType, int rxSubType)
void stopCalibration(bool showError)
int channelTrim
Trim position (usually center for sticks)
enum StickFunction stickFunction
Function mapped to this channel, stickFunctionMax for none.