ESP8266ComponentController.h 4.12 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009, 2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 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.
 
 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.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/


/// @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
    
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 56 57 58 59 60
    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)
61
    Q_PROPERTY(Vehicle*         vehicle         READ vehicle        CONSTANT)
dogmaphobic's avatar
dogmaphobic committed
62 63

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

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

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

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

private slots:
    void        _processTimeout     ();
    void        _commandAck         (UASInterface* uas, uint8_t compID, uint16_t command, uint8_t result);
    void        _ssidChanged        (QVariant value);
    void        _passwordChanged    (QVariant value);
    void        _baudChanged        (QVariant value);
93
    void        _versionChanged     (QVariant value);
dogmaphobic's avatar
dogmaphobic committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

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

private:
    QTimer      _timer;
    QStringList _channels;
    QStringList _baudRates;

    enum {
        WAIT_FOR_NOTHING,
        WAIT_FOR_REBOOT,
        WAIT_FOR_RESTORE
    };

    int         _waitType;
    int         _retries;
};

#endif // ESP8266ComponentController_H