cleanup weather widget code and update updater
This commit is contained in:
@@ -31,6 +31,6 @@
|
|||||||
/*
|
/*
|
||||||
* firmeware version string
|
* firmeware version string
|
||||||
*/
|
*/
|
||||||
#define __FIRMWARE__ "2020072304"
|
#define __FIRMWARE__ "2020072306"
|
||||||
|
|
||||||
#endif // _CONFIG_H
|
#endif // _CONFIG_H
|
||||||
|
|||||||
@@ -28,6 +28,11 @@
|
|||||||
#include "update.h"
|
#include "update.h"
|
||||||
#include "gui/mainbar/mainbar.h"
|
#include "gui/mainbar/mainbar.h"
|
||||||
#include "gui/statusbar.h"
|
#include "gui/statusbar.h"
|
||||||
|
#include "hardware/display.h"
|
||||||
|
|
||||||
|
EventGroupHandle_t update_event_handle = NULL;
|
||||||
|
TaskHandle_t _update_Task;
|
||||||
|
void update_Task( void * pvParameters );
|
||||||
|
|
||||||
lv_obj_t *update_settings_tile = NULL;
|
lv_obj_t *update_settings_tile = NULL;
|
||||||
lv_obj_t *update_btn = NULL;
|
lv_obj_t *update_btn = NULL;
|
||||||
@@ -90,7 +95,18 @@ void update_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_c
|
|||||||
update_status_label = lv_label_create( update_settings_tile, NULL);
|
update_status_label = lv_label_create( update_settings_tile, NULL);
|
||||||
lv_obj_add_style( update_status_label, LV_OBJ_PART_MAIN, style );
|
lv_obj_add_style( update_status_label, LV_OBJ_PART_MAIN, style );
|
||||||
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 );
|
||||||
|
|
||||||
|
update_event_handle = xEventGroupCreate();
|
||||||
|
xEventGroupClearBits( update_event_handle, UPDATE_REQUEST );
|
||||||
|
|
||||||
|
xTaskCreate(
|
||||||
|
update_Task, /* Function to implement the task */
|
||||||
|
"update Task", /* Name of the task */
|
||||||
|
10000, /* Stack size in words */
|
||||||
|
NULL, /* Task input parameter */
|
||||||
|
1, /* Priority of the task */
|
||||||
|
&_update_Task ); /* Task handle. */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exit_update_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
static void exit_update_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||||
@@ -102,40 +118,52 @@ static void exit_update_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
|||||||
|
|
||||||
static void update_event_handler(lv_obj_t * obj, lv_event_t event) {
|
static void update_event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||||
if(event == LV_EVENT_CLICKED) {
|
if(event == LV_EVENT_CLICKED) {
|
||||||
update_update_firmware();
|
xEventGroupSetBits( update_event_handle, UPDATE_REQUEST );
|
||||||
|
vTaskResume( _update_Task );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_update_firmware( void ) {
|
void update_Task( void * pvParameters ) {
|
||||||
if((WiFi.status() == WL_CONNECTED)) {
|
while( true ) {
|
||||||
|
vTaskDelay( 250 );
|
||||||
|
if ( xEventGroupGetBits( update_event_handle) & UPDATE_REQUEST ) {
|
||||||
|
if( WiFi.status() == WL_CONNECTED ) {
|
||||||
|
|
||||||
WiFiClient client;
|
uint32_t display_timeout = display_get_timeout();
|
||||||
client.setTimeout( 10 );
|
display_set_timeout( DISPLAY_MAX_TIMEOUT );
|
||||||
|
|
||||||
t_httpUpdate_return ret = httpUpdate.update( client, "http://www.neo-guerillaz.de/ttgo-t-watch2020_v1.ino.bin" );
|
WiFiClient client;
|
||||||
|
client.setTimeout( 10 );
|
||||||
|
|
||||||
switch(ret) {
|
lv_label_set_text( update_status_label, "start update ..." );
|
||||||
case HTTP_UPDATE_FAILED:
|
|
||||||
lv_label_set_text( update_status_label, "update failed" );
|
|
||||||
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HTTP_UPDATE_NO_UPDATES:
|
t_httpUpdate_return ret = httpUpdate.update( client, "http://www.neo-guerillaz.de/ttgo-t-watch2020_v1.ino.bin" );
|
||||||
lv_label_set_text( update_status_label, "no update" );
|
|
||||||
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case HTTP_UPDATE_OK:
|
switch(ret) {
|
||||||
lv_label_set_text( update_status_label, "update ok" );
|
case HTTP_UPDATE_FAILED:
|
||||||
|
lv_label_set_text( update_status_label, "update failed" );
|
||||||
|
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HTTP_UPDATE_NO_UPDATES:
|
||||||
|
lv_label_set_text( update_status_label, "no update" );
|
||||||
|
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HTTP_UPDATE_OK:
|
||||||
|
lv_label_set_text( update_status_label, "update ok" );
|
||||||
|
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
display_set_timeout( display_timeout );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lv_label_set_text( update_status_label, "turn wifi on!" );
|
||||||
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
||||||
lv_obj_invalidate( lv_scr_act() );
|
}
|
||||||
break;
|
xEventGroupClearBits( update_event_handle, UPDATE_REQUEST );
|
||||||
}
|
}
|
||||||
}
|
vTaskSuspend( _update_Task );
|
||||||
else {
|
|
||||||
lv_label_set_text( update_status_label, "turn wifi on!" );
|
|
||||||
lv_obj_align( update_status_label, update_btn, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
#include <TTGO.h>
|
#include <TTGO.h>
|
||||||
|
|
||||||
|
#define UPDATE_REQUEST _BV(0)
|
||||||
|
|
||||||
#define FIRMWARE_LOCATION "https://github.com/sharandac/My-TTGO-Watch/blob/master/ttgo-t-watch2020_v1.ino.bin"
|
#define FIRMWARE_LOCATION "https://github.com/sharandac/My-TTGO-Watch/blob/master/ttgo-t-watch2020_v1.ino.bin"
|
||||||
|
|
||||||
void update_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
void update_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||||
|
|||||||
@@ -31,15 +31,19 @@
|
|||||||
#include "gui/keyboard.h"
|
#include "gui/keyboard.h"
|
||||||
#include "images/resolve_owm_icon.h"
|
#include "images/resolve_owm_icon.h"
|
||||||
|
|
||||||
|
EventGroupHandle_t weather_widget_event_handle = NULL;
|
||||||
|
TaskHandle_t _weather_widget_sync_Task;
|
||||||
|
void weather_widget_sync_Task( void * pvParameters );
|
||||||
|
|
||||||
weather_config_t weather_config;
|
weather_config_t weather_config;
|
||||||
weather_forcast_t weather_today;
|
weather_forcast_t weather_today;
|
||||||
weather_forcast_t weather_forecast[ WEATHER_MAX_FORECAST ];
|
weather_forcast_t weather_forecast[ WEATHER_MAX_FORECAST ];
|
||||||
|
|
||||||
lv_tile_number weather_widget_tile_num = NO_TILE;
|
lv_tile_number weather_widget_tile_num = NO_TILE;
|
||||||
lv_tile_number weather_widget_setup_tile_num = NO_TILE;
|
lv_tile_number weather_widget_setup_tile_num = NO_TILE;
|
||||||
lv_obj_t *widget_cont = NULL;
|
lv_obj_t *weather_widget_cont = NULL;
|
||||||
lv_obj_t *widget_weather_condition_img = NULL;
|
lv_obj_t *weather_widget_condition_img = NULL;
|
||||||
lv_obj_t *widget_weather_temperature_label = NULL;
|
lv_obj_t *weather_widget_temperature_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 );
|
||||||
LV_IMG_DECLARE(owm_01d_64px);
|
LV_IMG_DECLARE(owm_01d_64px);
|
||||||
@@ -57,22 +61,39 @@ void weather_widget_setup( void ) {
|
|||||||
mainbar_set_tile_setup_cb( weather_widget_setup_tile_num, weather_widget_setup_tile_setup );
|
mainbar_set_tile_setup_cb( weather_widget_setup_tile_num, weather_widget_setup_tile_setup );
|
||||||
|
|
||||||
// get an widget container from main_tile
|
// get an widget container from main_tile
|
||||||
widget_cont = main_tile_register_widget();
|
weather_widget_cont = main_tile_register_widget();
|
||||||
|
|
||||||
// create widget weather condition icon and temperature label
|
// create widget weather condition icon and temperature label
|
||||||
widget_weather_condition_img = lv_imgbtn_create( widget_cont, NULL );
|
weather_widget_condition_img = lv_imgbtn_create( weather_widget_cont, NULL );
|
||||||
lv_imgbtn_set_src( widget_weather_condition_img, LV_BTN_STATE_RELEASED, &owm_01d_64px);
|
lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_RELEASED, &owm_01d_64px);
|
||||||
lv_imgbtn_set_src( widget_weather_condition_img, LV_BTN_STATE_PRESSED, &owm_01d_64px);
|
lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_PRESSED, &owm_01d_64px);
|
||||||
lv_imgbtn_set_src( widget_weather_condition_img, LV_BTN_STATE_CHECKED_RELEASED, &owm_01d_64px);
|
lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_CHECKED_RELEASED, &owm_01d_64px);
|
||||||
lv_imgbtn_set_src( widget_weather_condition_img, LV_BTN_STATE_CHECKED_PRESSED, &owm_01d_64px);
|
lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_CHECKED_PRESSED, &owm_01d_64px);
|
||||||
lv_obj_reset_style_list( widget_weather_condition_img, LV_OBJ_PART_MAIN );
|
lv_obj_reset_style_list( weather_widget_condition_img, LV_OBJ_PART_MAIN );
|
||||||
lv_obj_align( widget_weather_condition_img , widget_cont, LV_ALIGN_IN_TOP_LEFT, 0, 0 );
|
lv_obj_align( weather_widget_condition_img , weather_widget_cont, LV_ALIGN_IN_TOP_LEFT, 0, 0 );
|
||||||
lv_obj_set_event_cb( widget_weather_condition_img, enter_weather_widget_event_cb );
|
lv_obj_set_event_cb( weather_widget_condition_img, enter_weather_widget_event_cb );
|
||||||
|
|
||||||
widget_weather_temperature_label = lv_label_create( widget_cont , NULL);
|
weather_widget_temperature_label = lv_label_create( weather_widget_cont , NULL);
|
||||||
lv_label_set_text(widget_weather_temperature_label, "n/a");
|
lv_label_set_text( weather_widget_temperature_label, "n/a");
|
||||||
lv_obj_reset_style_list( widget_weather_temperature_label, LV_OBJ_PART_MAIN );
|
lv_obj_reset_style_list( weather_widget_temperature_label, LV_OBJ_PART_MAIN );
|
||||||
lv_obj_align(widget_weather_temperature_label, widget_cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
lv_obj_align( weather_widget_temperature_label, weather_widget_cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||||
|
|
||||||
|
// regster callback for wifi sync
|
||||||
|
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
|
xEventGroupSetBits( weather_widget_event_handle, WEATHER_WIDGET_SYNC_REQUEST );
|
||||||
|
vTaskResume( _weather_widget_sync_Task );
|
||||||
|
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
||||||
|
|
||||||
|
weather_widget_event_handle = xEventGroupCreate();
|
||||||
|
xEventGroupClearBits( weather_widget_event_handle, WEATHER_WIDGET_SYNC_REQUEST );
|
||||||
|
|
||||||
|
xTaskCreate(
|
||||||
|
weather_widget_sync_Task, /* Function to implement the task */
|
||||||
|
"weather sync Task", /* Name of the task */
|
||||||
|
10000, /* Stack size in words */
|
||||||
|
NULL, /* Task input parameter */
|
||||||
|
1, /* Priority of the task */
|
||||||
|
&_weather_widget_sync_Task ); /* Task handle. */
|
||||||
}
|
}
|
||||||
|
|
||||||
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 ) {
|
||||||
@@ -82,266 +103,51 @@ static void enter_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void weather_jump_to_forecast( void ) {
|
||||||
*
|
mainbar_jump_to_tilenumber( weather_widget_tile_num, LV_ANIM_ON );
|
||||||
*/
|
|
||||||
EventGroupHandle_t weather_event_handle = NULL;
|
|
||||||
TaskHandle_t _weather_sync_Task;
|
|
||||||
void weather_sync_Task( void * pvParameters );
|
|
||||||
|
|
||||||
lv_obj_t *weather_widget_setup_tile = NULL;
|
|
||||||
lv_obj_t *weather_apikey_textfield = NULL;
|
|
||||||
lv_obj_t *weather_lat_textfield = NULL;
|
|
||||||
lv_obj_t *weather_lon_textfield = NULL;
|
|
||||||
lv_obj_t *weather_autosync_onoff = NULL;
|
|
||||||
lv_style_t weather_widget_setup_style;
|
|
||||||
|
|
||||||
LV_IMG_DECLARE(exit_32px);
|
|
||||||
|
|
||||||
static void weather_apikey_event_cb( lv_obj_t * obj, lv_event_t event );
|
|
||||||
static void exit_weather_widget_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
|
||||||
static void weather_autosync_onoff_event_handler( lv_obj_t * obj, lv_event_t event );
|
|
||||||
|
|
||||||
void weather_widget_setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
|
||||||
lv_style_init( &weather_widget_setup_style );
|
|
||||||
lv_style_set_radius( &weather_widget_setup_style, LV_OBJ_PART_MAIN, 0);
|
|
||||||
lv_style_set_bg_color( &weather_widget_setup_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
|
||||||
lv_style_set_bg_opa( &weather_widget_setup_style, LV_OBJ_PART_MAIN, LV_OPA_100);
|
|
||||||
lv_style_set_border_width( &weather_widget_setup_style, LV_OBJ_PART_MAIN, 0);
|
|
||||||
lv_style_set_text_color( &weather_widget_setup_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
|
||||||
lv_style_set_image_recolor( &weather_widget_setup_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
|
||||||
|
|
||||||
weather_widget_setup_tile = lv_obj_create( tile, NULL);
|
|
||||||
lv_obj_set_size( weather_widget_setup_tile, hres , vres);
|
|
||||||
lv_obj_align( weather_widget_setup_tile, NULL, LV_ALIGN_CENTER, 0, 0);
|
|
||||||
lv_obj_add_style( weather_widget_setup_tile, LV_OBJ_PART_MAIN, &weather_widget_setup_style );
|
|
||||||
|
|
||||||
lv_obj_t *exit_btn = lv_imgbtn_create( weather_widget_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, style);
|
|
||||||
lv_obj_align( exit_btn, weather_widget_setup_tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
|
||||||
lv_obj_set_event_cb( exit_btn, exit_weather_widget_setup_event_cb );
|
|
||||||
|
|
||||||
lv_obj_t *exit_label = lv_label_create( weather_widget_setup_tile, NULL);
|
|
||||||
lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, style );
|
|
||||||
lv_label_set_text( exit_label, "open weather setup");
|
|
||||||
lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
|
||||||
|
|
||||||
lv_obj_t *weather_apikey_cont = lv_obj_create( weather_widget_setup_tile, NULL );
|
|
||||||
lv_obj_set_size(weather_apikey_cont, hres , 40);
|
|
||||||
lv_obj_add_style( weather_apikey_cont, LV_OBJ_PART_MAIN, style );
|
|
||||||
lv_obj_align( weather_apikey_cont, weather_widget_setup_tile, LV_ALIGN_IN_TOP_RIGHT, 0, 75 );
|
|
||||||
lv_obj_t *weather_apikey_label = lv_label_create( weather_apikey_cont, NULL);
|
|
||||||
lv_obj_add_style( weather_apikey_label, LV_OBJ_PART_MAIN, style );
|
|
||||||
lv_label_set_text( weather_apikey_label, "appid");
|
|
||||||
lv_obj_align( weather_apikey_label, weather_apikey_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
|
||||||
weather_apikey_textfield = lv_textarea_create( weather_apikey_cont, NULL);
|
|
||||||
lv_textarea_set_text( weather_apikey_textfield, weather_config.apikey );
|
|
||||||
lv_textarea_set_pwd_mode( weather_apikey_textfield, false);
|
|
||||||
lv_textarea_set_one_line( weather_apikey_textfield, true);
|
|
||||||
lv_textarea_set_cursor_hidden( weather_apikey_textfield, true);
|
|
||||||
lv_obj_set_width( weather_apikey_textfield, LV_HOR_RES /4 * 3 );
|
|
||||||
lv_obj_align( weather_apikey_textfield, weather_apikey_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
|
||||||
lv_obj_set_event_cb( weather_apikey_textfield, weather_apikey_event_cb );
|
|
||||||
|
|
||||||
lv_obj_t *weather_lat_cont = lv_obj_create( weather_widget_setup_tile, NULL );
|
|
||||||
lv_obj_set_size(weather_lat_cont, hres / 2 , 40 );
|
|
||||||
lv_obj_add_style( weather_lat_cont, LV_OBJ_PART_MAIN, style );
|
|
||||||
lv_obj_align( weather_lat_cont, weather_apikey_cont, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0 );
|
|
||||||
lv_obj_t *weather_lat_label = lv_label_create( weather_lat_cont, NULL);
|
|
||||||
lv_obj_add_style( weather_lat_label, LV_OBJ_PART_MAIN, style );
|
|
||||||
lv_label_set_text( weather_lat_label, "lat");
|
|
||||||
lv_obj_align( weather_lat_label, weather_lat_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
|
||||||
weather_lat_textfield = lv_textarea_create( weather_lat_cont, NULL);
|
|
||||||
lv_textarea_set_text( weather_lat_textfield, weather_config.lat );
|
|
||||||
lv_textarea_set_pwd_mode( weather_lat_textfield, false);
|
|
||||||
lv_textarea_set_one_line( weather_lat_textfield, true);
|
|
||||||
lv_textarea_set_cursor_hidden( weather_lat_textfield, true);
|
|
||||||
lv_obj_set_width( weather_lat_textfield, LV_HOR_RES / 4 );
|
|
||||||
lv_obj_align( weather_lat_textfield, weather_lat_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
|
||||||
lv_obj_set_event_cb( weather_lat_textfield, weather_apikey_event_cb );
|
|
||||||
|
|
||||||
lv_obj_t *weather_lon_cont = lv_obj_create( weather_widget_setup_tile, NULL );
|
|
||||||
lv_obj_set_size(weather_lon_cont, hres / 2 , 40 );
|
|
||||||
lv_obj_add_style( weather_lon_cont, LV_OBJ_PART_MAIN, style );
|
|
||||||
lv_obj_align( weather_lon_cont, weather_apikey_cont, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0 );
|
|
||||||
lv_obj_t *weather_lon_label = lv_label_create( weather_lon_cont, NULL);
|
|
||||||
lv_obj_add_style( weather_lon_label, LV_OBJ_PART_MAIN, style );
|
|
||||||
lv_label_set_text( weather_lon_label, "lon");
|
|
||||||
lv_obj_align( weather_lon_label, weather_lon_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
|
||||||
weather_lon_textfield = lv_textarea_create( weather_lon_cont, NULL);
|
|
||||||
lv_textarea_set_text( weather_lon_textfield, weather_config.lon );
|
|
||||||
lv_textarea_set_pwd_mode( weather_lon_textfield, false);
|
|
||||||
lv_textarea_set_one_line( weather_lon_textfield, true);
|
|
||||||
lv_textarea_set_cursor_hidden( weather_lon_textfield, true);
|
|
||||||
lv_obj_set_width( weather_lon_textfield, LV_HOR_RES / 4 );
|
|
||||||
lv_obj_align( weather_lon_textfield, weather_lon_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
|
||||||
lv_obj_set_event_cb( weather_lon_textfield, weather_apikey_event_cb );
|
|
||||||
|
|
||||||
lv_obj_t *weather_autosync_cont = lv_obj_create( weather_widget_setup_tile, NULL );
|
|
||||||
lv_obj_set_size( weather_autosync_cont, hres , 40);
|
|
||||||
lv_obj_add_style( weather_autosync_cont, LV_OBJ_PART_MAIN, style );
|
|
||||||
lv_obj_align( weather_autosync_cont, weather_lat_cont, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0 );
|
|
||||||
weather_autosync_onoff = lv_switch_create( weather_autosync_cont, NULL );
|
|
||||||
lv_switch_off( weather_autosync_onoff, LV_ANIM_ON );
|
|
||||||
lv_obj_align( weather_autosync_onoff, weather_autosync_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
|
||||||
lv_obj_set_event_cb( weather_autosync_onoff, weather_autosync_onoff_event_handler );
|
|
||||||
lv_obj_t *weather_autosync_label = lv_label_create( weather_autosync_cont, NULL);
|
|
||||||
lv_obj_add_style( weather_autosync_label, LV_OBJ_PART_MAIN, style );
|
|
||||||
lv_label_set_text( weather_autosync_label, "sync if wifi connected");
|
|
||||||
lv_obj_align( weather_autosync_label, weather_autosync_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
|
||||||
|
|
||||||
if ( weather_config.autosync )
|
|
||||||
lv_switch_on( weather_autosync_onoff, LV_ANIM_OFF );
|
|
||||||
else
|
|
||||||
lv_switch_off( weather_autosync_onoff, LV_ANIM_OFF );
|
|
||||||
|
|
||||||
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
|
||||||
xEventGroupSetBits( weather_event_handle, WEATHER_SYNC_REQUEST );
|
|
||||||
vTaskResume( _weather_sync_Task );
|
|
||||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
|
||||||
|
|
||||||
weather_event_handle = xEventGroupCreate();
|
|
||||||
xEventGroupClearBits( weather_event_handle, WEATHER_SYNC_REQUEST );
|
|
||||||
|
|
||||||
xTaskCreate(
|
|
||||||
weather_sync_Task, /* Function to implement the task */
|
|
||||||
"weather sync Task", /* Name of the task */
|
|
||||||
10000, /* Stack size in words */
|
|
||||||
NULL, /* Task input parameter */
|
|
||||||
1, /* Priority of the task */
|
|
||||||
&_weather_sync_Task ); /* Task handle. */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void weather_apikey_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
void weather_jump_to_setup( void ) {
|
||||||
if( event == LV_EVENT_CLICKED ) {
|
mainbar_jump_to_tilenumber( weather_widget_setup_tile_num, LV_ANIM_ON );
|
||||||
keyboard_set_textarea( obj );
|
|
||||||
}
|
|
||||||
else if ( event == LV_EVENT_DEFOCUSED ) {
|
|
||||||
keyboard_hide();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void weather_autosync_onoff_event_handler( lv_obj_t * obj, lv_event_t event ) {
|
void weather_sync_request( void ) {
|
||||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
xEventGroupSetBits( weather_widget_event_handle, WEATHER_WIDGET_SYNC_REQUEST );
|
||||||
if( lv_switch_get_state( obj ) ) {
|
vTaskResume( _weather_widget_sync_Task );
|
||||||
weather_config.autosync = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
weather_config.autosync = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exit_weather_widget_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
weather_config_t *weather_get_config( void ) {
|
||||||
switch( event ) {
|
return( &weather_config );
|
||||||
case( LV_EVENT_CLICKED ): keyboard_hide();
|
|
||||||
weather_save_config();
|
|
||||||
mainbar_jump_to_tilenumber( weather_widget_tile_num, LV_ANIM_ON );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void weather_sync_Task( void * pvParameters ) {
|
void weather_widget_sync_Task( void * pvParameters ) {
|
||||||
|
|
||||||
while( true ) {
|
while( true ) {
|
||||||
vTaskDelay( 250 );
|
vTaskDelay( 250 );
|
||||||
if ( xEventGroupGetBits( weather_event_handle ) & WEATHER_SYNC_REQUEST ) {
|
if ( xEventGroupGetBits( weather_widget_event_handle ) & WEATHER_WIDGET_SYNC_REQUEST ) {
|
||||||
if ( weather_config.autosync ) {
|
if ( weather_config.autosync ) {
|
||||||
weather_fetch_today( &weather_config, &weather_today );
|
weather_fetch_today( &weather_config, &weather_today );
|
||||||
if ( weather_today.valide ) {
|
if ( weather_today.valide ) {
|
||||||
Serial.printf("weather fetch ok\r\n");
|
Serial.printf("weather fetch ok\r\n");
|
||||||
lv_label_set_text( widget_weather_temperature_label, weather_today.temp );
|
lv_label_set_text( weather_widget_temperature_label, weather_today.temp );
|
||||||
lv_imgbtn_set_src( widget_weather_condition_img, LV_BTN_STATE_RELEASED, resolve_owm_icon( weather_today.icon ) );
|
lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_RELEASED, resolve_owm_icon( weather_today.icon ) );
|
||||||
lv_imgbtn_set_src( widget_weather_condition_img, LV_BTN_STATE_PRESSED, resolve_owm_icon( weather_today.icon ) );
|
lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_PRESSED, resolve_owm_icon( weather_today.icon ) );
|
||||||
lv_imgbtn_set_src( widget_weather_condition_img, LV_BTN_STATE_CHECKED_RELEASED, resolve_owm_icon( weather_today.icon ) );
|
lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_CHECKED_RELEASED, resolve_owm_icon( weather_today.icon ) );
|
||||||
lv_imgbtn_set_src( widget_weather_condition_img, LV_BTN_STATE_CHECKED_PRESSED, resolve_owm_icon( weather_today.icon ) );
|
lv_imgbtn_set_src( weather_widget_condition_img, LV_BTN_STATE_CHECKED_PRESSED, resolve_owm_icon( weather_today.icon ) );
|
||||||
lv_obj_align( widget_weather_temperature_label, widget_cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
lv_obj_align( weather_widget_temperature_label, weather_widget_cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xEventGroupClearBits( weather_event_handle, WEATHER_SYNC_REQUEST );
|
xEventGroupClearBits( weather_widget_event_handle, WEATHER_WIDGET_SYNC_REQUEST );
|
||||||
}
|
}
|
||||||
vTaskSuspend( _weather_sync_Task );
|
vTaskSuspend( _weather_widget_sync_Task );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
lv_obj_t *weather_widget_tile = NULL;
|
|
||||||
lv_style_t weather_widget_style;
|
|
||||||
|
|
||||||
LV_IMG_DECLARE(exit_32px);
|
|
||||||
LV_IMG_DECLARE(setup_32px);
|
|
||||||
LV_IMG_DECLARE(refresh_32px);
|
|
||||||
|
|
||||||
static void exit_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
|
||||||
static void setup_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
|
||||||
static void refresh_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
|
||||||
|
|
||||||
void weather_widget_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
|
||||||
lv_obj_t * exit_btn = lv_imgbtn_create(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, style);
|
|
||||||
lv_obj_align(exit_btn, tile, LV_ALIGN_IN_BOTTOM_LEFT, 10, -10 );
|
|
||||||
lv_obj_set_event_cb( exit_btn, exit_weather_widget_event_cb );
|
|
||||||
|
|
||||||
lv_obj_t * setup_btn = lv_imgbtn_create(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, style);
|
|
||||||
lv_obj_align(setup_btn, tile, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -10 );
|
|
||||||
lv_obj_set_event_cb( setup_btn, setup_weather_widget_event_cb );
|
|
||||||
|
|
||||||
lv_obj_t * reload_btn = lv_imgbtn_create(tile, NULL);
|
|
||||||
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_RELEASED, &refresh_32px);
|
|
||||||
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_PRESSED, &refresh_32px);
|
|
||||||
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_CHECKED_RELEASED, &refresh_32px);
|
|
||||||
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_CHECKED_PRESSED, &refresh_32px);
|
|
||||||
lv_obj_add_style(reload_btn, LV_IMGBTN_PART_MAIN, style);
|
|
||||||
lv_obj_align(reload_btn, tile, LV_ALIGN_IN_TOP_RIGHT, -10 , STATUSBAR_HEIGHT + 10 );
|
|
||||||
lv_obj_set_event_cb( reload_btn, refresh_weather_widget_event_cb );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void exit_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
|
||||||
switch( event ) {
|
|
||||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( MAIN_TILE, LV_ANIM_OFF );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setup_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
|
||||||
switch( event ) {
|
|
||||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( weather_widget_setup_tile_num, LV_ANIM_ON );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void refresh_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
|
||||||
switch( event ) {
|
|
||||||
case( LV_EVENT_CLICKED ): xEventGroupSetBits( weather_event_handle, WEATHER_SYNC_REQUEST );
|
|
||||||
vTaskResume( _weather_sync_Task );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void weather_save_config( void ) {
|
void weather_save_config( void ) {
|
||||||
|
|
||||||
strcpy( weather_config.apikey, lv_textarea_get_text( weather_apikey_textfield ) );
|
|
||||||
strcpy( weather_config.lat, lv_textarea_get_text( weather_lat_textfield ) );
|
|
||||||
strcpy( weather_config.lon, lv_textarea_get_text( weather_lon_textfield ) );
|
|
||||||
|
|
||||||
fs::File file = SPIFFS.open( WEATHER_CONFIG_FILE, FILE_WRITE );
|
fs::File file = SPIFFS.open( WEATHER_CONFIG_FILE, FILE_WRITE );
|
||||||
|
|
||||||
if ( !file ) {
|
if ( !file ) {
|
||||||
|
|||||||
@@ -24,11 +24,11 @@
|
|||||||
|
|
||||||
#include <TTGO.h>
|
#include <TTGO.h>
|
||||||
|
|
||||||
#define WEATHER_CONFIG_FILE "/weather.cfg"
|
#define WEATHER_CONFIG_FILE "/weather.cfg"
|
||||||
|
|
||||||
#define WEATHER_SYNC_REQUEST _BV(0)
|
#define WEATHER_WIDGET_SYNC_REQUEST _BV(0)
|
||||||
|
|
||||||
#define WEATHER_MAX_FORECAST 4
|
#define WEATHER_MAX_FORECAST 4
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char apikey[64] = "";
|
char apikey[64] = "";
|
||||||
@@ -52,6 +52,14 @@
|
|||||||
|
|
||||||
void weather_widget_setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
void weather_widget_setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||||
|
|
||||||
|
weather_config_t *weather_get_config( void );
|
||||||
|
|
||||||
|
void weather_jump_to_forecast( void );
|
||||||
|
|
||||||
|
void weather_jump_to_setup( void );
|
||||||
|
|
||||||
|
void weather_sync_request( void );
|
||||||
|
|
||||||
void weather_save_config( void );
|
void weather_save_config( void );
|
||||||
|
|
||||||
void weather_load_config( void );
|
void weather_load_config( void );
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ void weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *w
|
|||||||
char json[2000] = "";
|
char json[2000] = "";
|
||||||
StaticJsonDocument<2000> doc;
|
StaticJsonDocument<2000> doc;
|
||||||
|
|
||||||
|
weather_today->valide = false;
|
||||||
|
|
||||||
if ( !client.connect( OWM_HOST, OWM_PORT ) ) {
|
if ( !client.connect( OWM_HOST, OWM_PORT ) ) {
|
||||||
Serial.println("Connection failed");
|
Serial.println("Connection failed");
|
||||||
return;
|
return;
|
||||||
@@ -52,7 +54,6 @@ void weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *w
|
|||||||
while ( client.available() == 0 ) {
|
while ( client.available() == 0 ) {
|
||||||
if ( millis() - startMillis > 5000 ) {
|
if ( millis() - startMillis > 5000 ) {
|
||||||
client.stop();
|
client.stop();
|
||||||
weather_today->valide = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,12 +72,15 @@ void weather_fetch_today( weather_config_t *weather_config, weather_forcast_t *w
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
if ( data_begin == false ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DeserializationError error = deserializeJson( doc, json);
|
DeserializationError error = deserializeJson( doc, json);
|
||||||
if (error) {
|
if (error) {
|
||||||
Serial.print(F("deserializeJson() failed: "));
|
Serial.print(F("deserializeJson() failed: "));
|
||||||
Serial.println(error.c_str());
|
Serial.println(error.c_str());
|
||||||
weather_today->valide = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
93
src/gui/widget/weather/weather_forecast.cpp
Normal file
93
src/gui/widget/weather/weather_forecast.cpp
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Tu May 22 21:23:51 2020
|
||||||
|
* Copyright 2020 Dirk Brosswick
|
||||||
|
* Email: dirk.brosswick@googlemail.com
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* 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 "weather.h"
|
||||||
|
#include "weather_fetch.h"
|
||||||
|
#include "weather_forecast.h"
|
||||||
|
|
||||||
|
#include "gui/mainbar/mainbar.h"
|
||||||
|
#include "gui/mainbar/main_tile/main_tile.h"
|
||||||
|
#include "gui/statusbar.h"
|
||||||
|
#include "gui/keyboard.h"
|
||||||
|
|
||||||
|
lv_obj_t *weather_widget_tile = NULL;
|
||||||
|
lv_style_t weather_widget_style;
|
||||||
|
|
||||||
|
LV_IMG_DECLARE(exit_32px);
|
||||||
|
LV_IMG_DECLARE(setup_32px);
|
||||||
|
LV_IMG_DECLARE(refresh_32px);
|
||||||
|
|
||||||
|
static void exit_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||||
|
static void setup_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||||
|
static void refresh_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||||
|
|
||||||
|
void weather_widget_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||||
|
lv_obj_t * exit_btn = lv_imgbtn_create(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, style);
|
||||||
|
lv_obj_align(exit_btn, tile, LV_ALIGN_IN_BOTTOM_LEFT, 10, -10 );
|
||||||
|
lv_obj_set_event_cb( exit_btn, exit_weather_widget_event_cb );
|
||||||
|
|
||||||
|
lv_obj_t * setup_btn = lv_imgbtn_create(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, style);
|
||||||
|
lv_obj_align(setup_btn, tile, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -10 );
|
||||||
|
lv_obj_set_event_cb( setup_btn, setup_weather_widget_event_cb );
|
||||||
|
|
||||||
|
lv_obj_t * reload_btn = lv_imgbtn_create(tile, NULL);
|
||||||
|
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_RELEASED, &refresh_32px);
|
||||||
|
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_PRESSED, &refresh_32px);
|
||||||
|
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_CHECKED_RELEASED, &refresh_32px);
|
||||||
|
lv_imgbtn_set_src(reload_btn, LV_BTN_STATE_CHECKED_PRESSED, &refresh_32px);
|
||||||
|
lv_obj_add_style(reload_btn, LV_IMGBTN_PART_MAIN, style);
|
||||||
|
lv_obj_align(reload_btn, tile, LV_ALIGN_IN_TOP_RIGHT, -10 , STATUSBAR_HEIGHT + 10 );
|
||||||
|
lv_obj_set_event_cb( reload_btn, refresh_weather_widget_event_cb );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exit_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||||
|
switch( event ) {
|
||||||
|
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( MAIN_TILE, LV_ANIM_OFF );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setup_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||||
|
switch( event ) {
|
||||||
|
case( LV_EVENT_CLICKED ): weather_jump_to_setup();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void refresh_weather_widget_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||||
|
switch( event ) {
|
||||||
|
case( LV_EVENT_CLICKED ): weather_sync_request();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/gui/widget/weather/weather_forecast.h
Normal file
8
src/gui/widget/weather/weather_forecast.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef _WEATHER_FORECAST_H
|
||||||
|
#define _WEATHER_FORECAST_H
|
||||||
|
|
||||||
|
#include <TTGO.h>
|
||||||
|
|
||||||
|
void weather_widget_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||||
|
|
||||||
|
#endif // _WEATHER_FORECAST_H
|
||||||
179
src/gui/widget/weather/weather_setup.cpp
Normal file
179
src/gui/widget/weather/weather_setup.cpp
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Tu May 22 21:23:51 2020
|
||||||
|
* Copyright 2020 Dirk Brosswick
|
||||||
|
* Email: dirk.brosswick@googlemail.com
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* 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 "weather.h"
|
||||||
|
#include "weather_fetch.h"
|
||||||
|
#include "weather_setup.h"
|
||||||
|
|
||||||
|
#include "gui/mainbar/mainbar.h"
|
||||||
|
#include "gui/mainbar/main_tile/main_tile.h"
|
||||||
|
#include "gui/statusbar.h"
|
||||||
|
#include "gui/keyboard.h"
|
||||||
|
|
||||||
|
lv_obj_t *weather_widget_setup_tile = NULL;
|
||||||
|
lv_obj_t *weather_apikey_textfield = NULL;
|
||||||
|
lv_obj_t *weather_lat_textfield = NULL;
|
||||||
|
lv_obj_t *weather_lon_textfield = NULL;
|
||||||
|
lv_obj_t *weather_autosync_onoff = NULL;
|
||||||
|
lv_style_t weather_widget_setup_style;
|
||||||
|
|
||||||
|
LV_IMG_DECLARE(exit_32px);
|
||||||
|
|
||||||
|
static void weather_apikey_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||||
|
static void exit_weather_widget_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||||
|
static void weather_autosync_onoff_event_handler( lv_obj_t * obj, lv_event_t event );
|
||||||
|
|
||||||
|
void weather_widget_setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||||
|
|
||||||
|
weather_config_t *weather_config = weather_get_config();
|
||||||
|
|
||||||
|
lv_style_init( &weather_widget_setup_style );
|
||||||
|
lv_style_set_radius( &weather_widget_setup_style, LV_OBJ_PART_MAIN, 0);
|
||||||
|
lv_style_set_bg_color( &weather_widget_setup_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||||
|
lv_style_set_bg_opa( &weather_widget_setup_style, LV_OBJ_PART_MAIN, LV_OPA_100);
|
||||||
|
lv_style_set_border_width( &weather_widget_setup_style, LV_OBJ_PART_MAIN, 0);
|
||||||
|
lv_style_set_text_color( &weather_widget_setup_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||||
|
lv_style_set_image_recolor( &weather_widget_setup_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||||
|
|
||||||
|
weather_widget_setup_tile = lv_obj_create( tile, NULL);
|
||||||
|
lv_obj_set_size( weather_widget_setup_tile, hres , vres);
|
||||||
|
lv_obj_align( weather_widget_setup_tile, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
lv_obj_add_style( weather_widget_setup_tile, LV_OBJ_PART_MAIN, &weather_widget_setup_style );
|
||||||
|
|
||||||
|
lv_obj_t *exit_btn = lv_imgbtn_create( weather_widget_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, style);
|
||||||
|
lv_obj_align( exit_btn, weather_widget_setup_tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||||
|
lv_obj_set_event_cb( exit_btn, exit_weather_widget_setup_event_cb );
|
||||||
|
|
||||||
|
lv_obj_t *exit_label = lv_label_create( weather_widget_setup_tile, NULL);
|
||||||
|
lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, style );
|
||||||
|
lv_label_set_text( exit_label, "open weather setup");
|
||||||
|
lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||||
|
|
||||||
|
lv_obj_t *weather_apikey_cont = lv_obj_create( weather_widget_setup_tile, NULL );
|
||||||
|
lv_obj_set_size(weather_apikey_cont, hres , 40);
|
||||||
|
lv_obj_add_style( weather_apikey_cont, LV_OBJ_PART_MAIN, style );
|
||||||
|
lv_obj_align( weather_apikey_cont, weather_widget_setup_tile, LV_ALIGN_IN_TOP_RIGHT, 0, 75 );
|
||||||
|
lv_obj_t *weather_apikey_label = lv_label_create( weather_apikey_cont, NULL);
|
||||||
|
lv_obj_add_style( weather_apikey_label, LV_OBJ_PART_MAIN, style );
|
||||||
|
lv_label_set_text( weather_apikey_label, "appid");
|
||||||
|
lv_obj_align( weather_apikey_label, weather_apikey_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||||
|
weather_apikey_textfield = lv_textarea_create( weather_apikey_cont, NULL);
|
||||||
|
lv_textarea_set_text( weather_apikey_textfield, weather_config->apikey );
|
||||||
|
lv_textarea_set_pwd_mode( weather_apikey_textfield, false);
|
||||||
|
lv_textarea_set_one_line( weather_apikey_textfield, true);
|
||||||
|
lv_textarea_set_cursor_hidden( weather_apikey_textfield, true);
|
||||||
|
lv_obj_set_width( weather_apikey_textfield, LV_HOR_RES /4 * 3 );
|
||||||
|
lv_obj_align( weather_apikey_textfield, weather_apikey_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||||
|
lv_obj_set_event_cb( weather_apikey_textfield, weather_apikey_event_cb );
|
||||||
|
|
||||||
|
lv_obj_t *weather_lat_cont = lv_obj_create( weather_widget_setup_tile, NULL );
|
||||||
|
lv_obj_set_size(weather_lat_cont, hres / 2 , 40 );
|
||||||
|
lv_obj_add_style( weather_lat_cont, LV_OBJ_PART_MAIN, style );
|
||||||
|
lv_obj_align( weather_lat_cont, weather_apikey_cont, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0 );
|
||||||
|
lv_obj_t *weather_lat_label = lv_label_create( weather_lat_cont, NULL);
|
||||||
|
lv_obj_add_style( weather_lat_label, LV_OBJ_PART_MAIN, style );
|
||||||
|
lv_label_set_text( weather_lat_label, "lat");
|
||||||
|
lv_obj_align( weather_lat_label, weather_lat_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||||
|
weather_lat_textfield = lv_textarea_create( weather_lat_cont, NULL);
|
||||||
|
lv_textarea_set_text( weather_lat_textfield, weather_config->lat );
|
||||||
|
lv_textarea_set_pwd_mode( weather_lat_textfield, false);
|
||||||
|
lv_textarea_set_one_line( weather_lat_textfield, true);
|
||||||
|
lv_textarea_set_cursor_hidden( weather_lat_textfield, true);
|
||||||
|
lv_obj_set_width( weather_lat_textfield, LV_HOR_RES / 4 );
|
||||||
|
lv_obj_align( weather_lat_textfield, weather_lat_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||||
|
lv_obj_set_event_cb( weather_lat_textfield, weather_apikey_event_cb );
|
||||||
|
|
||||||
|
lv_obj_t *weather_lon_cont = lv_obj_create( weather_widget_setup_tile, NULL );
|
||||||
|
lv_obj_set_size(weather_lon_cont, hres / 2 , 40 );
|
||||||
|
lv_obj_add_style( weather_lon_cont, LV_OBJ_PART_MAIN, style );
|
||||||
|
lv_obj_align( weather_lon_cont, weather_apikey_cont, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, 0 );
|
||||||
|
lv_obj_t *weather_lon_label = lv_label_create( weather_lon_cont, NULL);
|
||||||
|
lv_obj_add_style( weather_lon_label, LV_OBJ_PART_MAIN, style );
|
||||||
|
lv_label_set_text( weather_lon_label, "lon");
|
||||||
|
lv_obj_align( weather_lon_label, weather_lon_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||||
|
weather_lon_textfield = lv_textarea_create( weather_lon_cont, NULL);
|
||||||
|
lv_textarea_set_text( weather_lon_textfield, weather_config->lon );
|
||||||
|
lv_textarea_set_pwd_mode( weather_lon_textfield, false);
|
||||||
|
lv_textarea_set_one_line( weather_lon_textfield, true);
|
||||||
|
lv_textarea_set_cursor_hidden( weather_lon_textfield, true);
|
||||||
|
lv_obj_set_width( weather_lon_textfield, LV_HOR_RES / 4 );
|
||||||
|
lv_obj_align( weather_lon_textfield, weather_lon_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||||
|
lv_obj_set_event_cb( weather_lon_textfield, weather_apikey_event_cb );
|
||||||
|
|
||||||
|
lv_obj_t *weather_autosync_cont = lv_obj_create( weather_widget_setup_tile, NULL );
|
||||||
|
lv_obj_set_size( weather_autosync_cont, hres , 40);
|
||||||
|
lv_obj_add_style( weather_autosync_cont, LV_OBJ_PART_MAIN, style );
|
||||||
|
lv_obj_align( weather_autosync_cont, weather_lat_cont, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0 );
|
||||||
|
weather_autosync_onoff = lv_switch_create( weather_autosync_cont, NULL );
|
||||||
|
lv_switch_off( weather_autosync_onoff, LV_ANIM_ON );
|
||||||
|
lv_obj_align( weather_autosync_onoff, weather_autosync_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||||
|
lv_obj_set_event_cb( weather_autosync_onoff, weather_autosync_onoff_event_handler );
|
||||||
|
lv_obj_t *weather_autosync_label = lv_label_create( weather_autosync_cont, NULL);
|
||||||
|
lv_obj_add_style( weather_autosync_label, LV_OBJ_PART_MAIN, style );
|
||||||
|
lv_label_set_text( weather_autosync_label, "sync if wifi connected");
|
||||||
|
lv_obj_align( weather_autosync_label, weather_autosync_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||||
|
|
||||||
|
if ( weather_config->autosync )
|
||||||
|
lv_switch_on( weather_autosync_onoff, LV_ANIM_OFF );
|
||||||
|
else
|
||||||
|
lv_switch_off( weather_autosync_onoff, LV_ANIM_OFF );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void weather_apikey_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||||
|
if( event == LV_EVENT_CLICKED ) {
|
||||||
|
keyboard_set_textarea( obj );
|
||||||
|
}
|
||||||
|
else if ( event == LV_EVENT_DEFOCUSED ) {
|
||||||
|
keyboard_hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void weather_autosync_onoff_event_handler( lv_obj_t * obj, lv_event_t event ) {
|
||||||
|
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||||
|
weather_config_t *weather_config = weather_get_config();
|
||||||
|
if( lv_switch_get_state( obj ) ) {
|
||||||
|
weather_config->autosync = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
weather_config->autosync = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exit_weather_widget_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||||
|
switch( event ) {
|
||||||
|
case( LV_EVENT_CLICKED ): keyboard_hide();
|
||||||
|
weather_config_t *weather_config = weather_get_config();
|
||||||
|
strcpy( weather_config->apikey, lv_textarea_get_text( weather_apikey_textfield ) );
|
||||||
|
strcpy( weather_config->lat, lv_textarea_get_text( weather_lat_textfield ) );
|
||||||
|
strcpy( weather_config->lon, lv_textarea_get_text( weather_lon_textfield ) );
|
||||||
|
weather_save_config();
|
||||||
|
weather_jump_to_forecast();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
src/gui/widget/weather/weather_setup.h
Normal file
8
src/gui/widget/weather/weather_setup.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef _WEATHER_SETUP_H
|
||||||
|
#define _WEATHER_SETUP_H
|
||||||
|
|
||||||
|
#include <TTGO.h>
|
||||||
|
|
||||||
|
void weather_widget_setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||||
|
|
||||||
|
#endif // _WEATHER_SETUP_H
|
||||||
Binary file not shown.
@@ -1 +1 @@
|
|||||||
2020072304
|
2020072306
|
||||||
|
|||||||
Reference in New Issue
Block a user