ESP8266ComponentController.h 4.32 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9

dogmaphobic's avatar
dogmaphobic committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34


/// @file
///     @brief  ESP8266 WiFi Config Qml Controller
///     @author Gus Grubba <mavlink@grubba.com>

#ifndef ESP8266ComponentController_H
#define ESP8266ComponentController_H

#include <QTimer>

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

Q_DECLARE_LOGGING_CATEGORY(ESP8266ComponentControllerLog)

namespace Ui {
    class ESP8266ComponentController;
}

class ESP8266ComponentController : public FactPanelController
{
    Q_OBJECT
dogmaphobic's avatar
dogmaphobic committed
35

dogmaphobic's avatar
dogmaphobic committed
36 37 38 39
public:
    ESP8266ComponentController      ();
    ~ESP8266ComponentController     ();

40 41 42 43 44 45 46 47 48 49 50 51
    Q_PROPERTY(int              componentID     READ componentID                                    CONSTANT)
    Q_PROPERTY(QString          version         READ version                                        NOTIFY versionChanged)
    Q_PROPERTY(QString          wifiIPAddress   READ wifiIPAddress                                  CONSTANT)
    Q_PROPERTY(QString          wifiSSID        READ wifiSSID           WRITE setWifiSSID           NOTIFY wifiSSIDChanged)
    Q_PROPERTY(QString          wifiPassword    READ wifiPassword       WRITE setWifiPassword       NOTIFY wifiPasswordChanged)
    Q_PROPERTY(QString          wifiSSIDSta     READ wifiSSIDSta        WRITE setWifiSSIDSta        NOTIFY wifiSSIDStaChanged)
    Q_PROPERTY(QString          wifiPasswordSta READ wifiPasswordSta    WRITE setWifiPasswordSta    NOTIFY wifiPasswordStaChanged)
    Q_PROPERTY(QStringList      wifiChannels    READ wifiChannels                                   CONSTANT)
    Q_PROPERTY(QStringList      baudRates       READ baudRates                                      CONSTANT)
    Q_PROPERTY(int              baudIndex       READ baudIndex          WRITE setBaudIndex          NOTIFY baudIndexChanged)
    Q_PROPERTY(bool             busy            READ busy                                           NOTIFY busyChanged)
    Q_PROPERTY(Vehicle*         vehicle         READ vehicle                                        CONSTANT)
dogmaphobic's avatar
dogmaphobic committed
52 53

    Q_INVOKABLE void restoreDefaults();
54
    Q_INVOKABLE void reboot         ();
dogmaphobic's avatar
dogmaphobic committed
55 56

    int             componentID     () { return MAV_COMP_ID_UDP_BRIDGE; }
57
    QString         version         ();
dogmaphobic's avatar
dogmaphobic committed
58
    QString         wifiIPAddress   ();
dogmaphobic's avatar
dogmaphobic committed
59 60
    QString         wifiSSID        ();
    QString         wifiPassword    ();
61 62
    QString         wifiSSIDSta     ();
    QString         wifiPasswordSta ();
dogmaphobic's avatar
dogmaphobic committed
63 64 65 66
    QStringList     wifiChannels    () { return _channels; }
    QStringList     baudRates       () { return _baudRates; }
    int             baudIndex       ();
    bool            busy            () { return _waitType != WAIT_FOR_NOTHING; }
67
    Vehicle*        vehicle         () { return _vehicle; }
dogmaphobic's avatar
dogmaphobic committed
68 69 70

    void        setWifiSSID         (QString id);
    void        setWifiPassword     (QString pwd);
71 72
    void        setWifiSSIDSta      (QString id);
    void        setWifiPasswordSta  (QString pwd);
dogmaphobic's avatar
dogmaphobic committed
73 74 75
    void        setBaudIndex        (int idx);

signals:
76 77 78 79 80 81 82
    void        versionChanged          ();
    void        wifiSSIDChanged         ();
    void        wifiPasswordChanged     ();
    void        wifiSSIDStaChanged      ();
    void        wifiPasswordStaChanged  ();
    void        baudIndexChanged        ();
    void        busyChanged             ();
dogmaphobic's avatar
dogmaphobic committed
83 84 85

private slots:
    void        _processTimeout     ();
86
    void        _commandAck         (uint8_t compID, uint16_t command, uint8_t result);
dogmaphobic's avatar
dogmaphobic committed
87 88 89
    void        _ssidChanged        (QVariant value);
    void        _passwordChanged    (QVariant value);
    void        _baudChanged        (QVariant value);
90
    void        _versionChanged     (QVariant value);
dogmaphobic's avatar
dogmaphobic committed
91 92 93 94 95 96 97 98 99

private:
    void        _reboot             ();
    void        _restoreDefaults    ();

private:
    QTimer      _timer;
    QStringList _channels;
    QStringList _baudRates;
dogmaphobic's avatar
dogmaphobic committed
100
    QString     _ipAddress;
dogmaphobic's avatar
dogmaphobic committed
101 102 103 104 105 106 107 108 109 110 111 112

    enum {
        WAIT_FOR_NOTHING,
        WAIT_FOR_REBOOT,
        WAIT_FOR_RESTORE
    };

    int         _waitType;
    int         _retries;
};

#endif // ESP8266ComponentController_H