mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Make page 254 page 0 instead
This commit is contained in:
parent
dad89c4224
commit
6020d6479b
@ -36,6 +36,7 @@
|
|||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
*********************/
|
*********************/
|
||||||
|
#define PAGE_START_INDEX 1 // Page number of array index 0
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
@ -72,7 +73,7 @@ static uint16_t sleepTimeShort = 60; // 1 second resolution
|
|||||||
static uint16_t sleepTimeLong = 120; // 1 second resolution
|
static uint16_t sleepTimeLong = 120; // 1 second resolution
|
||||||
|
|
||||||
uint8_t haspStartDim = 100;
|
uint8_t haspStartDim = 100;
|
||||||
uint8_t haspStartPage = 0;
|
uint8_t haspStartPage = 1;
|
||||||
uint8_t haspThemeId = 2;
|
uint8_t haspThemeId = 2;
|
||||||
uint16_t haspThemeHue = 200;
|
uint16_t haspThemeHue = 200;
|
||||||
char haspPagesPath[32] = "/pages.jsonl";
|
char haspPagesPath[32] = "/pages.jsonl";
|
||||||
@ -166,10 +167,10 @@ void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time)
|
|||||||
*/
|
*/
|
||||||
lv_obj_t * get_page_obj(uint8_t pageid)
|
lv_obj_t * get_page_obj(uint8_t pageid)
|
||||||
{
|
{
|
||||||
if(pageid == 254) return lv_layer_top();
|
if(pageid == 0) return lv_layer_top(); // 254
|
||||||
if(pageid == 255) return lv_layer_sys();
|
if(pageid == 255) return lv_layer_sys();
|
||||||
if(pageid >= sizeof pages / sizeof *pages) return NULL;
|
if(pageid > sizeof pages / sizeof *pages) return NULL; // >=0
|
||||||
return pages[pageid];
|
return pages[pageid - PAGE_START_INDEX];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_page_id(lv_obj_t * obj, uint8_t * pageid)
|
bool get_page_id(lv_obj_t * obj, uint8_t * pageid)
|
||||||
@ -179,7 +180,7 @@ bool get_page_id(lv_obj_t * obj, uint8_t * pageid)
|
|||||||
if(!page) return false;
|
if(!page) return false;
|
||||||
|
|
||||||
if(page == lv_layer_top()) {
|
if(page == lv_layer_top()) {
|
||||||
*pageid = 254;
|
*pageid = 0; // 254
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(page == lv_layer_sys()) {
|
if(page == lv_layer_sys()) {
|
||||||
@ -189,7 +190,7 @@ bool get_page_id(lv_obj_t * obj, uint8_t * pageid)
|
|||||||
|
|
||||||
for(uint8_t i = 0; i < sizeof pages / sizeof *pages; i++) {
|
for(uint8_t i = 0; i < sizeof pages / sizeof *pages; i++) {
|
||||||
if(page == pages[i]) {
|
if(page == pages[i]) {
|
||||||
*pageid = i;
|
*pageid = i + PAGE_START_INDEX;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -378,7 +379,8 @@ void haspSetup(void)
|
|||||||
switch(haspThemeId) {
|
switch(haspThemeId) {
|
||||||
#if(LV_USE_THEME_EMPTY == 1)
|
#if(LV_USE_THEME_EMPTY == 1)
|
||||||
case 0:
|
case 0:
|
||||||
th = lv_theme_empty_init(LV_COLOR_PURPLE, LV_COLOR_BLACK, LV_THEME_DEFAULT_FLAGS, haspFonts[0],
|
th = lv_theme_empty_init(lv_color_hsv_to_rgb(haspThemeHue, 100, 100),
|
||||||
|
lv_color_hsv_to_rgb(haspThemeHue, 100, 100), LV_THEME_DEFAULT_FLAGS, haspFonts[0],
|
||||||
haspFonts[1], haspFonts[2], haspFonts[3]);
|
haspFonts[1], haspFonts[2], haspFonts[3]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@ -420,10 +422,10 @@ void haspSetup(void)
|
|||||||
material_flags = LV_THEME_MATERIAL_FLAG_DARK;
|
material_flags = LV_THEME_MATERIAL_FLAG_DARK;
|
||||||
case 4: // Light
|
case 4: // Light
|
||||||
case 9: // Light (old id)
|
case 9: // Light (old id)
|
||||||
th = lv_theme_material_init(LV_COLOR_PURPLE, LV_COLOR_ORANGE,
|
th = lv_theme_material_init(
|
||||||
material_flags + LV_THEME_MATERIAL_FLAG_NO_FOCUS +
|
lv_color_hsv_to_rgb(haspThemeHue, 100, 100), lv_color_hsv_to_rgb(haspThemeHue, 100, 100),
|
||||||
LV_THEME_MATERIAL_FLAG_NO_TRANSITION,
|
material_flags + LV_THEME_MATERIAL_FLAG_NO_FOCUS + LV_THEME_MATERIAL_FLAG_NO_TRANSITION, haspFonts[0],
|
||||||
haspFonts[0], haspFonts[1], haspFonts[2], haspFonts[3]);
|
haspFonts[1], haspFonts[2], haspFonts[3]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -527,8 +529,8 @@ void haspGetVersion(char * version, size_t len)
|
|||||||
void haspClearPage(uint16_t pageid)
|
void haspClearPage(uint16_t pageid)
|
||||||
{
|
{
|
||||||
lv_obj_t * page = get_page_obj(pageid);
|
lv_obj_t * page = get_page_obj(pageid);
|
||||||
if(!page || pageid > 255) {
|
if(!page || pageid > (pageid > sizeof pages / sizeof *pages)) {
|
||||||
Log.warning(TAG_HASP, F("Page ID %u not defined"), pageid);
|
Log.warning(TAG_HASP, F("Invalid page %u"), pageid);
|
||||||
} else if(page == lv_layer_sys() /*|| page == lv_layer_top()*/) {
|
} else if(page == lv_layer_sys() /*|| page == lv_layer_top()*/) {
|
||||||
Log.warning(TAG_HASP, F("Cannot clear system layer"));
|
Log.warning(TAG_HASP, F("Cannot clear system layer"));
|
||||||
} else {
|
} else {
|
||||||
@ -544,20 +546,18 @@ uint8_t haspGetPage()
|
|||||||
|
|
||||||
void haspSetPage(uint8_t pageid)
|
void haspSetPage(uint8_t pageid)
|
||||||
{
|
{
|
||||||
lv_obj_t * page = get_page_obj(pageid);
|
if(pageid == 0 || pageid == 255) {
|
||||||
if(!page) {
|
|
||||||
Log.warning(TAG_HASP, F("Page ID %u not found"), pageid);
|
|
||||||
} else if(page == lv_layer_sys() || page == lv_layer_top()) {
|
|
||||||
Log.warning(TAG_HASP, F("%sCannot change to a layer"));
|
Log.warning(TAG_HASP, F("%sCannot change to a layer"));
|
||||||
} else {
|
} else {
|
||||||
// if(pageid != current_page) {
|
lv_obj_t * page = get_page_obj(pageid);
|
||||||
Log.notice(TAG_HASP, F("Changing page to %u"), pageid);
|
if(!page) {
|
||||||
current_page = pageid;
|
Log.warning(TAG_HASP, F("Invalid page %u"), pageid);
|
||||||
lv_scr_load(page);
|
} else {
|
||||||
|
Log.notice(TAG_HASP, F("Changing page to %u"), pageid);
|
||||||
hasp_object_tree(page, pageid, 0);
|
current_page = pageid;
|
||||||
|
lv_scr_load(page);
|
||||||
//}
|
hasp_object_tree(page, pageid, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,8 +640,21 @@ void dispatch_output_current_page()
|
|||||||
// Get or Set a page
|
// Get or Set a page
|
||||||
void dispatch_page(const char *, const char * page)
|
void dispatch_page(const char *, const char * page)
|
||||||
{
|
{
|
||||||
if(strlen(page) > 0 && atoi(page) < HASP_NUM_PAGES) {
|
if(strlen(page) > 0) {
|
||||||
haspSetPage(atoi(page));
|
if(hasp_util_is_only_digits(page)) {
|
||||||
|
uint8_t pageid = atoi(page);
|
||||||
|
haspSetPage(pageid);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if(!strcasecmp_P(page, PSTR("prev"))) {
|
||||||
|
dispatch_page_prev();
|
||||||
|
} else if(!strcasecmp_P(page, PSTR("next"))) {
|
||||||
|
dispatch_page_next();
|
||||||
|
} else {
|
||||||
|
Log.warning(TAG_MSGR, PSTR("Invalid page %s"), page);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_output_current_page();
|
dispatch_output_current_page();
|
||||||
@ -650,8 +663,8 @@ void dispatch_page(const char *, const char * page)
|
|||||||
void dispatch_page_next()
|
void dispatch_page_next()
|
||||||
{
|
{
|
||||||
uint8_t page = haspGetPage();
|
uint8_t page = haspGetPage();
|
||||||
if(page + 1 >= HASP_NUM_PAGES) {
|
if(page >= HASP_NUM_PAGES) {
|
||||||
page = 0;
|
page = 1;
|
||||||
} else {
|
} else {
|
||||||
page++;
|
page++;
|
||||||
}
|
}
|
||||||
@ -662,8 +675,8 @@ void dispatch_page_next()
|
|||||||
void dispatch_page_prev()
|
void dispatch_page_prev()
|
||||||
{
|
{
|
||||||
uint8_t page = haspGetPage();
|
uint8_t page = haspGetPage();
|
||||||
if(page == 0) {
|
if(page == 1) {
|
||||||
page = HASP_NUM_PAGES - 1;
|
page = HASP_NUM_PAGES;
|
||||||
} else {
|
} else {
|
||||||
page--;
|
page--;
|
||||||
}
|
}
|
||||||
@ -674,11 +687,9 @@ void dispatch_page_prev()
|
|||||||
// Clears a page id or the current page if empty
|
// Clears a page id or the current page if empty
|
||||||
void dispatch_clear_page(const char *, const char * page)
|
void dispatch_clear_page(const char *, const char * page)
|
||||||
{
|
{
|
||||||
if(strlen(page) == 0) {
|
uint8_t pageid = haspGetPage();
|
||||||
haspClearPage(haspGetPage());
|
if(strlen(page) > 0) pageid = atoi(page);
|
||||||
} else {
|
haspClearPage(pageid);
|
||||||
haspClearPage(atoi(page));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_dim(const char *, const char * level)
|
void dispatch_dim(const char *, const char * level)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user