add updater and some tiny changes
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "setup_tile/move_settings/move_settings.h"
|
||||
#include "setup_tile/display_settings/display_settings.h"
|
||||
#include "setup_tile/time_settings/time_settings.h"
|
||||
#include "setup_tile/update/update.h"
|
||||
|
||||
static lv_style_t mainbarstyle;
|
||||
static lv_obj_t *mainbar = NULL;
|
||||
@@ -28,7 +29,8 @@ lv_tile_entry_t tile_entry[ TILE_NUM ] {
|
||||
{ NULL, MOVE_SETTINGS_TILE, move_settings_tile_setup, { 2,4 } },
|
||||
{ NULL, DISPLAY_SETTINGS_TILE, display_settings_tile_setup, { 4,4 } },
|
||||
{ NULL, BATTERY_SETTINGS_TILE, battery_settings_tile_setup, { 6,4 } },
|
||||
{ NULL, TIME_SETTINGS_TILE, time_settings_tile_setup, { 8,4 } }
|
||||
{ NULL, TIME_SETTINGS_TILE, time_settings_tile_setup, { 8,4 } },
|
||||
{ NULL, UPDATE_SETTINGS_TILE, update_tile_setup, { 10,4 } }
|
||||
};
|
||||
|
||||
void mainbar_setup( void ) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
DISPLAY_SETTINGS_TILE,
|
||||
BATTERY_SETTINGS_TILE,
|
||||
TIME_SETTINGS_TILE,
|
||||
UPDATE_SETTINGS_TILE,
|
||||
TILE_NUM
|
||||
} lv_tile_number;
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ static void battery_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void move_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void display_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void time_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void update_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
|
||||
LV_IMG_DECLARE(wifi_64px);
|
||||
LV_IMG_DECLARE(battery_icon_64px);
|
||||
LV_IMG_DECLARE(move_64px);
|
||||
LV_IMG_DECLARE(brightness_64px);
|
||||
LV_IMG_DECLARE(time_64px);
|
||||
|
||||
LV_IMG_DECLARE(update_64px);
|
||||
|
||||
void setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
|
||||
@@ -62,6 +63,15 @@ void setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_co
|
||||
lv_obj_add_style( time_setup, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align( time_setup, tile, LV_ALIGN_IN_TOP_LEFT, 16+70+70, 48 );
|
||||
lv_obj_set_event_cb( time_setup, time_setup_event_cb );
|
||||
|
||||
lv_obj_t * update_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src( update_setup, LV_BTN_STATE_RELEASED, &update_64px);
|
||||
lv_imgbtn_set_src( update_setup, LV_BTN_STATE_PRESSED, &update_64px);
|
||||
lv_imgbtn_set_src( update_setup, LV_BTN_STATE_CHECKED_RELEASED, &update_64px);
|
||||
lv_imgbtn_set_src( update_setup, LV_BTN_STATE_CHECKED_PRESSED, &update_64px);
|
||||
lv_obj_add_style( update_setup, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align( update_setup, tile, LV_ALIGN_IN_TOP_LEFT, 16+70+70, 48+86 );
|
||||
lv_obj_set_event_cb( update_setup, update_setup_event_cb );
|
||||
}
|
||||
|
||||
static void wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
@@ -97,4 +107,11 @@ static void time_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( TIME_SETTINGS_TILE, LV_ANIM_OFF );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void update_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( UPDATE_SETTINGS_TILE, LV_ANIM_OFF );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -84,6 +84,7 @@ void time_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hre
|
||||
lv_obj_align( utczone_label, utczone_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||
utczone_list = lv_dropdown_create( utczone_cont, NULL);
|
||||
lv_dropdown_set_options( utczone_list, "-12\n-11\n-10\n-9\n-8\n-7\n-6\n-5\n-4\n-3\n-2\n-1\n0\n+1\n+2\n+3\n+4\n+5\n+6\n+7\n+8\n+9\n+10\n+11\n+12" );
|
||||
lv_obj_set_size( utczone_list, 70, 40 );
|
||||
lv_obj_align(utczone_list, utczone_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0);
|
||||
lv_obj_set_event_cb(utczone_list, utczone_event_handler);
|
||||
|
||||
|
||||
120
src/gui/mainbar/setup_tile/update/update.cpp
Normal file
120
src/gui/mainbar/setup_tile/update/update.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
#include "config.h"
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <HTTPClient.h>
|
||||
#include <HTTPUpdate.h>
|
||||
|
||||
#include "update.h"
|
||||
#include "gui/mainbar/mainbar.h"
|
||||
#include "gui/statusbar.h"
|
||||
|
||||
lv_obj_t *update_settings_tile = NULL;
|
||||
lv_obj_t *update_btn = NULL;
|
||||
lv_obj_t *update_status_label = NULL;
|
||||
lv_style_t update_settings_style;
|
||||
|
||||
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 );
|
||||
|
||||
LV_IMG_DECLARE(exit_32px);
|
||||
LV_IMG_DECLARE(time_32px);
|
||||
|
||||
void update_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
lv_style_init( &update_settings_style );
|
||||
lv_style_set_radius( &update_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_bg_color( &update_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||
lv_style_set_bg_opa( &update_settings_style, LV_OBJ_PART_MAIN, LV_OPA_100);
|
||||
lv_style_set_border_width( &update_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_text_color( &update_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
lv_style_set_image_recolor( &update_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
|
||||
update_settings_tile = lv_obj_create( tile, NULL);
|
||||
lv_obj_set_size( update_settings_tile, hres , vres);
|
||||
lv_obj_align( update_settings_tile, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_style( update_settings_tile, LV_OBJ_PART_MAIN, &update_settings_style );
|
||||
|
||||
lv_obj_t *exit_btn = lv_imgbtn_create( update_settings_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, update_settings_tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_set_event_cb( exit_btn, exit_update_setup_event_cb );
|
||||
|
||||
lv_obj_t *exit_label = lv_label_create( update_settings_tile, NULL);
|
||||
lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( exit_label, "update");
|
||||
lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *update_version_cont = lv_obj_create( update_settings_tile, NULL );
|
||||
lv_obj_set_size(update_version_cont, hres , 40);
|
||||
lv_obj_add_style( update_version_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( update_version_cont, update_settings_tile, LV_ALIGN_IN_TOP_RIGHT, 0, 75 );
|
||||
lv_obj_t *update_version_label = lv_label_create( update_version_cont, NULL);
|
||||
lv_obj_add_style( update_version_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( update_version_label, "firmware version" );
|
||||
lv_obj_align( update_version_label, update_version_cont, LV_ALIGN_IN_TOP_MID, 0, 0 );
|
||||
lv_obj_t *update_firmware_version_label = lv_label_create( update_version_cont, NULL);
|
||||
lv_obj_add_style( update_firmware_version_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( update_firmware_version_label, __FIRMWARE__ );
|
||||
lv_obj_align( update_firmware_version_label, update_version_cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0 );
|
||||
|
||||
update_btn = lv_btn_create( update_settings_tile, NULL);
|
||||
lv_obj_set_event_cb( update_btn, update_event_handler );
|
||||
lv_obj_align( update_btn, NULL, LV_ALIGN_CENTER, 0, 40);
|
||||
lv_obj_t *update_btn_label = lv_label_create( update_btn, NULL );
|
||||
lv_label_set_text( update_btn_label, "update");
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
static void exit_update_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( SETUP_TILE, LV_ANIM_OFF );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void update_event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||
if(event == LV_EVENT_CLICKED) {
|
||||
update_update_firmware();
|
||||
}
|
||||
}
|
||||
|
||||
void update_update_firmware( void ) {
|
||||
if((WiFi.status() == WL_CONNECTED)) {
|
||||
|
||||
WiFiClientSecure client;
|
||||
client.setTimeout(12000 / 1000);
|
||||
|
||||
t_httpUpdate_return ret = httpUpdate.update( client, "https://www.neo-guerillaz.de/ttgo-t-watch2020_v1.ino.bin" );
|
||||
|
||||
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 );
|
||||
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;
|
||||
|
||||
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 );
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
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 );
|
||||
}
|
||||
}
|
||||
11
src/gui/mainbar/setup_tile/update/update.h
Normal file
11
src/gui/mainbar/setup_tile/update/update.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _UPDATE_H
|
||||
#define _UPDATE_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
#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_update_firmware( void );
|
||||
|
||||
#endif // _UPDATE_H
|
||||
@@ -36,7 +36,7 @@ void splash_screen_stage_one( TTGOClass *ttgo ) {
|
||||
|
||||
for( int bl = 0 ; bl < display_get_brightness() ; bl++ ) {
|
||||
ttgo->bl->adjust( bl );
|
||||
delay(1);
|
||||
delay(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -291,15 +291,20 @@ void statusbar_event( lv_obj_t * statusbar, lv_event_t event ) {
|
||||
*/
|
||||
void statusbar_update_stepcounter( int step ) {
|
||||
char stepcounter[12]="";
|
||||
snprintf( stepcounter, sizeof( stepcounter ), "%d%", step );
|
||||
snprintf( stepcounter, sizeof( stepcounter ), "%d", step );
|
||||
lv_label_set_text( statusbar_stepcounterlabel, (const char *)stepcounter );
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_update_battery( uint32_t percent, bool charging, bool plug ) {
|
||||
void statusbar_update_battery( int32_t percent, bool charging, bool plug ) {
|
||||
char level[8]="";
|
||||
snprintf( level, sizeof( level ), "%d%%", percent );
|
||||
if ( percent >= 0 ) {
|
||||
snprintf( level, sizeof( level ), "%d%%", percent );
|
||||
}
|
||||
else {
|
||||
snprintf( level, sizeof( level ), "?" );
|
||||
}
|
||||
lv_label_set_text( statusicon[ STATUSBAR_BATTERY_PERCENT ].icon, (const char *)level );
|
||||
|
||||
if ( charging && plug ) {
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
void statusbar_style_icon( statusbar_icon_t icon, statusbar_style_t style );
|
||||
void statusbar_refresh( void );
|
||||
void statusbar_update_stepcounter( int step );
|
||||
void statusbar_update_battery( uint32_t percent, bool charging, bool plug );
|
||||
void statusbar_update_battery( int32_t percent, bool charging, bool plug );
|
||||
void statusbar_wifi_set_state( bool state, const char *wifiname );
|
||||
void statusbar_bluetooth_set_state( bool state );
|
||||
|
||||
|
||||
4
src/gui/widget/weather/weather.cpp
Normal file
4
src/gui/widget/weather/weather.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#include "config.h"
|
||||
#include "weather.h"
|
||||
|
||||
void wetaher_widget_setup( void );
|
||||
6
src/gui/widget/weather/weather.h
Normal file
6
src/gui/widget/weather/weather.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _WEATHER_H
|
||||
#define _WEATHER_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
#endif // _WEATHER_H
|
||||
Reference in New Issue
Block a user