Add new objects and attributes

This commit is contained in:
fvanroie 2020-04-21 10:49:45 +02:00
parent 7b8710ff35
commit cd658dd070
7 changed files with 115 additions and 37 deletions

View File

@ -631,14 +631,14 @@ typedef uint8_t lv_obj_user_data_t;
#endif
/*Tab (dependencies: lv_page, lv_btnm)*/
#define LV_USE_TABVIEW (LV_HIGH_RESOURCE_MCU)
#define LV_USE_TABVIEW 1
# if LV_USE_TABVIEW != 0
/*Time of slide animation [ms] (0: no animation)*/
# define LV_TABVIEW_DEF_ANIM_TIME 300
#endif
/*Tileview (dependencies: lv_page) */
#define LV_USE_TILEVIEW (LV_HIGH_RESOURCE_MCU)
#define LV_USE_TILEVIEW 1
#if LV_USE_TILEVIEW
/*Time of slide animation [ms] (0: no animation)*/
# define LV_TILEVIEW_DEF_ANIM_TIME 300

View File

@ -151,7 +151,7 @@ static lv_fs_res_t fs_open(lv_fs_drv_t * drv, void * file_p, const char * path,
lv_spiffs_file_t * fp = (lv_spiffs_file_t *)file_p; /*Just avoid the confusing casings*/
// Log.verbose(F("LVFS: Copying %s"), f.name());
Log.verbose(F("LVFS: %d"), __LINE__);
*fp = file;
if (fp != NULL) (*fp) = file;
// memcpy(fp,&file,sizeof(lv_spiffs_file_t));
Log.verbose(F("LVFS: %d"), __LINE__);
return LV_FS_RES_OK;

View File

@ -9,25 +9,23 @@
#include "lvgl.h"
#include "lv_conf.h"
#define LVGL7 1
//#include "../lib/lvgl/src/lv_widgets/lv_roller.h"
#if HASP_USE_SPIFFS
#if defined(ARDUINO_ARCH_ESP32)
#include "lv_zifont.h"
#include "SPIFFS.h"
#endif
#include "lv_zifont.h"
#include <FS.h> // Include the SPIFFS library
#endif
#include "lv_fs_if.h"
#include "hasp_debug.h"
#include "hasp_config.h"
#include "hasp_dispatch.h"
#include "hasp_wifi.h"
#include "hasp_gui.h"
#include "hasp_tft.h"
#include "lv_zifont.h"
//#include "hasp_attr_get.h"
#include "hasp_attribute.h"
#include "hasp.h"
@ -162,6 +160,19 @@ lv_obj_t * hasp_find_obj_from_id(lv_obj_t * parent, uint8_t objid)
lv_obj_t * grandchild = hasp_find_obj_from_id(child, objid);
if(grandchild) return grandchild;
/* check tabs */
if(check_obj_type(child, LV_HASP_TABVIEW)) {
uint16_t tabcount = lv_tabview_get_tab_count(child);
for(uint16_t i = 0; i < tabcount; i++) {
lv_obj_t * tab = lv_tabview_get_tab(child, i);
Log.verbose("Found tab %i", i);
if(tab->user_data && (lv_obj_user_data_t)objid == tab->user_data) return tab; // object found
grandchild = hasp_find_obj_from_id(tab, objid);
if(grandchild) return grandchild;
}
}
/* next sibling */
child = lv_obj_get_child(parent, child);
}
@ -329,34 +340,33 @@ void haspSetup()
// static lv_font_t *
// my_font = (lv_font_t *)lv_mem_alloc(sizeof(lv_font_t));
/******* File SustemTest ********************************************************************
lv_fs_init();
lv_fs_file_t f;
lv_fs_res_t res;
res = lv_fs_open(&f, "F:/pages.jsonl", LV_FS_MODE_RD);
if(res == LV_FS_RES_OK)
Log.error(F("Opening pages.json OK"));
else
Log.verbose(F("Opening pages.json from FS failed %d"), res);
/******* File System Test ********************************************************************/
lv_fs_file_t f;
lv_fs_res_t res;
res = lv_fs_open(&f, "F:/pages.jsonl", LV_FS_MODE_RD);
if(res == LV_FS_RES_OK)
Log.error(F("Opening pages.json OK"));
else
Log.verbose(F("Opening pages.json from FS failed %d"), res);
uint32_t btoread = 128;
uint32_t bread = 0;
char buffer[128];
uint32_t btoread = 128;
uint32_t bread = 0;
char buffer[128];
res = lv_fs_read(&f, buffer, 128, &bread);
if(res == LV_FS_RES_OK) {
Log.error(F("Reading pages.json OK %u"), bread);
buffer[127] = '\0';
Log.verbose(buffer);
} else
Log.verbose(F("Reading pages.json from FS failed %d"), res);
res = lv_fs_read(&f, &buffer, btoread, &bread);
if(res == LV_FS_RES_OK) {
Log.error(F("Reading pages.json OK %u"), bread);
buffer[127] = '\0';
Log.verbose(buffer);
} else
Log.verbose(F("Reading pages.json from FS failed %d"), res);
res = lv_fs_close(&f);
if(res == LV_FS_RES_OK)
Log.error(F("Closing pages.json OK"));
else
Log.verbose(F("Closing pages.json on FS failed %d"), res);
******* File SustemTest ********************************************************************/
res = lv_fs_close(&f);
if(res == LV_FS_RES_OK)
Log.error(F("Closing pages.json OK"));
else
Log.verbose(F("Closing pages.json on FS failed %d"), res);
/******* File System Test ********************************************************************/
/* ********** Font Initializations ********** */
lv_zifont_init();
@ -653,7 +663,7 @@ void haspClearPage(uint16_t pageid)
Log.warning(F("HASP: Cannot clear a layer"));
} else {
Log.notice(F("HASP: Clearing page %u"), pageid);
lv_obj_clean(pages[pageid]);
lv_page_clean(pages[pageid]);
}
}
@ -763,6 +773,11 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id)
lv_obj_set_event_cb(obj, btn_event_handler);
break;
}
case LV_HASP_IMAGE: {
obj = lv_img_create(parent_obj, NULL);
lv_obj_set_event_cb(obj, btn_event_handler);
break;
}
case LV_HASP_ARC: {
obj = lv_arc_create(parent_obj, NULL);
lv_obj_set_event_cb(obj, btn_event_handler);
@ -773,6 +788,30 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id)
lv_obj_set_event_cb(obj, btn_event_handler);
break;
}
case LV_HASP_OBJECT: {
obj = lv_obj_create(parent_obj, NULL);
lv_obj_set_event_cb(obj, btn_event_handler);
break;
}
case LV_HASP_PAGE: {
obj = lv_page_create(parent_obj, NULL);
break;
}
case LV_HASP_TABVIEW: {
obj = lv_tabview_create(parent_obj, NULL);
lv_obj_t * tab;
tab = lv_tabview_add_tab(obj, "tab 1");
lv_obj_set_user_data(tab, id + 1);
tab = lv_tabview_add_tab(obj, "tab 2");
lv_obj_set_user_data(tab, id + 2);
tab = lv_tabview_add_tab(obj, "tab 3");
lv_obj_set_user_data(tab, id + 3);
break;
}
case LV_HASP_TILEVIEW: {
obj = lv_tileview_create(parent_obj, NULL);
break;
}
/* ----- Color Objects ------ */
case LV_HASP_CPICKER: {
@ -830,7 +869,7 @@ void haspNewObject(const JsonObject & config, uint8_t & saved_page_id)
obj = lv_dropdown_create(parent_obj, NULL);
// lv_dropdown_set_fix_width(obj, width);
lv_dropdown_set_draw_arrow(obj, true);
lv_dropdown_set_anim_time(obj, 200);
// lv_dropdown_set_anim_time(obj, 200);
lv_obj_set_top(obj, true);
// lv_obj_align(obj, NULL, LV_ALIGN_IN_TOP_MID, 0, 20);
lv_obj_set_event_cb(obj, ddlist_event_handler);

View File

@ -49,7 +49,14 @@ enum lv_hasp_obj_type_t {
LV_HASP_DDLIST = 50,
LV_HASP_ROLLER = 51,
LV_HASP_IMAGE = 60,
LV_HASP_TABVIEW = 70,
LV_HASP_TILEVIEW = 71,
LV_HASP_CONTAINER = 90,
LV_HASP_OBJECT = 91,
LV_HASP_PAGE = 92,
};
/**********************

View File

@ -693,6 +693,23 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char
case ATTR_HIDDEN:
return update ? lv_obj_set_hidden(obj, is_true(payload)) : hasp_out_int(obj, attr, lv_obj_get_hidden(obj));
case ATTR_SRC:
if(check_obj_type(obj, LV_HASP_IMAGE)) {
if(update) {
return lv_img_set_src(obj, payload);
} else {
switch(lv_img_src_get_type(obj)) {
case LV_IMG_SRC_FILE:
return hasp_out_str(obj, attr, lv_img_get_file_name(obj));
case LV_IMG_SRC_SYMBOL:
return hasp_out_str(obj, attr, (char *)lv_img_get_src(obj));
default:
return;
}
}
}
break;
case ATTR_ROWS:
if(check_obj_type(obj, LV_HASP_ROLLER)) {
return update ? lv_roller_set_visible_row_count(obj, (uint8_t)val)
@ -837,8 +854,18 @@ bool check_obj_type(const char * lvobjtype, lv_hasp_obj_type_t haspobjtype)
return (strcmp_P(lvobjtype, PSTR("switch")) == 0); // || (strcmp_P(lvobjtype, PSTR("lv_sw")) == 0)
case LV_HASP_LED:
return (strcmp_P(lvobjtype, PSTR("led")) == 0);
case LV_HASP_IMAGE:
return (strcmp_P(lvobjtype, PSTR("img")) == 0);
case LV_HASP_CONTAINER:
return (strcmp_P(lvobjtype, PSTR("container")) == 0); // || (strcmp_P(lvobjtype, PSTR("lv_cont")) == 0)
case LV_HASP_OBJECT:
return (strcmp_P(lvobjtype, PSTR("page")) == 0); // || (strcmp_P(lvobjtype, PSTR("lv_cont")) == 0)
case LV_HASP_PAGE:
return (strcmp_P(lvobjtype, PSTR("obj")) == 0); // || (strcmp_P(lvobjtype, PSTR("lv_cont")) == 0)
case LV_HASP_TABVIEW:
return (strcmp_P(lvobjtype, PSTR("tabview")) == 0);
case LV_HASP_TILEVIEW:
return (strcmp_P(lvobjtype, PSTR("tileview")) == 0);
default:
return false;
}

View File

@ -225,6 +225,7 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t)
#define ATTR_MAX 45636
#define ATTR_VAL 15809
#define ATTR_TXT 9328
#define ATTR_SRC 4964
#define ATTR_ID 6715
#endif

View File

@ -619,9 +619,11 @@ void guiSetup()
/* allocate on iram (or psram ?) */
guiVDBsize = 16 * 1024u; // 32 KBytes * 2
static lv_disp_buf_t disp_buf;
static lv_color_t * guiVdbBuffer1 = (lv_color_t *)malloc(sizeof(lv_color_t) * guiVDBsize);
static lv_color_t * guiVdbBuffer2 = (lv_color_t *)malloc(sizeof(lv_color_t) * guiVDBsize);
lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize);
static lv_color_t * guiVdbBuffer1 =
(lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * guiVDBsize, MALLOC_CAP_8BIT);
// static lv_color_t * guiVdbBuffer2 = (lv_color_t *)malloc(sizeof(lv_color_t) * guiVDBsize);
// lv_disp_buf_init(&disp_buf, guiVdbBuffer1, guiVdbBuffer2, guiVDBsize);
lv_disp_buf_init(&disp_buf, guiVdbBuffer1, NULL, guiVDBsize);
#else
/* allocate on heap */
static lv_disp_buf_t disp_buf;
@ -665,7 +667,9 @@ void guiSetup()
Log.verbose(F("LVGL: Version : %u.%u.%u %s"), LVGL_VERSION_MAJOR, LVGL_VERSION_MINOR, LVGL_VERSION_PATCH,
PSTR(LVGL_VERSION_INFO));
Log.verbose(F("LVGL: Rotation : %d"), guiRotation);
#ifdef LV_MEM_SIZE
Log.verbose(F("LVGL: MEM size : %d"), LV_MEM_SIZE);
#endif
Log.verbose(F("LVGL: VFB size : %d"), (size_t)sizeof(lv_color_t) * guiVDBsize);
#if LV_USE_LOG != 0