Skip to content
APMFlightModesComponentController.h 3.62 KiB
Newer Older
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

Don Gagne's avatar
Don Gagne committed

#ifndef APMFlightModesComponentController_H
#define APMFlightModesComponentController_H

#include <QObject>
#include <QQuickItem>
#include <QList>
#include <QStringList>

#include "UASInterface.h"
#include "AutoPilotPlugin.h"
#include "FactPanelController.h"
#include "Vehicle.h"

/// MVC Controller for FlightModesComponent.qml.
class APMFlightModesComponentController : public FactPanelController
{
    Q_OBJECT
    
public:
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    enum SimpleModeValues {
        SimpleModeStandard = 0,
        SimpleModeSimple,
        SimpleModeSuperSimple,
        SimpleModeCustom
    };
    Q_ENUM(SimpleModeValues)

Don Gagne's avatar
Don Gagne committed
    APMFlightModesComponentController(void);
    
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    Q_PROPERTY(QString      modeParamPrefix         MEMBER _modeParamPrefix         CONSTANT)
    Q_PROPERTY(QString      modeChannelParam        MEMBER _modeChannelParam        CONSTANT)
    Q_PROPERTY(int          activeFlightMode        READ activeFlightMode           NOTIFY activeFlightModeChanged)
    Q_PROPERTY(int          channelCount            MEMBER _channelCount            CONSTANT)
    Q_PROPERTY(QVariantList channelOptionEnabled    READ channelOptionEnabled       NOTIFY channelOptionEnabledChanged)
    Q_PROPERTY(bool         simpleModesSupported    MEMBER _simpleModesSupported    CONSTANT)
    Q_PROPERTY(QStringList  simpleModeNames         MEMBER _simpleModeNames         CONSTANT)
    Q_PROPERTY(int          simpleMode              MEMBER _simpleMode              NOTIFY simpleModeChanged)
    Q_PROPERTY(QVariantList simpleModeEnabled       MEMBER _simpleModeEnabled       NOTIFY simpleModeEnabledChanged)
    Q_PROPERTY(QVariantList superSimpleModeEnabled  MEMBER _superSimpleModeEnabled  NOTIFY superSimpleModeEnabledChanged)

    Q_INVOKABLE void setSimpleMode(int fltModeIndex, bool enabled);
    Q_INVOKABLE void setSuperSimpleMode(int fltModeIndex, bool enabled);
Don Gagne's avatar
Don Gagne committed

Tomaz Canabrava's avatar
Tomaz Canabrava committed
    int activeFlightMode(void) const { return _activeFlightMode; }
    QVariantList channelOptionEnabled(void) const { return _rgChannelOptionEnabled; }
Don Gagne's avatar
Don Gagne committed

signals:
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    void activeFlightModeChanged        (int activeFlightMode);
    void channelOptionEnabledChanged    (void);
    void simpleModeChanged              (int simpleMode);
    void simpleModeEnabledChanged       (void);
    void superSimpleModeEnabledChanged  (void);

Don Gagne's avatar
Don Gagne committed
private slots:
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    void _rcChannelsChanged                     (int channelCount, int pwmValues[Vehicle::cMaxRcChannels]);
    void _updateSimpleParamsFromSimpleMode      (void);
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    void _setupSimpleModeEnabled     (void);
DonLakeFlyer's avatar
 
DonLakeFlyer committed

Don Gagne's avatar
Don Gagne committed
private:
Don Gagne's avatar
Don Gagne committed
    QString         _modeParamPrefix;
    QString         _modeChannelParam;
Don Gagne's avatar
Don Gagne committed
    int             _activeFlightMode;
    int             _channelCount;
    QVariantList    _rgChannelOptionEnabled;
DonLakeFlyer's avatar
 
DonLakeFlyer committed
    QStringList     _simpleModeNames;
    int             _simpleMode;
    Fact*           _simpleModeFact;
    Fact*           _superSimpleModeFact;
    bool            _simpleModesSupported;
    QVariantList    _simpleModeEnabled;
    QVariantList    _superSimpleModeEnabled;

    static const uint8_t    _allSimpleBits =    0x3F;
    static const int        _cChannelOptions =  10;
    static const int        _cSimpleModeBits =  8;
    static const int        _cFltModes =        6;

DonLakeFlyer's avatar
 
DonLakeFlyer committed
    static const char*      _simpleParamName;
    static const char*      _superSimpleParamName;

DonLakeFlyer's avatar
 
DonLakeFlyer committed
    static bool _typeRegistered;
Don Gagne's avatar
Don Gagne committed
};

#endif