Skip to content

Commit

Permalink
Add WiFi::end API and revise init_connsys
Browse files Browse the repository at this point in the history
 - Separate BLE and Wi-Fi cases when initializing connsys
 - Add WiFi::end API to allow user to manually turn-off wifi
  • Loading branch information
pablosun committed Feb 27, 2018
1 parent b372e26 commit 8928f18
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void _connsys_workaround()
{
// Wi-Fi must be initialized for BLE start-up
// declared in Arduino core's "variant.h"
init_global_connsys();
init_global_connsys_for_ble();
}
//////////////////////////////////////////////////

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ class WiFiClass
*/
String softAPmacAddress(void);

/////////////////////////////////////////////////////////////////////////////
// Turn off Wi-Fi function
/////////////////////////////////////////////////////////////////////////////

/*
* Turn off WiFi function
* You must either call begin()/scan()/softAP() again to
* restart WiFi function
*/
void end();

// Internal Use
public:
friend class WiFiClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ int WiFiClass::begin(const char* ssid, const char *passphrase)
return status;
}

void WiFiClass::end() {
int result = wifi_config_set_radio(0);
pr_debug("wifi_config_set_radio(0) returns %d\n", result);
}

void WiFiClass::config(IPAddress local_ip)
{
WiFiDrv::config(1, (uint32_t)local_ip, 0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ extern "C" {
/*****************************************************************************
* customization module feature option
*****************************************************************************/
//#define MTK_HAL_PLAIN_LOG_ENABLE
//#define MTK_HAL_NO_LOG_ENABLE
#define MTK_HAL_PLAIN_LOG_ENABLE
#define MTK_HAL_NO_LOG_ENABLE

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ static int32_t _wifi_ready_handler(wifi_event_t event,
return 0;
}

void init_global_connsys() {
static void init_global_connsys_impl(int enableWiFi) {
if(wifi_ready()) {
if(enableWiFi) {
pr_debug("[wifi_init] turn on wi-fi");
wifi_config_set_radio(1);
}
return;
}

Expand Down Expand Up @@ -112,12 +116,27 @@ void init_global_connsys() {
while (!wifi_ready()) {
delay(10);
}
pr_debug("[wifi/connsys ready] turn off radio first");

#if 0 // if we turn off wifi, and turn on again, subsequent wifi scan fails (as of v4.6.0)
if(!enableWiFi) {
pr_debug("[wifi_init] turn off wi-fi");
wifi_config_set_radio(0);
}
#endif

return;
}

void init_global_connsys_for_ble() {
// pass 1 to turn on Wi-Fi when it is already initialized
init_global_connsys_impl(0);
}


void init_global_connsys() {
// pass 1 to turn on Wi-Fi when it is already initialized
init_global_connsys_impl(1);
}

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern void post_init(void);
// communicate with each other to know if Wi-Fi
// is already initialized.
extern void init_global_connsys();
extern void init_global_connsys_for_ble();
extern bool wifi_ready();

#ifdef __cplusplus
Expand Down

0 comments on commit 8928f18

Please sign in to comment.