ESP8266ComponentController.h 4.28 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 53
public:
    ESP8266ComponentController      ();
    ~ESP8266ComponentController     ();

    Q_PROPERTY(int              componentID     READ componentID                            CONSTANT)
54
    Q_PROPERTY(QString          version         READ version                                NOTIFY versionChanged)
dogmaphobic's avatar
dogmaphobic committed
55
    Q_PROPERTY(QString          wifiIPAddress   READ wifiIPAddress                          CONSTANT)
dogmaphobic's avatar
dogmaphobic committed
56 57 58 59 60 61
    Q_PROPERTY(QString          wifiSSID        READ wifiSSID       WRITE setWifiSSID       NOTIFY wifiSSIDChanged)
    Q_PROPERTY(QString          wifiPassword    READ wifiPassword   WRITE setWifiPassword   NOTIFY wifiPasswordChanged)
    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)
dogmaphobic's avatar
dogmaphobic committed
62
    Q_PROPERTY(Vehicle*         vehicle         READ vehicle                                CONSTANT)
dogmaphobic's avatar
dogmaphobic committed
63 64

    Q_INVOKABLE void restoreDefaults();
65
    Q_INVOKABLE void reboot         ();
dogmaphobic's avatar
dogmaphobic committed
66 67

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

    void        setWifiSSID         (QString id);
    void        setWifiPassword     (QString pwd);
    void        setBaudIndex        (int idx);

signals:
83
    void        versionChanged      ();
dogmaphobic's avatar
dogmaphobic committed
84 85 86 87 88 89 90
    void        wifiSSIDChanged     ();
    void        wifiPasswordChanged ();
    void        baudIndexChanged    ();
    void        busyChanged         ();

private slots:
    void        _processTimeout     ();
91
    void        _commandAck         (uint8_t compID, uint16_t command, uint8_t result);
dogmaphobic's avatar
dogmaphobic committed
92 93 94
    void        _ssidChanged        (QVariant value);
    void        _passwordChanged    (QVariant value);
    void        _baudChanged        (QVariant value);
95
    void        _versionChanged     (QVariant value);
dogmaphobic's avatar
dogmaphobic committed
96 97 98 99 100 101 102 103 104

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

private:
    QTimer      _timer;
    QStringList _channels;
    QStringList _baudRates;
dogmaphobic's avatar
dogmaphobic committed
105
    QString     _ipAddress;
dogmaphobic's avatar
dogmaphobic committed
106 107 108 109 110 111 112 113 114 115 116 117

    enum {
        WAIT_FOR_NOTHING,
        WAIT_FOR_REBOOT,
        WAIT_FOR_RESTORE
    };

    int         _waitType;
    int         _retries;
};

#endif // ESP8266ComponentController_H