wifictl abstraction, add wifictl event callback
This commit is contained in:
@@ -21,7 +21,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <TTGO.h>
|
#include <TTGO.h>
|
||||||
#include <WiFi.h>
|
|
||||||
#include "esp_task_wdt.h"
|
#include "esp_task_wdt.h"
|
||||||
|
|
||||||
#include "weather.h"
|
#include "weather.h"
|
||||||
@@ -38,6 +37,7 @@
|
|||||||
#include "hardware/motor.h"
|
#include "hardware/motor.h"
|
||||||
#include "hardware/powermgm.h"
|
#include "hardware/powermgm.h"
|
||||||
#include "hardware/json_psram_allocator.h"
|
#include "hardware/json_psram_allocator.h"
|
||||||
|
#include "hardware/wifictl.h"
|
||||||
|
|
||||||
EventGroupHandle_t weather_widget_event_handle = NULL;
|
EventGroupHandle_t weather_widget_event_handle = NULL;
|
||||||
TaskHandle_t _weather_widget_sync_Task;
|
TaskHandle_t _weather_widget_sync_Task;
|
||||||
@@ -57,6 +57,8 @@ lv_obj_t *weather_widget_temperature_label = NULL;
|
|||||||
lv_obj_t *weather_widget_wind_label = NULL;
|
lv_obj_t *weather_widget_wind_label = NULL;
|
||||||
|
|
||||||
static void enter_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
static void enter_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||||
|
void weather_widget_wifictl_event_cb( EventBits_t event, char* msg );
|
||||||
|
|
||||||
LV_IMG_DECLARE(owm_01d_64px);
|
LV_IMG_DECLARE(owm_01d_64px);
|
||||||
LV_IMG_DECLARE(info_ok_16px);
|
LV_IMG_DECLARE(info_ok_16px);
|
||||||
LV_IMG_DECLARE(info_fail_16px);
|
LV_IMG_DECLARE(info_fail_16px);
|
||||||
@@ -116,20 +118,20 @@ void weather_app_setup( void ) {
|
|||||||
lv_obj_align( weather_widget_wind_label, weather_widget_cont, LV_ALIGN_IN_BOTTOM_MID, 0, +5);
|
lv_obj_align( weather_widget_wind_label, weather_widget_cont, LV_ALIGN_IN_BOTTOM_MID, 0, +5);
|
||||||
}
|
}
|
||||||
|
|
||||||
// regster callback for wifi sync
|
|
||||||
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
|
||||||
if ( weather_config.autosync ) {
|
|
||||||
weather_widget_sync_request();
|
|
||||||
}
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
|
||||||
|
|
||||||
// regster callback for wifi sync
|
|
||||||
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
|
||||||
lv_obj_set_hidden( weather_widget_info_img, true );
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_STOP );
|
|
||||||
|
|
||||||
weather_widget_event_handle = xEventGroupCreate();
|
weather_widget_event_handle = xEventGroupCreate();
|
||||||
xEventGroupClearBits( weather_widget_event_handle, WEATHER_WIDGET_SYNC_REQUEST );
|
|
||||||
|
wifictl_register_cb( WIFICTL_OFF | WIFICTL_CONNECT, weather_widget_wifictl_event_cb );
|
||||||
|
}
|
||||||
|
|
||||||
|
void weather_widget_wifictl_event_cb( EventBits_t event, char* msg ) {
|
||||||
|
switch( event ) {
|
||||||
|
case WIFICTL_CONNECT: if ( weather_config.autosync ) {
|
||||||
|
weather_widget_sync_request();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case WIFICTL_OFF: lv_obj_set_hidden( weather_widget_info_img, true );
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enter_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
static void enter_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <WiFi.h>
|
|
||||||
#include "esp_task_wdt.h"
|
#include "esp_task_wdt.h"
|
||||||
|
|
||||||
#include "weather.h"
|
#include "weather.h"
|
||||||
@@ -34,10 +33,10 @@
|
|||||||
#include "gui/keyboard.h"
|
#include "gui/keyboard.h"
|
||||||
|
|
||||||
#include "hardware/powermgm.h"
|
#include "hardware/powermgm.h"
|
||||||
|
#include "hardware/wifictl.h"
|
||||||
|
|
||||||
EventGroupHandle_t weather_forecast_event_handle = NULL;
|
EventGroupHandle_t weather_forecast_event_handle = NULL;
|
||||||
TaskHandle_t _weather_forecast_sync_Task;
|
TaskHandle_t _weather_forecast_sync_Task;
|
||||||
void weather_forecast_sync_Task( void * pvParameters );
|
|
||||||
|
|
||||||
lv_obj_t *weather_forecast_tile = NULL;
|
lv_obj_t *weather_forecast_tile = NULL;
|
||||||
lv_style_t weather_forecast_style;
|
lv_style_t weather_forecast_style;
|
||||||
@@ -52,6 +51,9 @@ lv_obj_t *weather_forecast_wind_label[ WEATHER_MAX_FORECAST ];
|
|||||||
|
|
||||||
weather_forcast_t weather_forecast[ WEATHER_MAX_FORECAST ];
|
weather_forcast_t weather_forecast[ WEATHER_MAX_FORECAST ];
|
||||||
|
|
||||||
|
void weather_forecast_sync_Task( void * pvParameters );
|
||||||
|
void weather_forecast_wifictl_event_cb( EventBits_t event, char* msg );
|
||||||
|
|
||||||
LV_IMG_DECLARE(exit_32px);
|
LV_IMG_DECLARE(exit_32px);
|
||||||
LV_IMG_DECLARE(setup_32px);
|
LV_IMG_DECLARE(setup_32px);
|
||||||
LV_IMG_DECLARE(refresh_32px);
|
LV_IMG_DECLARE(refresh_32px);
|
||||||
@@ -133,16 +135,19 @@ void weather_forecast_tile_setup( uint32_t tile_num ) {
|
|||||||
lv_obj_align( weather_forecast_time_label[ i ], weather_forecast_icon_imgbtn[ i ], LV_ALIGN_OUT_TOP_MID, 0, 0);
|
lv_obj_align( weather_forecast_time_label[ i ], weather_forecast_icon_imgbtn[ i ], LV_ALIGN_OUT_TOP_MID, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// regster callback for wifi sync
|
|
||||||
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
|
||||||
weather_config_t *weather_config = weather_get_config();
|
|
||||||
if ( weather_config->autosync )
|
|
||||||
weather_forecast_sync_request();
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
|
||||||
|
|
||||||
weather_forecast_event_handle = xEventGroupCreate();
|
weather_forecast_event_handle = xEventGroupCreate();
|
||||||
xEventGroupClearBits( weather_forecast_event_handle, WEATHER_FORECAST_SYNC_REQUEST );
|
|
||||||
|
|
||||||
|
wifictl_register_cb( WIFICTL_OFF | WIFICTL_CONNECT, weather_forecast_wifictl_event_cb );
|
||||||
|
}
|
||||||
|
|
||||||
|
void weather_forecast_wifictl_event_cb( EventBits_t event, char* msg ) {
|
||||||
|
switch( event ) {
|
||||||
|
case WIFICTL_CONNECT: weather_config_t *tmp_weather_config = weather_get_config();
|
||||||
|
if ( tmp_weather_config->autosync ) {
|
||||||
|
weather_forecast_sync_request();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exit_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
static void exit_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||||
|
|||||||
@@ -32,6 +32,6 @@
|
|||||||
/*
|
/*
|
||||||
* firmeware version string
|
* firmeware version string
|
||||||
*/
|
*/
|
||||||
#define __FIRMWARE__ "2020081422"
|
#define __FIRMWARE__ "2020081701"
|
||||||
|
|
||||||
#endif // _CONFIG_H
|
#endif // _CONFIG_H
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -94,6 +94,8 @@ static void exit_bluetooth_call_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void bluetooth_call_msg_pharse( char* msg ) {
|
void bluetooth_call_msg_pharse( char* msg ) {
|
||||||
|
static bool standby = false;
|
||||||
|
|
||||||
SpiRamJsonDocument doc( strlen( msg ) * 2 );
|
SpiRamJsonDocument doc( strlen( msg ) * 2 );
|
||||||
|
|
||||||
DeserializationError error = deserializeJson( doc, msg );
|
DeserializationError error = deserializeJson( doc, msg );
|
||||||
@@ -103,6 +105,13 @@ void bluetooth_call_msg_pharse( char* msg ) {
|
|||||||
else {
|
else {
|
||||||
if( !strcmp( doc["t"], "call" ) && !strcmp( doc["cmd"], "accept" ) ) {
|
if( !strcmp( doc["t"], "call" ) && !strcmp( doc["cmd"], "accept" ) ) {
|
||||||
statusbar_hide( true );
|
statusbar_hide( true );
|
||||||
|
if ( powermgm_get_event( POWERMGM_STANDBY ) ) {
|
||||||
|
standby = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
standby = false;
|
||||||
|
}
|
||||||
|
|
||||||
powermgm_set_event( POWERMGM_WAKEUP_REQUEST );
|
powermgm_set_event( POWERMGM_WAKEUP_REQUEST );
|
||||||
mainbar_jump_to_tilenumber( bluetooth_call_tile_num, LV_ANIM_OFF );
|
mainbar_jump_to_tilenumber( bluetooth_call_tile_num, LV_ANIM_OFF );
|
||||||
if ( doc["number"] ) {
|
if ( doc["number"] ) {
|
||||||
@@ -117,7 +126,9 @@ void bluetooth_call_msg_pharse( char* msg ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( !strcmp( doc["t"], "call" ) && !strcmp( doc["cmd"], "start" ) ) {
|
if( !strcmp( doc["t"], "call" ) && !strcmp( doc["cmd"], "start" ) ) {
|
||||||
powermgm_set_event( POWERMGM_WAKEUP_REQUEST );
|
if ( standby = true ) {
|
||||||
|
powermgm_set_event( POWERMGM_STANDBY_REQUEST );
|
||||||
|
}
|
||||||
mainbar_jump_to_maintile( LV_ANIM_OFF );
|
mainbar_jump_to_maintile( LV_ANIM_OFF );
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
lv_obj_invalidate( lv_scr_act() );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <WiFi.h>
|
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <HTTPUpdate.h>
|
#include <HTTPUpdate.h>
|
||||||
|
|
||||||
@@ -34,6 +33,7 @@
|
|||||||
#include "gui/statusbar.h"
|
#include "gui/statusbar.h"
|
||||||
#include "hardware/display.h"
|
#include "hardware/display.h"
|
||||||
#include "hardware/powermgm.h"
|
#include "hardware/powermgm.h"
|
||||||
|
#include "hardware/wifictl.h"
|
||||||
|
|
||||||
EventGroupHandle_t update_event_handle = NULL;
|
EventGroupHandle_t update_event_handle = NULL;
|
||||||
TaskHandle_t _update_Task;
|
TaskHandle_t _update_Task;
|
||||||
@@ -58,6 +58,8 @@ LV_IMG_DECLARE(setup_32px);
|
|||||||
LV_IMG_DECLARE(update_64px);
|
LV_IMG_DECLARE(update_64px);
|
||||||
LV_IMG_DECLARE(info_1_16px);
|
LV_IMG_DECLARE(info_1_16px);
|
||||||
|
|
||||||
|
void update_wifictl_event_cb( EventBits_t event, char* msg );
|
||||||
|
|
||||||
void update_tile_setup( void ) {
|
void update_tile_setup( void ) {
|
||||||
// get an app tile and copy mainstyle
|
// get an app tile and copy mainstyle
|
||||||
update_tile_num = mainbar_add_app_tile( 1, 2 );
|
update_tile_num = mainbar_add_app_tile( 1, 2 );
|
||||||
@@ -135,17 +137,18 @@ void update_tile_setup( void ) {
|
|||||||
lv_label_set_text( update_status_label, "" );
|
lv_label_set_text( update_status_label, "" );
|
||||||
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 5 );
|
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 5 );
|
||||||
|
|
||||||
// regster callback
|
wifictl_register_cb( WIFICTL_CONNECT, update_wifictl_event_cb );
|
||||||
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
|
||||||
if ( update_setup_get_autosync() ) {
|
|
||||||
update_check_version();
|
|
||||||
}
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
|
||||||
|
|
||||||
update_event_handle = xEventGroupCreate();
|
update_event_handle = xEventGroupCreate();
|
||||||
xEventGroupClearBits( update_event_handle, UPDATE_REQUEST );
|
xEventGroupClearBits( update_event_handle, UPDATE_REQUEST );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void update_wifictl_event_cb( EventBits_t event, char* msg ) {
|
||||||
|
if ( update_setup_get_autosync() ) {
|
||||||
|
update_check_version();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void enter_update_setup_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
static void enter_update_setup_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||||
switch( event ) {
|
switch( event ) {
|
||||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( update_tile_num + 1, LV_ANIM_OFF );
|
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( update_tile_num + 1, LV_ANIM_OFF );
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ lv_status_bar_t statusicon[ STATUSBAR_NUM ] =
|
|||||||
{
|
{
|
||||||
{ NULL, NULL, LV_ALIGN_IN_TOP_RIGHT, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
{ NULL, NULL, LV_ALIGN_IN_TOP_RIGHT, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||||
{ NULL, LV_SYMBOL_BATTERY_FULL, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
{ NULL, LV_SYMBOL_BATTERY_FULL, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||||
{ NULL, LV_SYMBOL_WIFI, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
|
||||||
{ NULL, LV_SYMBOL_BLUETOOTH, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
{ NULL, LV_SYMBOL_BLUETOOTH, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||||
|
{ NULL, LV_SYMBOL_WIFI, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||||
{ NULL, LV_SYMBOL_BELL, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
{ NULL, LV_SYMBOL_BELL, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||||
{ NULL, LV_SYMBOL_WARNING, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
{ NULL, LV_SYMBOL_WARNING, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||||
};
|
};
|
||||||
@@ -59,6 +59,8 @@ void statusbar_event( lv_obj_t * statusbar, lv_event_t event );
|
|||||||
void statusbar_wifi_event_cb( lv_obj_t *wifi, lv_event_t event );
|
void statusbar_wifi_event_cb( lv_obj_t *wifi, lv_event_t event );
|
||||||
void statusbar_bluetooth_event_cb( lv_obj_t *wifi, lv_event_t event );
|
void statusbar_bluetooth_event_cb( lv_obj_t *wifi, lv_event_t event );
|
||||||
void statusbar_blectl_event_cb( EventBits_t event, char* msg );
|
void statusbar_blectl_event_cb( EventBits_t event, char* msg );
|
||||||
|
void statusbar_wifictl_event_cb( EventBits_t event, char* msg );
|
||||||
|
|
||||||
|
|
||||||
LV_IMG_DECLARE(wifi_64px);
|
LV_IMG_DECLARE(wifi_64px);
|
||||||
LV_IMG_DECLARE(bluetooth_64px);
|
LV_IMG_DECLARE(bluetooth_64px);
|
||||||
@@ -184,6 +186,7 @@ void statusbar_setup( void )
|
|||||||
statusbar_style_icon( STATUSBAR_BLUETOOTH, STATUSBAR_STYLE_GRAY );
|
statusbar_style_icon( STATUSBAR_BLUETOOTH, STATUSBAR_STYLE_GRAY );
|
||||||
|
|
||||||
blectl_register_cb( BLECTL_CONNECT | BLECTL_DISCONNECT | BLECTL_PIN_AUTH , statusbar_blectl_event_cb );
|
blectl_register_cb( BLECTL_CONNECT | BLECTL_DISCONNECT | BLECTL_PIN_AUTH , statusbar_blectl_event_cb );
|
||||||
|
wifictl_register_cb( WIFICTL_CONNECT | WIFICTL_DISCONNECT | WIFICTL_OFF | WIFICTL_ON | WIFICTL_SCAN | WIFICTL_WPS_SUCCESS | WIFICTL_WPS_FAILED, statusbar_wifictl_event_cb );
|
||||||
}
|
}
|
||||||
|
|
||||||
void statusbar_blectl_event_cb( EventBits_t event, char* msg ) {
|
void statusbar_blectl_event_cb( EventBits_t event, char* msg ) {
|
||||||
@@ -195,6 +198,41 @@ void statusbar_blectl_event_cb( EventBits_t event, char* msg ) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void statusbar_wifictl_event_cb( EventBits_t event, char* msg ) {
|
||||||
|
log_i("wifictl event msg: %s", msg );
|
||||||
|
switch( event ) {
|
||||||
|
case WIFICTL_CONNECT: statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_WHITE );
|
||||||
|
statusbar_wifi_set_state( true, msg );
|
||||||
|
statusbar_show_icon( STATUSBAR_WIFI );
|
||||||
|
break;
|
||||||
|
case WIFICTL_DISCONNECT: statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||||
|
statusbar_wifi_set_state( true, msg );
|
||||||
|
statusbar_show_icon( STATUSBAR_WIFI );
|
||||||
|
break;
|
||||||
|
case WIFICTL_OFF: statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||||
|
statusbar_hide_icon( STATUSBAR_WIFI );
|
||||||
|
statusbar_wifi_set_state( false, "" );
|
||||||
|
break;
|
||||||
|
case WIFICTL_ON: statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||||
|
statusbar_wifi_set_state( true, msg );
|
||||||
|
statusbar_show_icon( STATUSBAR_WIFI );
|
||||||
|
break;
|
||||||
|
case WIFICTL_WPS_SUCCESS: statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||||
|
statusbar_wifi_set_state( true, msg );
|
||||||
|
statusbar_show_icon( STATUSBAR_WIFI );
|
||||||
|
break;
|
||||||
|
case WIFICTL_WPS_FAILED: statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||||
|
statusbar_wifi_set_state( true, msg );
|
||||||
|
statusbar_show_icon( STATUSBAR_WIFI );
|
||||||
|
break;
|
||||||
|
case WIFICTL_SCAN: statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||||
|
statusbar_wifi_set_state( true, msg );
|
||||||
|
statusbar_show_icon( STATUSBAR_WIFI );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
statusbar_refresh();
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -202,10 +240,9 @@ void statusbar_wifi_event_cb( lv_obj_t *wifi, lv_event_t event ) {
|
|||||||
if ( event == LV_EVENT_VALUE_CHANGED ) {
|
if ( event == LV_EVENT_VALUE_CHANGED ) {
|
||||||
switch ( lv_imgbtn_get_state( wifi ) ) {
|
switch ( lv_imgbtn_get_state( wifi ) ) {
|
||||||
case( LV_BTN_STATE_CHECKED_RELEASED ): wifictl_off();
|
case( LV_BTN_STATE_CHECKED_RELEASED ): wifictl_off();
|
||||||
break;
|
break;
|
||||||
case( LV_BTN_STATE_RELEASED ): wifictl_on();
|
case( LV_BTN_STATE_RELEASED ): wifictl_on();
|
||||||
break;
|
break;
|
||||||
default: break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,8 +270,8 @@ void statusbar_wifi_set_state( bool state, const char *wifiname ) {
|
|||||||
else {
|
else {
|
||||||
lv_imgbtn_set_state( statusbar_wifi, LV_BTN_STATE_CHECKED_RELEASED );
|
lv_imgbtn_set_state( statusbar_wifi, LV_BTN_STATE_CHECKED_RELEASED );
|
||||||
}
|
}
|
||||||
lv_label_set_long_mode( statusbar_wifilabel, LV_LABEL_LONG_SROLL_CIRC);
|
// lv_label_set_long_mode( statusbar_wifilabel, LV_LABEL_LONG_SROLL_CIRC);
|
||||||
lv_obj_set_width( statusbar_wifilabel, LV_HOR_RES);
|
// lv_obj_set_width( statusbar_wifilabel, LV_HOR_RES);
|
||||||
lv_label_set_text( statusbar_wifilabel, wifiname);
|
lv_label_set_text( statusbar_wifilabel, wifiname);
|
||||||
lv_obj_align( statusbar_wifilabel, statusbar_wifi, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
lv_obj_align( statusbar_wifilabel, statusbar_wifi, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||||
statusbar_refresh();
|
statusbar_refresh();
|
||||||
|
|||||||
@@ -38,8 +38,8 @@
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
STATUSBAR_BATTERY_PERCENT,
|
STATUSBAR_BATTERY_PERCENT,
|
||||||
STATUSBAR_BATTERY,
|
STATUSBAR_BATTERY,
|
||||||
STATUSBAR_WIFI,
|
|
||||||
STATUSBAR_BLUETOOTH,
|
STATUSBAR_BLUETOOTH,
|
||||||
|
STATUSBAR_WIFI,
|
||||||
STATUSBAR_BELL,
|
STATUSBAR_BELL,
|
||||||
STATUSBAR_WARNING,
|
STATUSBAR_WARNING,
|
||||||
STATUSBAR_NUM
|
STATUSBAR_NUM
|
||||||
|
|||||||
@@ -57,10 +57,11 @@ uint32_t gadgetbridge_msg_size = 0;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class BleCtlServerCallbacks: public BLEServerCallbacks {
|
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_set_event( BLECTL_CONNECT );
|
||||||
blectl_clear_event( BLECTL_DISCONNECT );
|
blectl_clear_event( BLECTL_DISCONNECT );
|
||||||
blectl_send_event_cb( BLECTL_CONNECT, (char*)"connected" );
|
blectl_send_event_cb( BLECTL_CONNECT, (char*)"connected" );
|
||||||
|
// pServer->updateConnParams( param->connect.remote_bda, 120, 180, 150, 10000 );
|
||||||
log_i("BLE connected");
|
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 = event;
|
||||||
blectl_event_cb_table[ blectl_event_cb_entrys - 1 ].event_cb = blectl_event_cb;
|
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 ) {
|
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 ) {
|
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 );
|
blectl_event_cb_table[ entry ].event_cb( event, msg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ void pmu_setup( TTGOClass *ttgo ) {
|
|||||||
log_e("target voltage set failed!");
|
log_e("target voltage set failed!");
|
||||||
if ( ttgo->power->setChargeControlCur( 300 ) )
|
if ( ttgo->power->setChargeControlCur( 300 ) )
|
||||||
log_e("charge current set failed!");
|
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!");
|
log_e("adc sample set failed!");
|
||||||
|
|
||||||
// Turn off unused power
|
// Turn off unused power
|
||||||
|
|||||||
@@ -32,12 +32,6 @@
|
|||||||
#define POWERMGM_WAKEUP_REQUEST _BV(5)
|
#define POWERMGM_WAKEUP_REQUEST _BV(5)
|
||||||
#define POWERMGM_PMU_BUTTON _BV(6)
|
#define POWERMGM_PMU_BUTTON _BV(6)
|
||||||
#define POWERMGM_BMA_DOUBLECLICK _BV(9)
|
#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
|
* @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
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
#include "TTGO.h"
|
||||||
|
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include <WiFi.h>
|
#include "wifictl.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "timesync.h"
|
#include "timesync.h"
|
||||||
#include "powermgm.h"
|
#include "powermgm.h"
|
||||||
@@ -32,29 +35,31 @@ void timesync_Task( void * pvParameters );
|
|||||||
|
|
||||||
timesync_config_t timesync_config;
|
timesync_config_t timesync_config;
|
||||||
|
|
||||||
|
void timesync_wifictl_event_cb( EventBits_t event, char* msg );
|
||||||
|
|
||||||
void timesync_setup( TTGOClass *ttgo ) {
|
void timesync_setup( TTGOClass *ttgo ) {
|
||||||
|
|
||||||
timesync_read_config();
|
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();
|
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 ) {
|
void timesync_save_config( void ) {
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
#include <esp_wifi.h>
|
#include <esp_wifi.h>
|
||||||
#include <esp_wps.h>
|
#include <esp_wps.h>
|
||||||
|
|
||||||
#include "powermgm.h"
|
|
||||||
#include "wifictl.h"
|
#include "wifictl.h"
|
||||||
#include "json_psram_allocator.h"
|
#include "json_psram_allocator.h"
|
||||||
|
|
||||||
@@ -33,6 +32,12 @@
|
|||||||
#include "webserver/webserver.h"
|
#include "webserver/webserver.h"
|
||||||
|
|
||||||
bool wifi_init = false;
|
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_StartTask( void );
|
||||||
void wifictl_Task( void * pvParameters );
|
void wifictl_Task( void * pvParameters );
|
||||||
@@ -59,8 +64,9 @@ void wifictl_setup( void ) {
|
|||||||
if ( wifi_init == true )
|
if ( wifi_init == true )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
wifictl_status = xEventGroupCreate();
|
||||||
|
|
||||||
wifi_init = true;
|
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
|
// clean network list table
|
||||||
for ( int entry = 0 ; entry < NETWORKLIST_ENTRYS ; entry++ ) {
|
for ( int entry = 0 ; entry < NETWORKLIST_ENTRYS ; entry++ ) {
|
||||||
@@ -73,107 +79,88 @@ void wifictl_setup( void ) {
|
|||||||
|
|
||||||
// register WiFi events
|
// register WiFi events
|
||||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
powermgm_set_event( POWERMGM_WIFI_ACTIVE );
|
wifictl_set_event( WIFICTL_ACTIVE );
|
||||||
powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_CONNECTED );
|
wifictl_clear_event( WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST | WIFICTL_SCAN | WIFICTL_CONNECT );
|
||||||
statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
if ( wifictl_get_event( WIFICTL_WPS_REQUEST ) )
|
||||||
statusbar_show_icon( STATUSBAR_WIFI );
|
wifictl_send_event_cb( WIFICTL_DISCONNECT, (char *)"wait for WPS" );
|
||||||
if ( powermgm_get_event( POWERMGM_WIFI_WPS_REQUEST ) )
|
|
||||||
statusbar_wifi_set_state( true, "wait for WPS" );
|
|
||||||
else {
|
else {
|
||||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
wifictl_set_event( WIFICTL_SCAN );
|
||||||
statusbar_wifi_set_state( true, "scan ..." );
|
wifictl_send_event_cb( WIFICTL_DISCONNECT, (char *)"scan ..." );
|
||||||
WiFi.scanNetworks();
|
WiFi.scanNetworks();
|
||||||
}
|
}
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
||||||
|
|
||||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
powermgm_set_event( POWERMGM_WIFI_ACTIVE );
|
wifictl_set_event( WIFICTL_ACTIVE );
|
||||||
powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_WPS_REQUEST );
|
wifictl_clear_event( WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST | WIFICTL_SCAN | WIFICTL_CONNECT | WIFICTL_WPS_REQUEST );
|
||||||
statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
|
||||||
statusbar_show_icon( STATUSBAR_WIFI );
|
|
||||||
int len = WiFi.scanComplete();
|
int len = WiFi.scanComplete();
|
||||||
for( int i = 0 ; i < len ; i++ ) {
|
for( int i = 0 ; i < len ; i++ ) {
|
||||||
for ( int entry = 0 ; entry < NETWORKLIST_ENTRYS ; entry++ ) {
|
for ( int entry = 0 ; entry < NETWORKLIST_ENTRYS ; entry++ ) {
|
||||||
if ( !strcmp( wifictl_networklist[ entry ].ssid, WiFi.SSID(i).c_str() ) ) {
|
if ( !strcmp( wifictl_networklist[ entry ].ssid, WiFi.SSID(i).c_str() ) ) {
|
||||||
wifiname = wifictl_networklist[ entry ].ssid;
|
wifiname = wifictl_networklist[ entry ].ssid;
|
||||||
wifipassword = wifictl_networklist[ entry ].password;
|
wifipassword = wifictl_networklist[ entry ].password;
|
||||||
statusbar_wifi_set_state( true, "connecting ..." );
|
wifictl_send_event_cb( WIFICTL_SCAN, (char *)"connecting ..." );
|
||||||
WiFi.begin( wifiname, wifipassword );
|
WiFi.begin( wifiname, wifipassword );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_SCAN_DONE );
|
}, WiFiEvent_t::SYSTEM_EVENT_SCAN_DONE );
|
||||||
|
|
||||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
powermgm_set_event( POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_ACTIVE );
|
wifictl_set_event( WIFICTL_CONNECT | WIFICTL_ACTIVE );
|
||||||
if ( powermgm_get_event( POWERMGM_WIFI_WPS_REQUEST ) ) {
|
if ( wifictl_get_event( WIFICTL_WPS_REQUEST ) ) {
|
||||||
log_i("store new SSID and psk from WPS");
|
log_i("store new SSID and psk from WPS");
|
||||||
wifictl_insert_network( WiFi.SSID().c_str(), WiFi.psk().c_str() );
|
wifictl_insert_network( WiFi.SSID().c_str(), WiFi.psk().c_str() );
|
||||||
wifictl_save_config();
|
wifictl_save_config();
|
||||||
}
|
}
|
||||||
powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_WPS_REQUEST );
|
wifictl_clear_event( WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST | WIFICTL_SCAN | WIFICTL_WPS_REQUEST );
|
||||||
statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_WHITE );
|
String label( wifiname );
|
||||||
statusbar_show_icon( STATUSBAR_WIFI );
|
|
||||||
String label(wifiname);
|
|
||||||
label.concat(' ');
|
label.concat(' ');
|
||||||
label.concat(WiFi.localIP().toString());
|
label.concat( WiFi.localIP().toString() );
|
||||||
//If you want to see your IPv6 address too, uncomment this.
|
wifictl_send_event_cb( WIFICTL_CONNECT, (char *)label.c_str() );
|
||||||
// label.concat('\n');
|
|
||||||
// label.concat(WiFi.localIPv6().toString());
|
|
||||||
statusbar_wifi_set_state( true, label.c_str() );
|
|
||||||
if ( wifictl_config.webserver ) {
|
if ( wifictl_config.webserver ) {
|
||||||
asyncwebserver_start();
|
asyncwebserver_start();
|
||||||
}
|
}
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
||||||
|
|
||||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
powermgm_set_event( POWERMGM_WIFI_ACTIVE );
|
wifictl_set_event( WIFICTL_ACTIVE );
|
||||||
powermgm_clear_event( POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ON_REQUEST );
|
wifictl_clear_event( WIFICTL_CONNECT | WIFICTL_OFF_REQUEST | WIFICTL_ON_REQUEST );
|
||||||
statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
if ( wifictl_get_event( WIFICTL_WPS_REQUEST ) )
|
||||||
statusbar_show_icon( STATUSBAR_WIFI );
|
wifictl_send_event_cb( WIFICTL_ON, (char *)"wait for WPS" );
|
||||||
if ( powermgm_get_event( POWERMGM_WIFI_WPS_REQUEST ) )
|
|
||||||
statusbar_wifi_set_state( true, "wait for WPS" );
|
|
||||||
else {
|
else {
|
||||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
wifictl_set_event( WIFICTL_SCAN );
|
||||||
statusbar_wifi_set_state( true, "scan ..." );
|
wifictl_send_event_cb( WIFICTL_ON, (char *)"scan ..." );
|
||||||
WiFi.scanNetworks();
|
WiFi.scanNetworks();
|
||||||
}
|
}
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_WIFI_READY );
|
}, WiFiEvent_t::SYSTEM_EVENT_WIFI_READY );
|
||||||
|
|
||||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
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();
|
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 );
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_STOP );
|
||||||
|
|
||||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
esp_wifi_wps_disable();
|
esp_wifi_wps_disable();
|
||||||
WiFi.begin();
|
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 );
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_WPS_ER_SUCCESS );
|
||||||
|
|
||||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
esp_wifi_wps_disable();
|
esp_wifi_wps_disable();
|
||||||
statusbar_wifi_set_state( true, "WPS failed" );
|
wifictl_send_event_cb( WIFICTL_WPS_SUCCESS, (char *)"wps failed" );
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_WPS_ER_FAILED );
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_WPS_ER_FAILED );
|
||||||
|
|
||||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
esp_wifi_wps_disable();
|
esp_wifi_wps_disable();
|
||||||
statusbar_wifi_set_state( true, "WPS timeout" );
|
wifictl_send_event_cb( WIFICTL_WPS_SUCCESS, (char *)"wps timeout" );
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_WPS_ER_TIMEOUT );
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_WPS_ER_TIMEOUT );
|
||||||
|
|
||||||
xTaskCreate( wifictl_Task, /* Function to implement the task */
|
xTaskCreate( wifictl_Task, /* Function to implement the task */
|
||||||
"wifictl Task", /* Name of the task */
|
"wifictl Task", /* Name of the task */
|
||||||
2000, /* Stack size in words */
|
3000, /* Stack size in words */
|
||||||
NULL, /* Task input parameter */
|
NULL, /* Task input parameter */
|
||||||
1, /* Priority of the task */
|
1, /* Priority of the task */
|
||||||
&_wifictl_Task ); /* Task handle. */
|
&_wifictl_Task ); /* Task handle. */
|
||||||
@@ -290,6 +277,75 @@ void wifictl_set_webserver( bool webserver ) {
|
|||||||
wifictl_save_config();
|
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 ) );
|
strncpy( wifictl_networklist[ entry ].password, password, sizeof( wifictl_networklist[ entry ].password ) );
|
||||||
wifictl_save_config();
|
wifictl_save_config();
|
||||||
WiFi.scanNetworks();
|
WiFi.scanNetworks();
|
||||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
wifictl_set_event( WIFICTL_SCAN );
|
||||||
return( true );
|
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 ) );
|
strncpy( wifictl_networklist[ entry ].password, password, sizeof( wifictl_networklist[ entry ].password ) );
|
||||||
wifictl_save_config();
|
wifictl_save_config();
|
||||||
WiFi.scanNetworks();
|
WiFi.scanNetworks();
|
||||||
powermgm_set_event( POWERMGM_WIFI_SCAN );
|
wifictl_set_event( WIFICTL_SCAN );
|
||||||
return( true );
|
return( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -383,10 +439,10 @@ void wifictl_on( void ) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
log_i("request wifictl on");
|
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();
|
yield();
|
||||||
}
|
}
|
||||||
powermgm_set_event( POWERMGM_WIFI_ON_REQUEST );
|
wifictl_set_event( WIFICTL_ON_REQUEST );
|
||||||
vTaskResume( _wifictl_Task );
|
vTaskResume( _wifictl_Task );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,17 +454,17 @@ void wifictl_off( void ) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
log_i("request wifictl off");
|
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();
|
yield();
|
||||||
}
|
}
|
||||||
powermgm_set_event( POWERMGM_WIFI_OFF_REQUEST );
|
wifictl_set_event( WIFICTL_OFF_REQUEST );
|
||||||
vTaskResume( _wifictl_Task );
|
vTaskResume( _wifictl_Task );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wifictl_standby( void ) {
|
void wifictl_standby( void ) {
|
||||||
log_i("request wifictl standby");
|
log_i("request wifictl standby");
|
||||||
wifictl_off();
|
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();
|
yield();
|
||||||
}
|
}
|
||||||
log_i("request wifictl standby done");
|
log_i("request wifictl standby done");
|
||||||
@@ -423,7 +479,7 @@ void wifictl_wakeup( void ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wifictl_start_wps( void ) {
|
void wifictl_start_wps( void ) {
|
||||||
if ( powermgm_get_event( POWERMGM_WIFI_WPS_REQUEST ) )
|
if ( wifictl_get_event( WIFICTL_WPS_REQUEST ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
log_i("start WPS");
|
log_i("start WPS");
|
||||||
@@ -438,7 +494,7 @@ void wifictl_start_wps( void ) {
|
|||||||
WiFi.mode( WIFI_OFF );
|
WiFi.mode( WIFI_OFF );
|
||||||
esp_wifi_stop();
|
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_set_mode( WIFI_MODE_STA ) );
|
||||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||||
@@ -456,20 +512,20 @@ void wifictl_Task( void * pvParameters ) {
|
|||||||
|
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
vTaskDelay( 500 );
|
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");
|
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 );
|
WiFi.mode( WIFI_OFF );
|
||||||
esp_wifi_stop();
|
esp_wifi_stop();
|
||||||
log_i("request wifictl off done");
|
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 );
|
WiFi.mode( WIFI_STA );
|
||||||
log_i("request wifictl on done");
|
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 );
|
vTaskSuspend( _wifictl_Task );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,8 @@
|
|||||||
#ifndef _WIFICTL_H
|
#ifndef _WIFICTL_H
|
||||||
#define _WIFICTL_H
|
#define _WIFICTL_H
|
||||||
|
|
||||||
|
#include "TTGO.h"
|
||||||
|
|
||||||
#define WIFICTL_DELAY 10
|
#define WIFICTL_DELAY 10
|
||||||
#define NETWORKLIST_ENTRYS 20
|
#define NETWORKLIST_ENTRYS 20
|
||||||
#define WIFICTL_LIST_FILE "/wifilist.cfg"
|
#define WIFICTL_LIST_FILE "/wifilist.cfg"
|
||||||
@@ -44,6 +46,25 @@
|
|||||||
bool webserver = false;
|
bool webserver = false;
|
||||||
} wifictl_config_t;
|
} 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
|
* @brief setup wifi controller routine
|
||||||
*/
|
*/
|
||||||
@@ -79,6 +100,11 @@
|
|||||||
* @brief switch off wifi
|
* @brief switch off wifi
|
||||||
*/
|
*/
|
||||||
void wifictl_off( void );
|
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_standby( void );
|
||||||
void wifictl_wakeup( void );
|
void wifictl_wakeup( void );
|
||||||
bool wifictl_get_autoon( void );
|
bool wifictl_get_autoon( void );
|
||||||
|
|||||||
Binary file not shown.
@@ -1 +1 @@
|
|||||||
{"version":"2020081422","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}
|
{"version":"2020081701","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}
|
||||||
|
|||||||
Reference in New Issue
Block a user