more feature
This commit is contained in:
58
src/gui/gui.cpp
Normal file
58
src/gui/gui.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <TTGO.h>
|
||||
|
||||
#include "gui.h"
|
||||
#include "statusbar.h"
|
||||
#include "keyboard.h"
|
||||
#include "mainbar/mainbar.h"
|
||||
|
||||
#include "hardware/powermgm.h"
|
||||
#include "hardware/display.h"
|
||||
|
||||
LV_IMG_DECLARE(bg2)
|
||||
|
||||
/**
|
||||
* Create a demo application
|
||||
*/
|
||||
void gui_setup(void)
|
||||
{
|
||||
lv_coord_t hres = lv_disp_get_hor_res(NULL);
|
||||
lv_coord_t vres = lv_disp_get_ver_res(NULL);
|
||||
|
||||
//Create wallpaper
|
||||
lv_obj_t *img_bin = lv_img_create( lv_scr_act() , NULL); /*Create an image object*/
|
||||
lv_img_set_src(img_bin, &bg2 );
|
||||
lv_obj_set_width( img_bin, hres );
|
||||
lv_obj_set_height( img_bin, vres );
|
||||
lv_obj_align(img_bin, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
mainbar_setup();
|
||||
statusbar_setup();
|
||||
keyboard_setup();
|
||||
lv_disp_trig_activity(NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void gui_loop( TTGOClass *ttgo ){
|
||||
|
||||
// do task handler if still an useraction or go to standby after timeout
|
||||
if ( !powermgm_get_event( POWERMGM_STANDBY ) ) {
|
||||
if (lv_disp_get_inactive_time(NULL) < display_get_timeout() * 1000 ) {
|
||||
lv_task_handler();
|
||||
if ( lv_disp_get_inactive_time(NULL) > ( ( display_get_timeout() * 1000 ) - display_get_brightness() * 8 ) ) {
|
||||
ttgo->bl->adjust( ( ( display_get_timeout() * 1000 ) - lv_disp_get_inactive_time(NULL) ) / 8 );
|
||||
}
|
||||
else {
|
||||
ttgo->bl->adjust( display_get_brightness() );
|
||||
}
|
||||
}
|
||||
else {
|
||||
powermgm_set_event( POWERMGM_PMU_BUTTON );
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src/gui/gui.h
Normal file
10
src/gui/gui.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _GUI_H
|
||||
|
||||
#define _GUI_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
void gui_setup( void );
|
||||
void gui_loop( TTGOClass *ttgo );
|
||||
|
||||
#endif // _STATUSBAR_H
|
||||
47
src/gui/keyboard.cpp
Normal file
47
src/gui/keyboard.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "keyboard.h"
|
||||
|
||||
static lv_obj_t *kb = NULL;
|
||||
static void kb_event_cb(lv_obj_t * ta, lv_event_t event);
|
||||
|
||||
void keyboard_setup( void ) {
|
||||
if ( kb != NULL )
|
||||
return;
|
||||
|
||||
kb = lv_keyboard_create( lv_scr_act() , NULL);
|
||||
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
|
||||
lv_keyboard_set_cursor_manage(kb, true);
|
||||
lv_obj_set_event_cb( kb, kb_event_cb );
|
||||
lv_obj_set_hidden( kb, true );
|
||||
|
||||
}
|
||||
|
||||
static void kb_event_cb(lv_obj_t * ta, lv_event_t event) {
|
||||
lv_keyboard_def_event_cb( ta, event );
|
||||
if ( event == LV_EVENT_CANCEL ) {
|
||||
lv_obj_set_hidden( kb, true );
|
||||
}
|
||||
if ( event == LV_EVENT_APPLY ) {
|
||||
lv_obj_set_hidden( kb, true );
|
||||
}
|
||||
}
|
||||
|
||||
void keyboard_set_textarea( lv_obj_t *textarea ){
|
||||
if ( kb == NULL )
|
||||
return;
|
||||
keyboard_show();
|
||||
lv_keyboard_set_textarea( kb, textarea );
|
||||
}
|
||||
|
||||
void keyboard_hide( void ) {
|
||||
if ( kb == NULL )
|
||||
return;
|
||||
lv_obj_set_hidden( kb, true );
|
||||
}
|
||||
|
||||
void keyboard_show( void ) {
|
||||
if ( kb == NULL )
|
||||
return;
|
||||
lv_obj_set_hidden( kb, false );
|
||||
}
|
||||
25
src/gui/keyboard.h
Normal file
25
src/gui/keyboard.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef _KEYBOARD_H
|
||||
#define _KEYBOARD_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
/*
|
||||
* @brief setup onscreen keyboard
|
||||
*/
|
||||
void keyboard_setup( void );
|
||||
/*
|
||||
* @brief activate onscreen keyboard and set output to an lv_obj aka textarea
|
||||
*
|
||||
* @ param textarea point to an lv_obj
|
||||
*/
|
||||
void keyboard_set_textarea( lv_obj_t *textarea );
|
||||
/*
|
||||
* @brief hide onscreen keyboard
|
||||
*/
|
||||
void keyboard_hide( void );
|
||||
/*
|
||||
* @brief show onscreen keyboard
|
||||
*/
|
||||
void keyboard_show( void );
|
||||
|
||||
#endif // _KEYBOARD_H
|
||||
54
src/gui/mainbar/app_tile/app_tile.cpp
Normal file
54
src/gui/mainbar/app_tile/app_tile.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "config.h"
|
||||
#include "../mainbar.h"
|
||||
#include "app_tile.h"
|
||||
|
||||
static void btn_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
|
||||
LV_IMG_DECLARE(wifi_64px);
|
||||
LV_IMG_DECLARE(bluetooth_64px);
|
||||
LV_IMG_DECLARE(time_64px);
|
||||
LV_IMG_DECLARE(brightness_64px);
|
||||
|
||||
void app_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
|
||||
lv_obj_t * wifi_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src(wifi_setup, LV_BTN_STATE_RELEASED, &wifi_64px);
|
||||
lv_imgbtn_set_src(wifi_setup, LV_BTN_STATE_PRESSED, &wifi_64px);
|
||||
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_set_event_cb( wifi_setup, btn_event_cb );
|
||||
|
||||
lv_obj_t * bluetooth_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src(bluetooth_setup, LV_BTN_STATE_RELEASED, &bluetooth_64px);
|
||||
lv_imgbtn_set_src(bluetooth_setup, LV_BTN_STATE_PRESSED, &bluetooth_64px);
|
||||
lv_imgbtn_set_src(bluetooth_setup, LV_BTN_STATE_CHECKED_RELEASED, &bluetooth_64px);
|
||||
lv_imgbtn_set_src(bluetooth_setup, LV_BTN_STATE_CHECKED_PRESSED, &bluetooth_64px);
|
||||
lv_obj_add_style(bluetooth_setup, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align(bluetooth_setup, tile, LV_ALIGN_IN_TOP_LEFT, 48+86, 48 );
|
||||
|
||||
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, 48, 48+86 );
|
||||
|
||||
lv_obj_t * brightness_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src(brightness_setup, LV_BTN_STATE_RELEASED, &brightness_64px);
|
||||
lv_imgbtn_set_src(brightness_setup, LV_BTN_STATE_PRESSED, &brightness_64px);
|
||||
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 );
|
||||
|
||||
}
|
||||
|
||||
static void btn_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_maintile( LV_ANIM_OFF );
|
||||
break;
|
||||
}
|
||||
}
|
||||
8
src/gui/mainbar/app_tile/app_tile.h
Normal file
8
src/gui/mainbar/app_tile/app_tile.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _APP_TILE_H
|
||||
#define _APP_TILE_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
void app_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
|
||||
#endif // _APP_TILE_H
|
||||
72
src/gui/mainbar/main_tile/main_tile.cpp
Normal file
72
src/gui/mainbar/main_tile/main_tile.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "../mainbar.h"
|
||||
#include "main_tile.h"
|
||||
|
||||
static lv_obj_t *timelabel = NULL;
|
||||
static lv_obj_t *datelabel = NULL;
|
||||
|
||||
static lv_style_t timestyle;
|
||||
static lv_style_t datestyle;
|
||||
|
||||
lv_task_t * task;
|
||||
|
||||
LV_FONT_DECLARE(Ubuntu_72px);
|
||||
LV_FONT_DECLARE(Ubuntu_16px);
|
||||
|
||||
void main_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
|
||||
lv_style_copy( ×tyle, style);
|
||||
lv_style_set_text_font( ×tyle, LV_STATE_DEFAULT, &Ubuntu_72px);
|
||||
|
||||
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);
|
||||
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);
|
||||
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 );
|
||||
lv_obj_align(datelabel, timelabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||
|
||||
time_t now;
|
||||
struct tm info;
|
||||
char buf[64];
|
||||
|
||||
time(&now);
|
||||
localtime_r(&now, &info);
|
||||
|
||||
strftime(buf, sizeof(buf), "%H:%M", &info);
|
||||
lv_label_set_text(timelabel, buf);
|
||||
strftime(buf, sizeof(buf), "%a %d.%b %Y", &info);
|
||||
lv_label_set_text(datelabel, buf);
|
||||
lv_obj_align(datelabel, timelabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||
|
||||
task = lv_task_create(main_tile_task, 1000, LV_TASK_PRIO_MID, NULL );
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void main_tile_task( lv_task_t * task ) {
|
||||
time_t now;
|
||||
struct tm info;
|
||||
char buf[64];
|
||||
|
||||
time(&now);
|
||||
localtime_r(&now, &info);
|
||||
|
||||
strftime(buf, sizeof(buf), "%H:%M", &info);
|
||||
lv_label_set_text(timelabel, buf);
|
||||
strftime(buf, sizeof(buf), "%a %d.%b %Y", &info);
|
||||
lv_label_set_text(datelabel, buf);
|
||||
lv_obj_align(datelabel, timelabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||
}
|
||||
9
src/gui/mainbar/main_tile/main_tile.h
Normal file
9
src/gui/mainbar/main_tile/main_tile.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _MAIL_TILE_H
|
||||
#define _MAIL_TILE_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
void main_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
void main_tile_task( lv_task_t * task );
|
||||
|
||||
#endif // _MAIL_TILE_H
|
||||
81
src/gui/mainbar/mainbar.cpp
Normal file
81
src/gui/mainbar/mainbar.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "mainbar.h"
|
||||
#include "main_tile/main_tile.h"
|
||||
#include "setup_tile/setup.h"
|
||||
#include "note_tile/note_tile.h"
|
||||
#include "app_tile/app_tile.h"
|
||||
|
||||
#include "setup_tile/wlan_settings/wlan_settings.h"
|
||||
#include "setup_tile/move_settings/move_settings.h"
|
||||
#include "setup_tile/display_settings/display_settings.h"
|
||||
|
||||
static lv_style_t mainbarstyle;
|
||||
static lv_obj_t *mainbar = NULL;
|
||||
|
||||
static lv_point_t valid_pos[ TILE_NUM ];
|
||||
|
||||
lv_tile_entry_t tile_entry[ TILE_NUM ] {
|
||||
{ NULL, MAIN_TILE, main_tile_setup, { 0 , 0 } },
|
||||
{ NULL, NOTE_TILE, note_tile_setup, { 1 , 0 } },
|
||||
{ NULL, APP_TILE, app_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 } }
|
||||
};
|
||||
|
||||
void mainbar_setup( void ) {
|
||||
|
||||
lv_style_init( &mainbarstyle );
|
||||
lv_style_set_radius(&mainbarstyle, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_bg_color(&mainbarstyle, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||
lv_style_set_bg_opa(&mainbarstyle, LV_OBJ_PART_MAIN, LV_OPA_0);
|
||||
lv_style_set_border_width(&mainbarstyle, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_text_color(&mainbarstyle, LV_OBJ_PART_MAIN, LV_COLOR_WHITE);
|
||||
lv_style_set_image_recolor(&mainbarstyle, LV_OBJ_PART_MAIN, LV_COLOR_WHITE);
|
||||
|
||||
mainbar = lv_tileview_create( lv_scr_act(), NULL);
|
||||
lv_tileview_set_valid_positions(mainbar, valid_pos, TILE_NUM );
|
||||
lv_tileview_set_edge_flash(mainbar, false);
|
||||
lv_obj_add_style( mainbar, LV_OBJ_PART_MAIN, &mainbarstyle );
|
||||
lv_page_set_scrlbar_mode(mainbar, LV_SCRLBAR_MODE_OFF);
|
||||
|
||||
for( int tile = 0 ; tile < TILE_NUM ; tile++ ) {
|
||||
tile_entry[ tile ].tile = lv_obj_create( mainbar, NULL);
|
||||
lv_obj_set_size( tile_entry[ tile ].tile, LV_HOR_RES, LV_VER_RES);
|
||||
lv_obj_reset_style_list( tile_entry[ tile ].tile, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( tile_entry[ tile ].tile, LV_OBJ_PART_MAIN, &mainbarstyle );
|
||||
lv_obj_set_pos( tile_entry[ tile ].tile, tile_entry[ tile ].pos.x * LV_HOR_RES , tile_entry[ tile ].pos.y * LV_VER_RES );
|
||||
lv_tileview_add_element( mainbar, tile_entry[ tile ].tile);
|
||||
if ( tile_entry[ tile ].tilecallback != NULL )
|
||||
tile_entry[ tile ].tilecallback( tile_entry[ tile ].tile, &mainbarstyle, LV_HOR_RES , LV_VER_RES );
|
||||
valid_pos[ tile ].x = tile_entry[ tile ].pos.x;
|
||||
valid_pos[ tile ].y = tile_entry[ tile ].pos.y;
|
||||
}
|
||||
mainbar_jump_to_maintile( LV_ANIM_OFF );
|
||||
}
|
||||
|
||||
void mainbar_jump_to_tile( lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim ) {
|
||||
lv_tileview_set_tile_act(mainbar, x, y, anim );
|
||||
}
|
||||
|
||||
void mainbar_jump_to_tilenumber( lv_tile_number tile_number, lv_anim_enable_t anim ) {
|
||||
for ( int tile = 0 ; tile < TILE_NUM; tile++ ) {
|
||||
if ( tile_entry[ tile ].tile_number == tile_number ) {
|
||||
lv_tileview_set_tile_act(mainbar, tile_entry[ tile ].pos.x, tile_entry[ tile ].pos.y, anim );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mainbar_jump_to_maintile( lv_anim_enable_t anim ) {
|
||||
for ( int tile = 0 ; tile < TILE_NUM; tile++ ) {
|
||||
if ( tile_entry[ tile ].tile_number == MAIN_TILE ) {
|
||||
lv_tileview_set_tile_act(mainbar, tile_entry[ tile ].pos.x, tile_entry[ tile ].pos.y, anim );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
51
src/gui/mainbar/mainbar.h
Normal file
51
src/gui/mainbar/mainbar.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef _MAINBAR_H
|
||||
#define _MAINBAR_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
typedef void ( * TILE_CALLBACK_FUNC ) ( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
|
||||
typedef enum {
|
||||
MAIN_TILE,
|
||||
SETUP_TILE,
|
||||
NOTE_TILE,
|
||||
APP_TILE,
|
||||
WLAN_SETTINGS_TILE,
|
||||
WLAN_PASSWORD_TILE,
|
||||
MOVE_SETTINGS_TILE,
|
||||
DISPLAY_SETTINGS_TILE,
|
||||
TILE_NUM
|
||||
} lv_tile_number;
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t *tile;
|
||||
lv_tile_number tile_number;
|
||||
TILE_CALLBACK_FUNC tilecallback;
|
||||
lv_point_t pos;
|
||||
} lv_tile_entry_t;
|
||||
|
||||
/*
|
||||
* @brief mainbar setup funktion
|
||||
* @param none
|
||||
*/
|
||||
void mainbar_setup( void );
|
||||
/*
|
||||
* @brief jump to the given tile
|
||||
* @param x x coordinate
|
||||
* @param y y coordinate
|
||||
*/
|
||||
void mainbar_jump_to_tile( lv_coord_t x, lv_coord_t y, lv_anim_enable_t anim );
|
||||
/*
|
||||
* @brief jump to the given tile
|
||||
* @param tile tile number
|
||||
* @param anim LV_ANIM_ON or LV_ANIM_OFF for animated switch
|
||||
*/
|
||||
void mainbar_jump_to_tilenumber( lv_tile_number tile_number, lv_anim_enable_t anim );
|
||||
/*
|
||||
* @brief jump direct to main tile
|
||||
* @param anim LV_ANIM_ON or LV_ANIM_OFF for animated switch
|
||||
*/
|
||||
void mainbar_jump_to_maintile( lv_anim_enable_t anim );
|
||||
|
||||
|
||||
#endif // _MAINBAR_H
|
||||
54
src/gui/mainbar/note_tile/note_tile.cpp
Normal file
54
src/gui/mainbar/note_tile/note_tile.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
#include "config.h"
|
||||
#include "../mainbar.h"
|
||||
#include "note_tile.h"
|
||||
|
||||
static void btn_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
|
||||
LV_IMG_DECLARE(wifi_64px);
|
||||
LV_IMG_DECLARE(bluetooth_64px);
|
||||
LV_IMG_DECLARE(time_64px);
|
||||
LV_IMG_DECLARE(brightness_64px);
|
||||
|
||||
void note_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
|
||||
lv_obj_t * wifi_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src(wifi_setup, LV_BTN_STATE_RELEASED, &wifi_64px);
|
||||
lv_imgbtn_set_src(wifi_setup, LV_BTN_STATE_PRESSED, &wifi_64px);
|
||||
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_set_event_cb( wifi_setup, btn_event_cb );
|
||||
|
||||
lv_obj_t * bluetooth_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src(bluetooth_setup, LV_BTN_STATE_RELEASED, &bluetooth_64px);
|
||||
lv_imgbtn_set_src(bluetooth_setup, LV_BTN_STATE_PRESSED, &bluetooth_64px);
|
||||
lv_imgbtn_set_src(bluetooth_setup, LV_BTN_STATE_CHECKED_RELEASED, &bluetooth_64px);
|
||||
lv_imgbtn_set_src(bluetooth_setup, LV_BTN_STATE_CHECKED_PRESSED, &bluetooth_64px);
|
||||
lv_obj_add_style(bluetooth_setup, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align(bluetooth_setup, tile, LV_ALIGN_IN_TOP_LEFT, 48+86, 48 );
|
||||
|
||||
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, 48, 48+86 );
|
||||
|
||||
lv_obj_t * brightness_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src(brightness_setup, LV_BTN_STATE_RELEASED, &brightness_64px);
|
||||
lv_imgbtn_set_src(brightness_setup, LV_BTN_STATE_PRESSED, &brightness_64px);
|
||||
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 );
|
||||
|
||||
}
|
||||
|
||||
static void btn_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_maintile( LV_ANIM_ON );
|
||||
break;
|
||||
}
|
||||
}
|
||||
8
src/gui/mainbar/note_tile/note_tile.h
Normal file
8
src/gui/mainbar/note_tile/note_tile.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _NOTE_TILE_H
|
||||
#define _NOTE_TILE_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
void note_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
|
||||
#endif // _NOTE_TILE_H
|
||||
113
src/gui/mainbar/setup_tile/display_settings/display_setting.cpp
Normal file
113
src/gui/mainbar/setup_tile/display_settings/display_setting.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "config.h"
|
||||
#include "display_settings.h"
|
||||
|
||||
#include "gui/mainbar/mainbar.h"
|
||||
#include "gui/statusbar.h"
|
||||
#include "hardware/display.h"
|
||||
|
||||
lv_obj_t *display_settings_tile1 = NULL;
|
||||
lv_obj_t *display_brightness_slider = NULL;
|
||||
lv_obj_t *display_timeout_slider = NULL;
|
||||
lv_obj_t *display_timeout_slider_label = NULL;
|
||||
lv_style_t display_settings_style;
|
||||
|
||||
LV_IMG_DECLARE(exit_32px);
|
||||
LV_IMG_DECLARE(brightness_64px);
|
||||
LV_IMG_DECLARE(time_64px);
|
||||
|
||||
static void exit_display_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void exit_display_brightness_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void exit_display_timeout_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
|
||||
void display_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
lv_style_init( &display_settings_style );
|
||||
lv_style_set_radius( &display_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_bg_color( &display_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||
lv_style_set_bg_opa( &display_settings_style, LV_OBJ_PART_MAIN, LV_OPA_100);
|
||||
lv_style_set_border_width( &display_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_text_color( &display_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
lv_style_set_image_recolor( &display_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
|
||||
display_settings_tile1 = lv_obj_create( tile, NULL);
|
||||
lv_obj_set_size(display_settings_tile1, hres , vres);
|
||||
lv_obj_align(display_settings_tile1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_style( display_settings_tile1, LV_OBJ_PART_MAIN, &display_settings_style );
|
||||
|
||||
lv_obj_t *exit_btn = lv_imgbtn_create( display_settings_tile1, 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, display_settings_tile1, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_set_event_cb( exit_btn, exit_display_setup_event_cb );
|
||||
|
||||
lv_obj_t *exit_label = lv_label_create( display_settings_tile1, NULL );
|
||||
lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( exit_label, "display settings");
|
||||
lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *brightness_cont = lv_obj_create( display_settings_tile1, NULL );
|
||||
lv_obj_set_size( brightness_cont, hres , 80 );
|
||||
lv_obj_add_style( brightness_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( brightness_cont, display_settings_tile1, LV_ALIGN_IN_TOP_RIGHT, 0, 75 );
|
||||
display_brightness_slider = lv_slider_create( brightness_cont, NULL );
|
||||
lv_slider_set_range( display_brightness_slider, 32, 255 );
|
||||
lv_obj_set_size( display_brightness_slider, hres - 100 , 10 );
|
||||
lv_obj_align( display_brightness_slider, brightness_cont, LV_ALIGN_IN_RIGHT_MID, -15, 0 );
|
||||
lv_obj_set_event_cb( display_brightness_slider, exit_display_brightness_setup_event_cb );
|
||||
lv_obj_t *brightness_icon = lv_img_create( brightness_cont, NULL );
|
||||
lv_img_set_src( brightness_icon, &brightness_64px );
|
||||
lv_obj_align( brightness_icon, brightness_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *timeout_cont = lv_obj_create( display_settings_tile1, NULL );
|
||||
lv_obj_set_size( timeout_cont, hres , 80 );
|
||||
lv_obj_add_style( timeout_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( timeout_cont, brightness_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
display_timeout_slider = lv_slider_create( timeout_cont, NULL );
|
||||
lv_slider_set_range( display_timeout_slider, 15, 300 );
|
||||
lv_obj_set_size(display_timeout_slider, hres - 100 , 10 );
|
||||
lv_obj_align( display_timeout_slider, timeout_cont, LV_ALIGN_IN_RIGHT_MID, -15, 0 );
|
||||
lv_obj_set_event_cb( display_timeout_slider, exit_display_timeout_setup_event_cb );
|
||||
display_timeout_slider_label = lv_label_create( timeout_cont, NULL );
|
||||
lv_obj_add_style( display_timeout_slider_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( display_timeout_slider_label, "");
|
||||
lv_obj_align( display_timeout_slider_label, display_timeout_slider, LV_ALIGN_OUT_BOTTOM_MID, 0, -5 );
|
||||
lv_obj_t *timeout_icon = lv_img_create( timeout_cont, NULL );
|
||||
lv_img_set_src( timeout_icon, &time_64px );
|
||||
lv_obj_align( timeout_icon, timeout_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||
|
||||
lv_slider_set_value( display_brightness_slider, display_get_brightness(), LV_ANIM_OFF );
|
||||
lv_slider_set_value( display_timeout_slider, display_get_timeout(), LV_ANIM_OFF );
|
||||
char temp[16]="";
|
||||
snprintf( temp, sizeof( temp ), "%d secounds", display_get_timeout() );
|
||||
lv_label_set_text( display_timeout_slider_label, temp );
|
||||
lv_obj_align( display_timeout_slider_label, display_timeout_slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
||||
}
|
||||
|
||||
|
||||
static void exit_display_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 );
|
||||
display_save_config();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void exit_display_brightness_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_VALUE_CHANGED ): display_set_brightness( lv_slider_get_value( obj ) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void exit_display_timeout_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_VALUE_CHANGED ): display_set_timeout( lv_slider_get_value( obj ) );
|
||||
char temp[16]="";
|
||||
snprintf( temp, sizeof( temp ), "%d secounds", lv_slider_get_value(obj) );
|
||||
lv_label_set_text( display_timeout_slider_label, temp );
|
||||
lv_obj_align( display_timeout_slider_label, display_timeout_slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 15 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef _DISPLAY_SETTINGS_H
|
||||
#define _DISPLAY_SETTINGS_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
void display_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
|
||||
#endif // _DISPLAY_SETTINGS_H
|
||||
113
src/gui/mainbar/setup_tile/move_settings/move_settings.cpp
Normal file
113
src/gui/mainbar/setup_tile/move_settings/move_settings.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
#include "config.h"
|
||||
#include "move_settings.h"
|
||||
|
||||
#include "gui/mainbar/mainbar.h"
|
||||
#include "gui/statusbar.h"
|
||||
#include "hardware/bma.h"
|
||||
|
||||
lv_obj_t *move_settings_tile1=NULL;
|
||||
lv_obj_t *stepcounter_onoff=NULL;
|
||||
lv_obj_t *doubleclick_onoff=NULL;
|
||||
lv_style_t move_settings_style;
|
||||
|
||||
LV_IMG_DECLARE(exit_32px);
|
||||
LV_IMG_DECLARE(move_32px);
|
||||
|
||||
static void exit_move_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void stepcounter_onoff_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||
static void doubleclick_onoff_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||
|
||||
void move_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
lv_style_init( &move_settings_style );
|
||||
lv_style_set_radius( &move_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_bg_color( &move_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||
lv_style_set_bg_opa( &move_settings_style, LV_OBJ_PART_MAIN, LV_OPA_100);
|
||||
lv_style_set_border_width( &move_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_text_color( &move_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
lv_style_set_image_recolor( &move_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
|
||||
move_settings_tile1 = lv_obj_create( tile, NULL);
|
||||
lv_obj_set_size(move_settings_tile1, hres , vres);
|
||||
lv_obj_align(move_settings_tile1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_style( move_settings_tile1, LV_OBJ_PART_MAIN, &move_settings_style );
|
||||
|
||||
lv_obj_t *exit_btn = lv_imgbtn_create( move_settings_tile1, 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, move_settings_tile1, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_set_event_cb( exit_btn, exit_move_setup_event_cb );
|
||||
|
||||
lv_obj_t *exit_label = lv_label_create( move_settings_tile1, NULL);
|
||||
lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( exit_label, "movement settings");
|
||||
lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *stepcounter_cont = lv_obj_create( move_settings_tile1, NULL );
|
||||
lv_obj_set_size(stepcounter_cont, hres , 40);
|
||||
lv_obj_add_style( stepcounter_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( stepcounter_cont, move_settings_tile1, LV_ALIGN_IN_TOP_RIGHT, 0, 75 );
|
||||
stepcounter_onoff = lv_switch_create( stepcounter_cont, NULL );
|
||||
lv_switch_off( stepcounter_onoff, LV_ANIM_ON );
|
||||
lv_obj_align( stepcounter_onoff, stepcounter_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
lv_obj_set_event_cb( stepcounter_onoff, stepcounter_onoff_event_handler );
|
||||
lv_obj_t *stepcounter_label = lv_label_create( stepcounter_cont, NULL);
|
||||
lv_obj_add_style( stepcounter_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( stepcounter_label, "step counter");
|
||||
lv_obj_align( stepcounter_label, stepcounter_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||
|
||||
lv_obj_t *doubleclick_cont = lv_obj_create( move_settings_tile1, NULL );
|
||||
lv_obj_set_size(doubleclick_cont, hres , 40);
|
||||
lv_obj_add_style( doubleclick_cont, LV_OBJ_PART_MAIN, style );
|
||||
lv_obj_align( doubleclick_cont, stepcounter_cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
doubleclick_onoff = lv_switch_create( doubleclick_cont, NULL );
|
||||
lv_switch_off( doubleclick_onoff, LV_ANIM_ON );
|
||||
lv_obj_align( doubleclick_onoff, doubleclick_cont, LV_ALIGN_IN_RIGHT_MID, -5, 0 );
|
||||
lv_obj_set_event_cb( doubleclick_onoff, doubleclick_onoff_event_handler );
|
||||
lv_obj_t *doubleclick_label = lv_label_create( doubleclick_cont, NULL);
|
||||
lv_obj_add_style( doubleclick_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( doubleclick_label, "double click");
|
||||
lv_obj_align( doubleclick_label, doubleclick_cont, LV_ALIGN_IN_LEFT_MID, 5, 0 );
|
||||
|
||||
if ( bma_get_config( BMA_DOUBLECLICK ) )
|
||||
lv_switch_on( doubleclick_onoff, LV_ANIM_OFF );
|
||||
else
|
||||
lv_switch_off( doubleclick_onoff, LV_ANIM_OFF );
|
||||
|
||||
if ( bma_get_config( BMA_STEPCOUNTER ) )
|
||||
lv_switch_on( stepcounter_onoff, LV_ANIM_OFF );
|
||||
else
|
||||
lv_switch_off( stepcounter_onoff, LV_ANIM_OFF );
|
||||
}
|
||||
|
||||
|
||||
static void exit_move_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 stepcounter_onoff_event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
if( lv_switch_get_state( obj ) ) {
|
||||
bma_set_config( BMA_STEPCOUNTER, true );
|
||||
}
|
||||
else {
|
||||
bma_set_config( BMA_STEPCOUNTER, false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void doubleclick_onoff_event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
if( lv_switch_get_state( obj ) ) {
|
||||
bma_set_config( BMA_DOUBLECLICK, true );
|
||||
}
|
||||
else {
|
||||
bma_set_config( BMA_DOUBLECLICK, false );
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/gui/mainbar/setup_tile/move_settings/move_settings.h
Normal file
8
src/gui/mainbar/setup_tile/move_settings/move_settings.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _MOVE_SETTINGS_H
|
||||
#define _MOVE_SETTINGS_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
void move_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
|
||||
#endif // _MOVE_SETTINGS_TILE_H
|
||||
72
src/gui/mainbar/setup_tile/setup.cpp
Normal file
72
src/gui/mainbar/setup_tile/setup.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "config.h"
|
||||
#include "setup.h"
|
||||
|
||||
#include "gui/mainbar/mainbar.h"
|
||||
|
||||
static void wifi_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 );
|
||||
|
||||
LV_IMG_DECLARE(wifi_64px);
|
||||
LV_IMG_DECLARE(bluetooth_64px);
|
||||
LV_IMG_DECLARE(move_64px);
|
||||
LV_IMG_DECLARE(brightness_64px);
|
||||
|
||||
void setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
|
||||
lv_obj_t * wifi_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src(wifi_setup, LV_BTN_STATE_RELEASED, &wifi_64px);
|
||||
lv_imgbtn_set_src(wifi_setup, LV_BTN_STATE_PRESSED, &wifi_64px);
|
||||
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_set_event_cb( wifi_setup, wifi_setup_event_cb );
|
||||
|
||||
lv_obj_t * bluetooth_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src( bluetooth_setup, LV_BTN_STATE_RELEASED, &bluetooth_64px);
|
||||
lv_imgbtn_set_src( bluetooth_setup, LV_BTN_STATE_PRESSED, &bluetooth_64px);
|
||||
lv_imgbtn_set_src( bluetooth_setup, LV_BTN_STATE_CHECKED_RELEASED, &bluetooth_64px);
|
||||
lv_imgbtn_set_src( bluetooth_setup, LV_BTN_STATE_CHECKED_PRESSED, &bluetooth_64px);
|
||||
lv_obj_add_style( bluetooth_setup, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align( bluetooth_setup, tile, LV_ALIGN_IN_TOP_LEFT, 48+86, 48 );
|
||||
|
||||
lv_obj_t * move_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src( move_setup, LV_BTN_STATE_RELEASED, &move_64px);
|
||||
lv_imgbtn_set_src( move_setup, LV_BTN_STATE_PRESSED, &move_64px);
|
||||
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_set_event_cb( move_setup, move_setup_event_cb );
|
||||
|
||||
lv_obj_t * brightness_setup = lv_imgbtn_create(tile, NULL);
|
||||
lv_imgbtn_set_src( brightness_setup, LV_BTN_STATE_RELEASED, &brightness_64px);
|
||||
lv_imgbtn_set_src( brightness_setup, LV_BTN_STATE_PRESSED, &brightness_64px);
|
||||
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_set_event_cb( brightness_setup, display_setup_event_cb );
|
||||
}
|
||||
|
||||
static void wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( WLAN_SETTINGS_TILE, LV_ANIM_OFF );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void move_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( MOVE_SETTINGS_TILE, LV_ANIM_OFF );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void display_setup_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): mainbar_jump_to_tilenumber( DISPLAY_SETTINGS_TILE, LV_ANIM_OFF );
|
||||
break;
|
||||
}
|
||||
}
|
||||
8
src/gui/mainbar/setup_tile/setup.h
Normal file
8
src/gui/mainbar/setup_tile/setup.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _SETUP_H
|
||||
#define _SETUP_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
void setup_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
|
||||
#endif // _SETUP_H
|
||||
228
src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp
Normal file
228
src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
#include "config.h"
|
||||
#include "wlan_settings.h"
|
||||
|
||||
#include "gui/mainbar/mainbar.h"
|
||||
#include "gui/statusbar.h"
|
||||
#include "gui/keyboard.h"
|
||||
|
||||
#include "hardware/wifictl.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
|
||||
LV_IMG_DECLARE(exit_32px);
|
||||
|
||||
lv_obj_t *wlan_settings_tile1=NULL;
|
||||
lv_obj_t *wifi_onoff=NULL;
|
||||
lv_obj_t *wifiname_list=NULL;
|
||||
lv_style_t wlan_settings_style;
|
||||
lv_style_t wlan_list_style;
|
||||
|
||||
static void exit_wifi_setup_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void exit_wifi_password_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void wifi_onoff_event_handler(lv_obj_t * obj, lv_event_t event);
|
||||
void wifi_settings_enter_pass_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
void WiFiScanDone(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||
|
||||
LV_IMG_DECLARE(lock_16px);
|
||||
LV_IMG_DECLARE(unlock_16px);
|
||||
LV_IMG_DECLARE(check_32px);
|
||||
LV_IMG_DECLARE(exit_32px);
|
||||
LV_IMG_DECLARE(trash_32px);
|
||||
|
||||
void wlan_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
lv_style_init( &wlan_settings_style );
|
||||
lv_style_set_radius( &wlan_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_bg_color( &wlan_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||
lv_style_set_bg_opa( &wlan_settings_style, LV_OBJ_PART_MAIN, LV_OPA_100);
|
||||
lv_style_set_border_width( &wlan_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_text_color( &wlan_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
lv_style_set_image_recolor( &wlan_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
|
||||
wlan_settings_tile1 = lv_obj_create( tile, NULL);
|
||||
lv_obj_set_size(wlan_settings_tile1, hres , vres);
|
||||
lv_obj_align(wlan_settings_tile1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_style( wlan_settings_tile1, LV_OBJ_PART_MAIN, &wlan_settings_style );
|
||||
|
||||
lv_obj_t *exit_btn = lv_imgbtn_create( wlan_settings_tile1, 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, wlan_settings_tile1, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_set_event_cb( exit_btn, exit_wifi_setup_event_cb );
|
||||
|
||||
lv_obj_t *exit_label = lv_label_create( wlan_settings_tile1, NULL);
|
||||
lv_obj_add_style( exit_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( exit_label, "wlan settings");
|
||||
lv_obj_align( exit_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||
|
||||
/*Copy the first switch and turn it ON*/
|
||||
wifi_onoff = lv_switch_create( wlan_settings_tile1, NULL );
|
||||
lv_switch_off( wifi_onoff, LV_ANIM_ON );
|
||||
lv_obj_align( wifi_onoff, exit_label, LV_ALIGN_OUT_RIGHT_MID, 30, 0 );
|
||||
lv_obj_set_event_cb( wifi_onoff, wifi_onoff_event_handler);
|
||||
|
||||
wifiname_list = lv_list_create( wlan_settings_tile1, NULL);
|
||||
lv_obj_set_size( wifiname_list, hres, 160);
|
||||
lv_style_init( &wlan_list_style );
|
||||
lv_style_set_border_width( &wlan_list_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_radius( &wlan_list_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_obj_add_style( wifiname_list, LV_OBJ_PART_MAIN, &wlan_list_style );
|
||||
lv_obj_align( wifiname_list, wlan_settings_tile1, LV_ALIGN_IN_TOP_MID, 0, 80);
|
||||
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
lv_switch_on( wifi_onoff, LV_ANIM_OFF );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_WIFI_READY );
|
||||
|
||||
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
lv_switch_off( wifi_onoff, LV_ANIM_OFF );
|
||||
while ( lv_list_remove( wifiname_list, 0 ) );
|
||||
}, WiFiEvent_t::SYSTEM_EVENT_STA_STOP );
|
||||
|
||||
WiFi.onEvent( WiFiScanDone, WiFiEvent_t::SYSTEM_EVENT_SCAN_DONE );
|
||||
}
|
||||
|
||||
lv_obj_t *wlan_password_tile1=NULL;
|
||||
lv_obj_t *wlan_password_name_label=NULL;
|
||||
lv_obj_t *wlan_password_pass_textfield=NULL;
|
||||
|
||||
static void wlan_password_event_cb(lv_obj_t * obj, lv_event_t event);
|
||||
static void apply_wifi_password_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
static void delete_wifi_password_event_cb( lv_obj_t * obj, lv_event_t event );
|
||||
|
||||
void wlan_password_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres ) {
|
||||
lv_style_init( &wlan_settings_style );
|
||||
lv_style_set_radius( &wlan_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_bg_color( &wlan_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||
lv_style_set_bg_opa( &wlan_settings_style, LV_OBJ_PART_MAIN, LV_OPA_100);
|
||||
lv_style_set_border_width( &wlan_settings_style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_text_color( &wlan_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
lv_style_set_image_recolor( &wlan_settings_style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
|
||||
wlan_password_tile1 = lv_obj_create( tile, NULL);
|
||||
lv_obj_set_size (wlan_password_tile1, hres , vres);
|
||||
lv_obj_align( wlan_password_tile1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_add_style( wlan_password_tile1, LV_OBJ_PART_MAIN, &wlan_settings_style );
|
||||
|
||||
lv_obj_t *exit_btn = lv_imgbtn_create( wlan_password_tile1, 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, wlan_password_tile1, LV_ALIGN_IN_TOP_LEFT, 10, STATUSBAR_HEIGHT + 10 );
|
||||
lv_obj_set_event_cb( exit_btn, exit_wifi_password_event_cb );
|
||||
|
||||
wlan_password_name_label = lv_label_create( wlan_password_tile1, NULL);
|
||||
lv_obj_add_style( wlan_password_name_label, LV_OBJ_PART_MAIN, style );
|
||||
lv_label_set_text( wlan_password_name_label, "wlan setting");
|
||||
lv_obj_align( wlan_password_name_label, exit_btn, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||
|
||||
wlan_password_pass_textfield = lv_textarea_create( wlan_password_tile1, NULL);
|
||||
lv_textarea_set_text( wlan_password_pass_textfield, "");
|
||||
lv_textarea_set_pwd_mode( wlan_password_pass_textfield, false);
|
||||
lv_textarea_set_one_line( wlan_password_pass_textfield, true);
|
||||
lv_textarea_set_cursor_hidden( wlan_password_pass_textfield, true);
|
||||
lv_obj_set_width( wlan_password_pass_textfield, LV_HOR_RES );
|
||||
lv_obj_align( wlan_password_pass_textfield, wlan_password_tile1, LV_ALIGN_IN_TOP_LEFT, 0, 75);
|
||||
lv_obj_set_event_cb( wlan_password_pass_textfield, wlan_password_event_cb );
|
||||
|
||||
lv_obj_t *apply_btn = lv_imgbtn_create( wlan_password_tile1, NULL);
|
||||
lv_imgbtn_set_src( apply_btn, LV_BTN_STATE_RELEASED, &check_32px);
|
||||
lv_imgbtn_set_src( apply_btn, LV_BTN_STATE_PRESSED, &check_32px);
|
||||
lv_imgbtn_set_src( apply_btn, LV_BTN_STATE_CHECKED_RELEASED, &check_32px);
|
||||
lv_imgbtn_set_src( apply_btn, LV_BTN_STATE_CHECKED_PRESSED, &check_32px);
|
||||
lv_obj_add_style( apply_btn, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align( apply_btn, wlan_password_pass_textfield, LV_ALIGN_OUT_BOTTOM_RIGHT, -10, 10 );
|
||||
lv_obj_set_event_cb( apply_btn, apply_wifi_password_event_cb );
|
||||
|
||||
lv_obj_t *delete_btn = lv_imgbtn_create( wlan_password_tile1, NULL);
|
||||
lv_imgbtn_set_src( delete_btn, LV_BTN_STATE_RELEASED, &trash_32px);
|
||||
lv_imgbtn_set_src( delete_btn, LV_BTN_STATE_PRESSED, &trash_32px);
|
||||
lv_imgbtn_set_src( delete_btn, LV_BTN_STATE_CHECKED_RELEASED, &trash_32px);
|
||||
lv_imgbtn_set_src( delete_btn, LV_BTN_STATE_CHECKED_PRESSED, &trash_32px);
|
||||
lv_obj_add_style( delete_btn, LV_IMGBTN_PART_MAIN, style);
|
||||
lv_obj_align( delete_btn, wlan_password_pass_textfield, LV_ALIGN_OUT_BOTTOM_LEFT, 10, 10 );
|
||||
lv_obj_set_event_cb( delete_btn, delete_wifi_password_event_cb );
|
||||
}
|
||||
|
||||
|
||||
static void apply_wifi_password_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
|
||||
if(event == LV_EVENT_CLICKED) {
|
||||
wifictl_insert_network( lv_label_get_text( wlan_password_name_label ), lv_textarea_get_text( wlan_password_pass_textfield ) );
|
||||
keyboard_hide();
|
||||
mainbar_jump_to_tilenumber( WLAN_SETTINGS_TILE, LV_ANIM_ON );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void delete_wifi_password_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
|
||||
if(event == LV_EVENT_CLICKED) {
|
||||
wifictl_delete_network( lv_label_get_text( wlan_password_name_label ) );
|
||||
keyboard_hide();
|
||||
mainbar_jump_to_tilenumber( WLAN_SETTINGS_TILE, LV_ANIM_ON );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void wlan_password_event_cb( lv_obj_t * obj, lv_event_t event )
|
||||
{
|
||||
if( event == LV_EVENT_CLICKED ) {
|
||||
keyboard_set_textarea( obj );
|
||||
}
|
||||
}
|
||||
|
||||
static void exit_wifi_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 exit_wifi_password_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
switch( event ) {
|
||||
case( LV_EVENT_CLICKED ): keyboard_hide();
|
||||
mainbar_jump_to_tilenumber( WLAN_SETTINGS_TILE, LV_ANIM_ON );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void wifi_onoff_event_handler(lv_obj_t * obj, lv_event_t event) {
|
||||
if(event == LV_EVENT_VALUE_CHANGED) {
|
||||
if( lv_switch_get_state( obj ) ) {
|
||||
wifictl_on();
|
||||
}
|
||||
else {
|
||||
wifictl_off();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_settings_enter_pass_event_cb( lv_obj_t * obj, lv_event_t event ) {
|
||||
if(event == LV_EVENT_CLICKED) {
|
||||
// strcpy( ssid, lv_list_get_btn_text(obj) );
|
||||
lv_label_set_text( wlan_password_name_label, lv_list_get_btn_text(obj) );
|
||||
lv_textarea_set_text( wlan_password_pass_textfield, "");
|
||||
mainbar_jump_to_tilenumber( WLAN_PASSWORD_TILE, LV_ANIM_ON );
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiScanDone(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||
|
||||
while (lv_list_remove( wifiname_list, 0 ) );
|
||||
|
||||
int len = WiFi.scanComplete();
|
||||
for( int i = 0 ; i < len ; i++ ) {
|
||||
if ( wifictl_is_known( WiFi.SSID(i).c_str() ) ) {
|
||||
lv_obj_t * wifiname_list_btn = lv_list_add_btn( wifiname_list, &unlock_16px, WiFi.SSID(i).c_str() );
|
||||
lv_obj_set_event_cb( wifiname_list_btn, wifi_settings_enter_pass_event_cb);
|
||||
}
|
||||
else {
|
||||
lv_obj_t * wifiname_list_btn = lv_list_add_btn( wifiname_list, &lock_16px, WiFi.SSID(i).c_str() );
|
||||
lv_obj_set_event_cb( wifiname_list_btn, wifi_settings_enter_pass_event_cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.h
Normal file
9
src/gui/mainbar/setup_tile/wlan_settings/wlan_settings.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _WLAN_SETTINGS_H
|
||||
#define _WLAN_SETTINGS_H
|
||||
|
||||
#include <TTGO.h>
|
||||
|
||||
void wlan_settings_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
void wlan_password_tile_setup( lv_obj_t *tile, lv_style_t *style, lv_coord_t hres, lv_coord_t vres );
|
||||
|
||||
#endif // _WLAN_SETTINGS_H
|
||||
55
src/gui/screenshot.cpp
Normal file
55
src/gui/screenshot.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "config.h"
|
||||
#include "screenshot.h"
|
||||
|
||||
lv_disp_drv_t screenshot_disp_drv;
|
||||
static lv_disp_buf_t screenshot_disp_buf;
|
||||
static lv_color_t screenshot_buf1[ LV_HOR_RES_MAX * 1 ];
|
||||
|
||||
lv_disp_t *system_disp;
|
||||
lv_disp_t *screenshot_disp;
|
||||
|
||||
static void screenshot_disp_flush( lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p );
|
||||
|
||||
void screenshot_setup( void ) {
|
||||
|
||||
system_disp = lv_disp_get_default();
|
||||
|
||||
lv_disp_buf_init(&screenshot_disp_buf, screenshot_buf1, NULL, LV_HOR_RES_MAX * 1 );
|
||||
|
||||
screenshot_disp_drv.hor_res = TFT_WIDTH;
|
||||
screenshot_disp_drv.ver_res = TFT_HEIGHT;
|
||||
screenshot_disp_drv.flush_cb = screenshot_disp_flush;
|
||||
screenshot_disp_drv.buffer = &screenshot_disp_buf;
|
||||
screenshot_disp = lv_disp_drv_register( &screenshot_disp_drv );
|
||||
|
||||
lv_disp_set_default( system_disp );
|
||||
}
|
||||
|
||||
void screenshot_take( void ) {
|
||||
/*
|
||||
unsigned char* image = (unsigned char*)ps_malloc(240 * 240 * 3);
|
||||
Serial.printf("Total heap: %d\r\n", ESP.getHeapSize());
|
||||
Serial.printf("Free heap: %d\r\n", ESP.getFreeHeap());
|
||||
Serial.printf("Total PSRAM: %d\r\n", ESP.getPsramSize());
|
||||
Serial.printf("Free PSRAM: %d\r\n", ESP.getFreePsram());
|
||||
*/
|
||||
lv_obj_invalidate(lv_scr_act());
|
||||
lv_disp_set_default( screenshot_disp );
|
||||
lv_refr_now( screenshot_disp );
|
||||
lv_obj_invalidate(lv_scr_act());
|
||||
lv_disp_set_default( system_disp );
|
||||
lv_refr_now( system_disp );
|
||||
|
||||
// free(image);
|
||||
}
|
||||
|
||||
static void screenshot_disp_flush( lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p ) {
|
||||
|
||||
int32_t x, y;
|
||||
for(y = area->y1; y <= area->y2; y++) {
|
||||
// Serial.printf("refresh Y=%d\r\n",y);
|
||||
// for(x = area->x1; x <= area->x2; x++) {
|
||||
// }
|
||||
}
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
36
src/gui/screenshot.h
Normal file
36
src/gui/screenshot.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef _SCREENSHOT_H
|
||||
#define _SCREENSHOT_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
void screenshot_setup( void );
|
||||
void screenshot_take( void );
|
||||
|
||||
struct _PNG_HEADER {
|
||||
uint8_t png[8] = { 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a };
|
||||
uint32_t len = 13;
|
||||
uint8_t IHDR[4] = { 'I', 'H', 'D', 'R' };
|
||||
uint32_t width = LV_HOR_RES_MAX;
|
||||
uint32_t height = LV_VER_RES_MAX;
|
||||
uint8_t bitdepth = 8;
|
||||
uint8_t colortype = 2;
|
||||
uint8_t compression = 0;
|
||||
uint8_t filter = 0;
|
||||
uint8_t interlace_method = 0;
|
||||
uint32_t crc = 0;
|
||||
};
|
||||
|
||||
struct _PNG_RGB_PIXEL {
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
struct _PNG_IDAT_CHUNCK {
|
||||
uint32_t len;
|
||||
uint8_t IDAT[ 4 ] = { 'I', 'D', 'A', 'T' };
|
||||
uint8_t data[ LV_HOR_RES_MAX * LV_VER_RES_MAX * sizeof( _PNG_RGB_PIXEL ) ];
|
||||
uint32_t crc;
|
||||
};
|
||||
|
||||
#endif // _SCREENSHOT_H
|
||||
61
src/gui/splashscreen.cpp
Normal file
61
src/gui/splashscreen.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "hardware/display.h"
|
||||
|
||||
lv_obj_t *preload = NULL;
|
||||
lv_obj_t *preload_label = NULL;
|
||||
lv_style_t style;
|
||||
|
||||
void splash_screen_stage_one( TTGOClass *ttgo ) {
|
||||
lv_style_init( &style );
|
||||
lv_style_set_radius(&style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_bg_color(&style, LV_OBJ_PART_MAIN, LV_COLOR_BLACK);
|
||||
lv_style_set_bg_opa(&style, LV_OBJ_PART_MAIN, LV_OPA_100);
|
||||
lv_style_set_border_width(&style, LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_text_color(&style, LV_OBJ_PART_MAIN, LV_COLOR_WHITE);
|
||||
|
||||
lv_obj_t *background = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size( background, LV_HOR_RES_MAX, LV_VER_RES_MAX );
|
||||
lv_obj_add_style( background, LV_OBJ_PART_MAIN, &style );
|
||||
lv_obj_align(background, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
preload = lv_bar_create( background, NULL);
|
||||
lv_obj_set_size(preload, LV_HOR_RES_MAX - 40, 20);
|
||||
lv_obj_add_style( preload, LV_OBJ_PART_MAIN, &style );
|
||||
lv_obj_align(preload, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_bar_set_anim_time(preload, 2000);
|
||||
lv_bar_set_value(preload, 0, LV_ANIM_ON);
|
||||
|
||||
preload_label = lv_label_create( background, NULL);
|
||||
lv_label_set_text( preload_label, "booting" );
|
||||
lv_obj_add_style( preload_label, LV_OBJ_PART_MAIN, &style );
|
||||
lv_obj_align(preload_label, preload, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
|
||||
|
||||
lv_disp_trig_activity(NULL);
|
||||
lv_task_handler();
|
||||
|
||||
for( int bl = 0 ; bl < display_get_brightness() ; bl++ ) {
|
||||
ttgo->bl->adjust( bl );
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void splash_screen_stage_update( const char* msg, int value ) {
|
||||
lv_disp_trig_activity(NULL);
|
||||
lv_task_handler();
|
||||
delay(100);
|
||||
lv_bar_set_value( preload, value, LV_ANIM_ON);
|
||||
lv_label_set_text( preload_label, msg );
|
||||
lv_obj_align( preload_label, preload, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
|
||||
lv_task_handler();
|
||||
}
|
||||
|
||||
void splash_screen_stage_finish( TTGOClass *ttgo ) {
|
||||
ttgo->bl->adjust( 0 );
|
||||
for( int bl = display_get_brightness() ; bl > 0 ; bl-- ) {
|
||||
ttgo->bl->adjust( bl );
|
||||
delay(1);
|
||||
}
|
||||
lv_obj_del( preload );
|
||||
lv_task_handler();
|
||||
}
|
||||
24
src/gui/splashscreen.h
Normal file
24
src/gui/splashscreen.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef _SPLASHSCREEN_H
|
||||
#define _SPLASHSCREEN_H
|
||||
|
||||
/*
|
||||
* @brief start splashscreen
|
||||
*
|
||||
* @param ttgo pointer to TTGOClass
|
||||
*/
|
||||
void splash_screen_stage_one( TTGOClass *ttgo );
|
||||
/*
|
||||
* @brief update spash screen text and bar
|
||||
*
|
||||
* @param msg splash screen text
|
||||
* @param value splash screen bar value (0-100)
|
||||
*/
|
||||
void splash_screen_stage_update( const char* msg, int value );
|
||||
/*
|
||||
* @brief finish splashscreen
|
||||
*
|
||||
* @param ttgo pointer to TTGOClass
|
||||
*/
|
||||
void splash_screen_stage_finish( TTGOClass *ttgo );
|
||||
|
||||
#endif // _SPLASHSCREEN_H
|
||||
337
src/gui/statusbar.cpp
Normal file
337
src/gui/statusbar.cpp
Normal file
@@ -0,0 +1,337 @@
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "config.h"
|
||||
#include <Arduino.h>
|
||||
#include <time.h>
|
||||
#include "gui.h"
|
||||
#include <WiFi.h>
|
||||
#include "string.h"
|
||||
#include <Ticker.h>
|
||||
#include "FS.h"
|
||||
#include "SD.h"
|
||||
|
||||
#include "statusbar.h"
|
||||
|
||||
#include "hardware/motor.h"
|
||||
#include "hardware/powermgm.h"
|
||||
#include "hardware/wifictl.h"
|
||||
|
||||
static lv_obj_t *statusbar = NULL;
|
||||
static lv_obj_t *statusbar_wifi = NULL;
|
||||
static lv_obj_t *statusbar_wifilabel = NULL;
|
||||
static lv_obj_t *statusbar_bluetooth = NULL;
|
||||
static lv_obj_t *statusbar_bluetoothlabel = NULL;
|
||||
static lv_obj_t *statusbar_stepcounterlabel = NULL;
|
||||
static lv_style_t statusbarstyle[ STATUSBAR_STYLE_NUM ];
|
||||
|
||||
lv_status_bar_t statusicon[ STATUSBAR_NUM ] =
|
||||
{
|
||||
{ NULL, NULL, LV_ALIGN_IN_TOP_RIGHT, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||
{ NULL, LV_SYMBOL_BATTERY_FULL, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||
{ NULL, LV_SYMBOL_WIFI, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||
{ NULL, LV_SYMBOL_BELL, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||
{ NULL, LV_SYMBOL_WARNING, LV_ALIGN_OUT_LEFT_MID, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] },
|
||||
};
|
||||
|
||||
void statusbar_event( lv_obj_t * statusbar, lv_event_t event );
|
||||
void statusbar_wifi_event_cb( lv_obj_t *wifi, lv_event_t event );
|
||||
void statusbar_bluetooth_event_cb( lv_obj_t *wifi, lv_event_t event );
|
||||
|
||||
LV_IMG_DECLARE(wifi_64px);
|
||||
LV_IMG_DECLARE(bluetooth_64px);
|
||||
LV_IMG_DECLARE(foot_16px);
|
||||
|
||||
/**
|
||||
* Create a demo application
|
||||
*/
|
||||
void statusbar_setup( void )
|
||||
{
|
||||
/*Copy a built-in style to initialize the new style*/
|
||||
lv_style_init(&statusbarstyle[ STATUSBAR_STYLE_NORMAL ] );
|
||||
lv_style_set_radius(&statusbarstyle[ STATUSBAR_STYLE_NORMAL ], LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_bg_color(&statusbarstyle[ STATUSBAR_STYLE_NORMAL ], LV_OBJ_PART_MAIN, LV_COLOR_WHITE);
|
||||
lv_style_set_bg_opa(&statusbarstyle[ STATUSBAR_STYLE_NORMAL ], LV_OBJ_PART_MAIN, LV_OPA_20);
|
||||
lv_style_set_border_width(&statusbarstyle[ STATUSBAR_STYLE_NORMAL ], LV_OBJ_PART_MAIN, 0);
|
||||
lv_style_set_text_color(&statusbarstyle[ STATUSBAR_STYLE_NORMAL ], LV_OBJ_PART_MAIN, LV_COLOR_WHITE);
|
||||
lv_style_set_image_recolor(&statusbarstyle[ STATUSBAR_STYLE_NORMAL ], LV_OBJ_PART_MAIN, LV_COLOR_WHITE);
|
||||
|
||||
lv_style_copy( &statusbarstyle[ STATUSBAR_STYLE_WHITE ], &statusbarstyle[ STATUSBAR_STYLE_WHITE ] );
|
||||
lv_style_set_bg_opa(&statusbarstyle[ STATUSBAR_STYLE_WHITE ], LV_OBJ_PART_MAIN, LV_OPA_0);
|
||||
lv_style_set_text_color(&statusbarstyle[ STATUSBAR_STYLE_WHITE ], LV_OBJ_PART_MAIN, LV_COLOR_WHITE);
|
||||
lv_style_set_image_recolor(&statusbarstyle[ STATUSBAR_STYLE_WHITE ], LV_OBJ_PART_MAIN, LV_COLOR_WHITE);
|
||||
|
||||
lv_style_copy( &statusbarstyle[ STATUSBAR_STYLE_RED ], &statusbarstyle[ STATUSBAR_STYLE_NORMAL ] );
|
||||
lv_style_set_bg_opa(&statusbarstyle[ STATUSBAR_STYLE_RED ], LV_OBJ_PART_MAIN, LV_OPA_0);
|
||||
lv_style_set_text_color(&statusbarstyle[ STATUSBAR_STYLE_RED ], LV_OBJ_PART_MAIN, LV_COLOR_RED);
|
||||
lv_style_set_image_recolor(&statusbarstyle[ STATUSBAR_STYLE_RED ], LV_OBJ_PART_MAIN, LV_COLOR_RED);
|
||||
|
||||
lv_style_copy( &statusbarstyle[ STATUSBAR_STYLE_GRAY ], &statusbarstyle[ STATUSBAR_STYLE_NORMAL ] );
|
||||
lv_style_set_bg_opa(&statusbarstyle[ STATUSBAR_STYLE_GRAY ], LV_OBJ_PART_MAIN, LV_OPA_0);
|
||||
lv_style_set_text_color(&statusbarstyle[ STATUSBAR_STYLE_GRAY ], LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||
lv_style_set_image_recolor(&statusbarstyle[ STATUSBAR_STYLE_GRAY ], LV_OBJ_PART_MAIN, LV_COLOR_GRAY);
|
||||
|
||||
lv_style_copy( &statusbarstyle[ STATUSBAR_STYLE_GREEN ], &statusbarstyle[ STATUSBAR_STYLE_NORMAL ] );
|
||||
lv_style_set_bg_opa(&statusbarstyle[ STATUSBAR_STYLE_GREEN ], LV_OBJ_PART_MAIN, LV_OPA_0);
|
||||
lv_style_set_text_color(&statusbarstyle[ STATUSBAR_STYLE_GREEN ], LV_OBJ_PART_MAIN, LV_COLOR_GREEN);
|
||||
lv_style_set_image_recolor(&statusbarstyle[ STATUSBAR_STYLE_GREEN ], LV_OBJ_PART_MAIN, LV_COLOR_GREEN);
|
||||
|
||||
lv_style_copy( &statusbarstyle[ STATUSBAR_STYLE_YELLOW ], &statusbarstyle[ STATUSBAR_STYLE_NORMAL ] );
|
||||
lv_style_set_bg_opa(&statusbarstyle[ STATUSBAR_STYLE_YELLOW ], LV_OBJ_PART_MAIN, LV_OPA_0);
|
||||
lv_style_set_text_color(&statusbarstyle[ STATUSBAR_STYLE_YELLOW ], LV_OBJ_PART_MAIN, LV_COLOR_YELLOW);
|
||||
lv_style_set_image_recolor(&statusbarstyle[ STATUSBAR_STYLE_YELLOW ], LV_OBJ_PART_MAIN, LV_COLOR_YELLOW);
|
||||
|
||||
lv_style_copy( &statusbarstyle[ STATUSBAR_STYLE_BLUE ], &statusbarstyle[ STATUSBAR_STYLE_NORMAL ] );
|
||||
lv_style_set_bg_opa(&statusbarstyle[ STATUSBAR_STYLE_BLUE ], LV_OBJ_PART_MAIN, LV_OPA_0);
|
||||
lv_style_set_text_color(&statusbarstyle[ STATUSBAR_STYLE_BLUE ], LV_OBJ_PART_MAIN, LV_COLOR_BLUE);
|
||||
lv_style_set_image_recolor(&statusbarstyle[ STATUSBAR_STYLE_BLUE ], LV_OBJ_PART_MAIN, LV_COLOR_BLUE);
|
||||
|
||||
statusbar = lv_cont_create( lv_scr_act(), NULL );
|
||||
lv_obj_set_width( statusbar, lv_disp_get_hor_res( NULL ) );
|
||||
lv_obj_set_height( statusbar, STATUSBAR_HEIGHT );
|
||||
lv_obj_reset_style_list( statusbar, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( statusbar, LV_OBJ_PART_MAIN, &statusbarstyle[ STATUSBAR_STYLE_NORMAL ] );
|
||||
lv_obj_align( statusbar, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0 );
|
||||
lv_obj_set_event_cb( statusbar, statusbar_event );
|
||||
|
||||
for( int i = 0 ; i < STATUSBAR_NUM ; i++ ) {
|
||||
if ( statusicon[i].symbol == NULL ) {
|
||||
statusicon[i].icon = lv_label_create( statusbar, NULL);
|
||||
lv_label_set_text( statusicon[i].icon, "100%" );
|
||||
}
|
||||
else {
|
||||
statusicon[i].icon = lv_img_create( statusbar , NULL);
|
||||
lv_img_set_src( statusicon[i].icon, statusicon[i].symbol );
|
||||
}
|
||||
lv_obj_reset_style_list( statusicon[i].icon, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( statusicon[i].icon, LV_OBJ_PART_MAIN, statusicon[i].style );
|
||||
if ( i == 0 )
|
||||
lv_obj_align(statusicon[i].icon, NULL, statusicon[i].align, -5, 4);
|
||||
else
|
||||
lv_obj_align(statusicon[i].icon, statusicon[i-1].icon, statusicon[i].align, -5, 0);
|
||||
}
|
||||
|
||||
static lv_style_t style;
|
||||
lv_style_init(&style);
|
||||
lv_style_copy( &style, &statusbarstyle[ STATUSBAR_STYLE_GRAY ] );
|
||||
|
||||
lv_style_set_image_recolor_opa(&style, LV_BTN_STATE_RELEASED, LV_OPA_100);
|
||||
lv_style_set_image_recolor(&style, LV_BTN_STATE_RELEASED, LV_COLOR_GRAY);
|
||||
lv_style_set_image_recolor_opa(&style, LV_BTN_STATE_PRESSED, LV_OPA_100);
|
||||
lv_style_set_image_recolor(&style, LV_BTN_STATE_PRESSED, LV_COLOR_GREEN);
|
||||
lv_style_set_image_recolor_opa(&style, LV_BTN_STATE_CHECKED_RELEASED, LV_OPA_100);
|
||||
lv_style_set_image_recolor(&style, LV_BTN_STATE_CHECKED_RELEASED, LV_COLOR_GRAY);
|
||||
lv_style_set_image_recolor_opa(&style, LV_BTN_STATE_CHECKED_PRESSED, LV_OPA_100);
|
||||
lv_style_set_image_recolor(&style, LV_BTN_STATE_CHECKED_PRESSED, LV_COLOR_GRAY);
|
||||
lv_style_set_image_recolor_opa(&style, LV_BTN_STATE_DISABLED, LV_OPA_100);
|
||||
lv_style_set_image_recolor(&style, LV_BTN_STATE_DISABLED, LV_COLOR_GREEN);
|
||||
|
||||
statusbar_wifi = lv_imgbtn_create( statusbar, NULL);
|
||||
lv_imgbtn_set_src(statusbar_wifi, LV_BTN_STATE_RELEASED, &wifi_64px);
|
||||
lv_imgbtn_set_src(statusbar_wifi, LV_BTN_STATE_PRESSED, &wifi_64px);
|
||||
lv_imgbtn_set_src(statusbar_wifi, LV_BTN_STATE_CHECKED_RELEASED, &wifi_64px);
|
||||
lv_imgbtn_set_src(statusbar_wifi, LV_BTN_STATE_CHECKED_PRESSED, &wifi_64px);
|
||||
lv_imgbtn_set_checkable(statusbar_wifi, true);
|
||||
lv_obj_add_style(statusbar_wifi, LV_IMGBTN_PART_MAIN, &style );
|
||||
lv_obj_align(statusbar_wifi, statusbar, LV_ALIGN_CENTER, 0, STATUSBAR_EXPAND_HEIGHT / 2 );
|
||||
lv_obj_set_event_cb(statusbar_wifi, statusbar_wifi_event_cb );
|
||||
lv_imgbtn_set_state( statusbar_wifi, LV_BTN_STATE_CHECKED_RELEASED );
|
||||
|
||||
/*Create a label on the Image button*/
|
||||
statusbar_wifilabel = lv_label_create(statusbar, NULL);
|
||||
lv_obj_reset_style_list( statusbar_wifilabel, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( statusbar_wifilabel, LV_OBJ_PART_MAIN, &statusbarstyle[ STATUSBAR_STYLE_GREEN ] );
|
||||
lv_label_set_text(statusbar_wifilabel, "");
|
||||
lv_obj_align(statusbar_wifilabel, statusbar_wifi, LV_ALIGN_OUT_BOTTOM_MID, 0, 0 );
|
||||
|
||||
lv_obj_t *statusbar_stepicon = lv_img_create(statusbar, NULL );
|
||||
lv_img_set_src( statusbar_stepicon, &foot_16px );
|
||||
lv_obj_reset_style_list( statusbar_stepicon, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( statusbar_stepicon, LV_OBJ_PART_MAIN, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] );
|
||||
lv_obj_align(statusbar_stepicon, statusbar, LV_ALIGN_IN_TOP_LEFT, 5, 4 );
|
||||
|
||||
statusbar_stepcounterlabel = lv_label_create(statusbar, NULL);
|
||||
lv_obj_reset_style_list( statusbar_stepcounterlabel, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( statusbar_stepcounterlabel, LV_OBJ_PART_MAIN, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] );
|
||||
lv_label_set_text(statusbar_stepcounterlabel, "0");
|
||||
lv_obj_align(statusbar_stepcounterlabel, statusbar_stepicon, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||
|
||||
statusbar_hide_icon( STATUSBAR_BELL );
|
||||
statusbar_hide_icon( STATUSBAR_WARNING );
|
||||
statusbar_hide_icon( STATUSBAR_WIFI );
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_wifi_event_cb( lv_obj_t *wifi, lv_event_t event ) {
|
||||
if ( event == LV_EVENT_VALUE_CHANGED ) {
|
||||
switch ( lv_imgbtn_get_state( wifi ) ) {
|
||||
case( LV_BTN_STATE_CHECKED_RELEASED ): wifictl_off();
|
||||
break;
|
||||
case( LV_BTN_STATE_RELEASED ): wifictl_on();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
motor_vibe( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_bluetooth_event_cb( lv_obj_t *wifi, lv_event_t event ) {
|
||||
if ( event == LV_EVENT_VALUE_CHANGED ) {
|
||||
switch ( lv_imgbtn_get_state( wifi ) ) {
|
||||
case( LV_BTN_STATE_RELEASED ): break;
|
||||
case( LV_BTN_STATE_PRESSED ): break;
|
||||
default: break;
|
||||
}
|
||||
motor_vibe( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_wifi_set_state( bool state, const char *wifiname ) {
|
||||
if( state ) {
|
||||
lv_imgbtn_set_state( statusbar_wifi, LV_BTN_STATE_RELEASED );
|
||||
}
|
||||
else {
|
||||
lv_imgbtn_set_state( statusbar_wifi, LV_BTN_STATE_CHECKED_RELEASED );
|
||||
}
|
||||
lv_label_set_text( statusbar_wifilabel, wifiname );
|
||||
lv_obj_align( statusbar_wifilabel, statusbar_wifi, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||
statusbar_refresh();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_bluetooth_set_state( bool state ) {
|
||||
if ( state ) {
|
||||
lv_imgbtn_set_state( statusbar_bluetooth, LV_BTN_STATE_RELEASED );
|
||||
}
|
||||
else {
|
||||
lv_imgbtn_set_state( statusbar_bluetooth, LV_BTN_STATE_PRESSED );
|
||||
}
|
||||
statusbar_refresh();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_hide_icon( int icon ) {
|
||||
if ( icon >= STATUSBAR_NUM ) return;
|
||||
|
||||
lv_obj_set_hidden( statusicon[ icon ].icon, true );
|
||||
statusbar_refresh();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_show_icon( int icon ) {
|
||||
if ( icon >= STATUSBAR_NUM ) return;
|
||||
|
||||
lv_obj_set_hidden( statusicon[ icon ].icon, false );
|
||||
statusbar_refresh();
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_style_icon( int icon, int style ) {
|
||||
if ( icon >= STATUSBAR_NUM || style >= STATUSBAR_STYLE_NUM ) return;
|
||||
|
||||
statusicon[ icon ].style = &statusbarstyle[ style ];
|
||||
statusbar_refresh();
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_refresh( void ) {
|
||||
for ( int i = 0 ; i < STATUSBAR_NUM ; i++ ) {
|
||||
if ( !lv_obj_get_hidden( statusicon[ i ].icon ) ) {
|
||||
if ( i == 0 ) {
|
||||
lv_obj_align( statusicon[ i ].icon, NULL, statusicon[ i ].align, -5, 4);
|
||||
} else {
|
||||
lv_obj_align( statusicon[ i ].icon, statusicon[ i - 1 ].icon, statusicon[ i ].align, -5, 0);
|
||||
}
|
||||
lv_obj_reset_style_list( statusicon[ i ].icon, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( statusicon[ i ].icon, LV_OBJ_PART_MAIN, statusicon[i].style );
|
||||
// lv_obj_set_style( statusicon[ i ].icon, statusicon[i].style );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_event( lv_obj_t * statusbar, lv_event_t event ) {
|
||||
if ( event == LV_EVENT_PRESSED ) {
|
||||
lv_obj_set_height( statusbar, STATUSBAR_EXPAND_HEIGHT );
|
||||
lv_style_set_bg_opa(&statusbarstyle[ STATUSBAR_STYLE_NORMAL ], LV_OBJ_PART_MAIN, LV_OPA_50);
|
||||
lv_obj_reset_style_list( statusbar, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( statusbar, LV_OBJ_PART_MAIN, &statusbarstyle[ STATUSBAR_STYLE_NORMAL ] );
|
||||
}
|
||||
else if ( event == LV_EVENT_RELEASED ) {
|
||||
lv_obj_set_height( statusbar, STATUSBAR_HEIGHT );
|
||||
lv_style_set_bg_opa(&statusbarstyle[ STATUSBAR_STYLE_NORMAL ], LV_OBJ_PART_MAIN, LV_OPA_20);
|
||||
lv_obj_reset_style_list( statusbar, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( statusbar, LV_OBJ_PART_MAIN, &statusbarstyle[ STATUSBAR_STYLE_NORMAL ] );
|
||||
}
|
||||
statusbar_refresh();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_update_stepcounter( int step ) {
|
||||
char stepcounter[12]="";
|
||||
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 ) {
|
||||
char level[8]="";
|
||||
snprintf( level, sizeof( level ), "%d%%", percent );
|
||||
lv_label_set_text( statusicon[ STATUSBAR_BATTERY_PERCENT ].icon, (const char *)level );
|
||||
|
||||
if ( charging && plug ) {
|
||||
lv_img_set_src( statusicon[ STATUSBAR_BATTERY ].icon, LV_SYMBOL_CHARGE );
|
||||
statusbar_style_icon( STATUSBAR_BATTERY, STATUSBAR_STYLE_RED );
|
||||
}
|
||||
else {
|
||||
if ( percent >= 75 ) {
|
||||
lv_img_set_src( statusicon[ STATUSBAR_BATTERY ].icon, LV_SYMBOL_BATTERY_FULL );
|
||||
} else if( percent >=50 && percent < 74) {
|
||||
lv_img_set_src( statusicon[ STATUSBAR_BATTERY ].icon, LV_SYMBOL_BATTERY_3 );
|
||||
} else if( percent >=35 && percent < 49) {
|
||||
lv_img_set_src( statusicon[ STATUSBAR_BATTERY ].icon, LV_SYMBOL_BATTERY_2 );
|
||||
} else if( percent >=15 && percent < 34) {
|
||||
lv_img_set_src( statusicon[ STATUSBAR_BATTERY ].icon, LV_SYMBOL_BATTERY_1 );
|
||||
} else if( percent >=0 && percent < 14) {
|
||||
lv_img_set_src( statusicon[ STATUSBAR_BATTERY ].icon, LV_SYMBOL_BATTERY_EMPTY );
|
||||
}
|
||||
|
||||
if ( percent >= 25 ) {
|
||||
statusbar_style_icon( STATUSBAR_BATTERY, STATUSBAR_STYLE_WHITE );
|
||||
}
|
||||
else if ( percent >= 15 ) {
|
||||
statusbar_style_icon( STATUSBAR_BATTERY, STATUSBAR_STYLE_YELLOW );
|
||||
}
|
||||
else {
|
||||
statusbar_style_icon( STATUSBAR_BATTERY, STATUSBAR_STYLE_RED );
|
||||
}
|
||||
|
||||
if ( plug ) {
|
||||
statusbar_style_icon( STATUSBAR_BATTERY, STATUSBAR_STYLE_GREEN );
|
||||
}
|
||||
}
|
||||
statusbar_refresh();
|
||||
}
|
||||
51
src/gui/statusbar.h
Normal file
51
src/gui/statusbar.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef _STATUSBAR_H
|
||||
|
||||
#define _STATUSBAR_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define STATUSBAR_HEIGHT 26
|
||||
#define STATUSBAR_EXPAND_HEIGHT 128
|
||||
|
||||
typedef struct {
|
||||
lv_obj_t *icon;
|
||||
const void *symbol;
|
||||
lv_align_t align;
|
||||
lv_style_t *style;
|
||||
} lv_status_bar_t;
|
||||
|
||||
enum {
|
||||
STATUSBAR_BATTERY_PERCENT,
|
||||
STATUSBAR_BATTERY,
|
||||
STATUSBAR_WIFI,
|
||||
STATUSBAR_BELL,
|
||||
STATUSBAR_WARNING,
|
||||
STATUSBAR_NUM
|
||||
};
|
||||
|
||||
enum {
|
||||
STATUSBAR_STYLE_NORMAL,
|
||||
STATUSBAR_STYLE_WHITE,
|
||||
STATUSBAR_STYLE_RED,
|
||||
STATUSBAR_STYLE_GRAY,
|
||||
STATUSBAR_STYLE_YELLOW,
|
||||
STATUSBAR_STYLE_GREEN,
|
||||
STATUSBAR_STYLE_BLUE,
|
||||
STATUSBAR_STYLE_NUM
|
||||
};
|
||||
|
||||
void statusbar_setup( void );
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void statusbar_hide_icon( int icon );
|
||||
void statusbar_show_icon( int icon );
|
||||
void statusbar_style_icon( int icon, int style );
|
||||
void statusbar_refresh( void );
|
||||
void statusbar_update_stepcounter( int step );
|
||||
void statusbar_update_battery( uint32_t percent, bool charging, bool plug );
|
||||
void statusbar_wifi_set_state( bool state, const char *wifiname );
|
||||
void statusbar_bluetooth_set_state( bool state );
|
||||
|
||||
#endif // _STATUSBAR_H
|
||||
|
||||
Reference in New Issue
Block a user