-
Notifications
You must be signed in to change notification settings - Fork 1
/
EspTouchSetup.cpp
166 lines (137 loc) · 3.27 KB
/
EspTouchSetup.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "EspTouchSetup.h"
#include <QTextStream>
EspTouchSetup::EspTouchSetup(QObject *parent): QObject(parent), mIsRunning(false)
{
}
bool EspTouchSetup::isRunning() const
{
return mIsRunning;
}
void EspTouchSetup::setRunning(bool isRunning)
{
if(isRunning == mIsRunning)
return;
if(isRunning){
runEspTouch();
}
else{
stopEspTouch();
}
}
QString EspTouchSetup::getPassword() const
{
return mPassword;
}
void EspTouchSetup::setPassword(const QString &password)
{
mPassword = password.trimmed();
emit passwordChanged();
}
QString EspTouchSetup::getSsid() const
{
return mSsid;
}
void EspTouchSetup::setSsid(const QString &ssid)
{
mSsid = ssid;
emit ssidChanged();
}
QString EspTouchSetup::getBssid() const
{
return mBssid;
}
void EspTouchSetup::setBssid(const QString &bssid)
{
mBssid = bssid;
emit bssidChanged();
}
QString EspTouchSetup::getAddress() const
{
return mAddress;
}
void EspTouchSetup::setAddress(const QString &address)
{
mAddress = address;
emit addressChanged();
}
QString EspTouchSetup::getHostIP() const
{
return mHostIP;
}
void EspTouchSetup::setHostIP(const QString &hostIP)
{
mHostIP = hostIP;
emit hostIPChanged();
}
QString EspTouchSetup::getHostMac() const
{
return mHostMac;
}
void EspTouchSetup::setHostMac(const QString &hostMac)
{
mHostMac = hostMac;
emit hostMacChanged();
}
void EspTouchSetup::gotHost(const QString& str)
{
QString astr(str);
QTextStream(stdout) << "EspTouchSetup CONFIGURED: " << astr << endl;
QStringList list = astr.split("/");
if(list.length() == 2){
setHostMac(list.at(0));
setHostIP(list.at(1));
emit hostFound(astr);
}
else
emit failed();
}
void EspTouchSetup::stopped()
{
mIsRunning = false;
QTextStream(stdout) << "EspTouchSetup STOPPED" << endl;
emit finished();
}
#if defined(Q_OS_IOS)
void EspTouchSetup::runEspTouch()
{
if(mIsRunning) return;
mIsRunning = true;
mTask = new EspTouchTaskIOS(mSsid, mBssid, mPassword);
connect(mTask, &EspTouchTaskIOS::finished, this, &EspTouchSetup::stopped);
connect(mTask, &EspTouchTaskIOS::finished, mTask, &EspTouchTaskIOS::deleteLater);
connect(mTask, &EspTouchTaskIOS::hostConfigured, this, &EspTouchSetup::gotHost);
mTask->start();
QTextStream(stdout) << "EspTouchSetup STARTED" << endl;
}
void EspTouchSetup::stopEspTouch()
{
QTextStream(stdout) << "EspTouchSetup CANCELING..." << endl;
mIsRunning = false;
mTask->stop();
}
#elif defined(Q_OS_ANDROID)
void EspTouchSetup::runEspTouch()
{
if(mIsRunning) return;
mIsRunning = true;
mTask = new EspTouchTaskAndroid(mSsid, mBssid, mPassword);
connect(mTask, &EspTouchTaskAndroid::finished, this, &EspTouchSetup::stopped);
connect(mTask, &EspTouchTaskAndroid::finished, mTask, &EspTouchTaskAndroid::deleteLater);
connect(mTask, &EspTouchTaskAndroid::hostConfigured, this, &EspTouchSetup::gotHost);
mTask->start();
QTextStream(stdout) << "EspTouchSetup STARTED" << endl;
}
void EspTouchSetup::stopEspTouch()
{
QTextStream(stdout) << "EspTouchSetup CANCELING..." << endl;
mIsRunning = false;
mTask->stop();
}
#else
void EspTouchSetup::runEspTouch()
{
}
void EspTouchSetup::stopEspTouch()
{
}
#endif