ESP8266ComponentController.h 4.9 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1
/*=====================================================================
dogmaphobic's avatar
dogmaphobic committed
2

dogmaphobic's avatar
dogmaphobic committed
3
 QGroundControl Open Source Ground Control Station
dogmaphobic's avatar
dogmaphobic committed
4

dogmaphobic's avatar
dogmaphobic committed
5
 (c) 2009, 2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
dogmaphobic's avatar
dogmaphobic committed
6

dogmaphobic's avatar
dogmaphobic committed
7
 This file is part of the QGROUNDCONTROL project
dogmaphobic's avatar
dogmaphobic committed
8

dogmaphobic's avatar
dogmaphobic committed
9 10 11 12
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
dogmaphobic's avatar
dogmaphobic committed
13

dogmaphobic's avatar
dogmaphobic committed
14 15 16 17
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
dogmaphobic's avatar
dogmaphobic committed
18

dogmaphobic's avatar
dogmaphobic committed
19 20
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
dogmaphobic's avatar
dogmaphobic committed
21

dogmaphobic's avatar
dogmaphobic committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 ======================================================================*/


/// @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
48

dogmaphobic's avatar
dogmaphobic committed
49 50 51 52
public:
    ESP8266ComponentController      ();
    ~ESP8266ComponentController     ();

53 54 55 56 57 58 59 60 61 62 63 64
    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
65 66

    Q_INVOKABLE void restoreDefaults();
67
    Q_INVOKABLE void reboot         ();
dogmaphobic's avatar
dogmaphobic committed
68 69

    int             componentID     () { return MAV_COMP_ID_UDP_BRIDGE; }
70
    QString         version         ();
dogmaphobic's avatar
dogmaphobic committed
71
    QString         wifiIPAddress   ();
dogmaphobic's avatar
dogmaphobic committed
72 73
    QString         wifiSSID        ();
    QString         wifiPassword    ();
74 75
    QString         wifiSSIDSta     ();
    QString         wifiPasswordSta ();
dogmaphobic's avatar
dogmaphobic committed
76 77 78 79
    QStringList     wifiChannels    () { return _channels; }
    QStringList     baudRates       () { return _baudRates; }
    int             baudIndex       ();
    bool            busy            () { return _waitType != WAIT_FOR_NOTHING; }
80
    Vehicle*        vehicle         () { return _vehicle; }
dogmaphobic's avatar
dogmaphobic committed
81 82 83

    void        setWifiSSID         (QString id);
    void        setWifiPassword     (QString pwd);
84 85
    void        setWifiSSIDSta      (QString id);
    void        setWifiPasswordSta  (QString pwd);
dogmaphobic's avatar
dogmaphobic committed
86 87 88
    void        setBaudIndex        (int idx);

signals:
89 90 91 92 93 94 95
    void        versionChanged          ();
    void        wifiSSIDChanged         ();
    void        wifiPasswordChanged     ();
    void        wifiSSIDStaChanged      ();
    void        wifiPasswordStaChanged  ();
    void        baudIndexChanged        ();
    void        busyChanged             ();
dogmaphobic's avatar
dogmaphobic committed
96 97 98

private slots:
    void        _processTimeout     ();
99
    void        _commandAck         (uint8_t compID, uint16_t command, uint8_t result);
dogmaphobic's avatar
dogmaphobic committed
100 101 102
    void        _ssidChanged        (QVariant value);
    void        _passwordChanged    (QVariant value);
    void        _baudChanged        (QVariant value);
103
    void        _versionChanged     (QVariant value);
dogmaphobic's avatar
dogmaphobic committed
104 105 106 107 108 109 110 111 112

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

private:
    QTimer      _timer;
    QStringList _channels;
    QStringList _baudRates;
dogmaphobic's avatar
dogmaphobic committed
113
    QString     _ipAddress;
dogmaphobic's avatar
dogmaphobic committed
114 115 116 117 118 119 120 121 122 123 124 125

    enum {
        WAIT_FOR_NOTHING,
        WAIT_FOR_REBOOT,
        WAIT_FOR_RESTORE
    };

    int         _waitType;
    int         _retries;
};

#endif // ESP8266ComponentController_H