Skip to content

Commit 9e8ac4a

Browse files
committed
Clean up code
1 parent 04fa61d commit 9e8ac4a

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

libraries/WiFi/src/WiFi.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ int arduino::WiFiClass::begin(char* ssid, const char *passphrase) {
2424
return WL_CONNECT_FAILED;
2525
}
2626

27-
if (wifi_if == NULL) {
27+
if (wifi_if == nullptr) {
2828
//Q: What is the callback for?
29-
cb();
30-
if(wifi_if == NULL) return WL_CONNECT_FAILED;
29+
_initializerCallback();
30+
if(wifi_if == nullptr) return WL_CONNECT_FAILED;
3131
}
3232

3333
// too long? break it off
@@ -50,18 +50,18 @@ int arduino::WiFiClass::begin(char* ssid, const char *passphrase) {
5050
int arduino::WiFiClass::beginAP(const char* ssid, const char *passphrase, uint8_t channel) {
5151

5252
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
53-
softap = WhdSoftAPInterface::get_default_instance();
53+
_softAP = WhdSoftAPInterface::get_default_instance();
5454
#endif
5555

56-
if (softap == NULL) {
56+
if (_softAP == NULL) {
5757
return WL_CONNECT_FAILED;
5858
}
5959

6060
ensureDefaultAPNetworkConfiguration();
6161

6262
//Set ap ssid, password and channel
63-
((WhdSoftAPInterface*)softap)->set_network(_ip, _netmask, _gateway);
64-
nsapi_error_t ret = ((WhdSoftAPInterface*)softap)->start(ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */, NULL, true /* cohexistance */);
63+
static_cast<WhdSoftAPInterface*>(_softAP)->set_network(_ip, _netmask, _gateway);
64+
nsapi_error_t ret = static_cast<WhdSoftAPInterface*>(_softAP)->start(ssid, passphrase, NSAPI_SECURITY_WPA2, channel, true /* dhcp server */, NULL, true /* cohexistance */);
6565

6666
return ret == NSAPI_ERROR_OK ? WL_AP_LISTENING : WL_CONNECT_FAILED;
6767
}
@@ -83,8 +83,8 @@ void arduino::WiFiClass::end() {
8383
}
8484

8585
int arduino::WiFiClass::disconnect() {
86-
if (softap != NULL) {
87-
return static_cast<WhdSoftAPInterface*>(softap)->stop();
86+
if (_softAP != nullptr) {
87+
return static_cast<WhdSoftAPInterface*>(_softAP)->stop();
8888
} else {
8989
return wifi_if->disconnect();
9090
}
@@ -171,7 +171,7 @@ static uint8_t sec2enum(nsapi_security_t sec)
171171

172172
int8_t arduino::WiFiClass::scanNetworks() {
173173
uint8_t count = 10;
174-
if (ap_list == NULL) {
174+
if (ap_list == nullptr) {
175175
ap_list = new WiFiAccessPoint[count];
176176
}
177177
return wifi_if->scan(ap_list, count);
@@ -243,8 +243,8 @@ arduino::IPAddress arduino::WiFiClass::gatewayIP() {
243243
}
244244

245245
NetworkInterface *arduino::WiFiClass::getNetwork() {
246-
if (softap != NULL) {
247-
return softap;
246+
if (_softAP != nullptr) {
247+
return _softAP;
248248
} else {
249249
return wifi_if;
250250
}

libraries/WiFi/src/WiFi.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,13 @@ typedef void* (*voidPrtFuncPtr)(void);
5555

5656
class WiFiClass
5757
{
58-
private:
59-
60-
static void init();
6158
public:
6259
static int16_t _state[MAX_SOCK_NUM];
6360
static uint16_t _server_port[MAX_SOCK_NUM];
6461

6562
WiFiClass(WiFiInterface* _if) : wifi_if(_if) {};
6663

67-
WiFiClass(voidPrtFuncPtr _cb) : cb(_cb) {};
64+
WiFiClass(voidPrtFuncPtr _cb) : _initializerCallback(_cb) {};
6865

6966
/*
7067
* Get the first socket available
@@ -294,27 +291,26 @@ class WiFiClass
294291
friend class WiFiClient;
295292
friend class WiFiServer;
296293

297-
public:
298294
NetworkInterface *getNetwork();
299295

300296
private:
301297

302-
EMACInterface* softap;
298+
EMACInterface* _softAP = nullptr;
303299
SocketAddress _ip = nullptr;
304300
SocketAddress _gateway = nullptr;
305301
SocketAddress _netmask = nullptr;
306302
SocketAddress _dnsServer1 = nullptr;
307303
SocketAddress _dnsServer2 = nullptr;
304+
char* _ssid = nullptr;
305+
wl_status_t _currentNetworkStatus = WL_IDLE_STATUS;
306+
WiFiInterface* wifi_if = nullptr;
307+
voidPrtFuncPtr _initializerCallback;
308+
WiFiAccessPoint* ap_list = nullptr;
309+
uint8_t connected_ap;
308310

309311
void ensureDefaultAPNetworkConfiguration();
310312
bool isVisible(char* ssid);
311313
arduino::IPAddress ipAddressFromSocketAddress(SocketAddress socketAddress);
312-
char* _ssid;
313-
wl_status_t _currentNetworkStatus = WL_IDLE_STATUS;
314-
WiFiInterface* wifi_if;
315-
voidPrtFuncPtr cb;
316-
WiFiAccessPoint* ap_list = NULL;
317-
uint8_t connected_ap;
318314
};
319315

320316
}

0 commit comments

Comments
 (0)