add activate/hibernate callback for tile jumps
This commit is contained in:
@@ -32,6 +32,6 @@
|
||||
/*
|
||||
* firmeware version string
|
||||
*/
|
||||
#define __FIRMWARE__ "2020081301"
|
||||
#define __FIRMWARE__ "2020081304"
|
||||
|
||||
#endif // _CONFIG_H
|
||||
|
||||
1399
src/gui/font/Ubuntu_32px.c
Normal file
1399
src/gui/font/Ubuntu_32px.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -42,8 +42,9 @@ lv_widget_entry_t widget_entry[ MAX_WIDGET_NUM ];
|
||||
LV_FONT_DECLARE(Ubuntu_72px);
|
||||
LV_FONT_DECLARE(Ubuntu_16px);
|
||||
|
||||
lv_task_t * task;
|
||||
void main_tile_task( lv_task_t * task );
|
||||
lv_task_t * main_tile_task;
|
||||
|
||||
void main_tile_update_task( lv_task_t * task );
|
||||
void main_tile_align_widgets( void );
|
||||
|
||||
void main_tile_setup( void ) {
|
||||
@@ -96,7 +97,7 @@ void main_tile_setup( void ) {
|
||||
lv_obj_set_hidden( widget_entry[ widget ].widget, true );
|
||||
}
|
||||
|
||||
task = lv_task_create( main_tile_task, 1000, LV_TASK_PRIO_MID, NULL );
|
||||
main_tile_task = lv_task_create( main_tile_update_task, 500, LV_TASK_PRIO_MID, NULL );
|
||||
}
|
||||
|
||||
lv_obj_t *main_tile_register_widget( void ) {
|
||||
@@ -137,20 +138,35 @@ uint32_t main_tile_get_tile_num( void ) {
|
||||
return( main_tile_num );
|
||||
}
|
||||
|
||||
|
||||
void main_tile_task( lv_task_t * task ) {
|
||||
void main_tile_update_task( lv_task_t * task ) {
|
||||
time_t now;
|
||||
struct tm info;
|
||||
char buf[64];
|
||||
char time_str[64]="";
|
||||
static char *old_time_str = NULL;
|
||||
|
||||
// on first run, alloc psram
|
||||
if ( old_time_str == NULL ) {
|
||||
old_time_str = (char *)ps_calloc( sizeof( time_str), 1 );
|
||||
if ( old_time_str == NULL ) {
|
||||
log_e("old_time_str allocation failed");
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
time( &now );
|
||||
localtime_r( &now, &info );
|
||||
|
||||
strftime( buf, sizeof(buf), "%H:%M", &info );
|
||||
lv_label_set_text( timelabel, buf );
|
||||
lv_obj_align( timelabel, clock_cont, LV_ALIGN_CENTER, 0, 0 );
|
||||
strftime( time_str, sizeof(time_str), "%H:%M", &info );
|
||||
|
||||
strftime( buf, sizeof(buf), "%a %d.%b %Y", &info );
|
||||
lv_label_set_text( datelabel, buf );
|
||||
// only update while time_str changes
|
||||
if ( strcmp( time_str, old_time_str ) ) {
|
||||
log_i("renew time_str: %s != %s", time_str, old_time_str );
|
||||
lv_label_set_text( timelabel, time_str );
|
||||
lv_obj_align( timelabel, clock_cont, LV_ALIGN_CENTER, 0, 0 );
|
||||
strlcpy( old_time_str, time_str, sizeof( time_str ) );
|
||||
|
||||
strftime( time_str, sizeof(time_str), "%a %d.%b %Y", &info );
|
||||
lv_label_set_text( datelabel, time_str );
|
||||
lv_obj_align( datelabel, clock_cont, LV_ALIGN_IN_BOTTOM_MID, 0, 0 );
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ static lv_obj_t *mainbar = NULL;
|
||||
|
||||
static lv_tile_t *tile = NULL;
|
||||
static lv_point_t *tile_pos_table = NULL;
|
||||
static uint32_t current_tile = 0;
|
||||
static uint32_t tile_entrys = 0;
|
||||
static uint32_t app_tile_pos = MAINBAR_APP_TILE_X_START;
|
||||
|
||||
@@ -110,6 +111,8 @@ uint32_t mainbar_add_tile( uint16_t x, uint16_t y ) {
|
||||
|
||||
lv_obj_t *my_tile = lv_cont_create( mainbar, NULL);
|
||||
tile[ tile_entrys - 1 ].tile = my_tile;
|
||||
tile[ tile_entrys - 1 ].activate_cb = NULL;
|
||||
tile[ tile_entrys - 1 ].hibernate_cb = NULL;
|
||||
lv_obj_set_size( tile[ tile_entrys - 1 ].tile, LV_HOR_RES, LV_VER_RES);
|
||||
//lv_obj_reset_style_list( tile[ tile_entrys - 1 ].tile, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( tile[ tile_entrys - 1 ].tile, LV_OBJ_PART_MAIN, &mainbar_style );
|
||||
@@ -133,6 +136,28 @@ lv_style_t *mainbar_get_slider_style( void ) {
|
||||
return( &mainbar_slider_style );
|
||||
}
|
||||
|
||||
bool mainbar_add_tile_hibernate_cb( uint32_t tile_number, MAINBAR_CALLBACK_FUNC hibernate_cb ) {
|
||||
if ( tile_number < tile_entrys ) {
|
||||
tile[ tile_number ].hibernate_cb = hibernate_cb;
|
||||
return( true );
|
||||
}
|
||||
else {
|
||||
log_e("tile number %d do not exist", tile_number );
|
||||
return( false );
|
||||
}
|
||||
}
|
||||
|
||||
bool mainbar_add_tile_activate_cb( uint32_t tile_number, MAINBAR_CALLBACK_FUNC activate_cb ) {
|
||||
if ( tile_number < tile_entrys ) {
|
||||
tile[ tile_number ].activate_cb = activate_cb;
|
||||
return( true );
|
||||
}
|
||||
else {
|
||||
log_e("tile number %d do not exist", tile_number );
|
||||
return( false );
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t mainbar_add_app_tile( uint16_t x, uint16_t y ) {
|
||||
uint32_t retval = -1;
|
||||
|
||||
@@ -163,7 +188,7 @@ lv_obj_t *mainbar_get_tile_obj( uint32_t tile_number ) {
|
||||
void mainbar_jump_to_maintile( lv_anim_enable_t anim ) {
|
||||
statusbar_hide( false );
|
||||
if ( tile_entrys != 0 ) {
|
||||
lv_tileview_set_tile_act( mainbar, 0, 0, anim );
|
||||
mainbar_jump_to_tilenumber( 0, anim );
|
||||
}
|
||||
else {
|
||||
log_e( "main tile do not exist" );
|
||||
@@ -172,7 +197,19 @@ void mainbar_jump_to_maintile( lv_anim_enable_t anim ) {
|
||||
|
||||
void mainbar_jump_to_tilenumber( uint32_t tile_number, lv_anim_enable_t anim ) {
|
||||
if ( tile_number < tile_entrys ) {
|
||||
log_i("jump to tile %d from tile %d", tile_number, current_tile );
|
||||
lv_tileview_set_tile_act( mainbar, tile_pos_table[ tile_number ].x, tile_pos_table[ tile_number ].y, anim );
|
||||
// call hibernate callback for the current tile if exist
|
||||
if ( tile[ current_tile ].hibernate_cb != NULL ) {
|
||||
log_i("call hibernate cb for tile: %d", current_tile );
|
||||
tile[ current_tile ].hibernate_cb();
|
||||
}
|
||||
// call activate callback for the new tile if exist
|
||||
if ( tile[ tile_number ].activate_cb != NULL ) {
|
||||
log_i("call activate cb for tile: %d", tile_number );
|
||||
tile[ tile_number ].activate_cb();
|
||||
}
|
||||
current_tile = tile_number;
|
||||
}
|
||||
else {
|
||||
log_e( "tile number %d do not exist", tile_number );
|
||||
|
||||
@@ -24,8 +24,12 @@
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
typedef void ( * MAINBAR_CALLBACK_FUNC ) ( void );
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t *tile;
|
||||
MAINBAR_CALLBACK_FUNC activate_cb;
|
||||
MAINBAR_CALLBACK_FUNC hibernate_cb;
|
||||
} lv_tile_t;
|
||||
|
||||
#define MAINBAR_APP_TILE_X_START 0
|
||||
@@ -88,6 +92,24 @@
|
||||
* @return lv_obj_t
|
||||
*/
|
||||
lv_obj_t * mainbar_get_tile_obj( uint32_t tile_number );
|
||||
/*
|
||||
* @brief register an hibernate callback function when leave the tile
|
||||
*
|
||||
* @param tile_number tile number
|
||||
* @param hibernate_cb pointer to the hibernate callback function
|
||||
*
|
||||
* @return true or false true means registration was success
|
||||
*/
|
||||
bool mainbar_add_tile_hibernate_cb( uint32_t tile_number, MAINBAR_CALLBACK_FUNC hibernate_cb );
|
||||
/*
|
||||
* @brief register an activate callback function when enter the tile
|
||||
*
|
||||
* @param tile_number tile number
|
||||
* @param activate_cb pointer to the activate callback function
|
||||
*
|
||||
* @return true or false true means registration was success
|
||||
*/
|
||||
bool mainbar_add_tile_activate_cb( uint32_t tile_number, MAINBAR_CALLBACK_FUNC activate_cb );
|
||||
/*
|
||||
* @brief get main tile style
|
||||
*
|
||||
|
||||
@@ -48,6 +48,8 @@ static void enter_battery_settings_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void enter_battery_view_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void exit_battery_view_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
void battery_view_update_task( lv_task_t *task );
|
||||
void battery_activate_cb( void );
|
||||
void battery_hibernate_cb( void );
|
||||
|
||||
void battery_view_tile_setup( uint32_t tile_num ) {
|
||||
// get an app tile and copy mainstyle
|
||||
@@ -163,9 +165,20 @@ void battery_view_tile_setup( uint32_t tile_num ) {
|
||||
lv_label_set_text( vbus_view_voltage, "2.4mV");
|
||||
lv_obj_align( vbus_view_voltage, vbus_voltage_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
|
||||
mainbar_add_tile_activate_cb( battery_view_tile_num, battery_activate_cb );
|
||||
mainbar_add_tile_activate_cb( battery_view_tile_num + 1, battery_activate_cb );
|
||||
mainbar_add_tile_hibernate_cb( battery_view_tile_num, battery_hibernate_cb );
|
||||
mainbar_add_tile_hibernate_cb( battery_view_tile_num + 1, battery_hibernate_cb );
|
||||
}
|
||||
|
||||
void battery_activate_cb( void ) {
|
||||
battery_view_task = lv_task_create(battery_view_update_task, 1000, LV_TASK_PRIO_LOWEST, NULL );
|
||||
}
|
||||
|
||||
void battery_hibernate_cb( void ) {
|
||||
lv_task_del( battery_view_task );
|
||||
}
|
||||
|
||||
static void enter_battery_view_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( battery_view_tile_num, LV_ANIM_OFF );
|
||||
|
||||
@@ -32,7 +32,6 @@ void screenshot_setup( void ) {
|
||||
log_e("error memory alloc");
|
||||
while(1);
|
||||
}
|
||||
SPIFFS.remove( SCREENSHOT_FILE_NAME );
|
||||
}
|
||||
|
||||
void screenshot_take( void ) {
|
||||
|
||||
@@ -173,7 +173,7 @@ void wifictl_setup( void ) {
|
||||
|
||||
xTaskCreate( wifictl_Task, /* Function to implement the task */
|
||||
"wifictl Task", /* Name of the task */
|
||||
5000, /* Stack size in words */
|
||||
2000, /* Stack size in words */
|
||||
NULL, /* Task input parameter */
|
||||
1, /* Priority of the task */
|
||||
&_wifictl_Task ); /* Task handle. */
|
||||
@@ -438,11 +438,6 @@ void wifictl_start_wps( void ) {
|
||||
WiFi.mode( WIFI_OFF );
|
||||
esp_wifi_stop();
|
||||
|
||||
statusbar_style_icon( STATUSBAR_WIFI, STATUSBAR_STYLE_GRAY );
|
||||
statusbar_show_icon( STATUSBAR_WIFI );
|
||||
statusbar_wifi_set_state( true, "wait for WPS" );
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
|
||||
powermgm_set_event( POWERMGM_WIFI_WPS_REQUEST );
|
||||
|
||||
ESP_ERROR_CHECK( esp_wifi_set_mode( WIFI_MODE_STA ) );
|
||||
@@ -466,15 +461,11 @@ void wifictl_Task( void * pvParameters ) {
|
||||
}
|
||||
|
||||
if ( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST ) ) {
|
||||
statusbar_wifi_set_state( false, "" );
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
WiFi.mode( WIFI_OFF );
|
||||
esp_wifi_stop();
|
||||
log_i("request wifictl off done");
|
||||
}
|
||||
else if ( powermgm_get_event( POWERMGM_WIFI_ON_REQUEST ) ) {
|
||||
statusbar_wifi_set_state( true, "activate" );
|
||||
lv_obj_invalidate( lv_scr_act() );
|
||||
WiFi.mode( WIFI_STA );
|
||||
log_i("request wifictl on done");
|
||||
}
|
||||
|
||||
@@ -85,12 +85,12 @@ void setup()
|
||||
*/
|
||||
|
||||
wifictl_on();
|
||||
// enable to store data in normal heap
|
||||
heap_caps_malloc_extmem_enable( 16*1024 );
|
||||
|
||||
splash_screen_stage_finish( ttgo );
|
||||
display_set_brightness( display_get_brightness() );
|
||||
|
||||
// enable to store data in normal heap
|
||||
heap_caps_malloc_extmem_enable( 16*1024 );
|
||||
blectl_setup();
|
||||
|
||||
Serial.printf("Total heap: %d\r\n", ESP.getHeapSize());
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
{"version":"2020081301","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}
|
||||
{"version":"2020081304","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}
|
||||
|
||||
Reference in New Issue
Block a user