cleanup weather widget code and update updater

This commit is contained in:
sharandac
2020-07-23 18:26:57 +02:00
parent 15e8ed70a7
commit 07598ece6b
12 changed files with 418 additions and 282 deletions

View File

@@ -28,6 +28,11 @@
#include "update.h"
#include "gui/mainbar/mainbar.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_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);
lv_obj_add_style( update_status_label, LV_OBJ_PART_MAIN, style );
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 ) {
@@ -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) {
if(event == LV_EVENT_CLICKED) {
update_update_firmware();
xEventGroupSetBits( update_event_handle, UPDATE_REQUEST );
vTaskResume( _update_Task );
}
}
void update_update_firmware( void ) {
if((WiFi.status() == WL_CONNECTED)) {
void update_Task( void * pvParameters ) {
while( true ) {
vTaskDelay( 250 );
if ( xEventGroupGetBits( update_event_handle) & UPDATE_REQUEST ) {
if( WiFi.status() == WL_CONNECTED ) {
WiFiClient client;
client.setTimeout( 10 );
uint32_t display_timeout = display_get_timeout();
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) {
case HTTP_UPDATE_FAILED:
lv_label_set_text( update_status_label, "update failed" );
lv_label_set_text( update_status_label, "start 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_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 );
lv_obj_invalidate( lv_scr_act() );
break;
t_httpUpdate_return ret = httpUpdate.update( client, "http://www.neo-guerillaz.de/ttgo-t-watch2020_v1.ino.bin" );
case HTTP_UPDATE_OK:
lv_label_set_text( update_status_label, "update ok" );
switch(ret) {
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_invalidate( lv_scr_act() );
break;
}
xEventGroupClearBits( update_event_handle, UPDATE_REQUEST );
}
}
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 );
vTaskSuspend( _update_Task );
}
}

View File

@@ -24,6 +24,8 @@
#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"
void update_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );