add timesync and timezone setup
This commit is contained in:
BIN
data/tile_map.ods
Normal file
BIN
data/tile_map.ods
Normal file
Binary file not shown.
@@ -5,6 +5,7 @@
|
||||
#include "../mainbar.h"
|
||||
#include "main_tile.h"
|
||||
|
||||
static lv_obj_t *clock_cont = NULL;
|
||||
static lv_obj_t *timelabel = NULL;
|
||||
static lv_obj_t *datelabel = NULL;
|
||||
|
||||
@@ -24,14 +25,18 @@ void main_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coo
|
||||
lv_style_copy( &datestyle, style);
|
||||
lv_style_set_text_font( &datestyle, LV_STATE_DEFAULT, &Ubuntu_16px);
|
||||
|
||||
/*Tile1: just a label*/
|
||||
timelabel = lv_label_create(tile, NULL);
|
||||
clock_cont = lv_obj_create( tile, NULL );
|
||||
lv_obj_set_size( clock_cont, hres , hres/2 );
|
||||
lv_obj_add_style( clock_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( clock_cont, tile, LV_ALIGN_CENTER, 0, 0 );
|
||||
|
||||
timelabel = lv_label_create( clock_cont , NULL);
|
||||
lv_label_set_text(timelabel, "00:00");
|
||||
lv_obj_reset_style_list( timelabel, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( timelabel, LV_OBJ_PART_MAIN, ×tyle );
|
||||
lv_obj_align(timelabel, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
datelabel = lv_label_create(tile, NULL);
|
||||
datelabel = lv_label_create( clock_cont , NULL);
|
||||
lv_label_set_text(datelabel, "1.Jan 1970");
|
||||
lv_obj_reset_style_list( datelabel, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( datelabel, LV_OBJ_PART_MAIN, &datestyle );
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "setup_tile/wlan_settings/wlan_settings.h"
|
||||
#include "setup_tile/move_settings/move_settings.h"
|
||||
#include "setup_tile/display_settings/display_settings.h"
|
||||
#include "setup_tile/time_settings/time_settings.h"
|
||||
|
||||
static lv_style_t mainbarstyle;
|
||||
static lv_obj_t *mainbar = NULL;
|
||||
@@ -22,11 +23,12 @@ lv_tile_entry_t tile_entry[ TILE_NUM ] {
|
||||
{ NULL, APP_TILE, app_tile_setup, { 1 , 0 } },
|
||||
{ NULL, NOTE_TILE, note_tile_setup, { 0 , 1 } },
|
||||
{ NULL, SETUP_TILE, setup_tile_setup, { 1 , 1 } },
|
||||
{ NULL, WLAN_SETTINGS_TILE, wlan_settings_tile_setup, { 1,3 } },
|
||||
{ NULL, WLAN_PASSWORD_TILE, wlan_password_tile_setup, { 2,3 } },
|
||||
{ NULL, MOVE_SETTINGS_TILE, move_settings_tile_setup, { 3,3 } },
|
||||
{ NULL, DISPLAY_SETTINGS_TILE, display_settings_tile_setup, { 5,3 } },
|
||||
{ NULL, BATTERY_SETTINGS_TILE, battery_settings_tile_setup, { 7,3 } }
|
||||
{ NULL, WLAN_SETTINGS_TILE, wlan_settings_tile_setup, { 0,4 } },
|
||||
{ NULL, WLAN_PASSWORD_TILE, wlan_password_tile_setup, { 0,5 } },
|
||||
{ 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 } }
|
||||
};
|
||||
|
||||
void mainbar_setup( void ) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
MOVE_SETTINGS_TILE,
|
||||
DISPLAY_SETTINGS_TILE,
|
||||
BATTERY_SETTINGS_TILE,
|
||||
TIME_SETTINGS_TILE,
|
||||
TILE_NUM
|
||||
} lv_tile_number;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "gui/statusbar.h"
|
||||
#include "hardware/pmu.h"
|
||||
|
||||
lv_obj_t *battery_settings_tile1=NULL;
|
||||
lv_obj_t *battery_settings_tile=NULL;
|
||||
lv_style_t battery_settings_style;
|
||||
|
||||
lv_obj_t *battery_design_cap;
|
||||
@@ -30,29 +30,29 @@ void battery_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t
|
||||
lv_style_set_text_color( &battery_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
lv_style_set_image_recolor( &battery_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
|
||||
battery_settings_tile1 = lv_obj_create( tile, NULL);
|
||||
lv_obj_set_size(battery_settings_tile1, hres , vres);
|
||||
lv_obj_align(battery_settings_tile1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_style( battery_settings_tile1, LV_OBJ_PART_MAIN, &battery_settings_style );
|
||||
battery_settings_tile = lv_obj_create( tile, NULL);
|
||||
lv_obj_set_size(battery_settings_tile, hres , vres);
|
||||
lv_obj_align(battery_settings_tile, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_style( battery_settings_tile, LV_OBJ_PART_MAIN, &battery_settings_style );
|
||||
|
||||
lv_obj_t *exit_btn = lv_imgbtn_create( battery_settings_tile1, NULL);
|
||||
lv_obj_t *exit_btn = lv_imgbtn_create( battery_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, battery_settings_tile1, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_align( exit_btn, battery_settings_tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_set_event_cb( exit_btn, exit_battery_setup_event_cb );
|
||||
|
||||
lv_obj_t *exit_label = lv_label_create( battery_settings_tile1, NULL);
|
||||
lv_obj_t *exit_label = lv_label_create( battery_settings_tile, NULL);
|
||||
lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( exit_label, "battery");
|
||||
lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *battery_design_cont = lv_obj_create( battery_settings_tile1, NULL );
|
||||
lv_obj_t *battery_design_cont = lv_obj_create( battery_settings_tile, NULL );
|
||||
lv_obj_set_size( battery_design_cont, hres , 25 );
|
||||
lv_obj_add_style( battery_design_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( battery_design_cont, battery_settings_tile1, LV_ALIGN_IN_TOP_RIGHT, 0, 75 );
|
||||
lv_obj_align( battery_design_cont, battery_settings_tile, LV_ALIGN_IN_TOP_RIGHT, 0, 75 );
|
||||
lv_obj_t *battery_design_cap_label = lv_label_create( battery_design_cont, NULL);
|
||||
lv_obj_add_style( battery_design_cap_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( battery_design_cap_label, "designed cap");
|
||||
@@ -62,7 +62,7 @@ void battery_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t
|
||||
lv_label_set_text( battery_design_cap, "380mAh");
|
||||
lv_obj_align( battery_design_cap, battery_design_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
|
||||
lv_obj_t *battery_current_cont = lv_obj_create( battery_settings_tile1, NULL );
|
||||
lv_obj_t *battery_current_cont = lv_obj_create( battery_settings_tile, NULL );
|
||||
lv_obj_set_size( battery_current_cont, hres , 25 );
|
||||
lv_obj_add_style( battery_current_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( battery_current_cont, battery_design_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
@@ -75,7 +75,7 @@ void battery_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t
|
||||
lv_label_set_text( battery_current_cap, "380mAh");
|
||||
lv_obj_align( battery_current_cap, battery_current_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
|
||||
lv_obj_t *battery_voltage_cont = lv_obj_create( battery_settings_tile1, NULL );
|
||||
lv_obj_t *battery_voltage_cont = lv_obj_create( battery_settings_tile, NULL );
|
||||
lv_obj_set_size( battery_voltage_cont, hres , 25 );
|
||||
lv_obj_add_style( battery_voltage_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( battery_voltage_cont, battery_current_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
@@ -88,7 +88,7 @@ void battery_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t
|
||||
lv_label_set_text( battery_voltage, "2.4mV");
|
||||
lv_obj_align( battery_voltage, battery_voltage_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
|
||||
lv_obj_t *battery_charge_cont = lv_obj_create( battery_settings_tile1, NULL );
|
||||
lv_obj_t *battery_charge_cont = lv_obj_create( battery_settings_tile, NULL );
|
||||
lv_obj_set_size( battery_charge_cont, hres , 25 );
|
||||
lv_obj_add_style( battery_charge_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( battery_charge_cont, battery_voltage_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 5 );
|
||||
@@ -101,7 +101,7 @@ void battery_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t
|
||||
lv_label_set_text( charge_current, "100mA");
|
||||
lv_obj_align( charge_current, battery_charge_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
|
||||
lv_obj_t *battery_discharge_cont = lv_obj_create( battery_settings_tile1, NULL );
|
||||
lv_obj_t *battery_discharge_cont = lv_obj_create( battery_settings_tile, NULL );
|
||||
lv_obj_set_size( battery_discharge_cont, hres , 25 );
|
||||
lv_obj_add_style( battery_discharge_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( battery_discharge_cont, battery_charge_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
@@ -114,7 +114,7 @@ void battery_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t
|
||||
lv_label_set_text( discharge_current, "100mA");
|
||||
lv_obj_align( discharge_current, battery_discharge_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
|
||||
lv_obj_t *vbus_voltage_cont = lv_obj_create( battery_settings_tile1, NULL );
|
||||
lv_obj_t *vbus_voltage_cont = lv_obj_create( battery_settings_tile, NULL );
|
||||
lv_obj_set_size( vbus_voltage_cont, hres , 25 );
|
||||
lv_obj_add_style( vbus_voltage_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( vbus_voltage_cont, battery_discharge_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
|
||||
@@ -7,11 +7,14 @@ static void wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
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 );
|
||||
|
||||
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);
|
||||
|
||||
|
||||
void setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
|
||||
@@ -21,7 +24,7 @@ void setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_co
|
||||
lv_imgbtn_set_src(wifi_setup, LV_BTN_STATE_CHECKED_RELEASED, &wifi_64px);
|
||||
lv_imgbtn_set_src(wifi_setup, LV_BTN_STATE_CHECKED_PRESSED, &wifi_64px);
|
||||
lv_obj_add_style(wifi_setup, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align(wifi_setup, tile, LV_ALIGN_IN_TOP_LEFT, 48, 48 );
|
||||
lv_obj_align(wifi_setup, tile, LV_ALIGN_IN_TOP_LEFT, 16, 48 );
|
||||
lv_obj_set_event_cb( wifi_setup, wifi_setup_event_cb );
|
||||
|
||||
lv_obj_t * battery_setup = lv_imgbtn_create(tile, NULL);
|
||||
@@ -30,7 +33,7 @@ void setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_co
|
||||
lv_imgbtn_set_src( battery_setup, LV_BTN_STATE_CHECKED_RELEASED, &battery_icon_64px);
|
||||
lv_imgbtn_set_src( battery_setup, LV_BTN_STATE_CHECKED_PRESSED, &battery_icon_64px);
|
||||
lv_obj_add_style( battery_setup, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align( battery_setup, tile, LV_ALIGN_IN_TOP_LEFT, 48+86, 48 );
|
||||
lv_obj_align( battery_setup, tile, LV_ALIGN_IN_TOP_LEFT, 16+70, 48 );
|
||||
lv_obj_set_event_cb( battery_setup, battery_setup_event_cb );
|
||||
|
||||
lv_obj_t * move_setup = lv_imgbtn_create(tile, NULL);
|
||||
@@ -39,7 +42,7 @@ void setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_co
|
||||
lv_imgbtn_set_src( move_setup, LV_BTN_STATE_CHECKED_RELEASED, &move_64px);
|
||||
lv_imgbtn_set_src( move_setup, LV_BTN_STATE_CHECKED_PRESSED, &move_64px);
|
||||
lv_obj_add_style( move_setup, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align( move_setup, tile, LV_ALIGN_IN_TOP_LEFT, 48, 48+86 );
|
||||
lv_obj_align( move_setup, tile, LV_ALIGN_IN_TOP_LEFT, 16, 48+86 );
|
||||
lv_obj_set_event_cb( move_setup, move_setup_event_cb );
|
||||
|
||||
lv_obj_t * brightness_setup = lv_imgbtn_create(tile, NULL);
|
||||
@@ -48,8 +51,17 @@ void setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_co
|
||||
lv_imgbtn_set_src( brightness_setup, LV_BTN_STATE_CHECKED_RELEASED, &brightness_64px);
|
||||
lv_imgbtn_set_src( brightness_setup, LV_BTN_STATE_CHECKED_PRESSED, &brightness_64px);
|
||||
lv_obj_add_style( brightness_setup, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align( brightness_setup, tile, LV_ALIGN_IN_TOP_LEFT, 48+86, 48+86 );
|
||||
lv_obj_align( brightness_setup, tile, LV_ALIGN_IN_TOP_LEFT, 16+70, 48+86 );
|
||||
lv_obj_set_event_cb( brightness_setup, display_setup_event_cb );
|
||||
|
||||
lv_obj_t * time_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src( time_setup, LV_BTN_STATE_RELEASED, &time_64px);
|
||||
lv_imgbtn_set_src( time_setup, LV_BTN_STATE_PRESSED, &time_64px);
|
||||
lv_imgbtn_set_src( time_setup, LV_BTN_STATE_CHECKED_RELEASED, &time_64px);
|
||||
lv_imgbtn_set_src( time_setup, LV_BTN_STATE_CHECKED_PRESSED, &time_64px);
|
||||
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 );
|
||||
}
|
||||
|
||||
static void wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
@@ -79,3 +91,10 @@ static void display_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void time_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( TIME_SETTINGS_TILE, LV_ANIM_OFF );
|
||||
break;
|
||||
}
|
||||
}
|
||||
107
src/gui/mainbar/setup_tile/time_settings/time_settings.cpp
Normal file
107
src/gui/mainbar/setup_tile/time_settings/time_settings.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "config.h"
|
||||
#include "time_settings.h"
|
||||
#include <WiFi.h>
|
||||
|
||||
#include "gui/mainbar/mainbar.h"
|
||||
#include "gui/statusbar.h"
|
||||
#include "hardware/timesync.h"
|
||||
|
||||
lv_obj_t *time_settings_tile=NULL;
|
||||
lv_style_t time_settings_style;
|
||||
lv_obj_t *utczone_list = NULL;
|
||||
lv_obj_t *wifisync_onoff = NULL;
|
||||
|
||||
LV_IMG_DECLARE(exit_32px);
|
||||
LV_IMG_DECLARE(time_32px);
|
||||
|
||||
static void exit_time_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void wifisync_onoff_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||
static void utczone_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||
|
||||
void time_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
lv_style_init( &time_settings_style );
|
||||
lv_style_set_radius( &time_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_bg_color( &time_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||
lv_style_set_bg_opa( &time_settings_style, LV_OBJ_PART_MAIN, LV_OPA_100);
|
||||
lv_style_set_border_width( &time_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_text_color( &time_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
lv_style_set_image_recolor( &time_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
|
||||
time_settings_tile = lv_obj_create( tile, NULL);
|
||||
lv_obj_set_size(time_settings_tile, hres , vres);
|
||||
lv_obj_align(time_settings_tile, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_style( time_settings_tile, LV_OBJ_PART_MAIN, &time_settings_style );
|
||||
|
||||
lv_obj_t *exit_btn = lv_imgbtn_create( time_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, time_settings_tile, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_set_event_cb( exit_btn, exit_time_setup_event_cb );
|
||||
|
||||
lv_obj_t *exit_label = lv_label_create( time_settings_tile, NULL);
|
||||
lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( exit_label, "time settings");
|
||||
lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *wifisync_cont = lv_obj_create( time_settings_tile, NULL );
|
||||
lv_obj_set_size(wifisync_cont, hres , 40);
|
||||
lv_obj_add_style( wifisync_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( wifisync_cont, time_settings_tile, LV_ALIGN_IN_TOP_RIGHT, 0, 75 );
|
||||
wifisync_onoff = lv_switch_create( wifisync_cont, NULL );
|
||||
lv_switch_off( wifisync_onoff, LV_ANIM_ON );
|
||||
lv_obj_align( wifisync_onoff, wifisync_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
lv_obj_set_event_cb( wifisync_onoff, wifisync_onoff_event_handler );
|
||||
lv_obj_t *wifisync_label = lv_label_create( wifisync_cont, NULL);
|
||||
lv_obj_add_style( wifisync_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( wifisync_label, "sync when connect");
|
||||
lv_obj_align( wifisync_label, wifisync_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *utczone_cont = lv_obj_create( time_settings_tile, NULL );
|
||||
lv_obj_set_size(utczone_cont, hres , 40);
|
||||
lv_obj_add_style( utczone_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( utczone_cont, wifisync_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
lv_obj_t *utczone_label = lv_label_create( utczone_cont, NULL);
|
||||
lv_obj_add_style( utczone_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( utczone_label, "utc timezone");
|
||||
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\n" );
|
||||
lv_obj_align(utczone_list, utczone_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0);
|
||||
lv_obj_set_event_cb(utczone_list, utczone_event_handler);
|
||||
|
||||
if ( timesync_get_timesync() )
|
||||
lv_switch_on( wifisync_onoff, LV_ANIM_OFF );
|
||||
else
|
||||
lv_switch_off( wifisync_onoff, LV_ANIM_OFF );
|
||||
|
||||
lv_dropdown_set_selected( utczone_list, timesync_get_timezone() + 12 );
|
||||
}
|
||||
|
||||
static void exit_time_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 wifisync_onoff_event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
if( lv_switch_get_state( obj ) ) {
|
||||
timesync_set_timesync( true );
|
||||
}
|
||||
else {
|
||||
timesync_set_timesync( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void utczone_event_handler(lv_obj_t * obj, lv_event_t event)
|
||||
{
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
timesync_set_timezone( lv_dropdown_get_selected( obj ) - 12 );
|
||||
printf("timezone: %d\n", lv_dropdown_get_selected( obj ) - 12 );
|
||||
}
|
||||
}
|
||||
16
src/gui/mainbar/setup_tile/time_settings/time_settings.h
Normal file
16
src/gui/mainbar/setup_tile/time_settings/time_settings.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _TIME_SETTINGS_H
|
||||
#define _TIME_SETTINGS_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
/*
|
||||
* @brief setup the display setup tile
|
||||
*
|
||||
* @param tile pointer to the tile obj
|
||||
* @param style pointer to the style obj
|
||||
* @param hres horizonal resolution
|
||||
* @param vres vertical resolution
|
||||
*/
|
||||
void time_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
|
||||
#endif // _TIME_SETTINGS_H
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
display_config_t display_config;
|
||||
|
||||
void display_read_config( void );
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@@ -27,10 +25,10 @@ void display_loop( TTGOClass *ttgo ) {
|
||||
*
|
||||
*/
|
||||
void display_save_config( void ) {
|
||||
fs::File file = SPIFFS.open( DISPLAY_COFIG_FILE, FILE_WRITE );
|
||||
fs::File file = SPIFFS.open( DISPLAY_CONFIG_FILE, FILE_WRITE );
|
||||
|
||||
if ( !file ) {
|
||||
Serial.printf("Can't save file: %s\r\n", DISPLAY_COFIG_FILE );
|
||||
Serial.printf("Can't save file: %s\r\n", DISPLAY_CONFIG_FILE );
|
||||
}
|
||||
else {
|
||||
file.write( (uint8_t *)&display_config, sizeof( display_config ) );
|
||||
@@ -42,10 +40,10 @@ void display_save_config( void ) {
|
||||
*
|
||||
*/
|
||||
void display_read_config( void ) {
|
||||
fs::File file = SPIFFS.open( DISPLAY_COFIG_FILE, FILE_READ );
|
||||
fs::File file = SPIFFS.open( DISPLAY_CONFIG_FILE, FILE_READ );
|
||||
|
||||
if (!file) {
|
||||
Serial.printf("Can't open file: %s!\r\n", DISPLAY_COFIG_FILE );
|
||||
Serial.printf("Can't open file: %s!\r\n", DISPLAY_CONFIG_FILE );
|
||||
}
|
||||
else {
|
||||
int filesize = file.size();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
uint32_t timeout = DISPLAY_MIN_TIMEOUT;
|
||||
} display_config_t;
|
||||
|
||||
#define DISPLAY_COFIG_FILE "/display.cfg"
|
||||
#define DISPLAY_CONFIG_FILE "/display.cfg"
|
||||
|
||||
/*
|
||||
* @brief setup display
|
||||
@@ -27,9 +27,13 @@
|
||||
*/
|
||||
void display_loop( TTGOClass *ttgo );
|
||||
/*
|
||||
* @brief save config for display to spiff
|
||||
* @brief save config for display to spiffs
|
||||
*/
|
||||
void display_save_config( void );
|
||||
/*
|
||||
* @brief read config for display from spiffs
|
||||
*/
|
||||
void display_read_config( void );
|
||||
/*
|
||||
* @brief read the timeout from config
|
||||
*
|
||||
|
||||
@@ -73,14 +73,17 @@ void pmu_loop( TTGOClass *ttgo ) {
|
||||
if ( xEventGroupGetBitsFromISR( pmu_event_handle ) & PMU_EVENT_AXP_INT ) {
|
||||
ttgo->power->readIRQ();
|
||||
if (ttgo->power->isVbusPlugInIRQ()) {
|
||||
powermgm_set_event( POWERMGM_PMU_BATTERY );
|
||||
motor_vibe( 1 );
|
||||
updatetrigger = true;
|
||||
}
|
||||
if (ttgo->power->isVbusRemoveIRQ()) {
|
||||
powermgm_set_event( POWERMGM_PMU_BATTERY );
|
||||
motor_vibe( 1 );
|
||||
updatetrigger = true;
|
||||
}
|
||||
if (ttgo->power->isChargingDoneIRQ()) {
|
||||
powermgm_set_event( POWERMGM_PMU_BATTERY );
|
||||
motor_vibe( 1 );
|
||||
updatetrigger = true;
|
||||
}
|
||||
@@ -107,7 +110,7 @@ uint32_t pmu_get_byttery_percent( TTGOClass *ttgo ) {
|
||||
if ( ttgo->power->getBattChargeCoulomb() < ttgo->power->getBattDischargeCoulomb() )
|
||||
ttgo->power->ClearCoulombcounter();
|
||||
|
||||
printf("Coulumb data: %0.1fmAh %0.1f%% (charge current: %0.1fmA, discharge current: %0.1fmA)\r",ttgo->power->getCoulombData(), (ttgo->power->getCoulombData()/380)*100, ttgo->power->getBattChargeCurrent(), ttgo->power->getBattDischargeCurrent() );
|
||||
// printf("Coulumb data: %0.1fmAh %0.1f%% (charge current: %0.1fmA, discharge current: %0.1fmA)\r",ttgo->power->getCoulombData(), (ttgo->power->getCoulombData()/380)*100, ttgo->power->getBattChargeCurrent(), ttgo->power->getBattDischargeCurrent() );
|
||||
|
||||
return( ( ttgo->power->getCoulombData() / PMU_BATTERY_CAP ) * 100 );
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "bma.h"
|
||||
#include "powermgm.h"
|
||||
#include "wifictl.h"
|
||||
#include "timesync.h"
|
||||
#include "motor.h"
|
||||
|
||||
EventGroupHandle_t powermgm_status = NULL;
|
||||
@@ -22,6 +23,7 @@ void powermgm_setup( TTGOClass *ttgo ) {
|
||||
pmu_setup( ttgo );
|
||||
bma_setup( ttgo );
|
||||
wifictl_setup();
|
||||
timesync_setup( ttgo );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -54,8 +56,11 @@ void powermgm_loop( TTGOClass *ttgo ) {
|
||||
if ( bma_get_config( BMA_STEPCOUNTER ) )
|
||||
ttgo->bma->enableStepCountInterrupt( false );
|
||||
powermgm_set_event( POWERMGM_STANDBY );
|
||||
// rtc_clk_cpu_freq_set(RTC_CPU_FREQ_2M);
|
||||
setCpuFrequencyMhz( 2 );
|
||||
setCpuFrequencyMhz( 10 );
|
||||
gpio_wakeup_enable ((gpio_num_t)AXP202_INT, GPIO_INTR_LOW_LEVEL);
|
||||
gpio_wakeup_enable ((gpio_num_t)BMA423_INT1, GPIO_INTR_HIGH_LEVEL);
|
||||
esp_sleep_enable_gpio_wakeup ();
|
||||
esp_light_sleep_start();
|
||||
}
|
||||
// clear event
|
||||
powermgm_clear_event( POWERMGM_PMU_BUTTON | POWERMGM_PMU_BATTERY | POWERMGM_BMA_WAKEUP );
|
||||
|
||||
112
src/hardware/timesync.cpp
Normal file
112
src/hardware/timesync.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
#include "config.h"
|
||||
#include "timesync.h"
|
||||
#include <WiFi.h>
|
||||
|
||||
EventGroupHandle_t time_event_handle = NULL;
|
||||
TaskHandle_t _timesync_Task;
|
||||
void timesync_Task( void * pvParameters );
|
||||
|
||||
timesync_config_t timesync_config;
|
||||
|
||||
void timesync_setup( TTGOClass *ttgo ) {
|
||||
|
||||
timesync_read_config();
|
||||
|
||||
WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
xEventGroupSetBits( time_event_handle, TIME_SYNC_REQUEST );
|
||||
vTaskResume( _timesync_Task );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP );
|
||||
|
||||
time_event_handle = xEventGroupCreate();
|
||||
xEventGroupClearBits( time_event_handle, TIME_SYNC_REQUEST );
|
||||
|
||||
xTaskCreate(
|
||||
timesync_Task, /* Function to implement the task */
|
||||
"timesync Task", /* Name of the task */
|
||||
10000, /* Stack size in words */
|
||||
NULL, /* Task input parameter */
|
||||
1, /* Priority of the task */
|
||||
&_timesync_Task ); /* Task handle. */
|
||||
|
||||
}
|
||||
|
||||
void timesync_save_config( void ) {
|
||||
fs::File file = SPIFFS.open( TIMESYNC_CONFIG_FILE, FILE_WRITE );
|
||||
|
||||
if ( !file ) {
|
||||
Serial.printf("Can't save file: %s\r\n", TIMESYNC_CONFIG_FILE );
|
||||
}
|
||||
else {
|
||||
file.write( (uint8_t *)×ync_config, sizeof( timesync_config ) );
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void timesync_read_config( void ) {
|
||||
fs::File file = SPIFFS.open( TIMESYNC_CONFIG_FILE, FILE_READ );
|
||||
|
||||
if (!file) {
|
||||
Serial.printf("Can't open file: %s!\r\n", TIMESYNC_CONFIG_FILE );
|
||||
}
|
||||
else {
|
||||
int filesize = file.size();
|
||||
if ( filesize > sizeof( timesync_config ) ) {
|
||||
Serial.printf("Failed to read configfile. Wrong filesize!\r\n" );
|
||||
}
|
||||
else {
|
||||
file.read( (uint8_t *)×ync_config, filesize );
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
bool timesync_get_timesync( void ) {
|
||||
return( timesync_config.timesync );
|
||||
}
|
||||
|
||||
void timesync_set_timesync( bool timesync ) {
|
||||
timesync_config.timesync = timesync;
|
||||
timesync_save_config();
|
||||
}
|
||||
|
||||
bool timesync_get_daylightsave( void ) {
|
||||
return( timesync_config.daylightsave );
|
||||
}
|
||||
|
||||
void timesync_set_daylightsave( bool daylightsave ) {
|
||||
timesync_config.daylightsave = daylightsave;
|
||||
timesync_save_config();
|
||||
}
|
||||
|
||||
int32_t timesync_get_timezone( void ) {
|
||||
return( timesync_config.timezone );
|
||||
}
|
||||
|
||||
void timesync_set_timezone( int32_t timezone ) {
|
||||
timesync_config.timezone = timezone;
|
||||
timesync_save_config();
|
||||
}
|
||||
|
||||
void timesync_Task( void * pvParameters ) {
|
||||
|
||||
while( true ) {
|
||||
vTaskDelay( 50 );
|
||||
|
||||
if ( xEventGroupGetBits( time_event_handle ) & TIME_SYNC_REQUEST ) {
|
||||
struct tm timeinfo;
|
||||
TTGOClass *ttgo = TTGOClass::getWatch();
|
||||
|
||||
long gmtOffset_sec = timesync_config.timezone * 3600;
|
||||
|
||||
configTime( gmtOffset_sec, 0, "pool.ntp.org" );
|
||||
|
||||
if( !getLocalTime( &timeinfo ) ) {
|
||||
Serial.println( "Failed to obtain time\r\n" );
|
||||
}
|
||||
ttgo->rtc->syncToRtc();
|
||||
xEventGroupClearBits( time_event_handle, TIME_SYNC_REQUEST );
|
||||
}
|
||||
|
||||
vTaskSuspend( _timesync_Task );
|
||||
}
|
||||
}
|
||||
67
src/hardware/timesync.h
Normal file
67
src/hardware/timesync.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef _TIME_SYNC_H
|
||||
#define _TIME_SYNC_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
#define TIME_SYNC_REQUEST _BV(0)
|
||||
|
||||
#define TIMESYNC_CONFIG_FILE "/timesync.cfg"
|
||||
|
||||
typedef struct {
|
||||
bool timesync = true;
|
||||
bool daylightsave = false;
|
||||
int32_t timezone = 0;
|
||||
} timesync_config_t;
|
||||
|
||||
/*
|
||||
* @brief setup display
|
||||
*
|
||||
* @param ttgo pointer to an TTGOClass
|
||||
*/
|
||||
void timesync_setup( TTGOClass *ttgo );
|
||||
/*
|
||||
* @brief save config for timesync to spiffs
|
||||
*/
|
||||
void timesync_save_config( void );
|
||||
/*
|
||||
* @brief read config for timesync from spiffs
|
||||
*/
|
||||
void timesync_read_config( void );
|
||||
/*
|
||||
* @brief get the status if timesync enable/disable
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
bool timesync_get_timesync( void );
|
||||
/*
|
||||
* @brief enable/disable automatic timesync when wifi is connected
|
||||
*
|
||||
* @param timesync true or false
|
||||
*/
|
||||
void timesync_set_timesync( bool timesync );
|
||||
/*
|
||||
* @brief get the status if daylightsave enable/disable
|
||||
*
|
||||
* @return true or false
|
||||
*/
|
||||
bool timesync_get_daylightsave( void );
|
||||
/*
|
||||
* @brief enable/disable daylight saving
|
||||
*
|
||||
* @param daylightsave true or false
|
||||
*/
|
||||
void timesync_set_daylightsave( bool daylightsave );
|
||||
/*
|
||||
* @brief get the current timezone
|
||||
*
|
||||
* @return timezone from UTC-12 to UTC+12
|
||||
*/
|
||||
int32_t timesync_get_timezone( void );
|
||||
/*
|
||||
* @brief set the current timezone
|
||||
*
|
||||
* @param timezone timezone from UTC-12 to UTC+12
|
||||
*/
|
||||
void timesync_set_timezone( int32_t timezone );
|
||||
|
||||
#endif // _TIME_SYNC_H
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "config.h"
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <esp_wifi.h>
|
||||
|
||||
#include "powermgm.h"
|
||||
#include "wifictl.h"
|
||||
@@ -237,9 +238,10 @@ void wifictl_Task( void * pvParameters ) {
|
||||
powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_ON_REQUEST );
|
||||
}
|
||||
else if ( powermgm_get_event( POWERMGM_WIFI_OFF_REQUEST ) ) {
|
||||
Serial.printf("wlan of request\r\n");
|
||||
Serial.printf("wlan off request\r\n");
|
||||
statusbar_wifi_set_state( false, "" );
|
||||
WiFi.mode( WIFI_OFF );
|
||||
esp_wifi_stop();
|
||||
powermgm_clear_event( POWERMGM_WIFI_OFF_REQUEST | POWERMGM_WIFI_ACTIVE | POWERMGM_WIFI_CONNECTED | POWERMGM_WIFI_SCAN | POWERMGM_WIFI_ON_REQUEST );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user