wifictl abstraction, add wifictl event callback

This commit is contained in:
sharandac
2020-08-17 11:29:11 +02:00
parent 3aeadc5fa9
commit 3c82a10771
16 changed files with 787 additions and 646 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -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 ) {
static bool standby = false;
SpiRamJsonDocument doc( strlen( msg ) * 2 );
DeserializationError error = deserializeJson( doc, msg );
@@ -103,6 +105,13 @@ void bluetooth_call_msg_pharse( char* msg ) {
else {
if( !strcmp( doc["t"], "call" ) && !strcmp( doc["cmd"], "accept" ) ) {
statusbar_hide( true );
if ( powermgm_get_event( POWERMGM_STANDBY ) ) {
standby = true;
}
else {
standby = false;
}
powermgm_set_event( POWERMGM_WAKEUP_REQUEST );
mainbar_jump_to_tilenumber( bluetooth_call_tile_num, LV_ANIM_OFF );
if ( doc["number"] ) {
@@ -117,7 +126,9 @@ void bluetooth_call_msg_pharse( char* msg ) {
}
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 );
lv_obj_invalidate( lv_scr_act() );
}

View File

@@ -21,7 +21,6 @@
*/
#include "config.h"
#include <Arduino.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
@@ -34,6 +33,7 @@
#include "gui/statusbar.h"
#include "hardware/display.h"
#include "hardware/powermgm.h"
#include "hardware/wifictl.h"
EventGroupHandle_t update_event_handle = NULL;
TaskHandle_t _update_Task;
@@ -58,6 +58,8 @@ LV_IMG_DECLARE(setup_32px);
LV_IMG_DECLARE(update_64px);
LV_IMG_DECLARE(info_1_16px);
void update_wifictl_event_cb( EventBits_t event, char* msg );
void update_tile_setup( void ) {
// get an app tile and copy mainstyle
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_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 5 );
// regster callback
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
if ( update_setup_get_autosync() ) {
update_check_version();
}
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
wifictl_register_cb( WIFICTL_CONNECT, update_wifictl_event_cb );
update_event_handle = xEventGroupCreate();
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 ) {
switch( event ) {
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( update_tile_num + 1, LV_ANIM_OFF );

View File

@@ -49,8 +49,8 @@ lv_status_bar_t statusicon[ STATUSBAR_NUM ] =
{
{ 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_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_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_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_bluetooth_event_cb( lv_obj_t *wifi, lv_event_t event );
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(bluetooth_64px);
@@ -184,6 +186,7 @@ void statusbar_setup( void )
statusbar_style_icon( STATUSBAR_BLUETOOTH, STATUSBAR_STYLE_GRAY );
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 ) {
@@ -195,6 +198,41 @@ void statusbar_blectl_event_cb( EventBits_t event, char* msg ) {
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 ) {
switch ( lv_imgbtn_get_state( wifi ) ) {
case( LV_BTN_STATE_CHECKED_RELEASED ): wifictl_off();
break;
case( LV_BTN_STATE_RELEASED ): wifictl_on();
break;
default: break;
break;
case( LV_BTN_STATE_RELEASED ): wifictl_on();
break;
}
}
}
@@ -233,8 +270,8 @@ void statusbar_wifi_set_state( bool state, const char *wifiname ) {
else {
lv_imgbtn_set_state( statusbar_wifi, LV_BTN_STATE_CHECKED_RELEASED );
}
lv_label_set_long_mode( statusbar_wifilabel, LV_LABEL_LONG_SROLL_CIRC);
lv_obj_set_width( statusbar_wifilabel, LV_HOR_RES);
// lv_label_set_long_mode( statusbar_wifilabel, LV_LABEL_LONG_SROLL_CIRC);
// lv_obj_set_width( statusbar_wifilabel, LV_HOR_RES);
lv_label_set_text( statusbar_wifilabel, wifiname);
lv_obj_align( statusbar_wifilabel, statusbar_wifi, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
statusbar_refresh();

View File

@@ -38,8 +38,8 @@
typedef enum {
STATUSBAR_BATTERY_PERCENT,
STATUSBAR_BATTERY,
STATUSBAR_WIFI,
STATUSBAR_BLUETOOTH,
STATUSBAR_WIFI,
STATUSBAR_BELL,
STATUSBAR_WARNING,
STATUSBAR_NUM