From 649bbf2289d9d6e9ce156c850043824a61245ad7 Mon Sep 17 00:00:00 2001 From: chrismcna Date: Fri, 21 Aug 2020 17:03:19 +0100 Subject: [PATCH] Wlan Setting - configure via bluetooth --- .../wlan_settings/wlan_settings.cpp | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp b/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp index ba56a8e..9fa3174 100644 --- a/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp +++ b/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp @@ -30,6 +30,8 @@ #include "hardware/wifictl.h" #include "hardware/motor.h" #include "webserver/webserver.h" +#include "hardware/blectl.h" +#include "hardware/json_psram_allocator.h" #include @@ -61,6 +63,9 @@ static void wifi_onoff_event_handler(lv_obj_t * obj, lv_event_t event); void wifi_settings_enter_pass_event_cb( lv_obj_t * obj, lv_event_t event ); void WiFiScanDone(WiFiEvent_t event, WiFiEventInfo_t info); +static void bluetooth_message_event_cb( EventBits_t event, char* msg ); +static void bluetooth_message_msg_pharse( char* msg ); + LV_IMG_DECLARE(lock_16px); LV_IMG_DECLARE(unlock_16px); LV_IMG_DECLARE(check_32px); @@ -369,6 +374,8 @@ void wlan_setup_tile_setup( uint32_t wifi_setup_tile_num ) { lv_switch_on( wifi_webserver_onoff, LV_ANIM_OFF); else lv_switch_off( wifi_webserver_onoff, LV_ANIM_OFF); + + blectl_register_cb( BLECTL_MSG, bluetooth_message_event_cb ); } static void wps_start_event_handler( lv_obj_t * obj, lv_event_t event ) { @@ -410,4 +417,35 @@ static void wifi_webserver_onoff_event_handler( lv_obj_t * obj, lv_event_t event } break; } -} \ No newline at end of file +} + + + +static void bluetooth_message_event_cb( EventBits_t event, char* msg ) { + switch( event ) { + case BLECTL_MSG: bluetooth_message_msg_pharse( msg ); + break; + } +} + +void bluetooth_message_msg_pharse( char* msg ) { + + SpiRamJsonDocument doc( strlen( msg ) * 2 ); + + DeserializationError error = deserializeJson( doc, msg ); + if ( error ) { + log_e("bluetooth message deserializeJson() failed: %s", error.c_str() ); + } + else { + if( !strcmp( doc["t"], "conf" ) ) { + if ( !strcmp( doc["app"], "settings" ) ) { + if ( !strcmp( doc["settings"], "wlan" ) ) { + motor_vibe(100); + wifictl_insert_network( doc["ssid"] |"" , doc["key"] |"" ); + } + } + + } + } + doc.clear(); +}