diff --git a/src/config.h b/src/config.h index fd97f7a..0e4fd8b 100644 --- a/src/config.h +++ b/src/config.h @@ -31,6 +31,6 @@ /* * firmeware version string */ - #define __FIRMWARE__ "2020080301" + #define __FIRMWARE__ "2020080305" #endif // _CONFIG_H diff --git a/src/gui/keyboard.cpp b/src/gui/keyboard.cpp index dd14e95..6e7f7d9 100644 --- a/src/gui/keyboard.cpp +++ b/src/gui/keyboard.cpp @@ -49,6 +49,7 @@ void keyboard_setup( void ) { lv_obj_align( kb_screen, lv_scr_act(), LV_ALIGN_CENTER, 0, 20); kb_textarea = lv_textarea_create( kb_screen, NULL ); + lv_obj_add_protect( kb_textarea, LV_PROTECT_CLICK_FOCUS); lv_obj_set_size( kb_textarea, LV_HOR_RES_MAX - 10, 60 ); lv_textarea_set_one_line( kb_textarea, true); lv_obj_align( kb_textarea, kb_screen, LV_ALIGN_IN_TOP_MID, 0, 5 ); @@ -64,13 +65,12 @@ void keyboard_setup( void ) { static void kb_event_cb( lv_obj_t * ta, lv_event_t event ) { lv_keyboard_def_event_cb( ta, event ); - Serial.printf("Keyboard event: %d\r\n", event ); - if ( event == LV_EVENT_CANCEL ) { - keyboard_hide(); - } - if ( event == LV_EVENT_APPLY ) { - lv_textarea_set_text( kb_user_textarea, lv_textarea_get_text( kb_textarea ) ); - keyboard_hide(); + switch( event ) { + case( LV_EVENT_CANCEL ): keyboard_hide(); + break; + case( LV_EVENT_APPLY ): lv_textarea_set_text( kb_user_textarea, lv_textarea_get_text( kb_textarea ) ); + keyboard_hide(); + break; } } diff --git a/src/gui/mainbar/setup_tile/display_settings/display_setting.cpp b/src/gui/mainbar/setup_tile/display_settings/display_setting.cpp index a78e0b4..d5dd0cd 100644 --- a/src/gui/mainbar/setup_tile/display_settings/display_setting.cpp +++ b/src/gui/mainbar/setup_tile/display_settings/display_setting.cpp @@ -32,6 +32,9 @@ lv_obj_t *display_settings_tile=NULL; lv_style_t display_settings_style; uint32_t display_tile_num; +lv_obj_t *display_setup_icon_cont = NULL; +lv_obj_t *display_setup_info_img = NULL; + lv_obj_t *display_brightness_slider = NULL; lv_obj_t *display_timeout_slider = NULL; lv_obj_t *display_timeout_slider_label = NULL; @@ -41,6 +44,7 @@ LV_IMG_DECLARE(brightness_64px); LV_IMG_DECLARE(exit_32px); LV_IMG_DECLARE(brightness_32px); LV_IMG_DECLARE(time_32px); +LV_IMG_DECLARE(info_update_16px); static void enter_display_setup_event_cb( lv_obj_t * obj, lv_event_t event ); static void exit_display_setup_event_cb( lv_obj_t * obj, lv_event_t event ); @@ -59,15 +63,20 @@ void display_settings_tile_setup( void ) { lv_obj_add_style( display_settings_tile, LV_OBJ_PART_MAIN, &display_settings_style ); // register an setup icon an set an callback - lv_obj_t *display_setup = lv_imgbtn_create ( setup_tile_register_setup(), NULL); - lv_imgbtn_set_src( display_setup, LV_BTN_STATE_RELEASED, &brightness_64px); - lv_imgbtn_set_src( display_setup, LV_BTN_STATE_PRESSED, &brightness_64px); - lv_imgbtn_set_src( display_setup, LV_BTN_STATE_CHECKED_RELEASED, &brightness_64px); - lv_imgbtn_set_src( display_setup, LV_BTN_STATE_CHECKED_PRESSED, &brightness_64px); - lv_obj_add_style( display_setup, LV_IMGBTN_PART_MAIN, mainbar_get_style() ); - lv_obj_align( display_setup, NULL, LV_ALIGN_CENTER, 0, 0 ); - lv_obj_set_event_cb( display_setup, enter_display_setup_event_cb ); + display_setup_icon_cont = setup_tile_register_setup(); + lv_obj_t *display_setup_icon = lv_imgbtn_create ( display_setup_icon_cont, NULL); + lv_imgbtn_set_src( display_setup_icon, LV_BTN_STATE_RELEASED, &brightness_64px); + lv_imgbtn_set_src( display_setup_icon, LV_BTN_STATE_PRESSED, &brightness_64px); + lv_imgbtn_set_src( display_setup_icon, LV_BTN_STATE_CHECKED_RELEASED, &brightness_64px); + lv_imgbtn_set_src( display_setup_icon, LV_BTN_STATE_CHECKED_PRESSED, &brightness_64px); + lv_obj_add_style( display_setup_icon, LV_IMGBTN_PART_MAIN, mainbar_get_style() ); + lv_obj_align( display_setup_icon, NULL, LV_ALIGN_CENTER, 0, 0 ); + lv_obj_set_event_cb( display_setup_icon, enter_display_setup_event_cb ); + display_setup_info_img = lv_img_create( display_setup_icon_cont, NULL ); + lv_img_set_src( display_setup_info_img, &info_update_16px ); + lv_obj_align( display_setup_info_img, display_setup_icon_cont, LV_ALIGN_IN_TOP_RIGHT, 0, 0 ); + lv_obj_set_hidden( display_setup_info_img, true ); lv_obj_t *exit_btn = lv_imgbtn_create( display_settings_tile, NULL); lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_RELEASED, &exit_32px); @@ -138,6 +147,7 @@ void display_settings_tile_setup( void ) { char temp[16]=""; if ( lv_slider_get_value( display_timeout_slider ) == DISPLAY_MAX_TIMEOUT ) { snprintf( temp, sizeof( temp ), "no timeout" ); + lv_obj_set_hidden( display_setup_info_img, false ); } else { snprintf( temp, sizeof( temp ), "%d secounds", lv_slider_get_value( display_timeout_slider ) ); @@ -176,9 +186,11 @@ static void display_timeout_setup_event_cb( lv_obj_t * obj, lv_event_t event ) { char temp[16]=""; if ( lv_slider_get_value(obj) == DISPLAY_MAX_TIMEOUT ) { snprintf( temp, sizeof( temp ), "no timeout" ); + lv_obj_set_hidden( display_setup_info_img, false ); } else { snprintf( temp, sizeof( temp ), "%d secounds", lv_slider_get_value(obj) ); + lv_obj_set_hidden( display_setup_info_img, true ); } lv_label_set_text( display_timeout_slider_label, temp ); lv_obj_align( display_timeout_slider_label, display_timeout_slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 ); @@ -186,10 +198,8 @@ static void display_timeout_setup_event_cb( lv_obj_t * obj, lv_event_t event ) { } } -static void display_rotation_event_handler( lv_obj_t * obj, lv_event_t event ) -{ - if(event == LV_EVENT_VALUE_CHANGED) { - motor_vibe( 1 ); - display_set_rotation( lv_dropdown_get_selected( obj ) * 90 ); +static void display_rotation_event_handler( lv_obj_t * obj, lv_event_t event ) { + switch( event ) { + case( LV_EVENT_VALUE_CHANGED ): display_set_rotation( lv_dropdown_get_selected( obj ) * 90 ); } } \ No newline at end of file diff --git a/src/gui/mainbar/setup_tile/move_settings/move_settings.cpp b/src/gui/mainbar/setup_tile/move_settings/move_settings.cpp index 371c728..06f0d59 100644 --- a/src/gui/mainbar/setup_tile/move_settings/move_settings.cpp +++ b/src/gui/mainbar/setup_tile/move_settings/move_settings.cpp @@ -134,25 +134,13 @@ static void exit_move_setup_event_cb( lv_obj_t * obj, lv_event_t event ) { } static void stepcounter_onoff_event_handler(lv_obj_t * obj, lv_event_t event) { - if(event == LV_EVENT_VALUE_CHANGED) { - motor_vibe( 1 ); - if( lv_switch_get_state( obj ) ) { - bma_set_config( BMA_STEPCOUNTER, true ); - } - else { - bma_set_config( BMA_STEPCOUNTER, false ); - } + switch( event ) { + case( LV_EVENT_VALUE_CHANGED): bma_set_config( BMA_STEPCOUNTER, lv_switch_get_state( obj ) ); } } static void doubleclick_onoff_event_handler(lv_obj_t * obj, lv_event_t event) { - if(event == LV_EVENT_VALUE_CHANGED) { - motor_vibe( 1 ); - if( lv_switch_get_state( obj ) ) { - bma_set_config( BMA_DOUBLECLICK, true ); - } - else { - bma_set_config( BMA_DOUBLECLICK, false ); - } + switch( event ) { + case( LV_EVENT_VALUE_CHANGED): bma_set_config( BMA_DOUBLECLICK, lv_switch_get_state( obj ) ); } } \ No newline at end of file diff --git a/src/gui/mainbar/setup_tile/time_settings/time_settings.cpp b/src/gui/mainbar/setup_tile/time_settings/time_settings.cpp index 4a74206..9aaf7ba 100644 --- a/src/gui/mainbar/setup_tile/time_settings/time_settings.cpp +++ b/src/gui/mainbar/setup_tile/time_settings/time_settings.cpp @@ -153,33 +153,19 @@ static void exit_time_setup_event_cb( lv_obj_t * obj, lv_event_t event ) { } static void wifisync_onoff_event_handler(lv_obj_t * obj, lv_event_t event) { - if(event == LV_EVENT_VALUE_CHANGED) { - motor_vibe( 1 ); - if( lv_switch_get_state( obj ) ) { - timesync_set_timesync( true ); - } - else { - timesync_set_timesync( false ); - } + switch( event ) { + case ( LV_EVENT_VALUE_CHANGED): timesync_set_timesync( lv_switch_get_state( obj ) ); } } static void daylight_onoff_event_handler(lv_obj_t * obj, lv_event_t event) { - if(event == LV_EVENT_VALUE_CHANGED) { - motor_vibe( 1 ); - if( lv_switch_get_state( obj ) ) { - timesync_set_daylightsave( true ); - } - else { - timesync_set_daylightsave( false ); - } + switch( event ) { + case ( LV_EVENT_VALUE_CHANGED): timesync_set_daylightsave( lv_switch_get_state( obj ) ); } } -static void utczone_event_handler(lv_obj_t * obj, lv_event_t event) -{ - if(event == LV_EVENT_VALUE_CHANGED) { - motor_vibe( 1 ); - timesync_set_timezone( lv_dropdown_get_selected( obj ) - 12 ); +static void utczone_event_handler(lv_obj_t * obj, lv_event_t event) { + switch( event ) { + case ( LV_EVENT_VALUE_CHANGED): timesync_set_timezone( lv_dropdown_get_selected( obj ) - 12 ); } } 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 d74cc68..7ba0cfd 100644 --- a/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp +++ b/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp @@ -36,18 +36,24 @@ LV_IMG_DECLARE(exit_32px); lv_obj_t *wifi_settings_tile=NULL; lv_style_t wifi_settings_style; -lv_style_t wifi_password_style; lv_style_t wifi_list_style; uint32_t wifi_settings_tile_num; lv_obj_t *wifi_password_tile=NULL; +lv_style_t wifi_password_style; lv_obj_t *wifi_password_name_label=NULL; lv_obj_t *wifi_password_pass_textfield=NULL; uint32_t wifi_password_tile_num; +lv_obj_t *wifi_setup_tile=NULL; +lv_style_t wifi_setup_style; +uint32_t wifi_setup_tile_num; + lv_obj_t *wifi_onoff=NULL; lv_obj_t *wifiname_list=NULL; +static void enter_wifi_settings_event_cb( lv_obj_t * obj, lv_event_t event ); +static void exit_wifi_settings_event_cb( lv_obj_t * obj, lv_event_t event ); static void enter_wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event ); static void exit_wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event ); static void wifi_onoff_event_handler(lv_obj_t * obj, lv_event_t event); @@ -60,11 +66,13 @@ LV_IMG_DECLARE(check_32px); LV_IMG_DECLARE(exit_32px); LV_IMG_DECLARE(trash_32px); LV_IMG_DECLARE(wifi_64px); +LV_IMG_DECLARE(setup_32px); void wlan_settings_tile_setup( void ) { // get an app tile and copy mainstyle - wifi_settings_tile_num = mainbar_add_app_tile( 2, 1 ); + wifi_settings_tile_num = mainbar_add_app_tile( 2, 2 ); wifi_password_tile_num = wifi_settings_tile_num + 1; + wifi_setup_tile_num = wifi_settings_tile_num + 2; wifi_settings_tile = mainbar_get_tile_obj( wifi_settings_tile_num ); lv_style_copy( &wifi_settings_style, mainbar_get_style() ); @@ -81,7 +89,7 @@ void wlan_settings_tile_setup( void ) { lv_imgbtn_set_src( wifi_setup, LV_BTN_STATE_CHECKED_PRESSED, &wifi_64px); lv_obj_add_style( wifi_setup, LV_IMGBTN_PART_MAIN, mainbar_get_style() ); lv_obj_align( wifi_setup, NULL, LV_ALIGN_CENTER, 0, 0 ); - lv_obj_set_event_cb( wifi_setup, enter_wifi_setup_event_cb ); + lv_obj_set_event_cb( wifi_setup, enter_wifi_settings_event_cb ); lv_obj_t *exit_btn = lv_imgbtn_create( wifi_settings_tile, NULL); lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_RELEASED, &exit_32px); @@ -90,19 +98,28 @@ void wlan_settings_tile_setup( void ) { lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_CHECKED_PRESSED, &exit_32px); lv_obj_add_style( exit_btn, LV_IMGBTN_PART_MAIN, &wifi_settings_style ); lv_obj_align( exit_btn, wifi_settings_tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 ); - lv_obj_set_event_cb( exit_btn, exit_wifi_setup_event_cb ); + lv_obj_set_event_cb( exit_btn, exit_wifi_settings_event_cb ); lv_obj_t *exit_label = lv_label_create( wifi_settings_tile, NULL); lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, &wifi_settings_style ); - lv_label_set_text( exit_label, "wlan settings"); + lv_label_set_text( exit_label, "wlan"); lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 ); + lv_obj_t *setup_btn = lv_imgbtn_create( wifi_settings_tile, NULL); + lv_imgbtn_set_src( setup_btn, LV_BTN_STATE_RELEASED, &setup_32px); + lv_imgbtn_set_src( setup_btn, LV_BTN_STATE_PRESSED, &setup_32px); + lv_imgbtn_set_src( setup_btn, LV_BTN_STATE_CHECKED_RELEASED, &setup_32px); + lv_imgbtn_set_src( setup_btn, LV_BTN_STATE_CHECKED_PRESSED, &setup_32px); + lv_obj_add_style( setup_btn, LV_IMGBTN_PART_MAIN, &wifi_settings_style ); + lv_obj_align( setup_btn, wifi_settings_tile, LV_ALIGN_IN_TOP_RIGHT, -10, STATUSBAR_HEIGHT + 10 ); + lv_obj_set_event_cb( setup_btn, enter_wifi_setup_event_cb ); + /*Copy the first switch and turn it ON*/ wifi_onoff = lv_switch_create( wifi_settings_tile, NULL ); lv_obj_add_protect( wifi_onoff, LV_PROTECT_CLICK_FOCUS); lv_obj_add_style( wifi_onoff, LV_SWITCH_PART_INDIC, mainbar_get_switch_style() ); lv_switch_off( wifi_onoff, LV_ANIM_ON ); - lv_obj_align( wifi_onoff, exit_label, LV_ALIGN_OUT_RIGHT_MID, 30, 0 ); + lv_obj_align( wifi_onoff, setup_btn, LV_ALIGN_OUT_LEFT_MID, -10, 0 ); lv_obj_set_event_cb( wifi_onoff, wifi_onoff_event_handler); wifiname_list = lv_list_create( wifi_settings_tile, NULL); @@ -125,20 +142,19 @@ void wlan_settings_tile_setup( void ) { WiFi.onEvent( WiFiScanDone, WiFiEvent_t::SYSTEM_EVENT_SCAN_DONE ); wlan_password_tile_setup( wifi_password_tile_num ); + wlan_setup_tile_setup( wifi_setup_tile_num ); } -static void enter_wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event ) { +static void enter_wifi_settings_event_cb( lv_obj_t * obj, lv_event_t event ) { switch( event ) { - case( LV_EVENT_CLICKED ): motor_vibe( 1 ); - mainbar_jump_to_tilenumber( wifi_settings_tile_num, LV_ANIM_OFF ); + case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( wifi_settings_tile_num, LV_ANIM_OFF ); break; } } -static void exit_wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event ) { +static void exit_wifi_settings_event_cb( lv_obj_t * obj, lv_event_t event ) { switch( event ) { - case( LV_EVENT_CLICKED ): motor_vibe( 1 ); - mainbar_jump_to_tilenumber( setup_get_tile_num(), LV_ANIM_OFF ); + case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( setup_get_tile_num(), LV_ANIM_OFF ); break; } } @@ -276,3 +292,72 @@ static void exit_wifi_password_event_cb( lv_obj_t * obj, lv_event_t event ) { break; } } + +lv_obj_t *wifi_autoon_onoff; +static void wifi_autoon_onoff_event_handler( lv_obj_t * obj, lv_event_t event ); + +void wlan_setup_tile_setup( uint32_t wifi_setup_tile_num ) { + // get an app tile and copy mainstyle + wifi_setup_tile = mainbar_get_tile_obj( wifi_setup_tile_num ); + lv_style_copy( &wifi_setup_style, mainbar_get_style() ); + lv_style_set_bg_color( &wifi_setup_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY); + lv_style_set_bg_opa( &wifi_setup_style, LV_OBJ_PART_MAIN, LV_OPA_100); + lv_style_set_border_width( &wifi_setup_style, LV_OBJ_PART_MAIN, 0); + lv_obj_add_style( wifi_setup_tile, LV_OBJ_PART_MAIN, &wifi_setup_style ); + + lv_obj_t *exit_btn = lv_imgbtn_create( wifi_setup_tile, NULL); + lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_RELEASED, &exit_32px); + lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_PRESSED, &exit_32px); + lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_CHECKED_RELEASED, &exit_32px); + lv_imgbtn_set_src( exit_btn, LV_BTN_STATE_CHECKED_PRESSED, &exit_32px); + lv_obj_add_style( exit_btn, LV_IMGBTN_PART_MAIN, &wifi_setup_style ); + lv_obj_align( exit_btn, wifi_setup_tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 ); + lv_obj_set_event_cb( exit_btn, exit_wifi_setup_event_cb ); + + lv_obj_t *exit_label = lv_label_create( wifi_setup_tile, NULL); + lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, &wifi_setup_style ); + lv_label_set_text( exit_label, "wlan settings"); + lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 ); + + lv_obj_t *wifi_autoon_onoff_cont = lv_obj_create( wifi_setup_tile, NULL ); + lv_obj_set_size(wifi_autoon_onoff_cont, LV_HOR_RES_MAX , 40); + lv_obj_add_style( wifi_autoon_onoff_cont, LV_OBJ_PART_MAIN, &wifi_setup_style ); + lv_obj_align( wifi_autoon_onoff_cont, wifi_setup_tile, LV_ALIGN_IN_TOP_RIGHT, 0, 75 ); + + wifi_autoon_onoff = lv_switch_create( wifi_setup_tile, NULL ); + lv_obj_add_protect( wifi_autoon_onoff, LV_PROTECT_CLICK_FOCUS); + lv_obj_add_style( wifi_autoon_onoff, LV_SWITCH_PART_INDIC, mainbar_get_switch_style() ); + lv_switch_off( wifi_autoon_onoff, LV_ANIM_ON ); + lv_obj_align( wifi_autoon_onoff, wifi_autoon_onoff_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 ); + lv_obj_set_event_cb( wifi_autoon_onoff, wifi_autoon_onoff_event_handler ); + lv_obj_t *wifi_autoon_label = lv_label_create( wifi_autoon_onoff_cont, NULL); + lv_obj_add_style( wifi_autoon_label, LV_OBJ_PART_MAIN, &wifi_setup_style ); + lv_label_set_text( wifi_autoon_label, "enable on wakeup"); + lv_obj_align( wifi_autoon_label, wifi_autoon_onoff_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 ); + + if ( wifictl_get_autoon() ) + lv_switch_on( wifi_autoon_onoff, LV_ANIM_OFF); + else + lv_switch_off( wifi_autoon_onoff, LV_ANIM_OFF); +} + +static void enter_wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event ) { + switch( event ) { + case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( wifi_setup_tile_num, LV_ANIM_ON ); + break; + } +} + +static void exit_wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event ) { + switch( event ) { + case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( wifi_settings_tile_num, LV_ANIM_ON ); + break; + } +} + +static void wifi_autoon_onoff_event_handler( lv_obj_t * obj, lv_event_t event ) { + switch (event) { + case (LV_EVENT_VALUE_CHANGED): wifictl_set_autoon( lv_switch_get_state( obj ) ); + break; + } +} \ No newline at end of file diff --git a/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.h b/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.h index 59f47fc..eed4a60 100644 --- a/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.h +++ b/src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.h @@ -26,5 +26,6 @@ void wlan_settings_tile_setup( void ); void wlan_password_tile_setup( uint32_t wifi_password_tile_num ); + void wlan_setup_tile_setup( uint32_t wifi_setup_tile_num ); #endif // _WLAN_SETTINGS_H \ No newline at end of file diff --git a/src/hardware/wifictl.cpp b/src/hardware/wifictl.cpp index 1d55c18..360d225 100644 --- a/src/hardware/wifictl.cpp +++ b/src/hardware/wifictl.cpp @@ -40,9 +40,12 @@ char *wifiname=NULL; char *wifipassword=NULL; struct networklist wifictl_networklist[ NETWORKLIST_ENTRYS ]; +wifictl_config_t wifictl_config; void wifictl_save_network( void ); void wifictl_load_network( void ); +void wifictl_save_config( void ); +void wifictl_load_config( void ); void wifictl_Task( void * pvParameters ); /* @@ -63,6 +66,7 @@ void wifictl_setup( void ) { // load network list from spiff wifictl_load_network(); + wifictl_load_config(); // register WiFi events WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) { @@ -131,15 +135,60 @@ void wifictl_setup( void ) { vTaskSuspend( _wifictl_Task ); } + /* * */ -void wifictl_save_network( void ) { +void wifictl_save_config( void ) { fs::File file = SPIFFS.open( WIFICTL_CONFIG_FILE, FILE_WRITE ); if ( !file ) { log_e("Can't save file: %s", WIFICTL_CONFIG_FILE ); } + else { + file.write( (uint8_t *)&wifictl_config, sizeof( wifictl_config ) ); + file.close(); + } +} + +/* + * + */ +void wifictl_load_config( void ) { + fs::File file = SPIFFS.open( WIFICTL_CONFIG_FILE, FILE_READ ); + + if (!file) { + log_e("Can't open file: %s", WIFICTL_CONFIG_FILE ); + } + else { + int filesize = file.size(); + if ( filesize > sizeof( wifictl_config ) ) { + log_e("Failed to read configfile. Wrong filesize!" ); + } + else { + file.read( (uint8_t *)&wifictl_config, filesize ); + } + file.close(); + } +} + +bool wifictl_get_autoon( void ) { + return( wifictl_config.autoon ); +} + +void wifictl_set_autoon( bool autoon ) { + wifictl_config.autoon = autoon; + wifictl_save_config(); +} +/* + * + */ +void wifictl_save_network( void ) { + fs::File file = SPIFFS.open( WIFICTL_LIST_FILE, FILE_WRITE ); + + if ( !file ) { + log_e("Can't save file: %s", WIFICTL_LIST_FILE ); + } else { file.write( (uint8_t *)wifictl_networklist, sizeof( wifictl_networklist ) ); file.close(); @@ -150,10 +199,10 @@ void wifictl_save_network( void ) { * */ void wifictl_load_network( void ) { - fs::File file = SPIFFS.open( WIFICTL_CONFIG_FILE, FILE_READ ); + fs::File file = SPIFFS.open( WIFICTL_LIST_FILE, FILE_READ ); if (!file) { - log_e("Can't open file: %s", WIFICTL_CONFIG_FILE ); + log_e("Can't open file: %s", WIFICTL_LIST_FILE ); } else { int filesize = file.size(); @@ -269,7 +318,9 @@ void wifictl_standby( void ) { } void wifictl_wakeup( void ) { - wifictl_on(); + if ( wifictl_config.autoon ) { + wifictl_on(); + } } /* * diff --git a/src/hardware/wifictl.h b/src/hardware/wifictl.h index 887608f..88e0346 100644 --- a/src/hardware/wifictl.h +++ b/src/hardware/wifictl.h @@ -24,13 +24,18 @@ #define WIFICTL_DELAY 10 #define NETWORKLIST_ENTRYS 20 - #define WIFICTL_CONFIG_FILE "/wifilist.cfg" + #define WIFICTL_LIST_FILE "/wifilist.cfg" + #define WIFICTL_CONFIG_FILE "/wificfg.cfg" struct networklist { char ssid[64]=""; char password[64]=""; }; + typedef struct { + bool autoon = true; + } wifictl_config_t; + /* * @brief setup wifi controller routine */ @@ -68,5 +73,7 @@ void wifictl_off( void ); void wifictl_standby( void ); void wifictl_wakeup( void ); + bool wifictl_get_autoon( void ); + void wifictl_set_autoon( bool autoon ); #endif // _WIFICTL_H \ No newline at end of file diff --git a/ttgo-t-watch2020_v1.ino.bin b/ttgo-t-watch2020_v1.ino.bin index f8bce8d..ce85a8f 100644 Binary files a/ttgo-t-watch2020_v1.ino.bin and b/ttgo-t-watch2020_v1.ino.bin differ diff --git a/ttgo-t-watch2020_v1.version.json b/ttgo-t-watch2020_v1.version.json index 9c93284..65e9481 100644 --- a/ttgo-t-watch2020_v1.version.json +++ b/ttgo-t-watch2020_v1.version.json @@ -1 +1 @@ -{"version":"2020080301","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"} +{"version":"2020080305","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}