some updates and fixes

This commit is contained in:
sharandac
2020-08-19 10:30:11 +02:00
parent 925069d6ea
commit d04544703f
12 changed files with 128 additions and 44 deletions

View File

@@ -32,6 +32,6 @@
/*
* firmeware version string
*/
#define __FIRMWARE__ "2020081803"
#define __FIRMWARE__ "2020081902"
#endif // _CONFIG_H

View File

@@ -103,6 +103,7 @@ void bluetooth_call_msg_pharse( char* msg ) {
log_e("bluetooth call deserializeJson() failed: %s", error.c_str() );
}
else {
if ( doc["t"] && doc["cmd"] ) {
if( !strcmp( doc["t"], "call" ) && !strcmp( doc["cmd"], "accept" ) ) {
statusbar_hide( true );
if ( powermgm_get_event( POWERMGM_STANDBY ) ) {
@@ -124,7 +125,9 @@ void bluetooth_call_msg_pharse( char* msg ) {
lv_obj_invalidate( lv_scr_act() );
motor_vibe(100);
}
}
if ( doc["t"] && doc["cmd"] ) {
if( !strcmp( doc["t"], "call" ) && !strcmp( doc["cmd"], "start" ) ) {
if ( standby == true ) {
powermgm_set_event( POWERMGM_STANDBY_REQUEST );
@@ -133,5 +136,6 @@ void bluetooth_call_msg_pharse( char* msg ) {
lv_obj_invalidate( lv_scr_act() );
}
}
}
doc.clear();
}

View File

@@ -143,8 +143,12 @@ void bluetooth_message_msg_pharse( char* msg ) {
lv_img_set_src( bluetooth_message_img, &message_32px );
}
if ( doc["body"] )
lv_label_set_text( bluetooth_message_msg_label, doc["body"] );
else
lv_label_set_text( bluetooth_message_msg_label, "" );
if ( doc["title"] )
lv_label_set_text( bluetooth_message_sender_label, doc["title"] );

View File

@@ -209,7 +209,7 @@ void update_Task( void * pvParameters ) {
log_i("start update task");
if ( xEventGroupGetBits( update_event_handle) & UPDATE_GET_VERSION_REQUEST ) {
int64_t firmware_version = update_check_new_version();
int64_t firmware_version = update_check_new_version( update_setup_get_url() );
if ( firmware_version > atol( __FIRMWARE__ ) && firmware_version > 0 ) {
char version_msg[48] = "";
snprintf( version_msg, sizeof( version_msg ), "new version: %lld", firmware_version );
@@ -224,7 +224,7 @@ void update_Task( void * pvParameters ) {
}
lv_obj_invalidate( lv_scr_act() );
}
if ( xEventGroupGetBits( update_event_handle) & UPDATE_REQUEST ) {
if ( ( xEventGroupGetBits( update_event_handle) & UPDATE_REQUEST ) && ( update_get_url() != NULL ) ) {
if( WiFi.status() == WL_CONNECTED ) {
uint32_t display_timeout = display_get_timeout();
@@ -237,7 +237,7 @@ void update_Task( void * pvParameters ) {
httpUpdate.rebootOnUpdate( false );
t_httpUpdate_return ret = httpUpdate.update( client, "http://www.neo-guerillaz.de/ttgo-t-watch2020_v1.ino.bin" );
t_httpUpdate_return ret = httpUpdate.update( client, update_get_url() );
switch(ret) {
case HTTP_UPDATE_FAILED:

View File

@@ -27,8 +27,6 @@
#define UPDATE_REQUEST _BV(0)
#define UPDATE_GET_VERSION_REQUEST _BV(1)
#define FIRMWARE_LOCATION "https://github.com/sharandac/My-TTGO-Watch/blob/master/ttgo-t-watch2020_v1.ino.bin"
void update_tile_setup( void );
void update_check_version( void );
void update_update_firmware( void );

View File

@@ -23,15 +23,15 @@
#include "HTTPClient.h"
#include "update_check_version.h"
#include "hardware/json_psram_allocator.h"
uint64_t update_check_new_version( void ) {
char url[512]="";
int httpcode = -1;
uint64_t version = -1;
char *firmwarehost = NULL;
char *firmwarefile = NULL;
char* firmwareurl = NULL;
int64_t firmwareversion = -1;
snprintf( url, sizeof( url ), "http://%s/%s", FIRMWARE_HOST, FIRMWARE_VERSION_FILE );
int64_t update_check_new_version( char *url ) {
int httpcode = -1;
HTTPClient check_update_client;
@@ -58,8 +58,77 @@ uint64_t update_check_new_version( void ) {
check_update_client.end();
version = atoll( doc["version"] );
if ( doc["host"] ) {
if ( firmwarehost == NULL ) {
firmwarehost = (char*)ps_calloc( strlen( doc["host"] ) + 1, 1 );
if ( firmwarehost == NULL ) {
log_e("ps_calloc error");
while(true);
}
}
else {
char * tmp_firmwarehost = (char*)ps_realloc( firmwarehost, strlen( doc["host"] ) + 1 );
if ( tmp_firmwarehost == NULL ) {
log_e("ps_realloc error");
while(true);
}
firmwarehost = tmp_firmwarehost;
}
strcpy( firmwarehost, doc["host"] );
log_i("firmwarehost: %s", firmwarehost );
}
if ( doc["file"] ) {
if ( firmwarefile == NULL ) {
firmwarefile = (char*)ps_calloc( strlen( doc["file"] ) + 1, 1 );
if ( firmwarefile == NULL ) {
log_e("ps_calloc error");
while(true);
}
}
else {
char * tmp_firmwarefile = (char*)ps_realloc( firmwarefile, strlen( doc["file"] ) + 1 );
if ( tmp_firmwarefile == NULL ) {
log_e("ps_realloc error");
while(true);
}
firmwarefile = tmp_firmwarefile;
}
strcpy( firmwarefile, doc["file"] );
log_i("firmwarefile: %s", firmwarefile );
}
if ( firmwarehost != NULL && firmwarefile != NULL ) {
if ( firmwareurl == NULL ) {
firmwareurl = (char*)ps_calloc( strlen( firmwarehost ) + strlen( firmwarefile ) + 5, 1 );
if ( firmwareurl == NULL ) {
log_e("ps_calloc error");
while(true);
}
}
else {
char * tmp_firmwareurl = (char*)ps_realloc( firmwareurl, strlen( firmwarehost ) + strlen( firmwarefile ) + 5 );
if ( tmp_firmwareurl == NULL ) {
log_e("ps_realloc error");
while(true);
}
firmwareurl = tmp_firmwareurl;
}
snprintf( firmwareurl, strlen( firmwarehost ) + strlen( firmwarefile ) + 5, "%s/%s", firmwarehost, firmwarefile );
log_i("firmwareurl: %s", firmwareurl );
}
if ( doc["version"] ) {
firmwareversion = atoll( doc["version"] );
}
doc.clear();
return( version );
return( firmwareversion );
}
const char* update_get_url( void ) {
if ( firmwareversion > 0 ) {
return( (const char*)firmwareurl );
}
return( NULL );
}

View File

@@ -24,12 +24,9 @@
#include <TTGO.h>
#define FIRMWARE_HOST "www.neo-guerillaz.de"
#define FIRMWARE_HOST_PORT 80
#define FIRMWARE_VERSION_FILE "ttgo-t-watch2020_v1.version.json"
#define UPDATE_JSON_BUFFER_SIZE 200
uint64_t update_check_new_version();
int64_t update_check_new_version( char *url );
const char* update_get_url( void );
#endif // _UPDATE_CHECK_VERSION_H

View File

@@ -128,6 +128,7 @@ void update_save_config( void ) {
SpiRamJsonDocument doc( 1000 );
doc["autosync"] = update_config.autosync;
doc["updateurl"] = update_config.updateurl;
if ( serializeJsonPretty( doc, file ) == 0) {
log_e("Failed to write config file");
@@ -153,6 +154,7 @@ void update_read_config( void ) {
}
else {
update_config.autosync = doc["autosync"].as<bool>();
strlcpy( update_config.updateurl, doc["updateurl"] | FIRMWARE_UPDATE_URL, sizeof( update_config.updateurl ) );
}
doc.clear();
}
@@ -184,3 +186,7 @@ void update_read_config( void ) {
bool update_setup_get_autosync( void ) {
return( update_config.autosync );
}
char* update_setup_get_url( void ) {
return( update_config.updateurl );
}

View File

@@ -27,11 +27,15 @@
#define UPDATE_CONFIG_FILE "/update.cfg"
#define UPDATE_JSON_CONFIG_FILE "/update.json"
#define FIRMWARE_UPDATE_URL "http://www.neo-guerillaz.de/ttgo-t-watch2020_v1.version.json"
typedef struct {
bool autosync = true;
char updateurl[512] = FIRMWARE_UPDATE_URL;
} update_config_t;
void update_setup_tile_setup( uint32_t tile_num );
bool update_setup_get_autosync( void );
char* update_setup_get_url( void );
#endif // _UPDATE_SETUP_H

View File

@@ -26,6 +26,8 @@
#include <esp_wifi.h>
#include <time.h>
#include "driver/adc.h"
#include "esp_pm.h"
#include "pmu.h"
#include "bma.h"

Binary file not shown.

View File

@@ -1 +1 @@
{"version":"2020081803","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}
{"version":"2020081902","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}