20 changed files with 918 additions and 36 deletions
@ -0,0 +1,211 @@
@@ -0,0 +1,211 @@
|
||||
/*===================================================================== |
||||
|
||||
QGroundControl Open Source Ground Control Station |
||||
|
||||
(c) 2009 - 2015 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/>. |
||||
|
||||
======================================================================*/ |
||||
|
||||
import QtQuick 2.5 |
||||
import QtQuick.Controls 1.2 |
||||
import QtQuick.Dialogs 1.2 |
||||
|
||||
import QGroundControl 1.0 |
||||
import QGroundControl.FactSystem 1.0 |
||||
import QGroundControl.FactControls 1.0 |
||||
import QGroundControl.Palette 1.0 |
||||
import QGroundControl.Controls 1.0 |
||||
import QGroundControl.ScreenTools 1.0 |
||||
import QGroundControl.Controllers 1.0 |
||||
|
||||
QGCView { |
||||
id: qgcView |
||||
viewPanel: panel |
||||
|
||||
QGCPalette { id: palette; colorGroupEnabled: panel.enabled } |
||||
|
||||
property int _firstColumn: ScreenTools.defaultFontPixelWidth * 20 |
||||
property int _secondColumn: ScreenTools.defaultFontPixelWidth * 12 |
||||
readonly property string dialogTitle: "controller WiFi Bridge" |
||||
|
||||
ESP8266ComponentController { |
||||
id: controller |
||||
factPanel: panel |
||||
} |
||||
|
||||
property Fact wifiChannel: controller.getParameterFact(controller.componentID, "WIFI_CHANNEL") |
||||
property Fact hostPort: controller.getParameterFact(controller.componentID, "WIFI_UDP_HPORT") |
||||
property Fact clientPort: controller.getParameterFact(controller.componentID, "WIFI_UDP_CPORT") |
||||
|
||||
QGCViewPanel { |
||||
id: panel |
||||
anchors.fill: parent |
||||
|
||||
Flickable { |
||||
anchors.fill: parent |
||||
clip: true |
||||
contentHeight: innerColumn.height |
||||
contentWidth: panel.width |
||||
boundsBehavior: Flickable.StopAtBounds |
||||
flickableDirection: Flickable.VerticalFlick |
||||
|
||||
Column { |
||||
id: innerColumn |
||||
width: panel.width |
||||
spacing: ScreenTools.defaultFontPixelHeight * 0.5 |
||||
|
||||
QGCLabel { |
||||
text: "WiFi Bridge Settings" |
||||
font.weight: Font.DemiBold |
||||
} |
||||
|
||||
Rectangle { |
||||
width: parent.width |
||||
height: wifiCol.height + (ScreenTools.defaultFontPixelHeight * 2) |
||||
color: palette.windowShade |
||||
Column { |
||||
id: wifiCol |
||||
anchors.margins: ScreenTools.defaultFontPixelHeight / 2 |
||||
anchors.verticalCenter: parent.verticalCenter |
||||
anchors.left: parent.left |
||||
spacing: ScreenTools.defaultFontPixelHeight / 2 |
||||
Row { |
||||
spacing: ScreenTools.defaultFontPixelWidth |
||||
QGCLabel { |
||||
text: "WiFi Channel" |
||||
width: _firstColumn |
||||
anchors.baseline: channelField.baseline |
||||
} |
||||
QGCComboBox { |
||||
id: channelField |
||||
width: _secondColumn |
||||
model: controller.wifiChannels |
||||
currentIndex: wifiChannel ? wifiChannel.value - 1 : 0 |
||||
onActivated: { |
||||
wifiChannel.value = index + 1 |
||||
} |
||||
} |
||||
} |
||||
Row { |
||||
spacing: ScreenTools.defaultFontPixelWidth |
||||
QGCLabel { |
||||
text: "WiFi SSID" |
||||
width: _firstColumn |
||||
anchors.baseline: ssidField.baseline |
||||
} |
||||
QGCTextField { |
||||
id: ssidField |
||||
width: _secondColumn |
||||
text: controller.wifiSSID |
||||
maximumLength: 16 |
||||
onEditingFinished: { |
||||
controller.wifiSSID = text |
||||
} |
||||
} |
||||
} |
||||
Row { |
||||
spacing: ScreenTools.defaultFontPixelWidth |
||||
QGCLabel { |
||||
text: "WiFi Password" |
||||
width: _firstColumn |
||||
anchors.baseline: passwordField.baseline |
||||
} |
||||
QGCTextField { |
||||
id: passwordField |
||||
width: _secondColumn |
||||
text: controller.wifiPassword |
||||
maximumLength: 16 |
||||
onEditingFinished: { |
||||
controller.wifiPassword = text |
||||
} |
||||
} |
||||
} |
||||
Row { |
||||
spacing: ScreenTools.defaultFontPixelWidth |
||||
QGCLabel { |
||||
text: "UART Baud Rate" |
||||
width: _firstColumn |
||||
anchors.baseline: baudField.baseline |
||||
} |
||||
QGCComboBox { |
||||
id: baudField |
||||
width: _secondColumn |
||||
model: controller.baudRates |
||||
currentIndex: controller.baudIndex |
||||
onActivated: { |
||||
controller.baudIndex = index |
||||
} |
||||
} |
||||
} |
||||
Row { |
||||
spacing: ScreenTools.defaultFontPixelWidth |
||||
QGCLabel { |
||||
text: "QGC UDP Port" |
||||
width: _firstColumn |
||||
anchors.baseline: qgcportField.baseline |
||||
} |
||||
QGCTextField { |
||||
id: qgcportField |
||||
width: _secondColumn |
||||
text: hostPort ? hostPort.valueString : "" |
||||
validator: IntValidator {bottom: 1024; top: 65535;} |
||||
inputMethodHints: Qt.ImhDigitsOnly |
||||
onEditingFinished: { |
||||
hostPort.value = text |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Row { |
||||
spacing: ScreenTools.defaultFontPixelWidth * 1.5 |
||||
QGCButton { |
||||
text: "Restore Defaults" |
||||
width: ScreenTools.defaultFontPixelWidth * 16 |
||||
onClicked: { |
||||
controller.restoreDefaults() |
||||
} |
||||
} |
||||
QGCButton { |
||||
text: "Restart WiFi Bridge" |
||||
enabled: !controller.busy |
||||
width: ScreenTools.defaultFontPixelWidth * 16 |
||||
onClicked: { |
||||
rebootDialog.visible = true |
||||
} |
||||
MessageDialog { |
||||
id: rebootDialog |
||||
visible: false |
||||
icon: StandardIcon.Warning |
||||
standardButtons: StandardButton.Yes | StandardButton.No |
||||
title: "Reboot WiFi Bridge" |
||||
text: "This will restart the WiFi Bridge so the settings you've changed can take effect. Note that you may have to change your computer WiFi settings and QGroundControl link settings to match these changes. Are you sure you want to restart it?" |
||||
onYes: { |
||||
controller.reboot() |
||||
rebootDialog.visible = false |
||||
} |
||||
onNo: { |
||||
rebootDialog.visible = false |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,318 @@
@@ -0,0 +1,318 @@
|
||||
/*=====================================================================
|
||||
|
||||
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>
|
||||
|
||||
#include "ESP8266ComponentController.h" |
||||
#include "AutoPilotPluginManager.h" |
||||
#include "QGCApplication.h" |
||||
#include "UAS.h" |
||||
|
||||
QGC_LOGGING_CATEGORY(ESP8266ComponentControllerLog, "ESP8266ComponentControllerLog") |
||||
|
||||
#define MAX_RETRIES 5 |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
ESP8266ComponentController::ESP8266ComponentController() |
||||
: _waitType(WAIT_FOR_NOTHING) |
||||
, _retries(0) |
||||
{ |
||||
for(int i = 1; i < 12; i++) { |
||||
_channels.append(QString::number(i)); |
||||
} |
||||
_baudRates.append("57600"); |
||||
_baudRates.append("115200"); |
||||
_baudRates.append("230400"); |
||||
_baudRates.append("460800"); |
||||
_baudRates.append("921600"); |
||||
connect(&_timer, &QTimer::timeout, this, &ESP8266ComponentController::_processTimeout); |
||||
UASInterface* uas = dynamic_cast<UASInterface*>(_vehicle->uas()); |
||||
connect(uas, &UASInterface::commandAck, this, &ESP8266ComponentController::_commandAck); |
||||
Fact* ssid = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSID4"); |
||||
connect(ssid, &Fact::valueChanged, this, &ESP8266ComponentController::_ssidChanged); |
||||
Fact* paswd = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PASSWORD4"); |
||||
connect(paswd, &Fact::valueChanged, this, &ESP8266ComponentController::_passwordChanged); |
||||
Fact* baud = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "UART_BAUDRATE"); |
||||
connect(baud, &Fact::valueChanged, this, &ESP8266ComponentController::_baudChanged); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
ESP8266ComponentController::~ESP8266ComponentController() |
||||
{ |
||||
|
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QString |
||||
ESP8266ComponentController::wifiSSID() |
||||
{ |
||||
uint32_t s1 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSID1")->rawValue().toUInt(); |
||||
uint32_t s2 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSID2")->rawValue().toUInt(); |
||||
uint32_t s3 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSID3")->rawValue().toUInt(); |
||||
uint32_t s4 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSID4")->rawValue().toUInt(); |
||||
char tmp[20]; |
||||
memcpy(&tmp[0], &s1, sizeof(uint32_t)); |
||||
memcpy(&tmp[4], &s2, sizeof(uint32_t)); |
||||
memcpy(&tmp[8], &s3, sizeof(uint32_t)); |
||||
memcpy(&tmp[12], &s4, sizeof(uint32_t)); |
||||
return QString(tmp); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::setWifiSSID(QString ssid) |
||||
{ |
||||
char tmp[20]; |
||||
memset(tmp, 0, sizeof(tmp)); |
||||
std::string sid = ssid.toStdString(); |
||||
strncpy(tmp, sid.c_str(), sizeof(tmp)); |
||||
Fact* f1 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSID1"); |
||||
Fact* f2 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSID2"); |
||||
Fact* f3 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSID3"); |
||||
Fact* f4 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_SSID4"); |
||||
uint32_t u; |
||||
memcpy(&u, &tmp[0], sizeof(uint32_t)); |
||||
f1->setRawValue(QVariant(u)); |
||||
memcpy(&u, &tmp[4], sizeof(uint32_t)); |
||||
f2->setRawValue(QVariant(u)); |
||||
memcpy(&u, &tmp[8], sizeof(uint32_t)); |
||||
f3->setRawValue(QVariant(u)); |
||||
memcpy(&u, &tmp[12], sizeof(uint32_t)); |
||||
f4->setRawValue(QVariant(u)); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
QString |
||||
ESP8266ComponentController::wifiPassword() |
||||
{ |
||||
uint32_t s1 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PASSWORD1")->rawValue().toUInt(); |
||||
uint32_t s2 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PASSWORD2")->rawValue().toUInt(); |
||||
uint32_t s3 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PASSWORD3")->rawValue().toUInt(); |
||||
uint32_t s4 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PASSWORD4")->rawValue().toUInt(); |
||||
char tmp[20]; |
||||
memcpy(&tmp[0], &s1, sizeof(uint32_t)); |
||||
memcpy(&tmp[4], &s2, sizeof(uint32_t)); |
||||
memcpy(&tmp[8], &s3, sizeof(uint32_t)); |
||||
memcpy(&tmp[12], &s4, sizeof(uint32_t)); |
||||
return QString(tmp); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::setWifiPassword(QString password) |
||||
{ |
||||
char tmp[20]; |
||||
memset(tmp, 0, sizeof(tmp)); |
||||
std::string pwd = password.toStdString(); |
||||
strncpy(tmp, pwd.c_str(), sizeof(tmp)); |
||||
Fact* f1 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PASSWORD1"); |
||||
Fact* f2 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PASSWORD2"); |
||||
Fact* f3 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PASSWORD3"); |
||||
Fact* f4 = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_PASSWORD4"); |
||||
uint32_t u; |
||||
memcpy(&u, &tmp[0], sizeof(uint32_t)); |
||||
f1->setRawValue(QVariant(u)); |
||||
memcpy(&u, &tmp[4], sizeof(uint32_t)); |
||||
f2->setRawValue(QVariant(u)); |
||||
memcpy(&u, &tmp[8], sizeof(uint32_t)); |
||||
f3->setRawValue(QVariant(u)); |
||||
memcpy(&u, &tmp[12], sizeof(uint32_t)); |
||||
f4->setRawValue(QVariant(u)); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int |
||||
ESP8266ComponentController::baudIndex() |
||||
{ |
||||
int b = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "UART_BAUDRATE")->rawValue().toInt(); |
||||
switch (b) { |
||||
case 57600: |
||||
return 0; |
||||
case 115200: |
||||
return 1; |
||||
case 230400: |
||||
return 2; |
||||
case 460800: |
||||
return 3; |
||||
case 921600: |
||||
default: |
||||
return 4; |
||||
} |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::setBaudIndex(int idx) |
||||
{ |
||||
if(idx >= 0 && idx != baudIndex()) { |
||||
int baud = 921600; |
||||
switch(idx) { |
||||
case 0: |
||||
baud = 57600; |
||||
break; |
||||
case 1: |
||||
baud = 115200; |
||||
break; |
||||
case 2: |
||||
baud = 230400; |
||||
break; |
||||
case 3: |
||||
baud = 460800; |
||||
break; |
||||
default: |
||||
baud = 921600; |
||||
} |
||||
Fact* b = getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "UART_BAUDRATE"); |
||||
b->setRawValue(baud); |
||||
} |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::reboot() |
||||
{ |
||||
_waitType = WAIT_FOR_REBOOT; |
||||
emit busyChanged(); |
||||
_retries = MAX_RETRIES; |
||||
_reboot(); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::restoreDefaults() |
||||
{ |
||||
_waitType = WAIT_FOR_RESTORE; |
||||
emit busyChanged(); |
||||
_retries = MAX_RETRIES; |
||||
_restoreDefaults(); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::_reboot() |
||||
{ |
||||
mavlink_message_t msg; |
||||
mavlink_msg_command_long_pack( |
||||
qgcApp()->toolbox()->mavlinkProtocol()->getSystemId(), |
||||
qgcApp()->toolbox()->mavlinkProtocol()->getComponentId(), |
||||
&msg, |
||||
_vehicle->id(), |
||||
MAV_COMP_ID_UDP_BRIDGE, |
||||
MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN, |
||||
1.0f, // Confirmation
|
||||
0.0f, // Param1
|
||||
1.0f, // Param2
|
||||
0.0f,0.0f,0.0f,0.0f,0.0f); |
||||
qCDebug(ESP8266ComponentControllerLog) << "_reboot()"; |
||||
_vehicle->sendMessageOnLink(_vehicle->priorityLink(), msg); |
||||
_timer.start(1000); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::_restoreDefaults() |
||||
{ |
||||
mavlink_message_t msg; |
||||
mavlink_msg_command_long_pack( |
||||
qgcApp()->toolbox()->mavlinkProtocol()->getSystemId(), |
||||
qgcApp()->toolbox()->mavlinkProtocol()->getComponentId(), |
||||
&msg, |
||||
_vehicle->id(), |
||||
MAV_COMP_ID_UDP_BRIDGE, |
||||
MAV_CMD_PREFLIGHT_STORAGE, |
||||
1.0f, // Confirmation
|
||||
2.0f, // Param1
|
||||
0.0f,0.0f,0.0f,0.0f,0.0f,0.0f); |
||||
qCDebug(ESP8266ComponentControllerLog) << "_restoreDefaults()"; |
||||
_vehicle->sendMessageOnLink(_vehicle->priorityLink(), msg); |
||||
_timer.start(1000); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::_processTimeout() |
||||
{ |
||||
if(!--_retries) { |
||||
qCDebug(ESP8266ComponentControllerLog) << "_processTimeout Giving Up"; |
||||
_timer.stop(); |
||||
_waitType = WAIT_FOR_NOTHING; |
||||
emit busyChanged(); |
||||
} else { |
||||
switch(_waitType) { |
||||
case WAIT_FOR_REBOOT: |
||||
qCDebug(ESP8266ComponentControllerLog) << "_processTimeout for Reboot"; |
||||
_reboot(); |
||||
break; |
||||
case WAIT_FOR_RESTORE: |
||||
qCDebug(ESP8266ComponentControllerLog) << "_processTimeout for Restore Defaults"; |
||||
_restoreDefaults(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::_commandAck(UASInterface*, uint8_t compID, uint16_t command, uint8_t result) |
||||
{ |
||||
if(compID == MAV_COMP_ID_UDP_BRIDGE) { |
||||
if(result != MAV_RESULT_ACCEPTED) { |
||||
qWarning() << "ESP8266ComponentController command" << command << "rejected."; |
||||
return; |
||||
} |
||||
if((_waitType == WAIT_FOR_REBOOT && command == MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN) || |
||||
(_waitType == WAIT_FOR_RESTORE && command == MAV_CMD_PREFLIGHT_STORAGE)) |
||||
{ |
||||
_timer.stop(); |
||||
_waitType = WAIT_FOR_NOTHING; |
||||
emit busyChanged(); |
||||
qCDebug(ESP8266ComponentControllerLog) << "_commandAck for" << command; |
||||
if(command == MAV_CMD_PREFLIGHT_STORAGE) { |
||||
_autopilot->refreshAllParameters(MAV_COMP_ID_UDP_BRIDGE); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::_ssidChanged(QVariant) |
||||
{ |
||||
emit wifiSSIDChanged(); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::_passwordChanged(QVariant) |
||||
{ |
||||
emit wifiPasswordChanged(); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void |
||||
ESP8266ComponentController::_baudChanged(QVariant) |
||||
{ |
||||
emit baudIndexChanged(); |
||||
} |
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
/*=====================================================================
|
||||
|
||||
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) |
||||
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) |
||||
|
||||
Q_INVOKABLE void restoreDefaults(); |
||||
Q_INVOKABLE void reboot(); |
||||
|
||||
int componentID () { return MAV_COMP_ID_UDP_BRIDGE; } |
||||
QString wifiSSID (); |
||||
QString wifiPassword (); |
||||
QStringList wifiChannels () { return _channels; } |
||||
QStringList baudRates () { return _baudRates; } |
||||
int baudIndex (); |
||||
bool busy () { return _waitType != WAIT_FOR_NOTHING; } |
||||
|
||||
void setWifiSSID (QString id); |
||||
void setWifiPassword (QString pwd); |
||||
void setBaudIndex (int idx); |
||||
|
||||
signals: |
||||
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); |
||||
|
||||
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
|
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
import QtQuick 2.2 |
||||
import QtQuick.Controls 1.2 |
||||
|
||||
import QGroundControl.FactSystem 1.0 |
||||
import QGroundControl.FactControls 1.0 |
||||
import QGroundControl.Controls 1.0 |
||||
import QGroundControl.Palette 1.0 |
||||
import QGroundControl.Controllers 1.0 |
||||
|
||||
FactPanel { |
||||
id: panel |
||||
anchors.fill: parent |
||||
color: qgcPal.windowShadeDark |
||||
|
||||
QGCPalette { id: qgcPal; colorGroupEnabled: enabled } |
||||
FactPanelController { id: controller; factPanel: panel } |
||||
|
||||
ESP8266ComponentController { |
||||
id: esp8266 |
||||
} |
||||
|
||||
property Fact debugEnabled: controller.getParameterFact(esp8266.componentID, "DEBUG_ENABLED") |
||||
property Fact wifiChannel: controller.getParameterFact(esp8266.componentID, "WIFI_CHANNEL") |
||||
property Fact wifiHostPort: controller.getParameterFact(esp8266.componentID, "WIFI_UDP_HPORT") |
||||
property Fact wifiClientPort: controller.getParameterFact(esp8266.componentID, "WIFI_UDP_CPORT") |
||||
property Fact uartBaud: controller.getParameterFact(esp8266.componentID, "UART_BAUDRATE") |
||||
|
||||
Column { |
||||
anchors.fill: parent |
||||
anchors.margins: 8 |
||||
VehicleSummaryRow { |
||||
labelText: "WiFi Channel:" |
||||
valueText: wifiChannel.valueString |
||||
} |
||||
VehicleSummaryRow { |
||||
labelText: "WiFi SSID:" |
||||
valueText: esp8266.wifiSSID |
||||
} |
||||
VehicleSummaryRow { |
||||
labelText: "WiFi Password:" |
||||
valueText: esp8266.wifiPassword |
||||
} |
||||
VehicleSummaryRow { |
||||
labelText: "QGC UDP Port:" |
||||
valueText: wifiHostPort.valueString |
||||
} |
||||
VehicleSummaryRow { |
||||
labelText: "UAV UDP Port:" |
||||
valueText: wifiClientPort.valueString |
||||
} |
||||
VehicleSummaryRow { |
||||
labelText: "UART Baud Rate:" |
||||
valueText: uartBaud.valueString |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 1.6 KiB |
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
/*=====================================================================
|
||||
|
||||
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/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
#include "PX4ESP8266Component.h" |
||||
#include "PX4AutoPilotPlugin.h" |
||||
|
||||
PX4ESP8266Component::PX4ESP8266Component(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) |
||||
: PX4Component(vehicle, autopilot, parent) |
||||
, _name(tr("WiFi Bridge")) |
||||
{ |
||||
|
||||
} |
||||
|
||||
QString PX4ESP8266Component::name(void) const |
||||
{ |
||||
return _name; |
||||
} |
||||
|
||||
QString PX4ESP8266Component::description(void) const |
||||
{ |
||||
return tr("The ESP8266 WiFi Bridge Component is used to setup the WiFi link."); |
||||
} |
||||
|
||||
QString PX4ESP8266Component::iconResource(void) const |
||||
{ |
||||
return "/qmlimages/wifi.svg"; |
||||
} |
||||
|
||||
bool PX4ESP8266Component::requiresSetup(void) const |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
bool PX4ESP8266Component::setupComplete(void) const |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
QStringList PX4ESP8266Component::setupCompleteChangedTriggerList(void) const |
||||
{ |
||||
return QStringList(); |
||||
} |
||||
|
||||
QUrl PX4ESP8266Component::setupSource(void) const |
||||
{ |
||||
return QUrl::fromUserInput("qrc:/qml/ESP8266Component.qml"); |
||||
} |
||||
|
||||
QUrl PX4ESP8266Component::summaryQmlSource(void) const |
||||
{ |
||||
return QUrl::fromUserInput("qrc:/qml/ESP8266ComponentSummary.qml"); |
||||
} |
||||
|
||||
QString PX4ESP8266Component::prerequisiteSetup(void) const |
||||
{ |
||||
return QString(); |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,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/>.
|
||||
|
||||
======================================================================*/ |
||||
|
||||
#ifndef PX4ESP8266Component_H |
||||
#define PX4ESP8266Component_H |
||||
|
||||
#include "PX4Component.h" |
||||
|
||||
class PX4ESP8266Component : public PX4Component |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
PX4ESP8266Component (Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent = NULL); |
||||
|
||||
// Virtuals from PX4Component
|
||||
QStringList setupCompleteChangedTriggerList() const; |
||||
|
||||
// Virtuals from VehicleComponent
|
||||
QString name () const; |
||||
QString description () const; |
||||
QString iconResource () const; |
||||
bool requiresSetup () const; |
||||
bool setupComplete () const; |
||||
QUrl setupSource () const; |
||||
QUrl summaryQmlSource () const; |
||||
QString prerequisiteSetup () const; |
||||
|
||||
private: |
||||
const QString _name; |
||||
QVariantList _summaryItems; |
||||
}; |
||||
|
||||
#endif |
Loading…
Reference in new issue