wifictl abstraction, add wifictl event callback
This commit is contained in:
@@ -57,10 +57,11 @@ uint32_t gadgetbridge_msg_size = 0;
|
||||
*
|
||||
*/
|
||||
class BleCtlServerCallbacks: public BLEServerCallbacks {
|
||||
void onConnect(BLEServer* pServer) {
|
||||
void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param ) {
|
||||
blectl_set_event( BLECTL_CONNECT );
|
||||
blectl_clear_event( BLECTL_DISCONNECT );
|
||||
blectl_send_event_cb( BLECTL_CONNECT, (char*)"connected" );
|
||||
// pServer->updateConnParams( param->connect.remote_bda, 120, 180, 150, 10000 );
|
||||
log_i("BLE connected");
|
||||
};
|
||||
|
||||
@@ -323,15 +324,16 @@ void blectl_register_cb( EventBits_t event, BLECTL_CALLBACK_FUNC blectl_event_cb
|
||||
|
||||
blectl_event_cb_table[ blectl_event_cb_entrys - 1 ].event = event;
|
||||
blectl_event_cb_table[ blectl_event_cb_entrys - 1 ].event_cb = blectl_event_cb;
|
||||
log_i("register event_cb success");
|
||||
log_i("register blectl_event_cb success");
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void blectl_send_event_cb( EventBits_t event, char *msg ) {
|
||||
for ( int entry = 0 ; entry < blectl_event_cb_entrys ; entry++ ){
|
||||
for ( int entry = 0 ; entry < blectl_event_cb_entrys ; entry++ ) {
|
||||
yield();
|
||||
if ( event & blectl_event_cb_table[ entry ].event ) {
|
||||
log_i("call event_cb");
|
||||
log_i("call blectl_event_cb");
|
||||
blectl_event_cb_table[ entry ].event_cb( event, msg );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ void pmu_setup( TTGOClass *ttgo ) {
|
||||
log_e("target voltage set failed!");
|
||||
if ( ttgo->power->setChargeControlCur( 300 ) )
|
||||
log_e("charge current set failed!");
|
||||
if ( ttgo->power->setAdcSamplingRate( AXP_ADC_SAMPLING_RATE_25HZ ) )
|
||||
if ( ttgo->power->setAdcSamplingRate( AXP_ADC_SAMPLING_RATE_200HZ ) )
|
||||
log_e("adc sample set failed!");
|
||||
|
||||
// Turn off unused power
|
||||
|
||||
@@ -32,12 +32,6 @@
|
||||
#define POWERMGM_WAKEUP_REQUEST _BV(5)
|
||||
#define POWERMGM_PMU_BUTTON _BV(6)
|
||||
#define POWERMGM_BMA_DOUBLECLICK _BV(9)
|
||||
#define POWERMGM_WIFI_ON_REQUEST _BV(10)
|
||||
#define POWERMGM_WIFI_OFF_REQUEST _BV(11)
|
||||
#define POWERMGM_WIFI_WPS_REQUEST _BV(12)
|
||||
#define POWERMGM_WIFI_ACTIVE _BV(13)
|
||||
#define POWERMGM_WIFI_SCAN _BV(14)
|
||||
#define POWERMGM_WIFI_CONNECTED _BV(15)
|
||||
|
||||
/*
|
||||
* @brief setp power managment, coordinate managment beween CPU, wifictl, pmu, bma, display, backlight and lvgl
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include "TTGO.h"
|
||||
|
||||
#include "time.h"
|
||||
#include <WiFi.h>
|
||||
#include "wifictl.h"
|
||||
#include "config.h"
|
||||
#include "timesync.h"
|
||||
#include "powermgm.h"
|
||||
@@ -32,29 +35,31 @@ void timesync_Task( void * pvParameters );
|
||||
|
||||
timesync_config_t timesync_config;
|
||||
|
||||
void timesync_wifictl_event_cb( EventBits_t event, char* msg );
|
||||
|
||||
void timesync_setup( TTGOClass *ttgo ) {
|
||||
|
||||
timesync_read_config();
|
||||
|
||||
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
if ( timesync_config.timesync ) {
|
||||
if ( xEventGroupGetBits( time_event_handle ) & TIME_SYNC_REQUEST ) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
xEventGroupSetBits( time_event_handle, TIME_SYNC_REQUEST );
|
||||
xTaskCreate( timesync_Task, /* Function to implement the task */
|
||||
"timesync Task", /* Name of the task */
|
||||
2000, /* Stack size in words */
|
||||
NULL, /* Task input parameter */
|
||||
1, /* Priority of the task */
|
||||
&_timesync_Task ); /* Task handle. */
|
||||
}
|
||||
}
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
||||
|
||||
time_event_handle = xEventGroupCreate();
|
||||
xEventGroupClearBits( time_event_handle, TIME_SYNC_REQUEST );
|
||||
|
||||
wifictl_register_cb( WIFICTL_CONNECT, timesync_wifictl_event_cb );
|
||||
}
|
||||
|
||||
void timesync_wifictl_event_cb( EventBits_t event, char* msg ) {
|
||||
if ( timesync_config.timesync ) {
|
||||
if ( xEventGroupGetBits( time_event_handle ) & TIME_SYNC_REQUEST ) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
xEventGroupSetBits( time_event_handle, TIME_SYNC_REQUEST );
|
||||
xTaskCreate( timesync_Task, /* Function to implement the task */
|
||||
"timesync Task", /* Name of the task */
|
||||
2000, /* Stack size in words */
|
||||
NULL, /* Task input parameter */
|
||||
1, /* Priority of the task */
|
||||
&_timesync_Task ); /* Task handle. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void timesync_save_config( void ) {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <esp_wifi.h>
|
||||
#include <esp_wps.h>
|
||||
|
||||
#include "powermgm.h"
|
||||
#include "wifictl.h"
|
||||
#include "json_psram_allocator.h"
|
||||
|
||||
@@ -33,6 +32,12 @@
|
||||
#include "webserver/webserver.h"
|
||||
|
||||
bool wifi_init = false;
|
||||
EventGroupHandle_t wifictl_status = NULL;
|
||||
portMUX_TYPE wifictlMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
wifictl_event_t *wifictl_event_cb_table = NULL;
|
||||
uint32_t wifictl_event_cb_entrys = 0;
|
||||
void wifictl_send_event_cb( EventBits_t event, char *msg );
|
||||
|
||||
void wifictl_StartTask( void );
|
||||
void wifictl_Task( void * pvParameters );
|
||||
@@ -59,8 +64,9 @@ void wifictl_setup( void ) {
|
||||
if ( wifi_init == true )
|
||||
return;
|
||||
|
||||
wifictl_status = xEventGroupCreate();
|
||||
|
||||
wifi_init = true;
|
||||
powermgm_clear_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_WPS_REQUEST );
|
||||
|
||||
// clean network list table
|
||||
for ( int entry = 0 ; entry < NETWORKLIST_ENTRYS ; entry++ ) {
|
||||
@@ -73,107 +79,88 @@ void wifictl_setup( void ) {
|
||||
|
||||
// register WiFi events
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
powermgm_set_event( POWERMGM_WIFI_ACTIVE );
|
||||
powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_CONNECTED );
|
||||
statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||
statusbar_show_icon( STATUSBAR_WIFI );
|
||||
if ( powermgm_get_event( POWERMGM_WIFI_WPS_REQUEST ) )
|
||||
statusbar_wifi_set_state( true, "wait for WPS" );
|
||||
wifictl_set_event( WIFICTL_ACTIVE );
|
||||
wifictl_clear_event( WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST | WIFICTL_SCAN | WIFICTL_CONNECT );
|
||||
if ( wifictl_get_event( WIFICTL_WPS_REQUEST ) )
|
||||
wifictl_send_event_cb( WIFICTL_DISCONNECT, (char *)"wait for WPS" );
|
||||
else {
|
||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
||||
statusbar_wifi_set_state( true, "scan ..." );
|
||||
wifictl_set_event( WIFICTL_SCAN );
|
||||
wifictl_send_event_cb( WIFICTL_DISCONNECT, (char *)"scan ..." );
|
||||
WiFi.scanNetworks();
|
||||
}
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
||||
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
powermgm_set_event( POWERMGM_WIFI_ACTIVE );
|
||||
powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_WPS_REQUEST );
|
||||
statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||
statusbar_show_icon( STATUSBAR_WIFI );
|
||||
wifictl_set_event( WIFICTL_ACTIVE );
|
||||
wifictl_clear_event( WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST | WIFICTL_SCAN | WIFICTL_CONNECT | WIFICTL_WPS_REQUEST );
|
||||
int len = WiFi.scanComplete();
|
||||
for( int i = 0 ; i < len ; i++ ) {
|
||||
for ( int entry = 0 ; entry < NETWORKLIST_ENTRYS ; entry++ ) {
|
||||
if ( !strcmp( wifictl_networklist[ entry ].ssid, WiFi.SSID(i).c_str() ) ) {
|
||||
wifiname = wifictl_networklist[ entry ].ssid;
|
||||
wifipassword = wifictl_networklist[ entry ].password;
|
||||
statusbar_wifi_set_state( true, "connecting ..." );
|
||||
wifictl_send_event_cb( WIFICTL_SCAN, (char *)"connecting ..." );
|
||||
WiFi.begin( wifiname, wifipassword );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_SCAN_DONE );
|
||||
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
powermgm_set_event( POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_ACTIVE );
|
||||
if ( powermgm_get_event( POWERMGM_WIFI_WPS_REQUEST ) ) {
|
||||
wifictl_set_event( WIFICTL_CONNECT | WIFICTL_ACTIVE );
|
||||
if ( wifictl_get_event( WIFICTL_WPS_REQUEST ) ) {
|
||||
log_i("store new SSID and psk from WPS");
|
||||
wifictl_insert_network( WiFi.SSID().c_str(), WiFi.psk().c_str() );
|
||||
wifictl_save_config();
|
||||
}
|
||||
powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_WPS_REQUEST );
|
||||
statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_WHITE );
|
||||
statusbar_show_icon( STATUSBAR_WIFI );
|
||||
String label(wifiname);
|
||||
wifictl_clear_event( WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST | WIFICTL_SCAN | WIFICTL_WPS_REQUEST );
|
||||
String label( wifiname );
|
||||
label.concat(' ');
|
||||
label.concat(WiFi.localIP().toString());
|
||||
//If you want to see your IPv6 address too, uncomment this.
|
||||
// label.concat('\n');
|
||||
// label.concat(WiFi.localIPv6().toString());
|
||||
statusbar_wifi_set_state( true, label.c_str() );
|
||||
label.concat( WiFi.localIP().toString() );
|
||||
wifictl_send_event_cb( WIFICTL_CONNECT, (char *)label.c_str() );
|
||||
if ( wifictl_config.webserver ) {
|
||||
asyncwebserver_start();
|
||||
}
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
||||
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
powermgm_set_event( POWERMGM_WIFI_ACTIVE );
|
||||
powermgm_clear_event( POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST );
|
||||
statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||
statusbar_show_icon( STATUSBAR_WIFI );
|
||||
if ( powermgm_get_event( POWERMGM_WIFI_WPS_REQUEST ) )
|
||||
statusbar_wifi_set_state( true, "wait for WPS" );
|
||||
wifictl_set_event( WIFICTL_ACTIVE );
|
||||
wifictl_clear_event( WIFICTL_CONNECT | WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST );
|
||||
if ( wifictl_get_event( WIFICTL_WPS_REQUEST ) )
|
||||
wifictl_send_event_cb( WIFICTL_ON, (char *)"wait for WPS" );
|
||||
else {
|
||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
||||
statusbar_wifi_set_state( true, "scan ..." );
|
||||
wifictl_set_event( WIFICTL_SCAN );
|
||||
wifictl_send_event_cb( WIFICTL_ON, (char *)"scan ..." );
|
||||
WiFi.scanNetworks();
|
||||
}
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_WIFI_READY );
|
||||
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
statusbar_hide_icon( STATUSBAR_WIFI );
|
||||
statusbar_wifi_set_state( false, "" );
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
asyncwebserver_end();
|
||||
powermgm_clear_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_WPS_REQUEST );
|
||||
wifictl_clear_event( WIFICTL_ACTIVE | WIFICTL_CONNECT | WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST | WIFICTL_SCAN | WIFICTL_WPS_REQUEST );
|
||||
wifictl_send_event_cb( WIFICTL_OFF, (char *)"" );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_STOP );
|
||||
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
esp_wifi_wps_disable();
|
||||
WiFi.begin();
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
wifictl_send_event_cb( WIFICTL_WPS_SUCCESS, (char *)"wps success" );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_WPS_ER_SUCCESS );
|
||||
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
esp_wifi_wps_disable();
|
||||
statusbar_wifi_set_state( true, "WPS failed" );
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
wifictl_send_event_cb( WIFICTL_WPS_SUCCESS, (char *)"wps failed" );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_WPS_ER_FAILED );
|
||||
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
esp_wifi_wps_disable();
|
||||
statusbar_wifi_set_state( true, "WPS timeout" );
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
wifictl_send_event_cb( WIFICTL_WPS_SUCCESS, (char *)"wps timeout" );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_WPS_ER_TIMEOUT );
|
||||
|
||||
xTaskCreate( wifictl_Task, /* Function to implement the task */
|
||||
"wifictl Task", /* Name of the task */
|
||||
2000, /* Stack size in words */
|
||||
3000, /* Stack size in words */
|
||||
NULL, /* Task input parameter */
|
||||
1, /* Priority of the task */
|
||||
&_wifictl_Task ); /* Task handle. */
|
||||
@@ -290,6 +277,75 @@ void wifictl_set_webserver( bool webserver ) {
|
||||
wifictl_save_config();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void wifictl_set_event( EventBits_t bits ) {
|
||||
portENTER_CRITICAL(&wifictlMux);
|
||||
xEventGroupSetBits( wifictl_status, bits );
|
||||
portEXIT_CRITICAL(&wifictlMux);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void wifictl_clear_event( EventBits_t bits ) {
|
||||
portENTER_CRITICAL(&wifictlMux);
|
||||
xEventGroupClearBits( wifictl_status, bits );
|
||||
portEXIT_CRITICAL(&wifictlMux);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
bool wifictl_get_event( EventBits_t bits ) {
|
||||
portENTER_CRITICAL(&wifictlMux);
|
||||
EventBits_t temp = xEventGroupGetBits( wifictl_status ) & bits;
|
||||
portEXIT_CRITICAL(&wifictlMux);
|
||||
if ( temp )
|
||||
return( true );
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
void wifictl_register_cb( EventBits_t event, WIFICTL_CALLBACK_FUNC wifictl_event_cb ) {
|
||||
wifictl_event_cb_entrys++;
|
||||
|
||||
if ( wifictl_event_cb_table == NULL ) {
|
||||
wifictl_event_cb_table = ( wifictl_event_t * )ps_malloc( sizeof( wifictl_event_t ) * wifictl_event_cb_entrys );
|
||||
if ( wifictl_event_cb_table == NULL ) {
|
||||
log_e("wifictl_event_cb_table malloc faild");
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
wifictl_event_t *new_wifictl_event_cb_table = NULL;
|
||||
|
||||
new_wifictl_event_cb_table = ( wifictl_event_t * )ps_realloc( wifictl_event_cb_table, sizeof( wifictl_event_t ) * wifictl_event_cb_entrys );
|
||||
if ( new_wifictl_event_cb_table == NULL ) {
|
||||
log_e("wifictl_event_cb_table realloc faild");
|
||||
while(true);
|
||||
}
|
||||
wifictl_event_cb_table = new_wifictl_event_cb_table;
|
||||
}
|
||||
|
||||
wifictl_event_cb_table[ wifictl_event_cb_entrys - 1 ].event = event;
|
||||
wifictl_event_cb_table[ wifictl_event_cb_entrys - 1 ].event_cb = wifictl_event_cb;
|
||||
log_i("register wifictl_event_cb success");
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void wifictl_send_event_cb( EventBits_t event, char *msg ) {
|
||||
for ( int entry = 0 ; entry < wifictl_event_cb_entrys ; entry++ ) {
|
||||
yield();
|
||||
if ( event & wifictl_event_cb_table[ entry ].event ) {
|
||||
log_i("call wifictl_event_cb");
|
||||
wifictl_event_cb_table[ entry ].event_cb( event, msg );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@@ -357,7 +413,7 @@ bool wifictl_insert_network( const char *ssid, const char *password ) {
|
||||
strncpy( wifictl_networklist[ entry ].password, password, sizeof( wifictl_networklist[ entry ].password ) );
|
||||
wifictl_save_config();
|
||||
WiFi.scanNetworks();
|
||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
||||
wifictl_set_event( WIFICTL_SCAN );
|
||||
return( true );
|
||||
}
|
||||
}
|
||||
@@ -368,7 +424,7 @@ bool wifictl_insert_network( const char *ssid, const char *password ) {
|
||||
strncpy( wifictl_networklist[ entry ].password, password, sizeof( wifictl_networklist[ entry ].password ) );
|
||||
wifictl_save_config();
|
||||
WiFi.scanNetworks();
|
||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
||||
wifictl_set_event( WIFICTL_SCAN );
|
||||
return( true );
|
||||
}
|
||||
}
|
||||
@@ -383,10 +439,10 @@ void wifictl_on( void ) {
|
||||
return;
|
||||
|
||||
log_i("request wifictl on");
|
||||
while( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST ) ) {
|
||||
while( wifictl_get_event( WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST ) ) {
|
||||
yield();
|
||||
}
|
||||
powermgm_set_event( POWERMGM_WIFI_ON_REQUEST );
|
||||
wifictl_set_event( WIFICTL_ON_REQUEST );
|
||||
vTaskResume( _wifictl_Task );
|
||||
}
|
||||
|
||||
@@ -398,17 +454,17 @@ void wifictl_off( void ) {
|
||||
return;
|
||||
|
||||
log_i("request wifictl off");
|
||||
while( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST ) ) {
|
||||
while( wifictl_get_event( WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST ) ) {
|
||||
yield();
|
||||
}
|
||||
powermgm_set_event( POWERMGM_WIFI_OFF_REQUEST );
|
||||
wifictl_set_event( WIFICTL_OFF_REQUEST );
|
||||
vTaskResume( _wifictl_Task );
|
||||
}
|
||||
|
||||
void wifictl_standby( void ) {
|
||||
log_i("request wifictl standby");
|
||||
wifictl_off();
|
||||
while( powermgm_get_event( POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_WPS_REQUEST ) ) {
|
||||
while( wifictl_get_event( WIFICTL_ACTIVE | WIFICTL_CONNECT | WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST | WIFICTL_SCAN | WIFICTL_WPS_REQUEST ) ) {
|
||||
yield();
|
||||
}
|
||||
log_i("request wifictl standby done");
|
||||
@@ -423,7 +479,7 @@ void wifictl_wakeup( void ) {
|
||||
}
|
||||
|
||||
void wifictl_start_wps( void ) {
|
||||
if ( powermgm_get_event( POWERMGM_WIFI_WPS_REQUEST ) )
|
||||
if ( wifictl_get_event( WIFICTL_WPS_REQUEST ) )
|
||||
return;
|
||||
|
||||
log_i("start WPS");
|
||||
@@ -438,7 +494,7 @@ void wifictl_start_wps( void ) {
|
||||
WiFi.mode( WIFI_OFF );
|
||||
esp_wifi_stop();
|
||||
|
||||
powermgm_set_event( POWERMGM_WIFI_WPS_REQUEST );
|
||||
wifictl_set_event( WIFICTL_WPS_REQUEST );
|
||||
|
||||
ESP_ERROR_CHECK( esp_wifi_set_mode( WIFI_MODE_STA ) );
|
||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||
@@ -456,20 +512,20 @@ void wifictl_Task( void * pvParameters ) {
|
||||
|
||||
while ( true ) {
|
||||
vTaskDelay( 500 );
|
||||
if ( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST ) && powermgm_get_event( POWERMGM_WIFI_ON_REQUEST ) ) {
|
||||
if ( wifictl_get_event( WIFICTL_OFF_REQUEST ) && wifictl_get_event( WIFICTL_ON_REQUEST ) ) {
|
||||
log_e("confused by wifictl on/off at the same time. off request accept");
|
||||
}
|
||||
|
||||
if ( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST ) ) {
|
||||
if ( wifictl_get_event( WIFICTL_OFF_REQUEST ) ) {
|
||||
WiFi.mode( WIFI_OFF );
|
||||
esp_wifi_stop();
|
||||
log_i("request wifictl off done");
|
||||
}
|
||||
else if ( powermgm_get_event( POWERMGM_WIFI_ON_REQUEST ) ) {
|
||||
else if ( wifictl_get_event( WIFICTL_ON_REQUEST ) ) {
|
||||
WiFi.mode( WIFI_STA );
|
||||
log_i("request wifictl on done");
|
||||
}
|
||||
powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_ON_REQUEST );
|
||||
wifictl_clear_event( WIFICTL_OFF_REQUEST | WIFICTL_ACTIVE | WIFICTL_CONNECT | WIFICTL_SCAN | WIFICTL_ON_REQUEST );
|
||||
vTaskSuspend( _wifictl_Task );
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@
|
||||
#ifndef _WIFICTL_H
|
||||
#define _WIFICTL_H
|
||||
|
||||
#include "TTGO.h"
|
||||
|
||||
#define WIFICTL_DELAY 10
|
||||
#define NETWORKLIST_ENTRYS 20
|
||||
#define WIFICTL_LIST_FILE "/wifilist.cfg"
|
||||
@@ -44,6 +46,25 @@
|
||||
bool webserver = false;
|
||||
} wifictl_config_t;
|
||||
|
||||
typedef void ( * WIFICTL_CALLBACK_FUNC ) ( EventBits_t event, char *msg );
|
||||
|
||||
typedef struct {
|
||||
EventBits_t event;
|
||||
WIFICTL_CALLBACK_FUNC event_cb;
|
||||
} wifictl_event_t;
|
||||
|
||||
#define WIFICTL_CONNECT _BV(0)
|
||||
#define WIFICTL_DISCONNECT _BV(1)
|
||||
#define WIFICTL_ON _BV(3)
|
||||
#define WIFICTL_OFF _BV(4)
|
||||
#define WIFICTL_ACTIVE _BV(5)
|
||||
#define WIFICTL_ON_REQUEST _BV(6)
|
||||
#define WIFICTL_OFF_REQUEST _BV(7)
|
||||
#define WIFICTL_WPS_REQUEST _BV(8)
|
||||
#define WIFICTL_WPS_SUCCESS _BV(9)
|
||||
#define WIFICTL_WPS_FAILED _BV(10)
|
||||
#define WIFICTL_SCAN _BV(11)
|
||||
|
||||
/*
|
||||
* @brief setup wifi controller routine
|
||||
*/
|
||||
@@ -79,6 +100,11 @@
|
||||
* @brief switch off wifi
|
||||
*/
|
||||
void wifictl_off( void );
|
||||
void wifictl_set_event( EventBits_t bits );
|
||||
bool wifictl_get_event( EventBits_t bits );
|
||||
void wifictl_clear_event( EventBits_t bits );
|
||||
void wifictl_register_cb( EventBits_t event, WIFICTL_CALLBACK_FUNC blectl_event_cb );
|
||||
void wifictl_send_event_cb( EventBits_t event, char *msg );
|
||||
void wifictl_standby( void );
|
||||
void wifictl_wakeup( void );
|
||||
bool wifictl_get_autoon( void );
|
||||
|
||||
Reference in New Issue
Block a user